Skip to content

fix: preserve worker environments during Doctor checks - #156160

Merged
steipete merged 1 commit into
mainfrom
codex/stable-activation-doctor-20260923
Sep 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/stable-activation-doctor-20260923

Conversation

@steipete

@steipete steipete commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes a Gateway crash after a diagnostic Doctor check closes its live worker-environment inventory, even though the shared database already has the current schema.

User Impact

Routine checks keep existing worker environments usable. Actual repairs still retire the old database generation, including when cleanup fails after repair; ownership refusals preserve the live generation. There are no schema, configuration, or permission changes.

Why This Change Was Made

The migration wrapper always closed shared-state resources after checking readiness. Move preparation and retirement into one asynchronous owner that records actual repair admission, preserving synchronous database transactions and the existing synchronous SDK repair API. Both migration callers use that owner.

Also keep a session-change callback from returning an already-tracked reconciliation promise into an ignored promise chain. The existing reconciliation owner continues to log failures and drain work at shutdown.

Evidence

  • Reproduced both no-op preparation modes with a real SQLite inventory: reads failed with Worker environment inventory has closed before the repair.
  • Reproduced the unhandled rejection through the actual placement startup/session-change subscription.
  • Reproduced a post-commit native-close failure that skipped resource retirement, with separate pre-admission refusal controls.
  • Focused tests exercise inventory reads and writes after checks, actual repair/reopening, failure settlement, ownership refusals, and existing migration callers.

The production failure was observed during an update; isolated source and SQLite tests exercise its owning boundaries. No production state or schema version was changed for these proofs. 204 focused tests passed (199 across 16 files in 118.37s;5 selected large-suite cases in 8.80s). The queued-event case costs150 ms and real inventory lifecycle cases1 s each. Independent P0–P2 review is clean. Production changes are net −3 lines. Local changed checks passed formatting, ratchets and initial core guards, then correctly refused the borrowed dependency tree at the TypeScript physical-containment gate; the full exact-head CI run subsequently passed, including production/test types, lint, build artifacts, docs and Windows checks.

The required published-driver × exact-candidate Package Acceptance run passed: [email protected] → a93d22b0a1816471b25912d8b192f1feae568451, trusted tooling 35fd3b1617e0afc48e4e08afd9e767c0585dda95, synthetic base scenario. The receipt records updater installation, updateOutcome: success, updateRecovery: null, Doctor and survival assertions, Gateway startup (51 s), /healthz and /readyz (1 s each), and RPC status (2 s). Package integrity and npm 12 installer acceptance also passed.

The separate first-hop post-core snapshot is unavailable because its redacted update output was truncated; this proves the completed survivor flow, not that missing intermediate observation. Stored-data compatibility is preserved: no DDL, schema version, persisted representation, permission or configuration change; the existing synchronous SDK repair API remains unchanged.

@clawsweeper

clawsweeper Bot commented Sep 23, 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.

@steipete
steipete marked this pull request as ready for review September 23, 2026 04:05
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: M labels Sep 23, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 23, 2026, 12:12 AM ET / 04:12 UTC.

ClawSweeper review

What this changes

Preserves live worker environments during Doctor readiness checks, joins resource retirement after actual repairs, and prevents queued reconciliation failures from leaking an unhandled rejection.

Merge readiness

⛔ Blocked before merge - 3 items remain

The fix remains necessary: current main still retires worker inventory after a successful no-op schema check. Source review found no blocking introduced defect.

Priority: P1
Reviewed head: a93d22b0a1816471b25912d8b192f1feae568451

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Recorded reviewer rating: A focused owner-level repair with meaningful regression coverage and no blocking source finding; the repository-specific update validation outcome remains to be recorded. Real behavior proof remains required by host policy.
Proof confidence 🌊 off-meta tidepool Recorded reviewer rating; Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: Verified repository-admin authorship exempts ordinary external-contributor proof. Reported SQLite lifecycle tests and the mocked session-event regression cover the changed owners, but do not establish the required completed published-driver update result. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Required by policy Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: Verified repository-admin authorship exempts ordinary external-contributor proof. Reported SQLite lifecycle tests and the mocked session-event regression cover the changed owners, but do not establish the required completed published-driver update result. No stored-data contract changes.
Evidence reviewed 8 items Current main still contains the defect: The fetched main revision unconditionally calls asynchronous database retirement after schema preparation, including when preparation returns no changes. The worker store registers for that retirement and subsequently rejects reads once closed.
Preparation and retirement share one owner: The new preparation owner records repair entry only inside the existing schema fence and awaits retirement in finally only after that entry. Both production migration callers use it; repository search found no remaining references to the removed internal preparation function.
Reconciliation retains error and shutdown ownership: The session callback now returns void instead of forwarding the reconciliation promise into an ignored derived promise. The existing tracking function still observes rejection, reports it, and exposes pending work to shutdown.
Findings None None.
Security None None.

How this fits together

Doctor prepares the shared SQLite database before maintenance proceeds. Worker environments use database-bound inventory resources, so retiring those resources affects subsequent Gateway reads and worker reconciliation.

flowchart TD
  A[Doctor or startup check] --> B[Shared database preparation]
  B --> C{Repair admitted?}
  C -->|No| D[Keep live worker inventory]
  C -->|Yes| E[Run synchronous repair]
  E --> F[Drain and retire database resources]
  D --> G[Gateway worker reconciliation]
  F --> H[Continue maintenance]
Loading

Before merge

  • Add real behavior proof - Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: Verified repository-admin authorship exempts ordinary external-contributor proof. Reported SQLite lifecycle tests and the mocked session-event regression cover the changed owners, but do not establish the required completed published-driver update result. No stored-data contract changes.
  • Complete next step (P2) - Record the completed 2026.9.5-to-candidate published-driver update validation result required for Doctor changes, linking the existing GitHub run and its observed outcome.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -3, Tests +199, Docs +5. Total +201 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 4 54 57 -3
Tests 15 239 40 +199
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 20 298 97 +201

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/infra/state-migrations.plugin-doctor.ts, migration/backfill/repair: src/state/openclaw-state-db.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep healthy inventory generations usable during readiness checks while making admitted repairs own complete retirement and preserving reconciliation's existing failure handling.

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

Yes, from source: create live worker inventory, run a current-schema preparation step, then read the inventory; current main unconditionally retires it. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes. Centralizing preparation and conditional retirement preserves existing repair and ownership checks, and the callback fix leaves reconciliation reporting and drainage with their current owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The reported update-time Doctor check can invalidate active worker inventory and trigger a Gateway failure.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit. This is the recorded reviewer rating; real behavior proof remains required by host policy.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: Verified repository-admin authorship exempts ordinary external-contributor proof. Reported SQLite lifecycle tests and the mocked session-event regression cover the changed owners, but do not establish the required completed published-driver update result. No stored-data contract changes.

Label justifications:

  • P1: The reported update-time Doctor check can invalidate active worker inventory and trigger a Gateway failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit. This is the recorded reviewer rating; real behavior proof remains required by host policy.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Required by policy: the recorded not-applicable assessment does not satisfy the current PR proof policy. Put relevant after-change evidence in the main PR body, then request a fresh review with @clawsweeper re-review. Recorded reviewer context: Verified repository-admin authorship exempts ordinary external-contributor proof. Reported SQLite lifecycle tests and the mocked session-event regression cover the changed owners, but do not establish the required completed published-driver update result. No stored-data contract changes.

Evidence

What I checked:

  • Current main still contains the defect: The fetched main revision unconditionally calls asynchronous database retirement after schema preparation, including when preparation returns no changes. The worker store registers for that retirement and subsequently rejects reads once closed. (src/infra/state-migrations.state-schema.ts:85, de32d6b7a12e)
  • Preparation and retirement share one owner: The new preparation owner records repair entry only inside the existing schema fence and awaits retirement in finally only after that entry. Both production migration callers use it; repository search found no remaining references to the removed internal preparation function. (src/state/openclaw-state-db.ts:150, a93d22b0a181)
  • Reconciliation retains error and shutdown ownership: The session callback now returns void instead of forwarding the reconciliation promise into an ignored derived promise. The existing tracking function still observes rejection, reports it, and exposes pending work to shutdown. (src/gateway/server-worker-placement-startup.ts:575, a93d22b0a181)
  • Focused regression coverage: Added cases exercise reads and writes after both no-op preparation modes, repair/reopening, a native-close failure after commit, and refusal before repair admission. The separate session-event test exercises the actual subscription with mocked dispatch. The captured PR body reports 204 passing focused tests; this read-only review did not execute them. (src/gateway/worker-environments/store-worker.test.ts:64, a93d22b0a181)
  • Public API and stored representation preserved: The plugin SDK continues exporting the unchanged synchronous repair API. The introduced changes alter lifecycle coordination without changing DDL, schema versions, persisted representations, configuration, or permission contracts. (src/plugin-sdk/doctor-repair-runtime.ts:19, a93d22b0a181)
  • Verified author role: GitHub's repository-permission endpoint confirms steipete has admin access, establishing the maintainer exemption from ordinary external-contributor runtime proof despite the CONTRIBUTOR association in the supplied snapshot.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Link the completed 2026.9.5-to-candidate published-driver validation result in the PR evidence.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The PR body now links the completed exact-head CI and published [email protected] → candidate a93d22b0a1816471b25912d8b192f1feae568451 Package Acceptance run. Both passed. The survivor receipt records updateOutcome: success, updateRecovery: null, Doctor/survival checks, and working Gateway health/readiness/status; the missing intermediate first-hop snapshot is explicitly identified. No DDL, schema version, persisted representation or permission changes are present, and the synchronous SDK repair contract is unchanged. This addresses the published-driver proof and compatibility evidence requests without changing the reviewed code.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit cb8658d into main Sep 23, 2026
283 checks passed
@steipete
steipete deleted the codex/stable-activation-doctor-20260923 branch September 23, 2026 04:49
@clawsweeper

clawsweeper Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix: preserve worker environments during Doctor checks This is item 1/1 in the current shard. Shard 0/1.

This temporary status tracks the active review worker. The completed review will appear in the durable ClawSweeper review comment.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
steipete added a commit that referenced this pull request Oct 17, 2026
#175185)

Per-database drainage (a state DB read-admission seal/reopen under event-loop stalls) closed the worker-environment store permanently, so every reconcile sweep failed with 'Worker environment inventory has closed' until a Gateway restart. Drainage now retires only the current database generation; the next ready() re-captures the same database file (identity-checked), reinstalls the inventory and keeps revocation subscriptions and a monotonic inventory version. Gateway shutdown still closes permanently. The earlier unhandled-rejection crash was already fixed by #156160.

Fixes #160521
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
openclaw#175185)

Per-database drainage (a state DB read-admission seal/reopen under event-loop stalls) closed the worker-environment store permanently, so every reconcile sweep failed with 'Worker environment inventory has closed' until a Gateway restart. Drainage now retires only the current database generation; the next ready() re-captures the same database file (identity-checked), reinstalls the inventory and keeps revocation subscriptions and a monotonic inventory version. Gateway shutdown still closes permanently. The earlier unhandled-rejection crash was already fixed by openclaw#156160.

Fixes openclaw#160521
tideclaw-bot pushed a commit that referenced this pull request Nov 6, 2026
#175185)

Per-database drainage (a state DB read-admission seal/reopen under event-loop stalls) closed the worker-environment store permanently, so every reconcile sweep failed with 'Worker environment inventory has closed' until a Gateway restart. Drainage now retires only the current database generation; the next ready() re-captures the same database file (identity-checked), reinstalls the inventory and keeps revocation subscriptions and a monotonic inventory version. Gateway shutdown still closes permanently. The earlier unhandled-rejection crash was already fixed by #156160.

Fixes #160521

(cherry picked from commit 6653b26)

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

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant