Skip to content

[ENG-21904][ENG-21905] fix(agents): timed-out sub-agents resume late and recovered overflows show a false error - #313

Merged
orswn merged 2 commits into
boonfrom
okka/eng-21904/timeout-overflow-fixes
Oct 29, 2026
Merged

orswn merged 2 commits into
boonfrom
okka/eng-21904/timeout-overflow-fixes

Conversation

@orswn

@orswn orswn commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Related: ENG-21904, ENG-21905

What Problem This Solves

Fixes two problems in long agent turns on customer boxes.

  • Timed-out sub-agents came back later. Some sub-agents do heavy spreadsheet work and hit their run timeout. The runner then started the next fallback model with a fresh full timeout, and the gateway aborted it about a minute later. A later orphan scan then reopened the timed-out run and resumed it. The resumed child posted out-of-date "corrections" to the user minutes or hours after the task was reported as timed out. In 2 days of logs from 77 boxes, 18 such resumes were found on 3 boxes.
  • Recovered context overflows showed a false error. A turn hit the mid-turn context precheck, compacted, retried, and delivered the right answer. The chat still showed "The run hit an error before it could finish" next to the answer. Sentry counted the recovered attempt as an error, so the fleet turn-failure alert fired. The precheck also fired when it did not need to: the request copy of a large tool result kept about 250,000 characters, while the session file kept 64,000. Recovery then found nothing to truncate and ran a full compaction.

Why This Change Was Made

Each fix targets one cause, and each keeps the existing behavior for other cases.

  • No new attempt after the run deadline. When the attempt's own run deadline aborts it, the runner surfaces the timeout. It does not rotate the auth profile or switch the model. An idle model stall still falls back. The attempt result gets a timedOutByRunDeadline flag, which only the deadline timer sets, and the embedded_run_failover_decision log line shows it.
  • No reopen of an ended run. Orphan recovery treated every hard timeout (timeout outcome, endedAt, session abortedLastRun) as an old restart interruption. It cleared endedAt and resumed the run. That rule is removed. Runs that a restart interrupts already stay unended, so restart resume still works.
  • The last attempt defines the run's lifecycle error. The reply runner and the agent command kept the first finishing error for the whole run. They now follow the last finishing event. A recovered retry ends with end. A failed last attempt still fails the run.
  • The precheck attempt end is a Sentry warning. The sentry-monitor plugin sends an agent_end with the precheck error as a warning message. The fingerprint does not change, so the existing issue keeps its history.
  • One per-result cap. The tool-result context guard caps the text of each result in the model request with the same function and limit as the persisted copy (64,000 characters for windows of 200k tokens or more). So in the current turn the model sees what later turns see, and the mid-turn precheck measures what recovery can truncate. Image blocks are kept. The originals in memory are not changed.

Trade-offs:

  • Callers with no outer deadline (cron, queued follow-ups, heartbeat, local CLI) no longer get a fallback attempt after the run deadline. The sub-agent registry already reports such a late finish as a timeout.
  • An overflow that recovery cannot fix also ends with the precheck error, so it is now a Sentry warning too. The user still gets the explicit overflow reply, and the run still fails.

This diverges from upstream. Upstream renews the gateway deadline for each fallback attempt (openclaw#141869), which can multiply the wall time of a turn by the length of the fallback chain. A later upstream sync must reconcile the two.

Not in this PR:

  • A default run timeout for sub-agents. They still inherit agents.defaults.timeoutSeconds.
  • Timeout-triggered compaction after the run deadline. It is not changed. A TODO marks it.

User Impact

  • A sub-agent that times out stops at its deadline. It does not come back later with an out-of-date answer.
  • A turn that recovers from a context overflow shows only the answer.
  • Large tool results no longer trigger a needless compaction mid-turn.
  • The fleet turn-failure alert no longer counts recovered overflow attempts.
  • Slack, Teams, and the TUI use the same runner code. They were not tested live.

Evidence

  • Focused Vitest, run with node scripts/run-vitest.mjs: every changed test file passes, plus model-fallback.run-embedded.e2e.test.ts. Each new behavior test failed on the base commit first.
  • tsgo (core, core tests, extensions, extension tests), oxlint, oxfmt --check, the import-cycle check, and git diff --check pass.
  • Live check on a local box with production config (same model chain, timeoutSeconds, compaction, and progress nudge settings), driven through the Boon web chat with a real model. Each scenario ran on the base commit first, then on this branch, with the same input. To keep runs short, the sub-agent run timeout was set to 60 s and the context window to 100,000 tokens.
Scenario Base commit This branch
Sub-agent hits its run deadline during model output 3 model attempts (2 fallbacks); terminal state 80 to 94 s after the deadline 1 attempt; surface_error with timedOutByRunDeadline: true 77 ms after the deadline
Gateway restart after a sub-agent timed out (record written by the base build, scanned by this branch) resumed orphaned session; a late "Correction" message in the parent chat no resume; the record keeps endedAt and the timeout outcome
Gateway restart while a sub-agent runs not run resumed; the child finished; the parent got the result
Two 120,000-character tool results in one turn false precheck (estimate 91,971 over a budget of 83,616); 2 compactions; answer plus the false error; 2 Sentry errors no precheck; no compaction; answer only; 0 Sentry events
Precheck that compaction recovers answer plus the false error; Sentry exception, level error answer only; Sentry message, level warning, same fingerprint
User message larger than the context window explicit overflow reply explicit overflow reply; Sentry level warning

Recovered context overflow turn, before and after


Summary by cubic

Fixes two long-turn agent failures: timed-out sub-agents no longer come back later with stale corrections, and turns that recover from a context overflow no longer show a false error next to the answer.

Behavior changes

  • When the attempt's own run deadline aborts it, the runner surfaces the timeout instead of starting a new fallback attempt with a fresh full timeout; idle model stalls still fall back.
  • Orphan recovery no longer reopens runs the registry already ended as timed out; restart-interrupted runs still resume.
  • The tool-result context guard now caps each result's text in the request copy to match the persisted copy, so the mid-turn precheck measures what recovery can truncate. Image blocks are kept.
  • The last finishing event defines the run's lifecycle error, so a recovered retry ends the run normally while a failed last attempt still fails it.
  • Sentry reports a precheck-aborted attempt as a warning with the same fingerprint instead of an error, so recovered overflows no longer fire the fleet turn-failure alert.

Trade-offs

  • Callers with no outer deadline (cron, queued follow-ups, heartbeat, local CLI) no longer get a fallback attempt after the run deadline.
  • An overflow that recovery cannot fix is now a Sentry warning; the user still gets the explicit overflow reply.
  • Upstream renews the gateway deadline per fallback attempt, so a later upstream sync must reconcile the difference.
  • The compaction retry that runs after a run-deadline timeout is left unchanged, marked with a TODO in the runner.

Written for commit cd1a366. Summary will update on new commits.

View guided diff Turn on auto-fix

A sub-agent run that hit its run timeout switched to the next fallback
model with a fresh full timeout. The gateway aborted that attempt about
a minute later, so the extra model time was lost. A later orphan scan
then cleared the end time of the timed-out run and resumed it. The
resumed child sent the parent out-of-date corrections minutes or hours
after the task had been reported as timed out.

A turn that hit the mid-turn context precheck and recovered still
showed "The run hit an error before it could finish" next to the real
answer, and Sentry counted the recovered attempt as an error. The
precheck also fired when it did not need to. The request copy of a
large tool result kept about 250,000 characters, but the session file
kept 64,000. Recovery truncated the session file, found nothing to
cut, and ran a full compaction.

Fix each cause:

- After the attempt's own run deadline fires, the embedded runner no
  longer rotates the auth profile or switches to a fallback model. It
  surfaces the timeout. An idle model stall still falls back. The
  failover decision log records timedOutByRunDeadline.
- Orphan recovery no longer reopens a run that the registry already
  ended as a timeout. Runs that a restart interrupts stay unended and
  still resume.
- The deferred lifecycle error of the reply runner and of the agent
  command follows the last finishing event. A recovered retry ends
  the run normally. A failed last attempt still fails the run.
- The sentry-monitor plugin reports an attempt that ends with the
  precheck error as a warning message with the same fingerprint.
- The tool-result context guard caps the text of each result in the
  request copy with the same rule as the persisted copy. Images are
  kept.

Trade-offs:

- Callers with no outer deadline (cron, queued follow-ups, heartbeat,
  local CLI) no longer get a fallback attempt after the run deadline.
- An overflow that recovery cannot fix is now a Sentry warning. The
  user still gets the explicit overflow reply.

Upstream took the other direction for the run deadline and renews the
gateway deadline for each fallback attempt (openclaw#141869).
A later upstream sync must reconcile the two.
@orswn
orswn requested a review from a team October 29, 2026 05:12
The embedded runner now has a TODO for the timeout-triggered
compaction retry after the run deadline. The repo lints TODO comments
as errors, so the line above it disables eslint/no-warning-comments.
The production suppression allowlist test lists every such
suppression, so add the new one.

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Re-review passes with all CI checks green (29 passed, 0 failed). The allowlist addition in test/scripts/lint-suppressions.test.ts resolves the previous tooling check failure, and commit signature is verified.

@orswn
orswn merged commit 6b8aa56 into boon Oct 29, 2026
146 checks passed
@orswn
orswn deleted the okka/eng-21904/timeout-overflow-fixes branch October 29, 2026 08:37
orswn added a commit that referenced this pull request Oct 30, 2026
…advice (#315)

When a long reply turn fails, the progress-nudge runner posts one
notice: "The run hit an error before it could finish. You can send the
request again, or narrow it into a smaller batch." Two cases make that
notice wrong.

The Boon web channel plugin already posts its own outcome for every
turn it dispatches: the reply, a failure message, or a halt row with
Retry or Continue. The core notice then lands next to that row. It
duplicates the plugin's failure message, or it contradicts a halt row
that the backend later retries on its own. In production, almost
every Boon web notice had a plugin or agent row in the same second.

A turn can also fail while sub-agents that it spawned keep running.
Their results still reach the user later, so "send the request again"
makes the user repeat work that is already in progress.

Add an optional ChannelCapabilities.reportsTurnOutcome flag. When the
delivery target's channel plugin declares it, the runner logs and
skips the terminal failure notice before any edit or send. Channels
without the flag keep the notice. When live sub-agent work spawned by
the failed turn remains, the notice uses the existing
subagent_still_working copy instead of the resend advice. Sub-agents
from earlier turns do not count, so an unrelated failed turn still
gets the resend advice. Progress nudges do not change.

Add a regression test for a false notice fixed in #313: a mid-turn
precheck error, then a recovered attempt that ends with
sessions_yield. The run must end, not fail.
The test fails when the reply runner keeps the earlier finishing
error.

Related: ENG-21129
orswn added a commit that referenced this pull request Nov 2, 2026
Cut the fork release for the 6 PRs merged to boon since
v2026.6.35-boon.2:

- #313 (ENG-21904, ENG-21905): no fallback after the run deadline, no
  late replies from timed-out sub-agents, and no false error notice
  after a recovered context precheck.
- #314 (ENG-21269): a parent that yielded keeps finished sub-agent
  results on later wakes.
- #315 (ENG-21129): skip the failure notice on channels that report
  their own turn outcome, and say the work continues while the failed
  turn's sub-agents still run.
- #311: qs override 6.16.1 (CVE-2026-82417).
- #317: follow-redirects override 1.16.2 (GHSA-mrwp-f3q8-3g9p).
- #312: Docker base digests to Node 24.22.1.

Bump the root package.json and npm-shrinkwrap.json, all 136 bundled
plugin manifests (scripts/sync-plugin-versions.ts), and the version and
openclaw peer floor in every extension npm-shrinkwrap.json. Add the
2026.6.35-boon.3 CHANGELOG.md section. No source or dependency change
beyond what already merged in the PRs above.
orswn added a commit that referenced this pull request Nov 2, 2026
Cut the fork release for the 6 PRs merged to boon since
v2026.6.35-boon.2:

- #313 (ENG-21904, ENG-21905): no fallback after the run deadline, no
  late replies from timed-out sub-agents, and no false error notice
  after a recovered context precheck.
- #314 (ENG-21269): a parent that yielded keeps finished sub-agent
  results on later wakes.
- #315 (ENG-21129): skip the failure notice on channels that report
  their own turn outcome, and say the work continues while the failed
  turn's sub-agents still run.
- #311: qs override 6.16.1 (CVE-2026-82417).
- #317: follow-redirects override 1.16.2 (GHSA-mrwp-f3q8-3g9p).
- #312: Docker base digests to Node 24.22.1.

Bump the root package.json and npm-shrinkwrap.json, all 136 bundled
plugin manifests (scripts/sync-plugin-versions.ts), and the version and
openclaw peer floor in every extension npm-shrinkwrap.json. Add the
2026.6.35-boon.3 CHANGELOG.md section. No source or dependency change
beyond what already merged in the PRs above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants