Skip to content

fix(a2a): handle stale pendingTaskId causing "Task not found" in batch storyboard runs - #1592

Closed
bokelley wants to merge 1 commit into
mainfrom
claude/issue-1585-a2a-task-not-found-batch-race
Closed

bokelley wants to merge 1 commit into
mainfrom
claude/issue-1585-a2a-task-not-found-batch-race

Conversation

@bokelley

@bokelley bokelley commented May 8, 2026

Copy link
Copy Markdown
Contributor

Closes #1585

In batch storyboard runs, all scenarios share a single AgentClient instance (via getOrCreateClient caching). When a prior scenario ends with an A2A working-state response, AgentClient.retainSession sets pendingTaskId. The storyboard poll path (waitForCompletion in task-map.ts) bypasses retainSession, so that task ID is never cleared. The next scenario inherits it; A2A 0.3.x defines no minimum retention TTL for completed tasks, so a seller that has evicted the completed task responds with "Task <uuid> not found" and the scenario fails.

Three fixes (root cause + two defense-in-depth):

  1. Root cause — AgentClient.clearPendingTask() (@internal) + task-map.ts finally block. After waitForCompletion resolves (or throws / times out), clearPendingTask() is called so the stale pendingTaskId is gone before the next scenario starts.

  2. Defense-in-depth — callA2AToolImpl (a2a.ts): when session.taskId is set and the seller returns "Task not found", retry once without the task ID. The guard is self-limiting: the recursive call passes taskId: undefined, so the guard cannot fire again.

  3. Defense-in-depth — pollTaskCompletion (TaskExecutor.ts): catch "Task not found" from getTaskStatus and return a descriptive failed TaskResult with an actionable error message rather than an opaque uncaught exception.

What-tested

  • npx tsc --noEmit: 2 pre-existing errors only (@types/node not installed, moduleResolution=node10 deprecation warning). No new errors introduced. Verified by running before and after changes.
  • npm run ci:quick: pre-existing environment failure (tsx: not found). Confirmed pre-existing by stashing changes and re-running.
  • Nits from second expert pass addressed: changeset body updated to describe all three fixes; one-line self-limiting comment added on the retry guard.

Pre-PR review

  • code-reviewer: approved — no blockers after second pass; nits addressed (changeset body updated, self-limiting comment added)
  • ad-tech-protocol-expert: approved — root-cause fix satisfies the spec-level concern; defense-in-depth retry correctly framed (dropping a stale prior-scenario taskId, not the current call's own ID); pollStartTime fix is sound

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num> →
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

Session: https://claude.ai/code/session_01NXzCFi3jJDNqXaDgQrPzKK


Generated by Claude Code

…h runs

Fixes adcp-client#1585. In batch storyboard runs all scenarios share a
single AgentClient instance. When a prior scenario ends with a working-state
A2A response the client retains pendingTaskId; if the poll path
(waitForCompletion) bypasses absorbServerSideMetadata that taskId is never
cleared and bleeds into the next scenario's message/send call. Sellers that
have evicted the completed task (A2A 0.3.x defines no minimum retention TTL)
return "Task <uuid> not found", causing the scenario to fail.

Two fixes:
• callA2AToolImpl (a2a.ts): retry once without the stale taskId when "Task
  not found" is returned while session.taskId is set.
• pollTaskCompletion (TaskExecutor.ts): catch "Task not found" from explicit
  polls and return a descriptive failed TaskResult instead of an uncaught
  exception.

https://claude.ai/code/session_01NXzCFi3jJDNqXaDgQrPzKK
@bokelley

bokelley commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of:

The two pieces from this PR that were not extracted:

  1. clearPendingTask() + task-map.ts finally block — superseded by fix(agent-client): narrow pendingTaskId auto-thread to same-skill same-context (#1590) #1593's narrowing. Clearing on every waitForCompletion would also drop intentional within-storyboard task resumption, which fix(agent-client): narrow pendingTaskId auto-thread to same-skill same-context (#1590) #1593 preserves correctly via (contextId, taskName) matching.
  2. callA2AToolImpl retry on "Task not found" — became risky after fix(agent-client): narrow pendingTaskId auto-thread to same-skill same-context (#1590) #1593 narrowed auto-threading. Post-fix(agent-client): narrow pendingTaskId auto-thread to same-skill same-context (#1590) #1593 the only ways a stale taskId reaches callA2AToolImpl are caller-supplied (e.g., HITL resume); silently retrying would mask a real eviction failure the buyer needs to surface.

@bokelley bokelley closed this May 8, 2026
@bokelley

bokelley commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

Acknowledged — thanks for the clear decomposition rationale. The three-way split (#1588 + #1593 + #1596) is a cleaner outcome: runner-level reset, SDK-level narrowing, and the surviving pollTaskCompletion improvement each land in the right layer without the coupling issues this PR carried. No further action from triage.


Generated by Claude Code

bokelley added a commit that referenced this pull request May 8, 2026
…evicted task

Catch "Task <id> not found" errors from getTaskStatus in
pollTaskCompletion and return a TaskResultFailure with an actionable
error message instead of letting an opaque exception escape the loop.

A2A 0.3.x defines no minimum retention TTL for completed tasks, so a
seller may evict a task between the buyer observing the working-state
response and the first explicit tasks/get poll firing. The error now
suggests using push notifications (reporting_webhook) or configuring a
longer task retention TTL on the seller.

Defense-in-depth follow-up to #1585. The cross-storyboard root cause
was already addressed in #1588 (resetContext per storyboard) and #1593
(narrowed pendingTaskId auto-thread to same-skill same-context); this
change improves the error surface for any residual case where an
evicted task is queried.

The not-found regex is bounded (\S{1,128}) to satisfy the CodeQL
polynomial-regex check on uncontrolled error strings.

Closes/supersedes #1592 (which proposed this same descriptive-error
fix bundled with two other changes that #1588 and #1593 obviated).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley added a commit that referenced this pull request May 8, 2026
…evicted task (#1596)

Catch "Task <id> not found" errors from getTaskStatus in
pollTaskCompletion and return a TaskResultFailure with an actionable
error message instead of letting an opaque exception escape the loop.

A2A 0.3.x defines no minimum retention TTL for completed tasks, so a
seller may evict a task between the buyer observing the working-state
response and the first explicit tasks/get poll firing. The error now
suggests using push notifications (reporting_webhook) or configuring a
longer task retention TTL on the seller.

Defense-in-depth follow-up to #1585. The cross-storyboard root cause
was already addressed in #1588 (resetContext per storyboard) and #1593
(narrowed pendingTaskId auto-thread to same-skill same-context); this
change improves the error surface for any residual case where an
evicted task is queried.

The not-found regex is bounded (\S{1,128}) to satisfy the CodeQL
polynomial-regex check on uncontrolled error strings.

Closes/supersedes #1592 (which proposed this same descriptive-error
fix bundled with two other changes that #1588 and #1593 obviated).

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

storyboard runner: A2A "Task X not found" on completed-task lookups during batch runs

2 participants