Repository navigation
fix(agents): settle stale subagent runs from their own execution after Gateway restarts - #185106
Merged
Merged
Conversation
…ution Share requester-wake recovery execution mapping between the lifecycle listener and registry sweep. Resolve terminal timestamps and prepared replies through the exact agent-job record, preserving the registered run's parent obligation instead of borrowing a later session execution's timestamps. Leave unknown execution identity with existing recovery and timeout owners, then report the existing bounded stale-run failure. Keep completion ownership and duplicate delivery suppression unchanged. Cover recovery claims and receipts, unrelated later parent follow-ups, duplicate events and sweep passes, bounded unknown-run failure, and yielded collector results. Update existing sweep fixtures to supply exact terminal evidence while retaining their lifecycle, retry, and routing assertions. Validation: all 18 W51/W54 and affected consumer suites passed twice on the Crabbox runner (1,016 test executions). New wake regressions failed on W51 base and passed with the fix. Box oxfmt, oxlint, targeted typecheck, and independent review passed.
…ous boot Prefer the live agent-job snapshot, then recover terminal state only when session.lastRunId matches the registered or mapped recovered execution. Read that exact execution's persisted visible final so a Gateway restart does not strand successful child work or borrow a later run's completion. Keep the existing settlement and required-final owners. No schema changes. Cover registered and recovered executions across SQLite runtime restart, including restored replies and exactly one parent completion. Validation: all 18 targeted suites twice, remote oxfmt/oxlint and targeted typecheck. Both new restart cases fail on dde16336890 and pass with this fix.
Recover a retired plain spawn from its registry row when a later turn already owns the child session. Finalize through interrupted recovery and notify its parent without changing the newer session or borrowing its completion evidence. Keep hidden recovery successors with their existing task-lineage owner. Cover later active and completed turns through SQLite shutdown/reopen, assert recovery ownership during delivery, and prevent duplicate delivery after another restart. Document the retained-task ownership boundary. Validation: both new regression cases fail on f23f0bc and pass twice here. Run the W54 18-suite set twice; 17 suites pass, while the timeout-then-success reply case in subagent-registry.test.ts fails identically on the unchanged base (missing completion.terminalReply). Remote format, lint, targeted typecheck, docs inventory, and independent review pass.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
steipete
marked this pull request as ready for review
October 26, 2026 22:29
Contributor
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
Author
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 27, 2026
…r Gateway restarts (openclaw#185106) * fix(agents): settle stale subagent runs from their own recovered execution Share requester-wake recovery execution mapping between the lifecycle listener and registry sweep. Resolve terminal timestamps and prepared replies through the exact agent-job record, preserving the registered run's parent obligation instead of borrowing a later session execution's timestamps. Leave unknown execution identity with existing recovery and timeout owners, then report the existing bounded stale-run failure. Keep completion ownership and duplicate delivery suppression unchanged. Cover recovery claims and receipts, unrelated later parent follow-ups, duplicate events and sweep passes, bounded unknown-run failure, and yielded collector results. Update existing sweep fixtures to supply exact terminal evidence while retaining their lifecycle, retry, and routing assertions. Validation: all 18 W51/W54 and affected consumer suites passed twice on the Crabbox runner (1,016 test executions). New wake regressions failed on W51 base and passed with the fix. Box oxfmt, oxlint, targeted typecheck, and independent review passed. * fix(agents): keep persisted completion evidence for runs from a previous boot Prefer the live agent-job snapshot, then recover terminal state only when session.lastRunId matches the registered or mapped recovered execution. Read that exact execution's persisted visible final so a Gateway restart does not strand successful child work or borrow a later run's completion. Keep the existing settlement and required-final owners. No schema changes. Cover registered and recovered executions across SQLite runtime restart, including restored replies and exactly one parent completion. Validation: all 18 targeted suites twice, remote oxfmt/oxlint and targeted typecheck. Both new restart cases fail on dde16336890 and pass with this fix. * fix(agents): settle interrupted spawn runs after session reuse Recover a retired plain spawn from its registry row when a later turn already owns the child session. Finalize through interrupted recovery and notify its parent without changing the newer session or borrowing its completion evidence. Keep hidden recovery successors with their existing task-lineage owner. Cover later active and completed turns through SQLite shutdown/reopen, assert recovery ownership during delivery, and prevent duplicate delivery after another restart. Document the retained-task ownership boundary. Validation: both new regression cases fail on f23f0bc and pass twice here. Run the W54 18-suite set twice; 17 suites pass, while the timeout-then-success reply case in subagent-registry.test.ts fails identically on the unchanged base (missing completion.terminalReply). Remote format, lint, targeted typecheck, docs inventory, and independent review pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Fixes false subagent failures and stuck parent batches after a Gateway crash when child sessions have since been reused.
User Impact
Parents receive the result attributable to their own child run. Interrupted plain spawns settle promptly after restart without changing a newer turn on the same session. No configuration changes or migration are required.
Why This Change Was Made
After a Gateway crash, the registry sweeper could settle a stale subagent run with another execution's timestamps.
settleStaleActiveSubagentRunreconciled from the session's current state and checked only timestamp freshness. When a later execution on the same session had ended, the stale row borrowed that execution's end time without its reply. The completion owner then correctly rejected it:subagent run ended before producing a final reply. The parent received a false failure even though the mapped execution had written a visible reply. In live three-level fleet runs with Gateway kills, this produced about two false failures per run after #184925.Fix:
One shared recovery mapping (
resolveRecoveredSubagentExecutions) from a recovered execution to its registered run. Both the lifecycle listener (added in fix(agents): recover interrupted nested requester wakes after Gateway restart #184925) and the sweeper use it.The sweeper settles a stale run only from evidence attributable to that run or its mapped recovered execution. The in-process agent-job snapshot is preferred, since it carries the reply. Otherwise the persisted session completion is used when
lastRunIdmatches, together with that execution's persisted reply. This keeps prompt settlement for runs that ended in a previous Gateway boot: a run finished, the Gateway died before the registry recorded it, and the next boot settles it as ok.Unattributable evidence is no longer borrowed. Such rows stay with their existing owners and the existing bounded stale cutoff, then use the existing visible failure path.
Registry restart recovery now settles an interrupted plain spawn run whose session was reused by later turns before restart recovery ran. The ownership check correctly refuses to mark the newer turn interrupted, but recovery then skipped the old row because it had no interruption marker. It stayed
runningforever under the dead lifecycle generation, and with attributable-only settlement its parent batch would wait for the 2 h stale cutoff. The row is now finalized asinterrupted-recoveryand the parent is informed; the newer session is preserved.Exact task ownership is unchanged. Later parent follow-ups (
sessions_send) are not credited to older runs. There is one parent completion per registered run.Evidence
kill -9at +120 s and +300 s):cwd; the scenario forbids respawning, so the fix(agents): explain worker cwd binding on patch root escapes #184901 guidance could not be applied.subagent-registry.test.ts"suppresses stale timeout announces when the same child run later finishes successfully" fails identically on origin/main 4a1cda8 (1 failed | 102 passed) and is tracked separately.CI result
The exact-head CI run 40412838433 found one inherited failure in
server.goal-child-authority.product.test.ts: the line 620 transcript assertion expects two user messages but also sees two hiddeninternal_systemgoal-continuation messages. The same test fails identically on main605f1aa3a0dusingnode scripts/run-vitest.mjs src/gateway/server.goal-child-authority.product.test.ts --maxWorkers=1. The test file is byte-identical on main and the tested PR merge. Landing uses the authorized native inherited-failure route; no assertion or runtime code was changed to bypass this failure.