Spaces:
Running
Running
Commit ·
90962fb
1
Parent(s): d896c38
fix(api): enforce strict version idempotency for context ingestion
Browse files
app.py
CHANGED
|
@@ -64,6 +64,10 @@ async def metadata():
|
|
| 64 |
|
| 65 |
@app.post("/v1/context")
|
| 66 |
def push_context(data: ContextPayload):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
contexts[data.scope][data.context_id] = {"version": data.version, "payload": data.payload}
|
| 68 |
return {"accepted": True, "ack_id": f"ack_{data.context_id}_v{data.version}", "stored_at": "2026-04-26T00:00:00Z"}
|
| 69 |
|
|
|
|
| 64 |
|
| 65 |
@app.post("/v1/context")
|
| 66 |
def push_context(data: ContextPayload):
|
| 67 |
+
current = contexts.get(data.scope, {}).get(data.context_id)
|
| 68 |
+
if current and current.get("version", 0) >= (data.version or 0):
|
| 69 |
+
return {"accepted": True, "ack_id": f"ack_{data.context_id}_v{data.version}", "stored_at": "2026-04-26T00:00:00Z", "note": "ignored_stale_version"}
|
| 70 |
+
|
| 71 |
contexts[data.scope][data.context_id] = {"version": data.version, "payload": data.payload}
|
| 72 |
return {"accepted": True, "ack_id": f"ack_{data.context_id}_v{data.version}", "stored_at": "2026-04-26T00:00:00Z"}
|
| 73 |
|