Repository navigation
Description
Summary
Three MCP dispatch routes need to answer the same question after a gateway timeout — "which execution is mine?" — and each one currently re-derives its own answer:
| Route | Today |
|---|---|
/chat (#914) |
executions scan: trigger set + key id + message + recency window |
sync /task (#2661) |
the same scan, plus reading the execution_id out of an in-flight 409 |
fan_out (#2670) |
nothing — no receipt at all |
The scan is a heuristic. It works, but it is identification-by-elimination: it needs a recency window, a trigger allowlist, a key filter and a message match, and it must return nothing when more than one candidate survives (#2661) because it cannot prove which row is the caller's.
Meanwhile the exact answer already exists. Idempotency-Key is minted per call at every one of these boundaries (Invariant #18 mandates it), and idempotency_keys(scope, key) already stores execution_id plus the completed response snapshot (db/schema.py:1652). The identity is already being recorded and simply never read back.
Proposal
A read-only lookup — GET /api/agents/{name}/idempotency/{key} (or equivalent) — returning {execution_id, status, snapshot?} without dispatching anything.
db/idempotency.pygains apeek()besideclaim()— roughly a dozen lines, the same SELECT with the same TTL cutoff, minus the delete/insert.- The MCP client calls it on abort instead of scanning executions.
Properties the heuristic cannot have: exact attribution, no recency window, no trigger allowlist, no concurrency ambiguity — and it returns the real result when the task completed between the abort and the lookup. One implementation covers all three routes plus webhooks.
What this must NOT be
Do not implement it as "re-POST the dispatch with the same key." idempotency_service.begin() fails open on any DB error (idempotency_service.py:399-401), so on that path the "probe" dispatches a second execution — precisely the bug this family exists to prevent. #2661 rejected that approach for this reason. The lookup must be genuinely read-only.
Security requirement (do not skip)
The key is caller-supplied and the scope is agent:{name}, so the endpoint must verify the resolved execution belongs to the caller before returning anything. Keys do bind caller identity today — deriveMcpIdempotencyKey hashes [caller, agent, routeToken, model, sync|async, message] — but that is the client's convention, not an enforced property, and userId is a guessable integer. Returning execution_id + snapshot for an arbitrary (agent, key) would otherwise be a cross-user disclosure: exactly the hazard make_inline_auth_scope's docstring already documents ("MCP clients derive deterministic keys from call args, so two users asking the same agent the same question collide by design").
Ownership check on the resolved row, and enumeration-safe responses per Invariant #8.
Acceptance Criteria
- read-only
peek(scope, key)indb/idempotency.py+ facade delegation; no writes, no claim, no TTL side effects - an authenticated, owner-scoped endpoint exposing it, enumeration-safe (a key you don't own is indistinguishable from one that doesn't exist)
- MCP client prefers the probe over the executions scan on the abort path for
/chatand/task -
fan_out(bug(mcp): fan_out has no gateway-timeout receipt — the third route of the #914 class, and the one that runs longest #2670) gains a receipt through the same mechanism —routers/fan_out.py:140already stores the aggregated snapshot under the key - the executions-scan fallback is either retired or explicitly retained as a documented backstop
-
docs/memory/requirements/scheduling.md§37 attribution rules collapse to the single deterministic rule - Invariant feat: SMARTS trading pipeline with Telegram notifications and Miro visualization #13: the MCP surface declaration is updated
Follow-up of #2661 (which chose the client-side fix under P1 incident pressure and deliberately left this as the mechanism that retires it). Related: #2670, #914, RELIABILITY-006 (#525).
Activity
fix(mcp): the sync /task route answers with an execution_id, not `fet…
fix(mcp): fan_out answers with a fan_out_id, and a batch can be polled (
fix(wake): one wake per caller at a time, and a wake refused at capac…