Repository navigation
fix: shorten the first update's outage by skipping an idle second Doctor - #206227
Conversation
…g to wait for During a package update the first Doctor deferred model retirement on every run, and that recorded deferral made the updater start a second Doctor after plugin convergence. With no plugin install to converge and no change from the deferred repairs, the second Doctor had nothing to do but still ran with the Gateway stopped.
…-idle-retirement-doctor
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: passed. What this changesThis PR avoids recording deferred model retirement when the existing repairs have nothing to change or warn about. Example: Update from v2026.11.10 with no installed plugins and no pending model repairs.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this maintainer-authored draft open: it addresses unnecessary update downtime still present on main, and source review found no definite introduced bug. Reviewed head: Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherDuring a shipped updater's first upgrade, candidate Doctor inspects configuration and plugin state; its retirement receipt helps the updater decide whether another Doctor must run before restart. flowchart TD
A[Published updater] --> B[Candidate Doctor]
B --> C[Plugin repair facts]
C --> D[Preview existing repairs]
D --> E[Retirement deferral receipt]
E --> F[Post-plugin Doctor selection]
F --> G[Gateway restart]
Technical reviewBest possible solution: Keep the retirement decision in Doctor and skip its second invocation only when existing repair owners establish that no deferred work remains. Do we have a high-confidence way to reproduce the issue? Current-main source connects unconditional package-swap deferral to the second-Doctor selector, and the linked discussion reports that extra invocation during published-release upgrades; no target code was executed in this read-only review. Is this the best way to solve the issue? The patch removes the unnecessary receipt at its producer, reuses existing repair owners, and conservatively retains deferral for install activity, records, warnings, and explicit replacements. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against eb0faf79a5be. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +68, Tests +86. Total +154 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 26, 2026, 6:41 PM ET / 23:41 UTC. |
|
Merged via squash auto-merge.
|
…tor (openclaw#206227) * fix(doctor): skip the second update Doctor when retirement has nothing to wait for During a package update the first Doctor deferred model retirement on every run, and that recorded deferral made the updater start a second Doctor after plugin convergence. With no plugin install to converge and no change from the deferred repairs, the second Doctor had nothing to do but still ran with the Gateway stopped. * test(update): give the retirement completion case a model reference to retire
…tor (#206227) * fix(doctor): skip the second update Doctor when retirement has nothing to wait for During a package update the first Doctor deferred model retirement on every run, and that recorded deferral made the updater start a second Doctor after plugin convergence. With no plugin install to converge and no change from the deferred repairs, the second Doctor had nothing to do but still ran with the Gateway stopped. * test(update): give the retirement completion case a model reference to retire (cherry picked from commit e25b5a5)
…tor (#206227) * fix(doctor): skip the second update Doctor when retirement has nothing to wait for During a package update the first Doctor deferred model retirement on every run, and that recorded deferral made the updater start a second Doctor after plugin convergence. With no plugin install to converge and no change from the deferred repairs, the second Doctor had nothing to do but still ran with the Gateway stopped. * test(update): give the retirement completion case a model reference to retire (cherry picked from commit e25b5a5) Companion audit: f9a8f18 is row 25, a separate warning cleanup once durable retirement completes; preserve that row order. Companion audit: f9a8f18 is independently selected at row 25. Release adaptation: Preview only the stable stale-plugin and model-reference repair owners; the source-only implicit OpenAI preservation step does not exist on stable. Co-authored-by: RomneyDa <[email protected]>
Related: #204775
What Problem This Solves
Updating from a published release (for example 2026.11.10) to this release runs this release's Doctor twice while the Gateway is stopped. The second run started on every such update: the first Doctor always recorded "model retirement deferred until configured plugin installation converges", and that recorded deferral makes the updater start a second Doctor after plugin convergence. On an install with no plugin to converge and no model reference to retire, that second Doctor repeated config and chat-history checks and changed nothing. It cost 6 to 7 s of outage on Linux and 46 to 53 s on Windows Server (2 vCPU).
User Impact
A first update from a published package no longer runs the idle second Doctor, so the Gateway is back sooner. The repairs and migrations are the same: the resulting schema versions, config, database row counts and a chat turn through the restarted Gateway match the build without this change. When retirement or stale plugin config repair does have work, or a plugin install can still change during convergence, the update waits and runs the second Doctor as before.
Why This Change Was Made
The model retirement owner (
runDoctorRepairSequence) already knows, at the moment it records the deferral, everything the second Doctor would decide on: the second Doctor starts from the config the first one writes, and with no install record and no pending install repair the plugin inventory cannot change in between. So before recording the deferral it now runs the three repairs the second pass would run (stale plugin config, implicit OpenAI primary, stale model references) on a private copy of the candidate config, in the same order. It records the deferral only if one of them would change or warn, or if convergence can still change plugins: any install record, install repair change, warning or notice, a failed plugin install, or explicit model replacements. No new stored field, flag or protocol: the post-core decision (completePostCorePluginUpdate) keeps reading the existing ledger step, which simply is not written when there is nothing to wait for.Cost: the private-copy check adds about 0.5 s inside the first Doctor (the "Config repairs" phase went from under 0.3 s to 0.8 s in the cells).
Update behavior. The installed 2026.11.10 runs the update. With the Gateway stopped it calls this release twice:
infra/update-migrated-finalize.worker.js --doctor(the first Doctor, through 2026.11.10'srunPackageUpdateDoctor), then--post-core, which runs this release'sopenclaw updatecontinuation. This change is in the first call: the first Doctor no longer records the deferral when nothing waits on convergence. The second call reads that ledger and, with plugins unchanged, no longer starts the second--doctor(and its capability probe). Nothing in the installed updater changes; any published driver that hands off to this release's post-core gets the shorter stop on its first update. Updates driven by this release's own path are unaffected unless they set the package-swap marker, and then the same rule applies.Where the first update's outage goes (Linux, before)
Installed published 2026.11.10 (npm global, systemd user Gateway), candidate
mainpacked as an unpublished version,/readyzprobed every 250 ms, run record step times, ms-stamped updater stderr. 4 GiB agent database with 1 MiB/s of writes while serving (cell G-base.1):--doctor, called by 2026.11.10--post-core, called by 2026.11.10--doctor, called by this release's post-coreDoctor runs twice inside the stop on Linux too, as on Windows. Doctor 1 is the real migration. Doctor 2 ran only because of the recorded deferral: plugins were unchanged (
finalize:plugins:0, retirement-only selection) and it changed nothing.Ranked by seconds the new release can remove without the installed updater:
Evidence
Driver for every cell: published 2026.11.10 from npm. Base candidate:
main(red at3495c164737, comparison base atfcc9a0648c2), packed as 2026.11.13. Head candidate: this PR's production code at474dce4fafa, packed as 2026.11.14 (later commits on the branch change one test and mergemain; no Doctor or update path file moved, checked withgit diff --name-only). Every run:openclaw update --yes --jsonexit 0, run recordsucceeded, Gateway serving the candidate afterwards.--doctor)3495c164737fcc9a0648c2fcc9a0648c2474dce4fafa474dce4fafa474dce4fafa3495c164737fcc9a0648c2474dce4fafa474dce4fafafcc9a0648c2474dce4fafafcc9a0648c2474dce4fafafcc9a0648c2474dce4fafaIn every head cell without a reason to wait, Doctor 2 did not run and post-update verification (the stretch that contains it) went from 9.9 to 13.7 s to 3.5 to 4.8 s. Not serving, base vs head: empty state 50.4, 50.5 and 56.5 s vs 43.8, 50.9 and 50.9 s (the ranges overlap; on this host identical cells differ by up to 7 s); 4 GiB store 107.2 and 108.7 s vs 93.6 and 99.1 s; configured model 60.7 vs 49.9 s. The N and F controls take the same path on both sides and still differ by 21 to 32 s: that is host load from other work on the machine (every phase of those head cells is slower, including the installed updater's own database snapshot), not this change.
Cells E and G are an empty state and a 4 GiB agent database under 1 MiB/s of writes. R has a configured model with an available provider (
anthropic/claude-sonnet-4-5), the usual case for a real install.Same repairs and migrations (state after each update, base vs head): for every pair, all five databases have the same
user_version(agent 45, state 42, quarantine 2, credentials 1, services 1), identical schema hash and identical row counts per table; the config file is identical apart from the port, which is random per cell, and the wizard timestamp;chat.injectthrough the restarted Gateway succeeds andchat.historyreturns both the new marker and the one written before the update.Negative controls (state that really needs the second Doctor):
agents.defaults.model.primarynames a provider that does not exist. Head still recordsfinalize:doctor:model-retirementas deferred, runs the second Doctor, and leaves the same config and databases as base.agents.defaults.model.primaryis replaced withanthropic/claude-sonnet-4-5andfinalize:doctor:model-retirementiscompletedon both sides.Recordings (replays of the raw cell output; timestamps and values come from the logs below):
Red (base):
https://github.com/user-attachments/assets/b352aabf-3cce-4611-ad03-7d279addc06c
Green (head):
https://github.com/user-attachments/assets/e22354ec-0f1e-4ef7-b93f-9a45c44e071b
Controls:
https://github.com/user-attachments/assets/8d4977f6-3227-4a2a-b5e0-6f9b955ac1b1
Raw: per-cell split (run record steps, systemd, /readyz)
Raw: Doctor phases from the stamped updater stderr
Raw: state comparison base vs head
Tests
src/commands/doctor/repair-sequencing.test.ts: newpackage update doctor passcases. The "nothing to change" case fails onmainand passes here; the four "waits" cases pass on both (they guard against skipping real work). 36/36 pass.src/cli/update-cli/update-command-resume-completion.test.ts: the "retires the settled model warning" case relied on the unconditional deferral. Its config now names a stale primary with an available fallback, so the deferral and its completion still happen and the case keeps testing warning retirement. 11/11 pass.doctor-config-flow,auth-alias-migration,auth-alias-preservation,doctor-repair-setup,doctor-config-flow.billing-route,doctor-update-run,doctor-health.update,deferred-update-warnings,update-command-resume-completion,update-command-fresh-doctor,repair-sequencing.pnpm tsgo:corepasses; session identity ratchet passes; autoreview (Codex, P0 to P2): no findings.Files audited in full: both touched test files. Nothing was removed; the only edit to an existing case is the config change above.
Windows estimate (not measured on this change). On Windows Server 2025 x64, 2 vCPU, published 2026.11.10 to
mainrecorded the same deferral, unchanged plugins and a retirement-only second Doctor of 46.3 to 52.8 s inside a 322 to 344 s outage. If that install has no plugin install record and nothing to retire (the onboarded test install appears to have neither, not verified), this change removes that run: roughly 45 to 55 s, about 15% of the outage. The first Doctor (107 to 114 s) and the installed updater's runtime retention are unchanged.Not proven: no Windows or macOS cell on this change; no cell with an externally installed plugin (those keep the second Doctor by design); one to three runs per cell, so totals are within host noise; the Doctor 1 section breakdown for the 4 GiB cell comes from progress line timestamps because the update's
Doctor sectionsdiagnostic is truncated (it now leads withpending.*entries).