Skip to content

fix: keep scheduled work with cron across Gateway restarts - #201757

Merged
steipete merged 2 commits into
mainfrom
fix/restart-resume-automation-owner-2661
Nov 19, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/restart-resume-automation-owner-2661

Conversation

@steipete

@steipete steipete commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Restarting the Gateway while a scheduled automation runs in an ordinary conversation can tell the conversation owner that their request could not resume, even though they never sent that request. Shutdown was selecting the cron execution for operator recovery; its marker cleared correctly, but the next interrupted occurrence could be selected again.

User Impact

Scheduled work keeps the cron scheduler's retry and next-tick behavior without an operator-authority failure notice. Interrupted operator turns still resume, and accepted queued inputs retain their durable custody. No configuration or schema changes are needed.

Why This Change Was Made

Shutdown selection now honors the live input's automation owner and avoids selecting the same controller operation again through the run registry. A child-root candidate cannot override an active root's cron ownership. Accepted user-reply obligations retain the existing recovery path, including retry backoff while the backend is detached. Selection reads the controller’s retained run association. Failure diagnostics use a current writer/lifecycle run ID when available instead of attributing the failure to a historical lastRunId.

The live-owner selection moved into a focused sibling module to stay within the existing line limit. Production grows by 44 lines for that boundary and the explicit ownership decision; there is no new cache or persisted state. Requester-settle recovery remains unchanged, including the completion restoration from #201706.

Evidence

The new real-Gateway regression fails on parent f250a678c8138fcf86799cb3ef2db692b61936c9: shutdown writes an unavailable-operator marker for the dashboard cron turn. With the fix, that marker is absent, a concurrent operator turn resumes, and cron runs on its next tick without an operator-authority notice. All 62 focused restart/admission/yield/custody tests passed. A second regression fails on the initial PR head when a steered cron turn detaches its backend; the repaired selector preserves its required user reply. The 34 steering tests and affected subagent cancellation tests pass.

A synthetic fixture contained 10,000 sessions, 1,000,000 events, a 35.13 GiB agent database, and 62,000 workspace files totaling 1.116 GB. Five counterbalanced pairs with three calls per arm used 30 operator and 30 cron registry-only owners. This measures the run-registry fallback, not provider retries or steering; that measured path is unchanged by the backoff repair. Markers fell from 60 to 30 and worker tasks from 121 to 61 per call. Median owner wall time was 174.38 → 49.20 ms, process CPU 142.18 → 75.34 ms, and separately sampled host allocation 6.96 → 3.71 MiB. Shared-host timing was noisy: timing A/A medians were 388.92/218.30 ms, CPU 183.92/152.81 ms; allocation A/A was 6.91/6.99 MiB. These are local APFS owner measurements, not production/btrfs restart latency claims.

The initial CI run also exposed a stale assertion in the existing graceful-shutdown parent test. It fails identically on exact main parent f250a678c8138; #201706 (d54f706b921a) restored the interrupted child completion, so the yielded parent receives that result instead of a generic resume. This PR updates the test to require exactly one matching child error completion, zero duplicate generic resumes, and a visible reply. Both graceful restart modes pass. This repairs an inherited main test regression; no subagent recovery implementation changes are included.

Validation: real-Gateway regression; four focused owner suites; pnpm check:changed; isolated Codex autoreview. No UI-imported production modules changed.

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: M labels Nov 19, 2026
@steipete
steipete marked this pull request as ready for review November 19, 2026 09:38
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T10:11:46.795483Z 839aba2 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 748fc24abd

ℹ️ 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".

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR leaves interrupted scheduled turns under cron ownership while preserving accepted user work and correcting restart-failure attribution.

Example: A cron job runs in agent:other:main:thread:restart-resume-0-stream when the Gateway restarts.

  • Before: Shutdown creates an operator recovery marker, which can produce a misleading authority failure.
  • After: Cron retains recovery ownership, while a concurrent operator turn keeps its ordinary restart continuation.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation resolves the prior finding, but supplied automated fixture results do not clear the required real-setup proof gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A conversation owner receives a restart-authority failure for scheduled work they did not submit.
Reason: The maintainer-authored direction restores the existing cron ownership contract without a new runtime setting; the added --automation flag is confined to the benchmark script.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still selects scheduled conversation work for operator recovery, and the prior backend-detach finding is resolved with no new blocking code defect found.

Priority: P2
Reviewed head: 839aba2cb41dae288eca725a54fcefd689db5774

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted runtime output from an isolated real-model Gateway showing interrupted conversation-targeted cron work returning to cron while operator work resumes, including accepted steering interrupted between backend attempts.
Agent review details

How this fits together

Gateway shutdown selects live controller and registry work, preserves queued-input custody, and writes session restart markers that startup consumes through existing authority checks.

flowchart TD
  A[Live session controller] --> C[Restart selection]
  B[Run registry] --> C
  C --> D[Session restart markers]
  D --> E[Startup authority admission]
  E --> F[Conversation continuation]
  C --> G[Cron retains scheduled work]
Loading

Technical review

Best possible solution:

Keep the existing controller, cron scheduler, and restart persistence owners, using retained logical run associations to preserve accepted user obligations.

Do we have a high-confidence way to reproduce the issue?

Current-main selection exposes the reported path, and the author reports a parent-red/head-green Gateway regression; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch fixes selection at its existing owner, preserves queued custody, and replaces the prior attached-backend check with the controller's retained association.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against dbf41b9173f6.

Provenance checked

  • Restart selection keeps the original intent (9344233: The restart redesign reused ordinary session input instead of reconstructing executions; later fixes retained cron's separate recovery owner.)
  • Retained backend run association keeps the original intent (36e277d: The session controller retains exact backend run identity across detach until operation settlement.)
  • Failure run attribution changes intended behavior with a stated reason (9344233: Earlier recovery used lastRunId as a diagnostic fallback; this PR explains that a historical run can misidentify the interrupted work.)
  • Yielded parent regression expectation keeps the original intent (d54f706: Startup restores the required interrupted child completion rather than issuing a duplicate generic parent resume.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +44, Tests +203, Docs +5, Other +17. Total +269 across 11 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 171 127 +44
Tests 4 250 47 +203
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 1 20 3 +17
Total 11 446 177 +269

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Runtime versus regression coverage Runtime +171/−127 lines; tests +250/−47 lines The net 44 runtime lines reuse existing ownership and move selection into one focused module; the tests cover cron exclusion, detached-backend custody, diagnostics, and restored child completion.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs misleading restart recovery for scheduled work in ordinary conversations without evidence of an urgent widespread outage.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-19T09:55:12.832Z sha 748fc24 :: needs changes before merge. :: [P2] Preserve accepted reply ownership while the backend is detached

Reviewed November 19, 2026, 5:13 AM ET / 10:13 UTC (Revision 2).

Use the existing retained run association so accepted user replies survive provider backoff. Update the inherited parent restart assertion from #201706 to require the restored child completion instead of a duplicate generic resume.
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L and removed size: M labels Nov 19, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the latest review on 839aba2cb41dae288eca725a54fcefd689db5774:

  1. Preserve accepted reply ownership while the backend is detached (P2). The selector now reads the operation's retained backend run IDs and checks their accepted-user obligation (selection lines 103–112). It reuses the controller's existing association (state lines 417–420); both prior exact-run consumers use that same owner API. The regression accepts a user reply, detaches the backend, then invokes shutdown persistence (test lines 64–74). It fails on the initial PR selector and passes with the repair. Steering and subagent cancellation tests also pass.

The cited CI parent-recovery failure reproduces on exact main parent f250a678c8138fcf86799cb3ef2db692b61936c9. Owner history identifies #201706 (d54f706b921a): startup restores the interrupted child's completion, while this older test still expected a generic parent resume. The test now requires exactly one matching child error completion, a visible reply, and zero generic duplicate resumes (assertions). Both graceful restart modes pass. No subagent recovery implementation changed.

The subprocess Gateway regression exercises the real scheduler, agent, session database, shutdown, startup admission and operator continuation against a deterministic synthetic Responses endpoint. It is red on the parent and green on this repair; cron runs on its next tick without an operator-authority notice. This is synthetic-provider boundary evidence, not a live-provider claim. No provider protocol, schema, configuration or migration changed. pnpm check:changed, focused tests, final test lint/typechecks and isolated Codex autoreview (P0–P2, scoped-clean) pass. Updated PR evidence includes the benchmark limits and inherited test regression. Exact-head CI is running.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit cb04fef into main Nov 19, 2026
133 of 138 checks passed
@steipete
steipete deleted the fix/restart-resume-automation-owner-2661 branch November 19, 2026 10:23
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 20, 2026
…201757)

* fix(gateway): keep interrupted automation with its scheduler

* fix(gateway): retain steered work between backend attempts

Use the existing retained run association so accepted user replies survive provider backoff. Update the inherited parent restart assertion from openclaw#201706 to require the restored child completion instead of a duplicate generic resume.
tideclaw-bot pushed a commit that referenced this pull request Nov 23, 2026
* fix(gateway): keep interrupted automation with its scheduler

* fix(gateway): retain steered work between backend attempts

Use the existing retained run association so accepted user replies survive provider backoff. Update the inherited parent restart assertion from #201706 to require the restored child completion instead of a duplicate generic resume.

(cherry picked from commit cb04fef)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 2324999c64c047bc97813153e345d35cdf26be2b)
(cherry picked from commit 1d8de7fa3709981f7b6fcfd176d79f0277f9112d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant