Repository navigation
fix(a2a): fail stale tasks whose agent turn never settles - #131464
zenglingbiao wants to merge 2 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. What this changesThe A2A plugin fails unfinished tasks after one hour and uses the originating task ID to associate an agent’s final reply with the right peer request. Review scores
Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 10 items remain Keep open. Current main and the latest release still leave the A2A task-lifetime and FIFO reply-correlation problems unresolved. This PR offers useful repair work, but its unchanged reviewed head can fail an active turn after one hour and can report a discarded final reply as delivered. Priority: P2 Decision needed
Before merge
Findings
Agent review detailsHow this fits togetherAuthenticated A2A peers submit tasks through the Gateway’s JSON-RPC endpoint. The plugin tracks each task while an agent runs, then returns its status and reply to peers through GetTask. flowchart LR
A[Authenticated peer] --> B[SendMessage handler]
B --> C[Task store]
B --> D[Agent turn]
D --> E[Final reply callback]
E --> C
C --> F[Expiry decision]
F --> G[GetTask result]
Technical reviewBest possible solution: Keep task-ID reply correlation, make stale cleanup depend on authoritative turn lifecycle so healthy work remains valid, and return explicit non-visible delivery results for discarded finals; consolidate expiry bookkeeping in that owner. Do we have a high-confidence way to reproduce the issue? Yes for the task-store defect: current main has no non-terminal expiry and selects the conversation queue head, and the supplied before/after store traces show both effects. A Gateway-level reproduction of the changed callback remains absent. Is this the best way to solve the issue? No, not yet. Task-ID correlation is the right direction, but fixed-time expiry cannot distinguish active work from abandoned work, and discarded delivery needs an explicit suppression result. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 979a8beefb34. Merge-risk optionsMaintainer options:
SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +20, Tests +126, Docs 0. Total +146 across 5 files. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed September 25, 2026, 5:06 PM ET / 21:06 UTC (Revision 5). |
86832ff to
a85dfcf
Compare
a85dfcf to
cb33c93
Compare
cb33c93 to
1652b15
Compare
|
@clawsweeper re-review — addressed the P1 finding: completeTask() now sweeps stale tasks before completing (a final delivery that is the first store op past the deadline is rejected), and each task owns an unref'd 1h expiry timer that fails it autonomously (re-armed on the SUBMITTED→WORKING status change, cleared on terminal transition, disarmed in stop()). New tests cover delivery-as-first-op-after-deadline, timer-driven idle expiry, and timer disarm on stop. Merged current main; new head 1652b15. Screenshot proof + transcripts on proof-assets-20260828, embedded in the PR body. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
Summary
A2aTaskStorenow fails non-terminal tasks that go an hour without a status change, so they age out under the existing terminal retention policy instead of living in memory forever — and final replies are delivered to the task that originated the turn, so a late reply from an expired turn is dropped instead of completing a newer task in the same conversation. Expiry is enforced twice: opportunistically on store access, and autonomously by a task-owned timer that fires even when the store sits idle. The one-hour cutoff is part of the documented channel contract indocs/channels/a2a.md.What Problem This Solves
Every authenticated peer
SendMessagecall creates a task (http.ts→taskStore.create()), and the store only ever reclaims terminal tasks (24 h / 500-entry retention). A task becomes terminal only when the agent delivers afinalreply.If an agent turn never settles — e.g. the model endpoint accepts the request and hangs — the task stays
TASK_STATE_SUBMITTED/TASK_STATE_WORKINGforever with no expiry path:#tasks,#taskOwners, and the conversation queues grew without bound (≈43 K tasks/day at 30 req/min from one peer), slowly leaking heap on a long-lived gateway.completeNext(contextId, text, peerName)): whichever task sat at the queue head received the next reply. Any turn settling out of order — or a late reply arriving after its task was failed/reaped — completed the wrong task. Concretely: a peer sends message A (turn hangs) then message B; when the hung turn A finally answers, its reply would be stored on B's newer task, and B's own reply would have nowhere to go.Root Cause
Why This Fix
completeTask(taskId, text): completes the task iff it exists and is still non-terminal; otherwise returnsundefinedand touches nothing else — a delayed reply from a swept, failed, or rejected turn is silently dropped and can never complete a newer same-context task. The delivery closure ininbound.tsalready knewparams.taskId(theonErrorpath used it), so delivery is now bound the same way.completeNextand the#pendingByContextqueue mechanism are removed: the inbound delivery closure was the only production caller, and the queue existed solely for reply correlation.create/getsweep non-terminal tasks older than 1 hour and transition them toTASK_STATE_FAILEDvia the existing#finishWithMessagepath, reusing all bookkeeping (waiter resolution, terminal retention). A peer polling a stuck task gets a spec-compliant terminal state instead of "not found", and the row then ages out like any other terminal task. The agent turn itself is never aborted — the store simply stops tracking it.completeTasksweeps before completing, so a final reply that is the first store operation to cross the deadline is rejected and the task fails instead of completing after the documented cutoff.setTimeoutat creation (re-armed on the SUBMITTED→WORKING status change, matching the "an hour without a status change" contract) that fails the task through the same#finishWithMessagepath — so an otherwise idle store still expires hung tasks with zero store traffic. The timer is cleared on any terminal transition and disarmed instop(), so it never fires twice, never completes a settled task, and never holds the process open.docs/channels/a2a.mdstates the contract explicitly: a task that stays non-terminal for one hour without a status change transitions toTASK_STATE_FAILED(terminal), a final reply arriving after that cutoff is discarded, and terminal tasks are cleaned up 24 hours after they settle.User Impact
TASK_STATE_FAILEDafter 1 hour (peers polling them see a proper terminal state) and are reclaimed by the existing 24 h retention; each final reply completes exactly the task that originated its turn, and orphaned late replies are discarded.Evidence
main): a task whose turn never settles is stillTASK_STATE_WORKINGafter 25 hours and is never reclaimed; a late reply for an already-terminal older task completes the newer same-context task and stores the wrong text on it; an idle task has no expiry owner at all (no timer registered) and a post-deadline delivery completes it.Real Behavior Proof
Real
A2aTaskStoreexercised directly (node --import tsx proof.mjs <repo-root>; the[time-compressed]segments shiftDate.nowto cross the sweep/retention windows without waiting in real time; the[timer-driven]segment capturessetTimeoutto fire the task's own expiry timer; the[real-time]segment uses no clock manipulation).Before (on main)
After (with fix)
Media proof (screenshots)
Before —
upstream/main@e188dead558:After — this branch @
1652b15acd7:Full transcripts (
131464-before.term/131464-after.term) and the proof script (proof-131464.mjs) are on the publicproof-assets-20260828branch for audit.Tests and Validation
extensions/a2a/src/task-store.test.ts, including the exact scenarios the review asked for:create/getcrosses the deadline; the delivery itself enforces it (reply rejected, taskTASK_STATE_FAILED, no artifacts).WORKING).stop().node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json, the extensions portion of thecheck-test-typeslane): clean.oxlintclean on all touched files.Review Follow-up
completeTasknow sweeps before completing, so a delivery that is the first store operation past the deadline is rejected; and each task now owns an unref'd expiry timer (re-armed on status change, cleared on terminal transition, disarmed instop()) that fails the task autonomously — no store traffic required. Covered by the three new tests listed above.main(e188dead558). New head:1652b15acd7.proof-assets-20260828branch (see Media proof above).