Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: agents can't recover from t3_background_wait refusals #37006

Closedyaacovcorcos(GitHub profile, opens in a new tab) opened this issue 4 comments

Before submitting

  • I searched existing issues and did not find a duplicate. Related: #31914 (the taskIds key in the guidance), #33658 (registration timeouts).

Area

apps/server

Summary

t3_background_wait refuses calls in ways the calling agent can't repair: it is listed to providers that can never serve it, a task that finished before registration looks like an invented ID, and a miss doesn't say which IDs are running. The refusals themselves are right (nothing is registered wrongly); the agent just gets nothing to retry with. We have been running the fix below in a fork and are happy to send a PR.

What happens

  • Same-response registration. Claude often sends Bash run_in_background and t3_background_wait in one assistant message. The task ID exists only in the Bash result, so the wait carries an ID the model made up. It is refused as unmatched, and the model usually retries a few seconds later with the real ID. The instruction text ("call t3_background_wait with its task ID before you end your turn") does not say when the ID exists. One model also sent {"taskId": "…"} (singular).
  • Finished before registration. A short command can end, with its task_notification handled and the roster entry gone, before the model's next response registers it. That is refused exactly like an invented ID.
  • Unsupported providers. BackgroundWaitTool has no McpSchema.EnabledWhen, so Codex, Pi, ACP agents and others list a tool that always fails with "This provider cannot mark background work as awaited." The handler maps that to invalid_request, so it reads as the agent's mistake.

Where

  • apps/server/src/mcp/toolkits/orchestrator/tools.ts: BackgroundWaitTool (description, no EnabledWhen).
  • apps/server/src/orchestration-v2/ThreadManagementService.ts: awaitBackgroundTasks; ThreadManagementBackgroundWaitError unmatched message.
  • packages/provider-core/src/server/ProviderAdapter.ts: awaitBackgroundTasks returns only { matched }.
  • apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts: matches the pending roster only; CLAUDE_BACKGROUND_WAIT_INSTRUCTIONS.
  • packages/provider-opencode/src/server/v2/adapter.ts: matches running shells only; the shell instruction text.

Proposed fix

  1. List the tool only where it works. Add an adapter-level capability (we used backgroundWait?: Effect.Effect<boolean> on the ProviderAdapterV2 service, so the composite OpenCode driver can answer for the protocol version a session would use). Stamp it on the MCP thread credential when it is minted, next to subagent, and annotate BackgroundWaitTool with an EnabledWhen that reads it. Keep the unsupported branch as a defence.
  2. Report finished tasks as settled. Each adapter remembers task IDs that finished on a thread (bounded; we keep 64 per session). awaitBackgroundTasks returns { matched, settled?, running? }. A registration whose IDs are only settled succeeds with settled: [...] ("already finished: read their output now") and holds nothing. A reused ID that is running again counts as running.
  3. Name the running tasks on a miss. When nothing matched and nothing settled, return up to 5 running, not-yet-awaited tasks with a bounded description (the command or task description). The unmatched message appends: "Running and not yet awaited here: <id> (). Call again with one of these IDs." The agent started those commands itself, so nothing new is disclosed.
  4. Say when the ID exists. Tool description and both instruction texts: "In a later response than the start, pass the ID its result shows: taskIds: [id]." (#31914 already fixes the taskIds key wording; this adds the "later response" part.)

Not proposed: waiting server-side for an unknown ID to appear (an invented ID never appears), treating every unmatched ID as success, or accepting taskId as an alias.

Tests we added

  • An invented ID while two tasks run returns matched: [] and both as running; an awaited task is no longer listed; after its task_notification, registering it returns settled: [id] (Claude adapter, driven by SDK frames).
  • The OpenCode shell tests that registered a finished shell now expect settled: [shellId].
  • The thread service passes settled through as success and appends the running list to the unmatched error.
  • EnabledWhen lists the tool for a credential with the capability and hides it otherwise.
  1. tanstack-source added labelsbug

  2. Note

    🤖 GPT-6 Astra responding on behalf of JB357345688

    A related observation for proposal 4, concerning which task types the tool description names.

    On T3 Code 0.1.10 with Claude Code 2.1.325, an Opus 5.5 parent passed its native Sol reviewer's task ID to t3_background_wait. This used T3's Claude provider through a custom API-compatible proxy.

    Provider log sequence, November 17, 2026, UTC (ID redacted):

    11:48:45.855  native task_started (resumed reviewer)
    11:48:47.591  t3_background_wait({"taskIds":["<reviewer-id>"]})
    11:48:47.615  invalid_request
    11:57:58.111  native task_notification: completed
    11:57:58.186  parent resumed

    The rejection correctly explained that subagent IDs are excluded. The result reached the parent, and the observed impact was one unnecessary failed call.

    The historical tool description referred broadly to background work and a task ID. The separate injected instruction specified a background command or Monitor. While revising the description, naming those accepted task types there too may be worth considering.

    This is one historical occurrence on custom routing. Reproduction on stock routing and testing whether revised wording changes the model's behavior remain outstanding.

  3. Adding 24h production telemetry from T3 Code 0.1.12-nightly.20261122.5111 (2,738 t3_background_wait calls across 6 orchestrator trees):

    • 300 calls (11.0%) failed with OrchestratorMcpFailure invalid_request: None of these IDs is running background work on this thread across 173 threads.
    • Cross-referencing each Claude Code transcript's Bash launch and <task-notification> timestamps:
      • 223 / 300 waited on a Bash task that had already completed (median task runtime 2.2s, p90 20s; t3_background_wait arrived a median 1.6s after completion, p90 6.1s). Treating already-finished task IDs on the thread as a satisfied no-op ({"matched": [], "finished": [...]}) instead of invalid_request would eliminate 74% of these failures.
      • 96 / 300 (slight overlap with above on multi-ID calls) were emitted in the same assistant response as the Bash launch using a hallucinated b######## ID because the injected prompt does not explicitly state "call after the launch returns its ID, never in the same response".
  4. #39421, now on main: Antigravity now accepts t3_background_wait while its own background command is running, removing the unsupported-provider refusal for that ACP provider.

    Not done: The issue still asks for filtering unsupported providers, recognizing finished tasks, naming running tasks on a miss, and clarifying when task IDs become available.

    Closing; open a new issue if what is left still matters to you.

  5. juliusmarminge closed this

  6. #38348, now on main: The merge hides t3_background_wait from providers without background-wait support, addressing the unsupported-provider refusals reported in this issue.

    Not done: The issue still asks for recovery from incorrect or already-finished task IDs, including running-task suggestions and guidance to register only after receiving the launch result; those changes are absent.

    Closing; open a new issue if what is left still matters to you.

Sign in to join this conversation.