feat(agent-core-v2): add the WaitFor tool for waiting on background tasks #3060
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 406 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.359
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #3060"
general
weight: 0.35
HelloWorldU
Related Issue
No public issue — the problem is explained below.
Problem
In goal mode, once the model dispatches background work (sub-agents or background bash), its only way to "wait" is to end the turn. Goal mode then immediately starts a new turn; the model finds the tasks still unfinished and ends that turn again — an idle re-invocation loop that wastes goal turns and tokens. There is no primitive for waiting on a background task inside the current turn.
What changed
WaitFor(timeout, task_id?)tool (agent-core-v2 task domain, next toTaskList/TaskOutput/TaskStop): suspends the tool call inside the current turn until the waited task finishes or the timeout (required, ≤ 600s) elapses. No LLM requests are made while waiting; a user interruption aborts the wait and never touches the task. Reuses the existingIAgentTaskService.waitprimitive; the no-task_idform races the tasks that were running at call time.output_pathfirst, then a[completed_during_wait]section (metadata +TaskOutputpointers for tasks that finished within the window), then[still_running]. A timeout returns the still-running list and is not an error; an unknowntask_iderrors; no running tasks returns immediately.WaitForare recorded as delivered via a durabletask.waitDeliveredrecord that folds into the existing undo/compaction-aware notification delivery set, so their automatic completion notification is suppressed. Already-enqueued notification requests are aborted, and a final enqueue-time recheck innotifyAgentTaskcloses the remaining build→enqueue race (caught by the new harness tests).WaitForinstead of ending the turn when it is waiting on background tasks (bothGOAL_CONTINUATION_PROMPTandgoal-active-reminder.md).wait_for_completedevent (outcome,timeout_ms,waited_ms,has_task_id,extra_completed_count).wait_forexperimental flag, default on (KIMI_CODE_EXPERIMENTAL_WAIT_FOR=falsedisables). Tool auto-approved likeTaskList/TaskOutput; added to agent/coder/tower-worker profiles; docs (en/zh) updated; changeset included.Tests: 30+ new tests — tool-level (schema, all outcomes, abort propagation), notification dedup timing (suppress on mark, abort pending, enqueue-time recheck, status-keyed, no cross-talk), restart/undo delivery discipline, harness end-to-end with real
AgentTaskService, goal-mode scenarios (bash/sub-agent/timeout-retry/ten-turn chain), and deadlock-attempt cases (nested wait chains unwind leaf-first; cross-agent waits are rejected; never-settling tasks are bounded by the timeout).Checklist
gen-changesetsskill (.changeset/wait-for-tool.md, minor).docs/en|zh/reference/tools.md, kept both locales in sync).