Repository navigation
fix(subagents): keep the failure cause on pending-error timeout announces - #125357
Conversation
…nces
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.
|
Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 6:30 PM ET / 22:30 UTC. ClawSweeper reviewWhat this changesThe PR retains a pending-error timeout’s cause in subagent completion output, renders it for the parent agent, and caps the resulting prompt status line. Merge readinessKeep open. Current main still discards the error from a pending-error timeout before announcing it to the parent; this PR repairs that projection without changing canonical terminal classification. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — execution before step 1 Assertions:
How this fits togetherGateway lifecycle events produce wait snapshots for child-agent runs. Subagent announcement code turns those snapshots into an internal completion event that is injected into the parent agent’s prompt. flowchart LR
A[Child lifecycle event] --> B[Gateway wait snapshot]
B --> C[Subagent outcome projection]
C --> D[Internal completion event]
D --> E[Parent agent prompt]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +31, Tests +150. Total +181 across 6 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the error only for the explicitly marked pending-error timeout, preserve the existing canonical classifier, and bound the sanitized status text at the shared prompt-formatting boundary. Do we have a high-confidence way to reproduce the issue? Yes, by source: a Gateway wait snapshot with status timeout, pendingError true, and error text reaches current main’s bare timeout branch; the focused regression test encodes that path. Is this the best way to solve the issue? Yes. The repair is at the announce projection that loses the already-normalized Gateway fact, while leaving terminal-state precedence with its canonical owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6669872a95f8. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
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.
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.
…t-error-masking # Conflicts: # src/agents/subagents/announce/subagent-announce-output.ts
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.
|
Merged via squash.
|
…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]>
Fixes #125356.
What Problem This Solves
When a subagent run fails, the parent agent is sometimes told only
status: timed out, with no cause — even though the runtime had the failure text in hand and had explicitly flagged the outcome as an error. The parent cannot then tell "ran out of budget, retry smaller" from "died on a runtime fault, retry differently", so it does neither and reports nothing useful to the user.A run that fails inside the 15s lifecycle error retry grace is handed to waiters as
status: "timeout"with the failure text attached andpendingError: true— seecreatePendingErrorTimeoutSnapshot()insrc/gateway/agent-turn/agent-job.ts.buildAgentRunTerminalOutcomeFromWaitResult()forwardswait.errorandbuildAgentRunTerminalOutcome()retains it, so the cause is available by the time the announce path runs.applySubagentWaitOutcome()discarded it. Thetimeoutcase rebuilt a bare{ status: "timeout" }whilefailurekeptterminalOutcome.error ?? waitError, and the announce status label had no slot for a timeout cause:This also made the announce path inconsistent with two other consumers of the same
AgentWaitResult, which already treatstatus: "timeout"+pendingError: trueas a failure carrying a cause:isPendingErrorAgentWaitTimeout()—src/agents/tools/sessions-send-tool.tsisDeliveryFailureWait()—src/agents/tools/sessions-send-tool.a2a.tspendingErrorwas already declared on the localAgentWaitResulttype insubagent-announce-output.tsand never read.Observed in production on 2026.6.11: a subagent aborted after ~54s against a 2400s budget with
promptError: "OpenClaw recorded a native Codex tool.call without a matching tool.result before the turn completed. missingToolResultCount=2". It ended ~2.8s before the parent'sagent.waitexpired — inside the grace window — so the parent receivedstatus: timed outplus5 tool call(s) made without visible output, with no cause and a budget the run never approached. The user-facing thread stalled.Change
subagent-announce-output.ts— on thetimeoutbranch, keepterminalOutcome.error ?? waitErroronly whenwait.pendingError === true, matching the existing sibling idiom.subagent-announce.ts— render it astimed out: <cause>when present.internal-events.ts— bound the status label before it enters prompt context (MAX_TASK_COMPLETION_STATUS_LABEL_CHARS = 500,…[truncated]marker) using the existingtruncateUtf16Safeprimitive, so an astral character on the boundary cannot leave a dangling surrogate. Only the child result was capped before; this also bounds the pre-existingfailed: ${outcome.error}path, which was unbounded onmain.Scope is deliberately narrow: genuine budget timeouts carry no
pendingError, produce noerror, and keep the exacttimed outlabel. The existingkeeps provider hard timeouts stronger than blocked wait metadatatest has nopendingErrorand stays green.Evidence
All runtime evidence was produced from a build of this branch, running a real gateway against two real HTTP model endpoints on the production
openai-completionstransport. The parent's first turn emits a genuinesessions_spawntool call, so the runtime really spawns a child; the endpoint records the exact prompt the parent receives.1. Genuine budget timeout — unchanged (negative control). Child hangs, hits
runTimeoutSeconds: 112; real announce delivered to the parent:No
pendingError, no cause, label identical to pre-patch behaviour.2. Failure path carries the cause end to end. Child's provider returns a real error:
3. The patched projection exercised against the shipped
dist/— the built artifact this PR produces, not the TS source and not mocks:4. Unit tests.
subagent-announce-output.test.ts— pending-error timeout keeps the cause; genuine budget timeout has none; wait error text withoutpendingErroris ignored (guards the narrow scope).subagent-announce.format.e2e.test.ts— thetimed out: <cause>label reaches the announce message.internal-events.test.ts— a large status label is truncated with a marker while keeping its prefix; ordinary labels are untouched; an emoji landing exactly on the truncation boundary leaves no unpaired surrogate.tsgo:prod,tsgo:core:test,tsgo:extensions:test,lint,format:check,deadcode:full,check:architecture,check:max-lines-ratchet,build:plugin-sdk:dtsall clean locally, pluscheck:docsandprotocol:checkpinned toupstream/main.What could not be synthesised locally, and why. The
{status:"timeout", pendingError:true}shape needs a child whose run ends on lifecycle phase"error"and a parent that learns the outcome throughagent.wait. With an in-process subagent neither holds: a handled provider error ends the run on phase"end"(recorded immediately → classifiedfailure), an aborted run emits no completion announce at all, and the parent receives the outcome directly rather than via the wait. In production the shape arises with an out-of-process harness child, which is where the original report came from. That the shape is real is also asserted by the codebase itself —isPendingErrorAgentWaitTimeout()andisDeliveryFailureWait()both branch on exactlystatus === "timeout" && pendingError === true.