Skip to content

fix(agents): stop canceled subagents reporting timeouts - #125407

Merged
vincentkoc merged 4 commits into
mainfrom
recovery/subagent-timeout-20260817
Aug 21, 2026
Merged

vincentkoc merged 4 commits into
mainfrom
recovery/subagent-timeout-20260817

Conversation

@steipete

@steipete steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Rebased once onto origin/main at ee79b0a49ae4b0ecd30f9e483c70c0f49f20232c.
  • Exact head: 71f734466bacbe574a10ead551db5305be3dd16d.
  • The sole rebase conflict preserved both contracts in subagent-registry.lifecycle-retry-grace.e2e.test.ts: the landed terminalReply fixture semantics from fix(ci): align lifecycle retry fixtures with terminal replies #127295 and this PR's structured provider-timeout fields.
  • Pre-fix reproduction: with the listener byte-identical to the old main, the bare-abort lifecycle case remained running and later became a timeout instead of subagent-killed.
  • Focused local proof: 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.
  • The unit, wait/announce projection, persistence, and TUI suites passed: 343 tests.
  • Exact-review repair: canonical provider timeout attribution now wins before the subagent cancellation override, including when lifecycle metadata retains aborted: true and stopReason: "restart".
  • Direct classifier coverage proves provider hard timeout remains timeout while restart plus incomplete blocked liveness remains cancellation.
  • The lifecycle E2E shard did not start locally because the shared install contained stale built plugin artifacts (@openclaw/ai/transports export mismatch). Exact-head hosted CI/Testbox owns that proof; no dependency reconciliation was performed in the GWT.
  • Fresh autoreview after the exact-review repair: clean, no accepted/actionable findings, correctness 0.97.
  • git diff --check origin/main...HEAD: clean.
  • Production LOC: +90/-86 (net +4). Tests: +97/-21 (net +76). The production growth establishes one shared subagent cancellation owner while preserving canonical timeout precedence across listener, wait, and announcement projections.

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.

@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Aug 17, 2026
@steipete
steipete marked this pull request as ready for review August 17, 2026 20:45
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 17, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 6:36 PM ET / 22:36 UTC.

ClawSweeper review

What this changes

The 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 readiness

⚠️ Ready for maintainer review - 2 items remain

Keep 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
Reviewed head: b1d911386eaf4bc13499f7f74772980a6d0ecf23

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused owner-boundary coverage, preserves structured timeout handling, and has no supported correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal lifecycle repair is outside the external-contributor proof gate; the PR supplies focused lifecycle E2E and exact-head CI evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal lifecycle repair is outside the external-contributor proof gate; the PR supplies focused lifecycle E2E and exact-head CI evidence.
Evidence reviewed 6 items Current-main gap: Current main does not contain the new subagent classifier; its listener still schedules every bare aborted lifecycle end as a timeout, which is the reported misclassification.
Owner-boundary repair: The listener builds the shared terminal outcome, preserves structured timeouts, and schedules only a bare abort as provisional cancellation; all other cancellation paths complete as killed.
Shared contract and sibling projections: The shared builder defines bare aborted lifecycle data as cancellation and structured timeout attribution as timeout; the wait and announcement consumers use the subagent-specific classifier.
Findings None None.
Security None None.

How this fits together

Subagent 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]
Loading

Before merge

  • Resolve merge risk (P1) - Production code is net +2 lines for a bug fix; the new shared subagent classifier is justified only while it remains the single owner used by listener, wait, and announcement projections.
  • Complete next step (P2) - No repair lane is needed: this active maintainer PR has a coherent owner-boundary fix and no actionable review finding.
Agent review details

Security

None.

PR surface

Source +2, Tests +47. Total +49 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 88 86 +2
Tests 2 68 21 +47
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 156 107 +49

Review metrics

Metric Value Why it matters
Production versus test delta production +88/-86 (net +2); tests +68/-21 (net +47) The small production increase introduces one reusable subagent classifier while the tests cover cancellation, structured timeout, and resumed delivery behavior.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    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.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best 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.

Labels

Label justifications:

  • P1: A cancelled subagent can otherwise be reported and announced as a timeout, affecting active agent workflows.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal lifecycle repair is outside the external-contributor proof gate; the PR supplies focused lifecycle E2E and exact-head CI evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the registry-family refactor that introduced this listener surface and all three commits in the current repair series. (role: introduced and recently revised behavior; confidence: high; commits: 1ced7441eb6a, b1d911386eaf; files: src/agents/subagents/registry/subagent-registry-listener.ts, src/agents/subagents/registry/subagent-registry-pending-lifecycle.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-17T20:53:08.260Z sha de9a443 :: needs maintainer review before merge. :: none

@vincentkoc vincentkoc self-assigned this Aug 21, 2026
@vincentkoc
vincentkoc force-pushed the recovery/subagent-timeout-20260817 branch from b1d9113 to 85a623f Compare August 21, 2026 18:33
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Exact head: 85a623fe6a27ceff3562abc2fe6bd67094c9ed99

Please verify the rebased cancellation classifier, the preserved #127295 terminalReply fixture semantics, and the structured provider-timeout cases.

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Exact head: 71f734466bacbe574a10ead551db5305be3dd16d

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 aborted: true plus stopReason: "restart".

Please verify the repaired precedence and the preserved #127295 terminalReply fixture semantics.

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc
vincentkoc merged commit 9de2b23 into main Aug 21, 2026
231 of 232 checks passed
@vincentkoc
vincentkoc deleted the recovery/subagent-timeout-20260817 branch August 21, 2026 19:02
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 22, 2026
)

* 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]>
rishitamrakar added a commit to rishitamrakar/openclaw that referenced this pull request Aug 23, 2026
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.
zeroaltitude added a commit to zeroaltitude/openclaw that referenced this pull request Aug 23, 2026
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.
zeroaltitude added a commit to zeroaltitude/openclaw that referenced this pull request Aug 23, 2026
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.
steipete added a commit that referenced this pull request Aug 23, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 24, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants