Repository navigation
refactor: resume running sessions after graceful restarts - #185730
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
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. |
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: faad203a6e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
faad203 to
ea480fd
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea480fd470
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
a4d8e70 to
0497f26
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0497f26319
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
0497f26 to
5813756
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5813756cbb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
76bbf03 to
201ea12
Compare
|
@clawsweeper re-review Current head: |
|
🦞👀 Re-review progress:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 201ea12c50
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
201ea12 to
5862784
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5862784246
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const client = createSyntheticPluginRuntimeClient({ | ||
| operatorRoleActor: { kind: "operator", profileId: authority.profileId }, | ||
| operatorRunAuthority: authority, | ||
| scopes: [...authority.scopes], | ||
| }); |
There was a problem hiding this comment.
Preserve mention publication for retained queued inputs
When a queued Control UI message contains human mentions and survives a graceful restart, this synthetic client has no authenticatedUserProfile. Although createGatewayChatUserTurnController restores selectedMentions from the retained message, it derives senderProfileId exclusively from client.authenticatedUserProfile and consequently skips installing onOriginalInputCommitted. Staging does not publish mentions, so the message eventually executes without notifying its selected recipients. Derive the mention publication sender from the freshly admitted queued-input principal as well.
Useful? React with 👍 / 👎.
| ...(message["__openclaw"]?.suppressCommandInterpretation === true | ||
| ? { suppressCommandInterpretation: true } | ||
| : {}), | ||
| queueMode: "followup", |
There was a problem hiding this comment.
Restore the reply target when readmitting queued messages
When an accepted queued message replies to an earlier transcript message, the retained message preserves __openclaw.replyToId, but this reconstructed chat.send request omits it. createGatewayChatUserTurnController only creates replyContextFieldsPromise from request.p.replyToId, and the dispatch path restores only the approved message text, not its reply metadata. The resumed turn therefore loses the quoted target and sender context, so an input such as “do this instead” can execute without the reference the user selected. Restore the retained reply target during readmission.
Useful? React with 👍 / 👎.
What Problem This Solves
Graceful Gateway restarts can wait on busy agent work for tens of seconds, then reconstruct execution through competing recovery owners and hold new user input behind recovered runs.
The motivating incident had 15 restarts in one day, each draining roughly 170–185 operations including about 20 agent runs. Restart recovery occupied approximately 290 non-test files / 57k lines across a dozen owners, following roughly 200 restart-fix commits in 30 days. One new prompt waited 14m15s in admission behind recovered work. Shutdown also failed on retained plugin resources and stalled for about 80 seconds in lifetime sidecar cleanup.
User Impact
A graceful restart records which root sessions are running, promptly aborts their work, then sends each one ordinary input asking it to inspect current state and continue. Captured queued user messages follow in FIFO order under each sender's current authority. New messages use ordinary steering and queueing. The Control UI shows the conversation and normal composer, without recovery banners, interrupted-input notices, or bulk dismissal.
Accepted loss: a crash or SIGKILL records no shutdown marker, so nothing automatically resumes. The transcript remains available and a new user message works. Background processes do not survive a replacement process. When the shutdown snapshot saw running background exec, the same single resume input also says exactly: “Background exec processes were stopped; rerun them if still needed.” There is no exactly-once guarantee for external effects, child task adoption, or startup orphan reconstruction.
Refused or unavailable stores are skipped and logged, so one refused agent cannot hold healthy agents’ chat admission closed. If inventory discovery itself fails, automatic resume is skipped with a warning and fresh input remains available for healthy sessions.
Markers are cleared before admission. A crash or admission failure in that startup window can lose the automatic resume; no effect or input exactly-once machinery is added. The transcript and a fresh user input remain the recovery path.
Old recovery fields and inference-only queued rows remain readable but inert. Their text is preserved; normal retention may reclaim data previously pinned only by dead recovery state. There is no schema migration, Doctor migration, new config option, dependency change, or protocol version bump.
sessions.recoveris retired: repository-wide client inspection found only Control UI callers, with no shipped native client contract to preserve.Why This Change Was Made
Peter's direction:
One new owner,
src/gateway/session-restart-resume.ts, snapshots the existing live run, subagent requester ancestry, and background-process owners after admission closes and before aborting them. It storesresumeAfterRestart: { queuedInputIds, hadBackgroundExec?: true }in the existingsession_nodes.entry_json, with one replacement batch per physical session store. Nothing is checkpointed per turn or tool for restart recovery. Startup clears each marker and admits the standard resume input through the existing session-event path, preserving current admission, tool authority, routing, and reply delivery.Short cleanup cutoffs apply only to existing
exitAfterClose:trueprocess hosts; embeddedGatewayServer.close()joins owned cleanup. Startup rollback receives no inferred intent. The shutdown/supervisor ownersrc/cli/gateway-cli/run-loop-cleanup.tsowns bounded cleanup joins and exit classification. Bounded-grace leftovers are logged; lifecycle setsprocess.exitCodeand returns naturally. Retained resources prohibit reusing the runtime for an in-process restart. The already-armed native hard-exit watchdog is the sole backstop for leaked handles; a watchdog signal/nonzero exit in that case is accepted. Real required-write/finalizer failures remain failures. Healthy global retirement measured 2327ms, so resource cleanup gets 5s headroom; required persistence has a 3s bound. The existing owned-process supervisor receives its normal 5s TERM policy plus 1s extinction headroom before shared-state retirement. No line-cap or test-budget limits were raised.The coordinated cutover decisions are:
sessions.recovermethod, schema, validators, and manual recovery UI.exitAfterClose:trueis set; embedded close joins owned cleanup. Log leftover sidecars/plugin resources and exit rather than reuse an unsafe runtime. Bounded leftovers alone set exit code 0 and return naturally; leaked handles may require the existing native watchdog. Never reuse a retained runtime in-process.Live agent-tool caller context is preserved through resumed gateway tools and forced preflight compaction. Ordinary dispatch-error persistence, explicit completion reply obligations, quiet child completion, automation yield, and live FIFO reservation release from related fixes are retained. Restart reconstruction versions of those paths are deleted.
Evidence and current CI
Ready for coordinator admin merge at tested head
921837281c640928bda5f15cfb9af233fd88cdba, integrated maine85b3c8ddf64f463bf12b5abed67e55253f6a739. The coordinator owns landing; no merge attempt, new CI wait, or all-green CI claim.nice -n5, tests--maxWorkers=8)All requested 55 gateway/agent files reached assertions (775 passed / 2 RPC-timeout failures). Both timeout files pass final-head proof; the earlier failures remain investigated intermittent observations, not proven fixed/inherited. Exact current-main comparison reproduces only the 9 listed UI failures. No assertion loosening or timeout/retry/budget increase.
Acceptance is one isolated real Gateway with a mock provider and parallel sessions: running stream/tool/root-child/background work; idle exclusion; current authority and active caller context; gateway-backed tool and forced preflight compaction; ordinary steering; exact shutdown-captured FIFO and crash-left exclusion; final replies/history; graceful managed/SIGTERM shutdown and documented SIGKILL loss. All final assertions reached. Explicit PR e2e routing is retained.
Original installed base proof was semantically red: resume count 0/no final reply; SIGTERM20,542/20,543ms against unchanged10,000ms. Steering/FIFO passed on base and are not claimed red. Dedicated worktree removed, lease stopped. Embedded held-reset regression is separately red on b740/green with the boundary fix. Tooltip delayed reopen is red twice before repair/green after. Earlier slow Darwin shutdown and RPC observations remain unresolved; passing replays do not diagnose them.
Core, gateway-server, UI and UI-e2e-chat targeted types, matching type-aware lint, format, line-cap ratchet and diff checks pass. Gateway-other/UI-components proof is reused with unchanged inputs. Fresh isolated Codex P1 repair and conflict reviews are scoped-clean; author pr-simplify completed. 65 of 67 rebased patches are identical; remaining differences are retained main import context and combined UI readiness fences. Dependencies unchanged.
Original run 40486652848's 70 failed jobs were classified/repaired in prior batches (retired symbols, static cycle, lint, fixtures, ordinary FIFO/delivery/cleanup/current authority). Baseline changes only shrink retired entries. This new repair deletes no test. Main matching signatures for UI inheritance are independently reproduced with the native runner on the exact integrated main, rather than inferred from job names.
Commands use repository wrappers, nice -n5 / maxWorkers=8 and separate module caches. Full per-invocation results and exact commands are in the coordinator report. No live Gateway, production state, real channels/providers, deployment, release or version/config/dependency change.
Change size
1452 files changed, 19667 insertions(+), 124765 deletions(-); net -105,098 LOC.No line-cap, lint, test-budget or ratchet limits were raised.
Deleted tests and retained contracts
The deleted inventory contains 149 test/support/scenario paths: 137 pinned removed behavior plus 12 replaced by acceptance; zero duplicates. Six additional test/support paths are renamed/adapted with live behavior retained and counted separately. Rewritten cases moved into focused siblings to obey grandfathered caps; unrelated tests were not trimmed. Removed variants also include restored paused-child reservation reconstruction, operator/requester snapshot custody, recovery aggregate merging and obsolete startup observer modes; ordinary completion/yield, Stop and resource integrity remain.
Exact deleted paths by reason
Pinned removed reconstruction (137)
src/config/sessions/recovery-notice.test.ts— tombstone-bound hidden notice settlement, retired by generic resume.src/gateway/server.recovery-notice-history.test.ts— old recoverStore / sessions.recover notice continuation, retired by generic resume.src/infra/outbound/delivery-queue.recovery-notice.test.ts— special restart-notice history custody, retired; ordinary produced-byte replay tests retained.src/sessions/recovery-notice.test-support.ts— sole fixture for deleted special restart-notice tests.src/gateway/server.chat-goal-recovery.test-support.ts— newly landed Goal reconstruction bridge, superseded by the generic resume input.packages/gateway-protocol/src/schema/sessions-recover.test.tsqa/scenarios/runtime/gateway-restart-unclaimed-delivery.yamlsrc/agents/agent-command-admission-facts.test.tssrc/agents/agent-command-recovery-owner.test.tssrc/agents/agent-command-restart-recovery.test.tssrc/agents/agent-command.harness-compaction-custody.test.tssrc/agents/agent-command.recovery-source.test.tssrc/agents/agent-command.restart-settlement.test.tssrc/agents/agent-harness-completion-ownership.test.tssrc/agents/agent-harness-completion.test-support.tssrc/agents/agent-tools.restart-safe.test.tssrc/agents/bash-tools.exec-notify.test.tssrc/agents/code-mode-recovery.integration.test.tssrc/agents/interrupted-input-context.integration.test.tssrc/agents/main-session-recovery/main-session-harness-completion.test-harness.tssrc/agents/main-session-recovery/main-session-parent-recovery.test-harness.tssrc/agents/main-session-recovery/main-session-recovery-checkpoint.test.tssrc/agents/main-session-recovery/main-session-recovery-empty-aggregate.test.tssrc/agents/main-session-recovery/main-session-recovery-replay-boundary.test-harness.tssrc/agents/main-session-recovery/main-session-recovery-run-ownership.test.tssrc/agents/main-session-recovery/main-session-recovery-runtime.test-support.tssrc/agents/main-session-recovery/main-session-recovery-runtime.test.tssrc/agents/main-session-recovery/main-session-recovery-saturation.test-harness.tssrc/agents/main-session-recovery/main-session-recovery-state.terminal-residue.test.tssrc/agents/main-session-recovery/main-session-recovery-state.test-support.tssrc/agents/main-session-recovery/main-session-recovery-state.test.tssrc/agents/main-session-recovery/main-session-recovery-store.test-support.tssrc/agents/main-session-recovery/main-session-recovery-store.test.tssrc/agents/main-session-recovery/main-session-recovery-yield.test.tssrc/agents/main-session-recovery/main-session-restart-abort.integration.test.tssrc/agents/main-session-recovery/main-session-restart-dispatch-start.test.tssrc/agents/main-session-recovery/main-session-restart-owner-release.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-admission.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-delivery.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-discovery.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-fixture.test-support.tssrc/agents/main-session-recovery/main-session-restart-recovery-marking.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-peer-source.test-support.tssrc/agents/main-session-recovery/main-session-restart-recovery-peer-source.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-priority.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-resume-policy.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-retry.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-source-admission.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-terminal.test.tssrc/agents/main-session-recovery/main-session-restart-recovery-transcript.test-support.tssrc/agents/main-session-recovery/main-session-restart-recovery.memory.test.tssrc/agents/main-session-recovery/main-session-restart-recovery.test.tssrc/agents/main-session-recovery/main-session-terminal-approval-migration.test-support.tssrc/agents/main-session-recovery/main-session-terminal-approval.test-harness.tssrc/agents/pending-final-recovery-source.test.tssrc/agents/subagents/completion/subagent-completion-admission.queue-receipt.test.tssrc/agents/subagents/registry/subagent-accepted-recovery.restart-integration.test.tssrc/agents/subagents/registry/subagent-detached-recovery.restart-integration.test.tssrc/agents/subagents/registry/subagent-orphan-recovery.live-tail.test-support.tssrc/agents/subagents/registry/subagent-orphan-recovery.raw-owner.test-support.tssrc/agents/subagents/registry/subagent-orphan-recovery.restart-integration.test.tssrc/agents/subagents/registry/subagent-parent-recovery.restart-integration.test.tssrc/agents/subagents/registry/subagent-plain-spawn.restart-integration.test.tssrc/agents/subagents/registry/subagent-registry-queued-recovery.test.tssrc/agents/subagents/registry/subagent-registry-restart-recovery.test-support.tssrc/agents/subagents/registry/subagent-registry-restart-recovery.test.tssrc/agents/subagents/registry/subagent-registry-restore.test-support.tssrc/agents/subagents/registry/subagent-registry.persistence.orphan.test-support.tssrc/agents/subagents/registry/subagent-registry.persistence.wake.test-support.tssrc/agents/subagents/registry/subagent-registry.requester-completion.test-support.tssrc/agents/subagents/registry/subagent-registry.restored-settlement.test-support.tssrc/agents/subagents/registry/subagent-wake-recovery.restart-integration.test.tssrc/agents/subagents/spawn/subagent-spawn.recovery.test-support.tssrc/agents/tools/message-tool-retry-delivery.test.tssrc/auto-reply/reply/agent-runner.runreplyagent.transcript-claim.cases.tssrc/auto-reply/reply/recovery-controller.fixture.test-support.tssrc/auto-reply/reply/reply-turn-admission.recovery.test.tssrc/auto-reply/reply/restart-recovery-claim.durability.test.tssrc/auto-reply/reply/restart-recovery-claim.lifecycle.test.tssrc/auto-reply/reply/restart-recovery-claim.pending-input.test.tssrc/auto-reply/reply/restart-recovery-claim.successor.test.tssrc/auto-reply/reply/restart-recovery-claim.test.tssrc/commands/doctor-main-session-recovery.test.tssrc/config/sessions/main-session-recovery-fixtures.test-support.tssrc/config/sessions/restart-recovery-receipt.test.tssrc/config/sessions/restart-recovery-state.test.tssrc/config/sessions/session-accessor.recovery.test.tssrc/config/sessions/session-entry-recovery.worker.test.tssrc/config/sessions/session-transcript.worker.recovery-imports.test.tssrc/gateway/agent-input-recovery.test.tssrc/gateway/agent-turn/agent-restart-recovery-context.test.tssrc/gateway/chat-input-recovery.authority.test.tssrc/gateway/chat-input-recovery.test.tssrc/gateway/gateway.sessions-send-recovery.diagnostics.test-support.tssrc/gateway/gateway.sessions-send-recovery.diagnostics.test.tssrc/gateway/gateway.sessions-send-recovery.test.tssrc/gateway/operator-run-recovery.requester.test.tssrc/gateway/server-instance-runtime.native-restart-recovery.test.tssrc/gateway/server-instance-runtime.operator-recovery.test.tssrc/gateway/server-methods/agent.restart-recovery.test-support.tssrc/gateway/server-methods/chat-restart-recovery.worker.test.tssrc/gateway/server-methods/session-recovery-continuation.test.tssrc/gateway/server-recovery-runtime.test-support.tssrc/gateway/server-restart-sentinel.system-event-owner.test.tssrc/gateway/server-rpc-restart-owner.test.tssrc/gateway/server-run-shutdown.recovery.test.tssrc/gateway/server-startup-observers.test.tssrc/gateway/server.chat.orphaned-recovery.test.tssrc/gateway/server.recovery-peer-authority.test.tssrc/gateway/server.sessions.recover-in-place.test.tssrc/gateway/server.sessions.recover.authorization.test.tssrc/gateway/server.sessions.recover.test.tssrc/gateway/server.sessions.recovery-order.test.tssrc/gateway/server.sessions.recovery.test-support.tssrc/gateway/server.startup-recovery-boundary.test.tssrc/gateway/server.startup-recovery-webchat.test.tssrc/gateway/server.startup-recovery.test-support.tssrc/gateway/server.subagent-settle-replay-recovery.test-support.tssrc/gateway/server.subagent-settle-replay.harness.test.tssrc/gateway/server.subagent-settle-replay.test-support.tssrc/gateway/session-delivery-clock-jump.integration.test.tssrc/gateway/session-lifecycle-state.recovery.test.tssrc/gateway/session-send-recovery.authority.test.tssrc/gateway/session-send-recovery.delivery.mocks.test-support.tssrc/gateway/session-send-recovery.discovery.mocks.test-support.tssrc/gateway/session-send-recovery.notice-order.test-support.tssrc/gateway/session-send-recovery.quarantine.test.tssrc/gateway/session-send-recovery.test-support.tssrc/gateway/session-send-recovery.test.tssrc/gateway/session-send-recovery.upgrade.test.tssrc/gateway/session-startup-run-outcomes.test.tssrc/gateway/worker-environments/provider-provisioning.shutdown-replay.test.tssrc/infra/outbound/delivery-completion.recovery.integration.test.tstest/gateway-recovered-parent-continuation.live.test.tstest/gateway-subagent-restart.live.test.tsui/src/e2e/peer-followup-restart.real-gateway.e2e.test.tsui/src/e2e/sidebar-restart-recovery.e2e.test.tsReplaced by acceptance e2e (12)
src/cli/gateway-cli/run-loop-force.test-support.tssrc/cli/gateway-cli/run-loop-shutdown-budget.test-support.tstest/gateway-background-process-restart.e2e.test.tstest/gateway-goal-resume-restart.e2e.test.tstest/gateway-process-shutdown-recovery.e2e.test.tstest/gateway-restart-abort-settlement.e2e.test.tstest/gateway-restored-requester-settle.e2e.test.tstest/gateway-session-resume-restart.e2e.test.tstest/gateway-subagent-authority-restart.e2e.test.tstest/gateway-subagent-restart.e2e.test.tstest/gateway-tool-handoff-restart.e2e.test.tstest/gateway-widget-restart.e2e.test.tsThe failed-completion publication-reconciliation case moves to
subagent-completion-admission.store.test.ts; prepared-media promotion/publication ordering moves tosession-produced-media-delivery.test.ts; ordinary inference-time permission change moves togateway-session-permission.e2e.test.ts.src/gateway/session-delivery-clock-jump.integration.test.tsis deliberately removed because its entire contract replayed queued inference (agentTurn/ active system events) after a wall-clock jump. That execution path is retired, so renaming its fixtures would restore the wrong behavior. Clock rollback/jump/released-claim scheduling for already-produced byte delivery remains covered bysrc/infra/session-delivery-queue-runtime.test.ts(including “recomputes future claim timers after a clock jump” and “drains an eligible entry across a clock rollback”), with prepared-media retries insession-delivery-queue.storage.test.tsand produced-media publication ordering insession-produced-media-delivery.test.ts.Retained live responsibilities have named tests: current principal grants (
operator-run-authority.principal.test.ts), live caller/compaction custody (agent-command.compaction-custody.test.tsand acceptance), reversible suspend (gateway-suspend-coordinator.test.ts), shutdown exit/reuse (run-loop.direct-stop-active-work.process.test.ts,run-loop.test.ts,server-close.test.ts), normal chat admission/errors (server.chat.gateway-server-chat-b.test.ts,chat-send-detached-dispatch.test.ts), ordinary child completion/yield (server.subagent-silent-completion.product.test.ts, requester-settle dispatch/command reply-policy and automation-yield suites), produced outbound/media delivery (outbound delivery queue andsession-produced-media-delivery.test.ts), passive sentinel (server-restart-sentinel.test.ts), provisioning/file integrity (worker placement/provider/workspace-result suites), cron authority/catch-up (cron integration and requester cron authority), live harness security (agent-harness/native custody and SDK completion), and pending-input retention/FIFO (session-pending-input-history.test.tsand acceptance). Presence is not a claim that every suite has run on the final head; exact-head CI is the broad verdict.Control UI
Before: synthetic restart state with the manual Resume banner.
After: the same synthetic conversation with the ordinary composer. Inspected before/after screenshots are attached below.
The focused streaming repair preserves the normal assistant identity while a run has no persisted message yet. These synthetic captures were inspected in full: