fix: keep a sub-agent's task when a retry reloads oversized history (#201636) Root cause: src/config/sessions/session-model-context-window.ts:168 takes a history suffix that starts inside the current turn when that turn's tool results exceed the history byte cap, so a retry that reloads history mid-turn loses the request that opened the turn. Fixes #201605 ## What Problem This Solves A sub-agent working through a long, tool-heavy task (screenshots, large reads) can hit a provider stream error such as `degenerate_output`. OpenClaw retries on the same model, but the retry's request no longer contains the sub-agent's task. The model only sees the system prompt, a failure note and "continue the current task", so it answers without doing the work and the parent receives a "completed" child that did nothing. ## User Impact User impact: after a transient provider failure, a sub-agent (or any agent turn) whose tool results have grown past the history byte cap retries with its task still in front of the model and continues the work. Turns under the cap, new turns, and retries whose failed stream produced no output are unchanged. ## Why This Change Was Made The first attempt builds its history in memory. A retry reloads the transcript through the bounded history window, which keeps the newest events that fit in eight bytes per context token. Inside one long turn there is no later turn boundary to align to, so the window kept only the newest tool frames and dropped the turn's user request. The internal continuation prompt then became the first user message, which is the `historyRewrite(message 0 (user) differs ...)` line in the report. The window now keeps the request that opened the current turn and fills the rest of the cap with the newest frames, the same way it already reserves the latest compaction summary. If that request cannot fit beside any frame, the old suffix is kept. Saved history is not changed. ## Evidence Real Gateway from source with a local OpenAI Responses provider that records every request. The parent calls `sessions_spawn` with a task; the child reads two screenshot-sized images, then its third stream emits text followed by a runaway tool call that trips `degenerate_output`. - `main` (67aacbb676), twice: the retry request is `[system, failed-turn note, "Continue the current task...", runtime context]`, with no task. The child ends with `stopReason=stop` 1.3 s later. - This branch, twice: the retry request starts with the same task message as the first attempt, and the child continues the task. - Controls on both builds: a sub-agent turn that does not fail is identical; an output-free failure and a small-history failure already kept the task. - Regression test `keeps the current turn's request when its tool frames exceed the byte cap`: fails on `main` (`expected [ 3, 4, 5 ] to deeply equal [ +0, 3, 4, 5 ]`), passes here. Observed request lines: https://github.com/openclaw/openclaw/pull/201636#issuecomment-7000817156 Re-run after the review fix (tool ownership kept): https://github.com/openclaw/openclaw/pull/201636#issuecomment-7001542528 Thanks @mike1122real-hub for the detailed report with the four failure timings and the history-rewrite line. ## Merge danger Two-way door: the change only selects which saved events are loaded for one model request and writes nothing, so a revert fully restores the old selection. Blast radius: embedded agent turns whose loaded history exceeds the byte cap in the middle of a turn; they now send the turn's request plus slightly fewer of the oldest tool frames from that turn. Co-authored-by: Ayaan Zaidi <hi@obviy.us>
Current
·
C2
·2026-11
fix: keep a sub-agent's task when a retry reloads oversized history (…
Find Your Interest
- Your AI Agents Will Be Attacked. Red-Team Them First
- No. 7 UCLA escapes upset from CSUF thanks to Trent Perry's heroics
- Rockets 119, Pacers 104: Alperen Şengün exits, Reed Sheppard gets hot and rotation tweaks
- 'Discussed with him': Tim Paine's claim of innocence in Sandpapergate under the spotlight after Cameron Bancroft's revelations
- 'College GameDay' lands A-list guest picker for Miami-Virginia Tech
- Maikel Garcia trade: This blockbuster deal looks like a win-win for Mariners and Royals
- Maikel Garcia trade: This looks like a win-win for Seattle and Kansas City in blockbuster deal
- UNC vs. Marshall game preview, info, prediction and more
- Iowa football secures commitment from No. 2 kicker in 2028 class
- Kickoff time announced for USC's November 28 rivalry matchup with UCLA
Current
·
C2
·2026-11





