Skip to content

fix(gateway): keep Doctor maintenance entry working under the shared lease liveness policy - #164697

Merged
steipete merged 1 commit into
mainfrom
upd/upd-lease-liveness-doctor-regression
Oct 4, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-lease-liveness-doctor-regression

Conversation

@steipete

@steipete steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Doctor can report a generic Gateway ownership failure instead of the real newer-schema refusal, and session recovery cleanup can stop before reaching its manifest directory-sync policy.

Related: #164546.

Why This Change Was Made

The campaign bisect passes at 5421a7803640 and fails from 06da0de86c0a. Its new maintenance lease inspection inherited two unrelated runtime-reader requirements: supported schema admission before inspecting the lease, and mandatory removal of the disposable snapshot afterward.

The captured gateway-owner query returned []: there was no owner PID, host, boot/PID namespace, heartbeat age, or expiry. No liveness predicate branch refused the shared-schema fixture. Runtime admission threw SqliteSchemaVersionError for schema 21 versus supported 20 before the predicate ran. The retirement-disposal sibling instead completed lease inspection and then failed private-snapshot cleanup before its expected manifest result.

The Gateway lease owner now opens the fresh private snapshot under current maintenance custody, preserves Doctor's exact legacy catalog read admission, and leaves schema compatibility to Doctor before repair. Native reader closure remains mandatory and precedes best-effort snapshot disposal; the snapshot owner warns and retains cleanup responsibility when disposal fails. The shared liveness predicate and ordinary runtime admission remain unchanged.

User Impact

Doctor reports the actual schema or manifest outcome. Disposable snapshot cleanup problems become warnings instead of blocking maintenance entry. Live and fresh unverifiable Gateway owners still refuse maintenance, and newer schemas still refuse repair before source changes. No config, CLI, schema, dependency, or update/rollback contract changes.

Evidence

Regressions

  • src/flows/doctor-health.dangling-workshop-index.test.ts: reproduced the original failure on the assigned main base. The original shared-schema expectation and database/config byte-preservation assertions remain unchanged.
  • src/commands/doctor-session-sqlite.retirement-disposal.test.ts: reproduced 2 failures / 11 passes with the earlier candidate. After separating disposable cleanup, all 13 passed unchanged: both the simulated Windows unsupported-sync case and the injected manifest EIO case reach their intended boundary.
  • Extended the existing lease-owner table with a newer-schema foreign-owner case. It fails before the schema-admission fix and passes afterward, proving no repair callback or source mutation occurs for a fresh foreign owner.

Local validation

  • The lease-owner, dangling-Workshop-index, and retirement-disposal suites passed three complete repetitions: 51 tests per repetition; wall times 107.21, 87.50, and 89.56 seconds.
  • All 72 remaining required family/importer files ran once, in batches of 15, 15, 15, 15, and 12 files. Every executed test passed, with existing platform-specific skips. Batch wall times were 144.99, 323.45, 158.13, 77.32, and 1169.67 seconds. The final batch included 15m45s of shared runtime build preparation, separate from test time.
  • node scripts/check-changed.mjs passed locally, including production/test type graphs, lint, formatting, ratchets, and runtime import-cycle checks (683.25 seconds).
  • Changed-test cost: node scripts/run-vitest.mjs src/infra/gateway-owner-lease.test.ts --maxWorkers=1 passed all 33 tests in 22.15 seconds wall time; summed reported test time was 11.479 seconds.
  • Independent Codex P1 autoreview on the final source: scoped-clean, no accepted/actionable findings.
  • git diff --check passed. Hosted PR CI is separate from this completed local proof.

Slow pre-existing suites (waived)

The maintainer explicitly waived these existing timings; they are not introduced by this repair. No timeouts, retries, skips, or assertions were weakened.

  • src/flows/doctor-health.test.ts: 209.046 seconds of reported test time in the prior Linux run; its 46 service-inspection cases accounted for 158.697 seconds. The final local run recorded 284.838 seconds for the file.
  • src/commands/doctor-maintenance.admission-activation.test.ts: 35.592 seconds for “restores within the native deadline when each fresh private snapshot costs two seconds,” 34.972 seconds for “refuses an update committed after native restart message preparation,” and 33.228 seconds for “retains final native custody revocation after restart message preparation.” The final local run recorded 45.395, 44.042, and 43.295 seconds respectively.

Change size

Production: +22/-8 lines. Tests: +17/-6 lines. Documentation: +5/-0 lines. No new production module, exported name, or test file.

Inspect the Gateway lease under maintenance custody before Doctor applies
runtime schema admission. Close the native reader before handing disposable
snapshot cleanup back to its warning-and-retry owner.

Restore the newer-schema diagnostic and session retirement manifest outcomes
regressed by #164546 without changing lease liveness or data-risk refusals.
@clawsweeper

clawsweeper Bot commented Oct 4, 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 size: S labels Oct 4, 2026
@steipete
steipete marked this pull request as ready for review October 4, 2026 01:57
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 10:08 PM ET / October 4, 2026, 02:08 UTC (Revision 2).

ClawSweeper review

What this changes

The PR lets Doctor inspect Gateway ownership before runtime schema admission and makes disposable snapshot cleanup failures warn after the inspection reader closes.

Merge readiness

✅ Ready for maintainer review

The repair remains useful on current main, and no introduced correctness or security defect was found. The previous review’s empty finding list remains appropriate.

Priority: P2
Reviewed head: a2930a143a79ceae54b63cfcc140f90c3b4e52f5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful negative coverage and no actionable introduced defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified repository-admin author is exempt from ordinary external-contributor proof. Reported tests exercise the maintenance lease owner and Doctor refusal paths, but are supplemental evidence; no new authority-bearing value or stored-data contract is introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified repository-admin author is exempt from ordinary external-contributor proof. Reported tests exercise the maintenance lease owner and Doctor refusal paths, but are supplemental evidence; no new authority-bearing value or stored-data contract is introduced.
Evidence reviewed 8 items Pinned introduced change: The merge-base-to-head diff changes only maintenance lease inspection, its existing regression table, and recovery documentation; the liveness predicate and ordinary runtime reader remain unchanged.
Still needed on current main: Fetched main still calls the runtime-admitting read wrapper during maintenance lease inspection. That wrapper checks supported schema before executing the lease query, preserving the reported diagnostic failure.
Repair remains schema guarded: Doctor prepares database preflight and awaits its schema-upgrade guard before either index repair or legacy catalog readability repair. The patch does not remove or relocate that guard.
Findings None None.
Security None None.

How this fits together

Doctor acquires exclusive state custody before performing database maintenance. Its Gateway lease check excludes active owners, then Doctor’s schema guard determines whether repair may proceed.

flowchart TD
A[Doctor maintenance request] --> B[Exclusive state custody]
B --> C[Private database snapshot]
C --> D[Gateway lease inspection]
D --> E[Refuse active owner]
D --> F[Close reader and clean snapshot]
F --> G[Doctor schema guard]
G --> H[Repair or schema refusal]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +14, Tests +11, Docs +5. Total +30 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 22 8 +14
Tests 1 17 6 +11
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 44 14 +30

Review metrics

None.

Technical review

Best possible solution:

Keep lease inspection under current maintenance custody while leaving repair compatibility with Doctor and disposable cleanup with the snapshot owner.

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

Yes, source establishes the failure path: current main applies runtime schema admission before maintenance lease inspection, and existing Doctor regressions exercise newer-schema refusal and source preservation. No tests were executed during this read-only review.

Is this the best way to solve the issue?

Yes, the patch uses the existing native reader and cleanup owners while preserving Doctor’s schema guard and shared liveness predicate.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This bounded repair restores Doctor’s schema diagnostics and maintenance cleanup outcomes without changing Gateway liveness policy.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The verified repository-admin author is exempt from ordinary external-contributor proof. Reported tests exercise the maintenance lease owner and Doctor refusal paths, but are supplemental evidence; no new authority-bearing value or stored-data contract is introduced.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff changes only maintenance lease inspection, its existing regression table, and recovery documentation; the liveness predicate and ordinary runtime reader remain unchanged. (src/infra/gateway-owner-lease.ts:85, a2930a143a79)
  • Still needed on current main: Fetched main still calls the runtime-admitting read wrapper during maintenance lease inspection. That wrapper checks supported schema before executing the lease query, preserving the reported diagnostic failure. (src/infra/gateway-owner-lease.ts:85, 244993e1b722)
  • Repair remains schema guarded: Doctor prepares database preflight and awaits its schema-upgrade guard before either index repair or legacy catalog readability repair. The patch does not remove or relocate that guard. (src/flows/doctor-health.ts:244, a2930a143a79)
  • Current custody and negative coverage: Inspection rechecks owner-held database access after snapshot preparation. The extended real-SQLite maintenance table covers current, quarantined, and newer state with a fresh foreign owner, asserting refusal before the callback and preservation of database bytes. (src/infra/gateway-owner-lease.test.ts:289, a2930a143a79)
  • Cleanup responsibility preserved: The snapshot cleanup owner reports best-effort disposal failures and retains directory ownership for exit or signal cleanup. Native connection cleanup still throws on failed reader closure, preventing maintenance from continuing past an unsettled reader. (src/infra/sqlite-readonly-location-cleanup.ts, a2930a143a79)
  • Verified merge result: The raw test-merge record has the pinned base followed by the pinned PR head. Comparing its result with that base confirms the same focused production change, without attributing unrelated endpoint drift to this PR. (src/infra/gateway-owner-lease.ts:85, 9417ef18bbc5)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-04T02:02:59.211Z sha a2930a1 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 9aee9ad into main Oct 4, 2026
192 checks passed
@steipete
steipete deleted the upd/upd-lease-liveness-doctor-regression branch October 4, 2026 02:29
RomneyDa pushed a commit that referenced this pull request Oct 4, 2026
…lease liveness policy (#164697)

After #164546 made the owner lease share the state lock's liveness policy, Doctor's maintenance entry inherited runtime schema admission and strict snapshot-cleanup requirements from the acquisition path and refused with GatewayLockError / DoctorSqliteMaintenanceLockUnavailableError on state it exists to repair (doctor-health.dangling-workshop-index and doctor-session-sqlite.retirement-disposal went red on main). Maintenance lease inspection is now separate from runtime schema admission while keeping the lease check and the native-reader closure requirement; foreign-owner refusal is unchanged. Bisected: passes at 5421a78, fails from 06da0de.

(cherry picked from commit 9aee9ad)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…lease liveness policy (openclaw#164697)

After openclaw#164546 made the owner lease share the state lock's liveness policy, Doctor's maintenance entry inherited runtime schema admission and strict snapshot-cleanup requirements from the acquisition path and refused with GatewayLockError / DoctorSqliteMaintenanceLockUnavailableError on state it exists to repair (doctor-health.dangling-workshop-index and doctor-session-sqlite.retirement-disposal went red on main). Maintenance lease inspection is now separate from runtime schema admission while keeping the lease check and the native-reader closure requirement; foreign-owner refusal is unchanged. Bisected: passes at 9cee184, fails from 24dbf43.
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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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