[Bug]: delegate_task with mode: "wait" triggers continuous 30s polling loop in cell-based agent harnesses #30006
Area#
apps/server (also touches packages/contracts, packages/provider-core)
Steps to reproduce#
- Use T3 Code with an orchestrating agent running under Codex (or any harness executing tool calls inside bounded execution cells/scripts).
- The orchestrating parent agent delegates a task to a subagent using
delegate_taskwithmode: "wait":await tools.mcp__t3_code__delegate_task({ task: "Remediate Gate 1 bounded lexer probe", mode: "wait", timeoutMs: 1800000, target: { providerInstanceId: "a2a", model: "gemini-3.8-flash-high" } }); - The delegated subagent executes normally in its child thread, taking several minutes (e.g., 9–12 minutes) to complete build, tests, and edits.
- Observe the parent agent session logs while the subagent is working.
Expected behavior#
The parent agent should either:
- Receive an immediate async acknowledgment (
taskId) and suspend its turn without polling until the subagent completes, OR - The orchestration server should enforce asynchronous delegation and reject or coerce
mode: "wait"for tasks that exceed standard execution slices, OR - The wait mechanism should pause without triggering active re-prompting every 30 seconds.
Actual behavior#
- In cell-based execution environments like Codex
exec, tool execution is sliced into 30-second windows. When a synchronous wait exceeds 30 seconds, the runner returns an intermediate status:"Script running with cell ID 53, Wall time 31.0 seconds". - The LLM receives this status and enters an active polling loop using its internal
waittool:{"name": "wait", "arguments": "{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"} - Because the parent thread context has already accumulated history (~200,000 tokens), every single 30-second tick sends the entire 200k prompt back into the model.
- The model wakes up every 30–33 seconds, outputs internal thoughts/status commentary, and calls
waitagain. - In our real session logs (
rollout-2026-11-03T06-06-54-01a19f5f-b67b-7161-aa91-2e270136ead4.jsonl):- Over ~12 minutes of subagent runtime, this loop executed over 25 times.
- Input token processing logged for this single turn reached ~19,000,000 tokens (cumulative prompt tokens across 30-sec ticks; thread total was 87M+).
- Note on caching: While prompt caching mitigates the pure financial cost of cached input tokens on supporting providers, this active polling still:
- Consumes API rate limits (RPM / TPM quotas).
- Burns output generation tokens and un-cached context on every tick (reasoning/thoughts + tool calls).
- Creates unnecessary latency, context churn, and log spam.
- Defeats the reactive orchestration design where the parent should be idle while children work.
Impact#
Major degradation or frequent failure (unnecessary token processing, rate limit exhaustion, context churn, and violation of reactive orchestration rules).
Version or commit#
main @ commit 13fa924ecb0049246dfd4ea77b44051b76c220ab
Environment#
macOS 15.3, T3 Code Server (apps/server), Codex app-server harness with gemini-3.8-flash-high / gpt-4o orchestrator.
Logs or stack traces#
Repeated function calls in Codex rollout session logs:
4867:{"timestamp":"2026-11-03T06:55:42.891Z","ordinal":4866,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
4875:{"timestamp":"2026-11-03T06:56:16.742Z","ordinal":4874,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
4879:{"timestamp":"2026-11-03T06:56:49.750Z","ordinal":4878,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
4885:{"timestamp":"2026-11-03T06:57:23.328Z","ordinal":4884,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
4891:{"timestamp":"2026-11-03T06:57:57.264Z","ordinal":4890,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
4899:{"timestamp":"2026-11-03T06:58:31.821Z","ordinal":4898,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
4903:{"timestamp":"2026-11-03T06:59:04.585Z","ordinal":4902,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
4909:{"timestamp":"2026-11-03T06:59:38.374Z","ordinal":4908,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
4915:{"timestamp":"2026-11-03T07:00:12.768Z","ordinal":4914,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
4923:{"timestamp":"2026-11-03T07:00:49.012Z","ordinal":4922,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"fc_...","name":"wait","arguments":"{\"cell_id\":\"53\",\"yield_time_ms\":30000,\"max_tokens\":1200}"...
Per-turn usage stats recorded in the session:
- Prompt tokens:
199,900per tick - Cumulative processed prompt tokens in turn:
~19,000,000 - Thread total tokens:
87,566,225
Root Cause Analysis & Contradiction in Rules#
- Instruction vs Tool Contract Discrepancy:
The orchestration instructions specifically state:
However,"Follow a running delegate's next. Do not poll it (task_status, sleep, watchers, Monitor, ScheduleWakeup, wait)."
OrchestratorMcpDelegateTaskInputinpackages/contracts/src/orchestratorMcp.tsexplicitly documents and permits:
Andmode: Schema.optional(Schema.Literals(["async", "wait"]).annotate({ description: "Default 'async'. 'wait' only if this turn needs the result. A question or approval ends the wait." }))OrchestratorMcpService.tsimplements a blocking wait up toMAX_WAIT_TIMEOUT_MS = 60 * 60 * 1_000(1 hour) with a default of 10 minutes (DEFAULT_WAIT_TIMEOUT_MS). - Impedance Mismatch with Sliced Execution Environments: Harnesses like Codex execute commands in timed slices (typically 30 seconds). A 10-to-60-minute blocking tool call inevitably trips this slice boundary, returning control to the agent with a running cell ID. The model then defaults to cell-waiting, generating a continuous stream of LLM roundtrips with the entire conversation history.
Workaround#
Always call delegate_task with mode: "async" and end the agent turn immediately, allowing T3 Code's completion wake mechanism to resume the parent thread when the child finishes.
Suggested Fixes#
- Deprecate or Remove
mode: "wait"indelegate_task: Because delegated subagents are inherently asynchronous and unpredictable in duration, blocking on them inside a tool call is anti-pattern for agent loops. Enforcingmode: "async"guarantees zero token burn during subagent execution. - Auto-coerce
mode: "wait"tomode: "async"on the Server: InOrchestratorMcpService.ts, when handlingdelegate_task, ifmode: "wait"is specified (or when coming from cell-based providers), return the task immediately withstatus: "working",completionWake: "always", and the instruction"Completion wakes this thread, so end your turn. Do not wait on it or poll it." - Clarify Orchestration Instructions:
Ensure
T3_CODE_ORCHESTRATION_SECTIONSexplicitly tells models to always delegate with"mode": "async"and that synchronous waiting on child agents is prohibited.
vedmalex(GitHub profile, opens in a new tab) changed the title
tanstack-source added labelsbug
maria-rcks closed this
Sign in to join this conversation.