Skip to content

fix(agent-client): narrow pendingTaskId auto-thread to same-skill same-context (#1590) - #1593

Merged
bokelley merged 2 commits into
mainfrom
bokelley/agent-client-tighten-pending-taskid
May 8, 2026
Merged

bokelley merged 2 commits into
mainfrom
bokelley/agent-client-tighten-pending-taskid

Conversation

@bokelley

@bokelley bokelley commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Change

`AgentClient` now pairs the retained server-side task handle with the `(contextId, taskName)` it was returned under (`PendingTaskHandle`). `withSession()` only auto-threads `pendingTask.taskId` onto an outbound call when:

  1. The caller didn't switch `contextId` (existing behavior), AND
  2. The retained handle's `contextId` matches the effective outbound contextId, AND
  3. The retained handle's `taskName` matches the outbound skill name.

A different skill or switched contextId signals new work; the retained handle is stale, and sending it produces "Task not found" against spec-compliant sellers.

HITL flows (`createMediaBuy` → `input-required` → `createMediaBuy` resume) match same-skill same-context and continue to thread as before. Caller-supplied `options.taskId` always wins regardless of skill match — explicit > implicit.

Public surface

  • `getPendingTaskId()` returns the same value as before — public API unchanged.
  • `resetContext()` clears the handle as before.
  • Every method on `AgentClient` now passes its skill name to the private `withSession` helper. 31 internal call sites updated; `executeTask` passes the dynamic `taskName` argument through.

Test plan

  • Existing `a2a-context-retention.test.js` (10 tests) all pass — covers the documented HITL retain/resume contract.
  • Three new tests pin the narrowing: different-skill same-context drops the taskId; same-skill same-context still threads (HITL); explicit `options.taskId` wins regardless of skill match.
  • Focused related suites pass: `agent-client-in-process`, `storyboard-runner-`, `storyboard-idempotency-invariant`, `protocol-response-parser-`, `task-executor-async-patterns`, `async-patterns-master`, `handler-controlled-flow`, `execute-task-error-envelope`, `idempotency-client`, `single-agent-client-needs-auth`, `protocol-client-needs-auth`, `match`, `match-fluent` — 219 / 219 pass.
  • `tsc --noEmit` clean. `prettier --check` clean.
  • Wonderstruck staging revalidation post-merge — combined with fix(storyboard-runner): reset retained A2A session ids per storyboard (#1585) #1588 the cross-storyboard "Task not found" failures should clear.

🤖 Generated with Claude Code

bokelley and others added 2 commits May 8, 2026 07:52
…e-context (closes #1590)

Pair the retained server-side task handle with the `(contextId, taskName)`
it was returned under. `withSession()` now auto-threads `pendingTask.taskId`
onto an outbound call only when the call is plausibly a continuation of the
SAME task — same skill name AND same effective `contextId`. A different
skill or switched contextId signals new work; the retained handle is stale
per A2A 0.3.0 §3.4, and sending it produces "Task not found" against
spec-compliant sellers.

Defense in depth on top of the storyboard-runner reset (#1588). Runner
level fix protects `comply()`-style harnesses that own client lifecycle;
SDK-level narrowing protects every adopter who reuses one AgentClient
across logically distinct conversations without an explicit reset.

HITL flows (createMediaBuy → input-required → createMediaBuy resume) match
same-skill same-context and continue to thread. Caller-supplied
`options.taskId` always wins.

Public surface unchanged: `getPendingTaskId()` returns the same value,
`resetContext()` clears the handle as before.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…view nit)

Per code-reviewer feedback on #1593: the original "(e.g., deferred without
serverTaskId)" example understated the surface — non-spec A2A Tasks
missing `contextId` or `taskName` ALSO land in this branch by design and
are deliberately NOT retained as a fresh handle, since auto-threading a
partially-keyed taskId into the next call is exactly the leak class the
narrowing closes.

No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit 6f41b27 into main May 8, 2026
8 checks passed
@bokelley
bokelley deleted the bokelley/agent-client-tighten-pending-taskid branch May 8, 2026 11:55
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]>
@github-actions github-actions Bot mentioned this pull request May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AgentClient.withSession: auto-thread pendingTaskId only when contextId matches the retained task's session

1 participant