Repository navigation
[ENG-21265] fix(engine): retry a mid-stream cut-off once in smaller steps + opt-in spawn failure backstop - #298
Conversation
…teps (ENG-21265) A model generation cut off mid-stream (SDK "stream ended before message_stop", Bedrock "messageStop", gateway "upstream error during stream", or a stream that closed mid tool call) went to model fallback and, when every model failed, to a sub-agent re-spawn; each restart re-sent the same oversized call, which kept being dropped (Egan thread 15003: ~60 min, ~714k tokens). Retry once on the same model, from the existing transcript, with an instruction to redo that step split into smaller tool calls. Skipped for rate-limit / overload / auth / billing / edge-blocked failures, for aborted or timed-out runs, and when the attempt left delivery/media/async evidence. After the one retry the existing failure handling applies. Full-loop test: cut off, then complete => 2 attempts, same model, no fallback; without the retry the run ends after 1 attempt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wns (ENG-21265) Adds agents.defaults.subagents.maxConsecutiveFailures (unset/0 = off). After N failed child runs in a row for one requester session, the next sessions_spawn is refused with guidance to report and ask the user. A new user turn (unmarked or external_user provenance) or a successful child restarts the count; completion wakes and internal handoffs keep counting. Runs are looked up under the completion-owner key they register under. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 21 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
View guided diff | Turn on auto-fix | Re-trigger cubic
…stop - Match the unclosed-content-block (Anthropic/Bedrock) and proxy terminal-event cut-offs, which the transports actually emit. - In-flight child runs no longer break the failure streak; the refusal lists only the failed attempts. - Ceiling test asserts the exhausted retry surfaces as an incomplete-turn error; terminal-evidence cases cover client tool calls, delivery, media. - Docs: the cap applies to sub-agent spawns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Approved (head 4a1bd4a)
Engine-level fix for ENG-21265: a mid-stream cut-off gets one same-model retry in smaller steps, and the sub-agent spawn backstop is opt-in and off by default.
Verified
- Cut-off patterns match what the transports actually emit:
anthropic-transport-stream.ts:1600/1621,amazon-bedrock/stream.runtime.ts:290/307,runtime/proxy.ts:394. They are also consistent withfailover-matches.ts:168-172. - The retry sits after the silent-error retry and before fallback and profile rotation. It reuses the existing
nextAttemptPromptOverrideandsuppressNextUserMessagePersistencemechanism (run.ts ~1731/2030), so the original user message is not re-sent. Capped at 1 per run (MAX_STREAM_CUTOFF_RETRIES). - Guards are correct: abort, timeout, idle timeout, promptError, auth, rate-limit and billing are skipped.
RETRYABLE_REASONSis an allowlist, so wrapped rate_limit/overloaded/edge_blocked/format keep their own handling.hasAttemptTerminalStateexcludes delivery, media, yield and client tool calls. - Backstop is lazy-gated on
maxConsecutiveFailures(unset or 0 returns null before any lookup), runs before side effects, and reads the registry undercompletionRequesterSessionKey. In-flight runs are skipped (neither extend nor break the streak). Reset happens once per user turn, andinter_sessionandinternal_systemkeep counting. - Config surface: zod, types, docs and generated baselines are aligned. Rolling-deploy safe, because it adds an optional key only.
- Local run on this SHA:
run.stream-cutoff-retry,stream-cutoff-retry,subagent-consecutive-failures,subagent-spawn.consecutive-failures= 53 tests, all pass. - CI: all substantive checks green (checks-node-*, dispatch). Only skipped/cancelled-superseded jobs otherwise. cubic: all findings addressed.
Non-blocking notes
- ACP runtime spawns (
runtime: "acp") bypass the backstop. This is documented as sub-agent only; worth a follow-up if ACP loops show up. - The streak-reset map is in-process, so a gateway restart re-baselines it on the next user turn. Acceptable for a backstop.
- Effectiveness depends on the model obeying the "smaller calls" instruction. Canary on Egan's host is the real proof. Watch for
[stream-cutoff-retry]warn logs andstream_cutoff_retryin the trace, and whether the retry succeeds or just burns one extra attempt.
There was a problem hiding this comment.
Code Review: APPROVE
Verdict: APPROVE (siap-rilis)
Summary & Technical Verification
- Mid-Stream Cut-Off Retry (ENG-21265): Adds single-attempt retry on the same model for generations terminated prematurely during active streaming (e.g. Bedrock dropping 8-15 minute single tool calls). Prompts the model with explicit instructions to break large payloads into smaller tool calls or disk artifacts.
- Failure Classification Safety: Correctly gates retries so non-retryable failures (auth, billing, rate-limits, timeouts, aborts, or turns with committed terminal side-effects) bypass the retry and preserve existing fallback mechanisms.
- Opt-In Subagent Spawn Backstop: Introduces
maxConsecutiveFailuresconfiguration to halt runaway spawn loops after consecutive failures under the same completion requester session, ignoring in-flight runs and resetting upon fresh user turns. - Test Coverage & CI: 44 unit tests in
stream-cutoff-retry.test.ts, full embedded agent runner loop tests inrun.stream-cutoff-retry.test.ts, plus 42 unit and integration tests across subagent failure backstops. All 155 CI checks passed cleanly.
…ailed spawns (ENG-21265) Found by gateway e2e: - Model fallback re-enters the runner once per candidate with the same runId, so a per-call counter gave every fallback model its own smaller-steps retry. Key the budget by runId: one retry per user turn. - The backstop refusal listed every attempt as "(unlabeled)" because sessions_spawn stores the agent-given name as `label`, not `taskName`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ENG-21265 e2e test reportResult: with the fix ( How it was tested (end-to-end, not unit tests)
Results
Request traces (fake-provider view)S1 after (fix): S1 before ( S7 (backstop on): Bugs the e2e found (fixed in
|
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
…nId (ENG-21265) Cron and CLI runs reuse the session id as runId, so the runId-keyed map left a spent budget behind and later executions of the same session got no retry. runWithModelFallback now opens one budget scope per execution (AsyncLocalStorage, global singleton); every fallback candidate shares it and each new execution starts fresh. No global map, nothing to evict. The fallback-chain test also asserts the fallback attempt's model id. Co-Authored-By: Claude Opus 5.5 <[email protected]>
E2E addendum:
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* chore(release): bump version 2026.6.35-boon.1 -> 2026.6.35-boon.2 Cuts the fork release covering the 9 PRs merged to boon since v2026.6.35-boon.1: #298 (ENG-21265) stuck-generation cut-off retry + sub-agent spawn backstop, #299 workspaceDir threading through outbound channel media adapters, #304 (ENG-19208) real inbound media path in the system prompt, #301 (ENG-21585) forced sessions_yield on narrated sub-agent turns, #305 message-tool source reply observed outside message_tool_only, #306 (ENG-19103) reasoning-stream callbacks honor message_tool_only, #303 sub-agent/completion-turn usage attribution, #302 clears 7 high-severity pnpm-audit-prod advisories, #300 (ENG-21588) boon-estimation trajectory label detail. Bump root package.json/npm-shrinkwrap.json, all bundled plugin manifests, and the version + openclaw peer floor in every extension npm-shrinkwrap.json. Add the 2026.6.35-boon.2 CHANGELOG.md section. No additional dependency or source changes beyond what already shipped in #299 and #302. Co-Authored-By: Claude Sonnet 5 <[email protected]> * docs(changelog): fold PR #309's advisory fixes into the 2026.6.35-boon.2 entry --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
ENG-21265: one giant model call shouldn't sink the whole job
Targets
boon, the branch production runs. This supersedes #296, which targeted the stalemainmirror.The bug
Egan's Pass 3 builds an Excel workbook through a single tool call. That makes one generation run for 8–15 minutes, and Bedrock drops streams that long. When a drop happened after tool use,
run.tstreated it as not safe to replay and failed the run. Model fallback ran next, then the parent re-spawned the sub-agent. Every retry re-sent the same giant call, so it failed the same way each time.The result was about 60 minutes, about 714k tokens, and then an error. Any skill that builds a large artifact in one call can hit this.
The fix (engine-level: covers every skill, no skill edits)
run/stream-cutoff-retry.ts, wired intorun.ts).What counts as cut off: the stream ended mid-generation. That covers SDK
stream ended before message_stop, BedrockmessageStop, Anthropic/Bedrockstream ended with an unclosed content block, proxystream ended before terminal event, gatewayupstream error during stream, andcompleted stream with an incomplete tool call.The retry: one retry on the same model, inside the run. Its prompt tells the model to redo that step as several smaller tool calls, or to put a long reply into a file.
What's kept: completed tool work stays. The original user message isn't sent again.
Why it redoes the step: a half-written tool call can't be resumed, and the transport strips errored turns before they reach the provider. So the retry has to redo the step, smaller.
When it's skipped:
hasAttemptTerminalState).In those cases the existing handling applies.
Cap: one retry per run, per the ticket's acceptance criteria ("max 1 retry before requiring user confirmation"). It shows up in the trace as
stream_cutoff_retry.subagent-consecutive-failures.ts,subagent-spawn-backstop.ts). Opt-in viaagents.defaults.subagents.maxConsecutiveFailures; it's off when unset or0.sessions_spawnis refused. The refusal message tells the agent to report what was attempted and ask the user before trying again.runtime: "subagent"). ACP runs aren't recorded in the sub-agent registry.external_user.inter_session);internal_system).attempt.ts→agent-tools→openclaw-tools→sessions_spawn→ spawn context.ownership.completionRequesterSessionKey, the key they're actually registered under. fix(engine): retry a cut-off model generation in smaller steps instead of restarting the job (ENG-21265) #296 queried the rawagentSessionKey, which misses runs whenever a completion owner differs from the caller. A test now pins this.Proof
boon:run.stream-cutoff-retry.test.tsdrives the realrunEmbeddedAgentloop.stream-cutoff-retry.test.tshas 44 tests. All cut-off variants retry. Rate-limit, overload, auth, billing, format, and edge-blocked failures don't. Abort, timeout, and terminal evidence don't. Only one retry happens.spawnSubagentDirect. They failed first, then passed. They cover:tsgo:core,tsgo:test, oxlint, oxfmt, andconfig:docs:checkpass. The embedded-agent-runner and subagent suites pass.Known limits
Rollout
maxConsecutiveFailures: 3on Egan's host, then roll out to the fleet.🤖 Generated with Claude Code