Skip to content

fix: keep restart recovery from starving scheduled jobs - #192197

Merged
steipete merged 4 commits into
mainfrom
steipete/perf-micro-restart-resume-floods-cron-nested-lane-20260919
Nov 3, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/perf-micro-restart-resume-floods-cron-nested-lane-20260919

Conversation

@steipete

@steipete steipete commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Restart-resumed dashboard turns were classified as cron work, flooding the eight-wide cron-nested lane ahead of new jobs. Cron jobs also spent their runtime budgets during explicit capacity waits.

User Impact

Host restart events use the existing bounded restart-recovery lane, configured by agents.defaults.maxConcurrent. New cron runs can proceed while recovery drains; scheduled automation retains its cron lane and per-session ordering remains intact. The scheduler preserves remaining runtime across reported lane waits, including waits after execution begins. Silent setup and teardown stalls remain bounded. No new config, cache, or schema.

Measured fairness tradeoff: new cron queue p99 falls 8.47 s→1ms, while recovery queue p99 rises 8.93 s→10.11s and median peak RSS rises 2.98→3.22GiB. Owner-accepted worse metrics: on 2026-11-03, the lead explicitly accepted recovery p99 +13%, worst-trial recovery wait +25%, and peak RSS +8% in exchange for new cron queue p99 8.47 s → 1 ms, with all 40 recoveries completing.

Why This Change Was Made

The reply runner routed every internal event to cron-nested even though restart events retain sourceTool restart provenance. The existing restart-recovery capacity owner was already configured but this dispatch did not select it. Selecting that lane fixes the classification at its owner with no new admission machinery.

The watchdog now pauses explicit lane waits and resumes the remaining budget. It retains the silent-startup protection introduced in #188982. cron.maxConcurrentRuns was deliberately retired/rejected in #111382; current docs do not advertise it, so no option is restored.

Production delta: +9 lines (+3 lane selection, +6 remaining-budget accounting). Net tests/helper: +455; measurement tooling: +114. Documentation explains runtime-budget and recovery-lane behavior.

Evidence

The committed real-Gateway harness interrupts 40 dashboard turns via SIGTERM, requires graceful exit and 40 durable markers, restarts at width 8, and submits 12 public cron runs 100 ms apart. All 40 unique recoveries and 12 persisted successful cron outcomes settle. The regression fails at its intended lane assertion on exact baseline 37f6f4e. The watchdog regression also fails before the fix: two 20-minute lane waits preserve a 1-second budget; 250 ms spent leaves 750 ms.

Final campaign: synthetic 35.13GiB DB, 10,000 sessions / 1 million events, 62,000 workspace files / 1.116 GB, APFS clones. Two A/A controls plus five counterbalanced baseline/candidate pairs, serial fresh state/ports. Identical profiling; source/build/apparatus hashes pinned. Existing usage projection warms through public usage.cost before workload, with warmup recorded separately. Every trial has 2 profiles and 52 queue observations. Local deterministic Responses service uses 1-second recovery service; this proves real Gateway/storage/queue behavior, not production provider or btrfs latency.

Each table cell is the median across five trial statistics, followed by the trial range. Within-trial p99 is nearest-rank maximum with 12/40 samples; no production-tail extrapolation.

Metric Baseline Candidate
New cron lane wait p50/p99 7,712/8,471ms 0/1ms
New cron request→model p50 9,229ms [9,099–9,331] 1,580ms [1,216–1,914]
New cron request→model p99 9,806ms [9,317–10,534] 3,018ms [2,336–3,531]
Recovery lane wait p50 7,755ms [5,487–8,325] 7,612ms [6,441–9,819]
Recovery lane wait p99 8,929ms [7,521–9,406] 10,111ms [8,801–11,759]
Recovery first→model dispatch p99 16,680ms [12,032–17,711] 18,229ms [13,678–20,315]
Restart→first recovery model 14,359ms [11,188–14,513] 11,265ms [10,257–16,419]
Gateway process CPU 49,393ms [39,956–53,523] 50,011ms [42,353–55,932]
Main-thread CPU 15,738ms [13,371–18,624] 16,357ms [13,859–18,819]
Sampled main-isolate allocation 8.03GiB [7.52–8.10] 8.20GiB [8.01–8.50]
Peak Gateway RSS 2.98GiB [2.90–3.03] 3.22GiB [2.90–3.55]

A/A changes: process CPU +5.3%, main CPU +9.2%, sampled allocation +3.2%, cron queue p99 +0.04%, recovery queue p99 −2.5%. Candidate median process CPU +1.3%, allocation +2.1%; these are smaller than A/A movement, not a statistical no-regression claim. Host load rose later; all samples are retained. First cron model call began after 33–38 completed recoveries on baseline and before any completed recovery in every candidate.

Recovery tail and memory worsen: median recovery queue p99 +13.2%, worst trial +25.0%, median RSS+8.0%. The worst candidate tail occurred at lower recorded host load than its paired baseline; noise alone is not an adequate explanation. Profiles show similar totalCPU and additional concurrent cron preparation/GC work; they do not prove one exclusive cause. Existing independent lanes allow cron to overlap eight recoveries. The lead explicitly accepted this bounded fairness/resource tradeoff on 2026-11-03. Landing is authorized under the inherited-red exception for the sole CI root failure: #191459 test-budget debt, reproduced on the exact CI main parent. Failed CI remains recorded as failed; security and review gates are not waived.

ProcessCPU includes Gateway workers, excludes child processes/local model server; sampled allocation and CPU profiles cover the main isolate. Profiles end after settled workload before cleanup. Initial restart still requires SIGTERM exit 0. Earlier cold-fixture shutdown-grace failures and one missing beforeExit-only profile were excluded as setup/capture failures; final explicit checkpoints passed all 12 trials.

Focused proof: 115 tests across 8 files / 5 shards, including real N40 restart (47.27 s); cron/session-model/command consumers, lane limits, session events, prefix stability. Targeted type/lint/format and diff checks pass. Independent full Codex autoreview and each fixture-only delta are scoped-clean through P2. Hosted Codex review completed on current head cffe3cc with no findings. No changed production module is UI-imported.

Current-head CI 41711052126, attempt 2: all selected jobs/security pass except test-line ratchet and its aggregate. Attempt1 checkout exhausted 3 fetch timeouts; one diagnosed infrastructure rerun succeeded at checkout. The remaining failure is reproduced on exact CI main parent 8e68dcc: 6,442,159 test LF versus 6,441,800 ceiling, 359 over, exit 1, comparing against pre-introducer parent e016b63. Introducer dde161a / #191459 added 405 test LF without allocation against 46 slack. Our 455 LF have 455 allocation. Native inherited-failure evidence pins actual tested merge a5b5aebabf1773dafdfddba8292afc9afa44c89d and unchanged failure-owner inputs. No CI-green claim.

pnpm check:changed separately found inherited unused export ui/src/pages/systems/systems-sidebar.tsx: systemKind, reproduced on exact original baseline 37f6f4e. Introducer 9ce5ba1 / #192070 removed its final external consumer. All change-specific findings were fixed and focused checks passed. Both inherited defects are recorded as main regressions for follow-up; no unrelated UI changes or allocation inflation.

Route host restart events through the existing bounded recovery lane. Preserve cron execution budget across explicit lane waits while retaining setup and execution watchdogs. Add real-process restart and timeout regressions with a synthetic performance harness.
@clawsweeper

clawsweeper Bot commented Nov 3, 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: L labels Nov 3, 2026
@steipete
steipete marked this pull request as ready for review November 3, 2026 19:14
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T20:19:39.159079Z cffe3cc 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.

@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. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 3, 2026
@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR separates restart recovery from cron capacity and preserves job runtime budgets across explicit lane waits.

Example: Forty conversations resume after a Gateway restart while 12 new cron runs arrive.

  • Before: Recovery work occupies cron capacity, delaying scheduled jobs and consuming their timeout budgets while queued.
  • After: Recovery uses its existing eight-wide lane independently, and queued jobs resume with their remaining runtime budget.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused and apparently correct, with meaningful production-entry-point evidence and green exact-head gates; declared performance acceptance remains incomplete.
Proof confidence 🦐 gold shrimp (3/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: Scheduled jobs wait behind restarted conversations and can time out before receiving execution capacity.
Reason: The maintainer-authored direction corrects demonstrated contention using existing owners and explicitly explains the changed timeout semantics.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a source-confirmed scheduling defect with a focused implementation and no definite introduced bugs found.

Priority: P2
Reviewed head: 32d57ff20d7eb1741b58339ce32b60b04b12215d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The declared large-state A/A controls and five counterbalanced A/B pairs remain unfinished, including their recovery-latency, CPU, and allocation acceptance results.
Agent review details

How this fits together

The reply runner selects execution lanes for conversation and automation turns; the cron watchdog consumes admission and execution callbacks to enforce job timeouts and cancellation.

flowchart TD
  A[Restart resume inputs] --> B[Reply runner]
  C[Scheduled jobs] --> B
  B --> D[Restart recovery lane]
  B --> E[Cron lane]
  E --> F[Agent execution]
  F --> G[Cron watchdog]
Loading

Technical review

Best possible solution:

Use the existing recovery lane and watchdog to isolate recovery capacity while charging only active runtime against cron budgets.

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

Current-main source establishes both paths; the author also reports intended baseline failures for the real-Gateway and watchdog regressions, which were not rerun during this read-only review.

Is this the best way to solve the issue?

The implementation fixes classification and accounting at their existing owners, preserves admission checks, and introduces no competing scheduler or configuration surface.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +9, Tests +419, Docs +24, Other +109. Total +561 across 11 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 2 24 15 +9
Tests 3 422 3 +419
Docs 3 27 3 +24
Config 0 0 0 0
Generated 0 0 0 0
Other 3 109 0 +109
Total 11 582 21 +561

Review metrics

Metric Value Why it matters
Production versus test growth Runtime +24/-15 lines; tests +422/-3 lines The nine net runtime lines reuse existing owners; test growth covers the real process-restart boundary and remaining-budget regression.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Restart bursts can delay scheduled work and cause premature timeouts, with impact limited to capacity contention.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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.

Reviewed November 3, 2026, 2:31 PM ET / 19:31 UTC.

@steipete
steipete merged commit ad524e6 into main Nov 3, 2026
177 of 183 checks passed
@steipete
steipete deleted the steipete/perf-micro-restart-resume-floods-cron-nested-lane-20260919 branch November 3, 2026 21:20
@steipete

steipete commented Nov 3, 2026

Copy link
Copy Markdown
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 Nov 4, 2026
)

* fix: keep restart recovery from starving scheduled jobs

Route host restart events through the existing bounded recovery lane. Preserve cron execution budget across explicit lane waits while retaining setup and execution watchdogs. Add real-process restart and timeout regressions with a synthetic performance harness.

* test: allow large restart fixtures to drain during shutdown

* test: prepare usage projection before large restart measurements

* test: capture restart profiles before fixture cleanup
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Release adaptation: backport only the Socket Mode reconnect waiter owner
and focused regression tests; omit the performance harness and main-only
transport documentation addition. Add listener-count assertions for timer
settlement and disconnect cancellation; adjust the test allocation to 41.

Companion dispositions: #198007 is specific to SDK 3.2 callback/abort
semantics and is not applicable to this line pinned to socket-mode 3.1.0.
#197657 retires main allocations; other audit hits (#200523, #197009,
#194964, #184507, #192197, #192051, #190003, #189850) only overlap the
excluded shared perf README. No later #188745 mention through bd692e9.

(cherry picked from commit a1d1da7)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
)

* fix: keep restart recovery from starving scheduled jobs

Route host restart events through the existing bounded recovery lane. Preserve cron execution budget across explicit lane waits while retaining setup and execution watchdogs. Add real-process restart and timeout regressions with a synthetic performance harness.

* test: allow large restart fixtures to drain during shutdown

* test: prepare usage projection before large restart measurements

* test: capture restart profiles before fixture cleanup

(cherry picked from commit ad524e6)

Release adaptation: Keep restart-recovery lane routing and pause cron execution budget during explicit restart-recovery admission. Exclude performance harness and large restart-lane E2E expansion; focused watchdog regression retained. No schema change.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant