Repository navigation
fix(agents): stop canceled subagents reporting timeouts - #125407
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 6:36 PM ET / 22:36 UTC. ClawSweeper reviewWhat this changesThe PR makes subagent lifecycle, wait, and announcement paths classify explicit cancellation ahead of timeout-like liveness signals, with regression coverage for delayed completion and restart delivery. Merge readinessKeep open for normal maintainer review: the current main branch still contains the old bare-abort-to-timeout path, while this PR consistently routes subagent projections through the shared terminal outcome. No actionable patch defect was found. Likely related people: steipete (high confidence; introduced the registry family and authored the current repair). Priority: P1 Review scores
Verification
How this fits togetherSubagent lifecycle events enter the registry, which persists a terminal state and triggers any completion announcement. Wait and announcement code consume that terminal outcome to decide whether users see cancellation, timeout, failure, or success. flowchart LR
A[Subagent lifecycle event] --> B[Registry listener]
B --> C[Shared terminal outcome]
C --> D[Subagent cancellation classification]
D --> E[Grace scheduler and stored run]
E --> F[Wait and announcement paths]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +2, Tests +47. Total +49 across 7 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge the shared-classification repair after the normal exact-head merge refresh, preserving the one subagent-specific override rather than duplicating terminal-precedence rules in each projection. Do we have a high-confidence way to reproduce the issue? Yes—at high confidence from source: current main routes a bare aborted end event into timeout grace, and the focused lifecycle E2E scenario targets that exact path. Is this the best way to solve the issue? Yes—the PR reuses the canonical terminal-outcome builder and limits cancellation precedence to subagent projections, preserving the generic blocked-liveness contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 27cb5d021fd1. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
b1d9113 to
85a623f
Compare
|
@clawsweeper re-review Exact head: Please verify the rebased cancellation classifier, the preserved #127295 |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Exact head: The prior P1 is fixed: canonical provider hard-timeout classification now wins before the subagent cancellation override, with direct classifier coverage and a lifecycle case retaining Please verify the repaired precedence and the preserved #127295 |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
) * fix(agents): preserve cancelled subagent outcomes * fix(agents): preserve provisional cancellation precedence * fix(agents): scope cancellation precedence to subagents * fix(agents): preserve provider timeout precedence --------- Co-authored-by: Vincent Koc <[email protected]>
The branch predated openclaw#125407, which replaced the generic classifier here with classifySubagentTerminalOutcome so explicit restart/aborted stop reasons stay cancellations while real provider timeouts still classify as timeouts. Resolving the merge with the generic call would have reverted that. Keep main's classifier and apply the pending-error cause inside its timeout case; the two are orthogonal. A pending-error snapshot carries no stopReason (createPendingErrorTimeoutSnapshot drops it), so the cancellation override never fires for it. Test: restart and aborted stop reasons with blocked liveness stay cancellations rather than being reported as failures.
Conflict in subagent-announce-output.ts resolved by taking main's new work and keeping this branch's reason to exist. Main added classifySubagentTerminalOutcome (openclaw#125407, "stop canceled subagents reporting timeouts"), a subagent-specific wrapper around classifyAgentRunTerminalOutcome that returns "cancellation" for aborted stop reasons. This branch adds the orthogonal distinction that a bare status:"timeout" is a WAIT EXPIRY rather than a confirmed child death, tracked via timeoutDisposition. Those are complementary, not competing, so the resolution adopts main's classifier and keeps this branch's timeout body. Note the side effect: this branch already carried a case "cancellation" arm, but the base classifier never returns that value, so it was dead code here. Main's wrapper activates it — the merge makes existing branch code live rather than merely coexisting with it. cancellation/failure/success arms were byte-identical on both sides. The classifySubagentTerminalOutcome import arrived from main's side already. NOT YET VALIDATED: the scratch worktree has no node_modules, so no typecheck ran.
Two import-block conflicts, both from main moving the subagent classifier into its own module (classifySubagentTerminalOutcome in subagents/subagent-terminal-outcome.ts, openclaw#125407) so the base classifier is no longer imported at these sites. Resolved by usage rather than by preference. For each file the conflict block was excised before counting, so the counts reflect real call sites and not the markers themselves: subagent-announce-output.ts base classifier called: no AgentRunDisposition: yes subagent-registry-run-wait.ts base classifier called: no AgentRunDisposition: yes So both files take main's narrowed import of buildAgentRunTerminalOutcomeFromWaitResult, drop classifyAgentRunTerminalOutcome as genuinely unused after main's refactor, and keep this branch's `AgentRunDisposition` type import, which has real usages and carries the branch's disposition tracking. Accepting main's refactor while preserving branch utility, per instruction. NOT YET VALIDATED: pnpm install still running in this worktree; no typecheck yet.
…nces (#125357) * fix(subagents): keep the failure cause on pending-error timeout announces A run that fails inside the lifecycle error retry grace window is handed to waiters as `status: "timeout"` with the failure text attached and `pendingError: true` (createPendingErrorTimeoutSnapshot). applySubagentWaitOutcome rebuilt that as a bare `{ status: "timeout" }`, dropping the cause, and the announce status label had no slot for it — so the parent agent was told only "timed out" for a child that had actually errored, and could neither retry appropriately nor report the real blocker. Two other consumers of the same wait result already treat this shape as a failure with a cause (isPendingErrorAgentWaitTimeout in sessions-send-tool, isDeliveryFailureWait in sessions-send-tool.a2a); the subagent announce path was the outlier. Keep the cause when `pendingError === true` and render it as "timed out: <cause>". Genuine budget timeouts carry no pendingError and are unchanged. Tests: 3 unit cases for applySubagentWaitOutcome (pending-error timeout keeps the cause; budget timeout has none; wait error text without pendingError is ignored) and an announce format case asserting the "timed out: <cause>" label. * fix(agents): bound the task-completion status label in prompt context statusLabel embeds caller-supplied error text ("failed: <cause>", and now "timed out: <cause>"), but only the child result was capped before being projected into the parent agent's prompt — a large provider or lifecycle error could enter the model context unbounded and crowd out the result and the reply instruction. Cap the single status line at the shared internal-event formatting boundary, which covers both the pre-existing "failed: <cause>" path and the new timeout cause. Tests: a large-error status label is truncated with a marker and keeps its prefix; ordinary status labels are unchanged. * fix(agents): reuse truncateUtf16Safe for the status-label cap The status-label cap used a raw String.slice, which can split a UTF-16 surrogate pair when provider or lifecycle error text ends on an astral character, sending a dangling surrogate into the parent agent's prompt. Reuse the existing truncateUtf16Safe primitive instead of a parallel implementation, matching agent-run-terminal-reply.ts. Test: an emoji landing exactly on the truncation boundary keeps the label within the cap, ends with the marker, and leaves no unpaired surrogate or replacement character. * fix(subagents): keep main's subagent cancellation classifier The branch predated #125407, which replaced the generic classifier here with classifySubagentTerminalOutcome so explicit restart/aborted stop reasons stay cancellations while real provider timeouts still classify as timeouts. Resolving the merge with the generic call would have reverted that. Keep main's classifier and apply the pending-error cause inside its timeout case; the two are orthogonal. A pending-error snapshot carries no stopReason (createPendingErrorTimeoutSnapshot drops it), so the cancellation override never fires for it. Test: restart and aborted stop reasons with blocked liveness stay cancellations rather than being reported as failures. * refactor(subagents): reuse canonical status label truncation --------- Co-authored-by: Peter Steinberger <[email protected]>
…nces (openclaw#125357) * fix(subagents): keep the failure cause on pending-error timeout announces A run that fails inside the lifecycle error retry grace window is handed to waiters as `status: "timeout"` with the failure text attached and `pendingError: true` (createPendingErrorTimeoutSnapshot). applySubagentWaitOutcome rebuilt that as a bare `{ status: "timeout" }`, dropping the cause, and the announce status label had no slot for it — so the parent agent was told only "timed out" for a child that had actually errored, and could neither retry appropriately nor report the real blocker. Two other consumers of the same wait result already treat this shape as a failure with a cause (isPendingErrorAgentWaitTimeout in sessions-send-tool, isDeliveryFailureWait in sessions-send-tool.a2a); the subagent announce path was the outlier. Keep the cause when `pendingError === true` and render it as "timed out: <cause>". Genuine budget timeouts carry no pendingError and are unchanged. Tests: 3 unit cases for applySubagentWaitOutcome (pending-error timeout keeps the cause; budget timeout has none; wait error text without pendingError is ignored) and an announce format case asserting the "timed out: <cause>" label. * fix(agents): bound the task-completion status label in prompt context statusLabel embeds caller-supplied error text ("failed: <cause>", and now "timed out: <cause>"), but only the child result was capped before being projected into the parent agent's prompt — a large provider or lifecycle error could enter the model context unbounded and crowd out the result and the reply instruction. Cap the single status line at the shared internal-event formatting boundary, which covers both the pre-existing "failed: <cause>" path and the new timeout cause. Tests: a large-error status label is truncated with a marker and keeps its prefix; ordinary status labels are unchanged. * fix(agents): reuse truncateUtf16Safe for the status-label cap The status-label cap used a raw String.slice, which can split a UTF-16 surrogate pair when provider or lifecycle error text ends on an astral character, sending a dangling surrogate into the parent agent's prompt. Reuse the existing truncateUtf16Safe primitive instead of a parallel implementation, matching agent-run-terminal-reply.ts. Test: an emoji landing exactly on the truncation boundary keeps the label within the cap, ends with the marker, and leaves no unpaired surrogate or replacement character. * fix(subagents): keep main's subagent cancellation classifier The branch predated openclaw#125407, which replaced the generic classifier here with classifySubagentTerminalOutcome so explicit restart/aborted stop reasons stay cancellations while real provider timeouts still classify as timeouts. Resolving the merge with the generic call would have reverted that. Keep main's classifier and apply the pending-error cause inside its timeout case; the two are orthogonal. A pending-error snapshot carries no stopReason (createPendingErrorTimeoutSnapshot drops it), so the cancellation override never fires for it. Test: restart and aborted stop reasons with blocked liveness stay cancellations rather than being reported as failures. * refactor(subagents): reuse canonical status label truncation --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Fixes an issue where canceling a subagent could be reported as a timeout when its lifecycle end event carried a bare
aborted: true. The registry listener independently interpreted that signal as timeout, started timeout retry grace, and could later announce the canceled run as timed out.Why This Change Was Made
The listener now uses the canonical agent-run terminal outcome builder and a subagent-owned classifier for cancellation, timeout, and failure precedence. Explicit cancellation outranks blocked or abandoned liveness for subagent projections; a bare abort stays provisional during the existing grace window so a later authoritative yield or manual kill can supersede it; structured provider timeouts retain their existing behavior.
User Impact
Canceled subagent runs are no longer mislabeled or announced as provider timeouts. Real provider timeouts keep their existing grace, delivery, and restart behavior.
Evidence
origin/mainatee79b0a49ae4b0ecd30f9e483c70c0f49f20232c.71f734466bacbe574a10ead551db5305be3dd16d.subagent-registry.lifecycle-retry-grace.e2e.test.ts: the landedterminalReplyfixture semantics from fix(ci): align lifecycle retry fixtures with terminal replies #127295 and this PR's structured provider-timeout fields.main, the bare-abort lifecycle case remainedrunningand later became a timeout instead ofsubagent-killed.node scripts/run-vitest.mjs src/agents/agent-run-terminal-outcome.test.ts src/agents/subagents/registry/subagent-registry.test.ts src/agents/subagents/announce/subagent-announce-output.test.ts src/tui/embedded-backend.test.ts src/agents/subagents/registry/subagent-registry.lifecycle-retry-grace.e2e.test.ts src/agents/subagents/registry/subagent-registry.persistence.resume.test.ts.aborted: trueandstopReason: "restart".timeoutwhile restart plus incomplete blocked liveness remainscancellation.@openclaw/ai/transportsexport mismatch). Exact-head hosted CI/Testbox owns that proof; no dependency reconciliation was performed in the GWT.git diff --check origin/main...HEAD: clean.Live-provider proof was not run. The deterministic lifecycle E2E injects the producer-owned abort and timeout fields and covers announcement plus persisted restart delivery.
AI-assisted: yes. The maintainer reviewed the complete diff and understands the ownership change.