Skip to content

fix(doctor): recover registrations after interrupted schema upgrades - #145595

Merged
steipete merged 1 commit into
mainfrom
codex/doctor-registry-recovery
Sep 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/doctor-registry-recovery

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators rerunning Doctor after an interrupted agent schema upgrade could still find a retained agent missing from registry-based discovery. The database could already have committed its current schema while its registration retained the previous version.

Why This Change Was Made

Doctor now revalidates its maintenance lease and publishes the registration after every successfully verified agent migration, including a retry that does not advance the physical schema. The existing registry owner retains path, import, and deletion fencing. Upgrade messages still describe only actual schema transitions.

User Impact

Running openclaw doctor --fix with a compatible build can recover these stale registrations, including registered databases inside the active state directory whose agents are no longer configured. The documentation describes this retry path. Each successfully scanned database receives the existing registration metadata refresh; database schemas and discovery scope are unchanged.

Evidence

  • The focused regression failed on the original code: physical schema was current, but registry-based discovery returned no agent. It passes with the fix.
  • All 43 tests passed across migration targets, media persistence, additive schema repair, and canonical transcript archives.
  • The regression uses native database initialization and the existing registration API, with an isolated retained database outside the configured agent layout.
  • check:changed passed, including core/test typechecks, lint, formatting, storage guards, and import-cycle validation.
  • Independent autoreview completed P0 scoped-clean with no findings.
  • An isolated native 19-to-20 interruption immediately after the agent schema commit reproduced the stale registration on the original implementation. With this candidate, ordinary Doctor retry converged physical schema, schema metadata, and registry to version 20 while preserving the original backups, transcript witness, and archive data.
  • Exact-head CI passed for b9fbeed73bec6f1f118ca861b813d5c9504d1b39.
  • The untouched published [email protected] updater successfully installed this candidate tarball through the real openclaw update command. Migration rehearsal, Gateway canary, and final Doctor all passed; the retained agent advanced from state/agent schemas 16/19 to 17/20 with registry version 20.
  • A separate fresh profile passed packaged native database initialization, actual Doctor, and config validation, with exactly one main registration and physical/schema-metadata/registry version 20. The initial fixture had incorrectly expected Doctor alone to create an unused agent database; its failed adapter record remains retained, and the corrected proof links the already-successful updater receipt without rerunning it.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 size: XS maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 04:44
@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 Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 12:51 AM ET / 04:51 UTC.

ClawSweeper review

What this changes

Doctor refreshes database registrations after successful verification even when a retry does not advance the schema, with regression coverage and recovery documentation.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful, focused repair: current main and v2026.9.4 still contain the retry gap. No introduced correctness defect was found, and the maintainer-protected PR is not eligible for automatic closure.

Priority: P2
Reviewed head: b9fbeed73bec6f1f118ca861b813d5c9504d1b39

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow owner-level repair with meaningful regression coverage and no concrete correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its reported native-database regression covers migration-to-registry recovery, but does not establish the separate published-updater validation required by repository policy.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its reported native-database regression covers migration-to-registry recovery, but does not establish the separate published-updater validation required by repository policy.
Evidence reviewed 7 items Current main still contains the defect: At the fetched main revision, registration is conditional on a non-registry source or a physical schema advance. A retained registry target whose schema already committed satisfies neither condition.
Latest release retains the same condition: The v2026.9.4 source has the same conditional registration at lines 597–600. GitHub’s contents endpoint supplied the release source after the local historical blob could not be loaded.
Repair preserves the registration owner: The introduced change rechecks maintenance ownership after awaiting migration, then calls the existing registration operation. That operation retains import exclusion, transactional deletion fencing, the existing upsert fields, and discovery-cache invalidation.
Findings None None.
Security None None.

How this fits together

Doctor verifies and migrates agent databases, then records their availability in OpenClaw’s shared registry. Registry-based discovery uses those records to find compatible agent databases.

flowchart TD
  A[Doctor repair request] --> B[Discover configured and retained databases]
  B --> C[Verify ownership and schema]
  C --> D[Recheck maintenance lease]
  D --> E[Refresh shared registry]
  E --> F[Discover compatible agent databases]
Loading

Before merge

  • Resolve merge risk (P1) - Published-updater-to-candidate behavior has not been demonstrated in the supplied evidence; focused database tests do not cover that complete upgrade entry point.
  • Complete next step (P2) - Record published-updater-to-candidate validation of retained-database registration recovery and fresh-profile behavior before merge.
Agent review details

Security

None.

PR surface

Source 0, Tests +29, Docs +2. Total +31 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 29 0 +29
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 34 3 +31

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep registration recovery in Doctor’s existing verified migration path, preserving registry safeguards and confirming the supported upgrade flow.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep registration recovery in Doctor’s existing verified migration path, preserving registry safeguards and confirming the supported upgrade flow.

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

Yes, from source: a current-schema retained database with an older registry version is omitted by discovery, and main’s no-op migration skips refreshing it. The added regression models this exact state; this review did not execute it.

Is this the best way to solve the issue?

Yes. Refreshing through the existing registry owner after successful verification repairs the interrupted publication without introducing another discovery path, schema, or configuration option.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs a bounded recovery failure where retained agent databases remain absent from registry discovery after an interrupted upgrade.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its reported native-database regression covers migration-to-registry recovery, but does not establish the separate published-updater validation required by repository policy.

Label justifications:

  • P2: This repairs a bounded recovery failure where retained agent databases remain absent from registry discovery after an interrupted upgrade.
  • 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 maintainer-authored PR is exempt from the external-contributor proof gate. Its reported native-database regression covers migration-to-registry recovery, but does not establish the separate published-updater validation required by repository policy.

Evidence

What I checked:

  • Current main still contains the defect: At the fetched main revision, registration is conditional on a non-registry source or a physical schema advance. A retained registry target whose schema already committed satisfies neither condition. (src/infra/state-migrations.media-persistence.ts:621, ca96441ed94f)
  • Latest release retains the same condition: The v2026.9.4 source has the same conditional registration at lines 597–600. GitHub’s contents endpoint supplied the release source after the local historical blob could not be loaded. (src/infra/state-migrations.media-persistence.ts:598, 3a9d69db306c)
  • Repair preserves the registration owner: The introduced change rechecks maintenance ownership after awaiting migration, then calls the existing registration operation. That operation retains import exclusion, transactional deletion fencing, the existing upsert fields, and discovery-cache invalidation. (src/infra/state-migrations.media-persistence.ts:621, b9fbeed73bec)
  • Regression exercises the missing retry case: The added test creates a current-schema retained database outside the configured layout, records an older registry version, verifies discovery omits it, then verifies migration restores discovery without claiming a schema transition. Existing sibling cases cover unregistered databases, renamed owners, foreign paths, and missing/imported entries. (src/infra/state-migrations.media-persistence-targets.test.ts:97, b9fbeed73bec)
  • Production entry point: Doctor’s migration plan invokes this owner in doctor mode with configured database targets; the preflight fallback also invokes it when the normal media migration was not attempted. (src/infra/state-migrations.doctor.ts:1477, b9fbeed73bec)
  • Validation evidence and remaining policy gate: The complete supplied PR body reports a failing-before/passing-after regression, 43 passing focused tests, and successful changed checks. It does not record the published-driver × candidate validation required by root policy for Doctor changes. This read-only review ran no target code; git diff --check passed. (AGENTS.md, b9fbeed73bec)

Likely related people:

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

Rank-up moves

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

  • Record the repository-required published-updater-to-candidate check, including retained-database recovery and a fresh-profile sanity check, with private details redacted.

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
steipete merged commit 3f0b8a1 into main Sep 12, 2026
262 checks passed
@steipete
steipete deleted the codex/doctor-registry-recovery branch September 12, 2026 05:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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