Skip to content

fix(sessions): skip empty-index receipt demand when owner has no database - #149260

Merged
steipete merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/session-empty-index-deferred-startup-gate
Sep 15, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/session-empty-index-deferred-startup-gate

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #149263.

What Problem This Solves

#148901 tightened the deferred-plugin session migration gates: startup now requires a sha256-bound verified-import receipt from every roster owner of an empty legacy session index, while Doctor only issues that receipt when the owner already has a session database (the new verifiedImport gate in doctor-session-sqlite.ts, which deliberately "must never create a database solely for an unused shared-index owner").

For a configured-but-unused agent — an empty legacy sessions.json ({}), a deferred plugin session migration pending, and no SQLite database yet — the two gates deadlock each other:

  1. Startup throws SessionStoreMigrationRequiredError: Legacy session store requires migration: ... Run "openclaw doctor --fix" ...
  2. openclaw doctor --fix runs, imports zero records, and (by design) refuses to create a database just to hold the receipt — so no receipt is ever issued
  3. Startup throws the same error again. The suggested remedy can never satisfy the requirement; the only escape is manually deleting state files

A receipt could never be valid for such an owner anyway: receipts bind the database identity, which a later-created database would invalidate. And a zero-record source has nothing to replay.

Why This Change Was Made

Startup exempts an owner only when its legacy index is empty, its database is absent, no verified import receipt exists, and the source directory has no unindexed transcript history. Doctor and startup share the transcript-directory scan in legacy-store-inspection.ts.

The maintainer narrowing validates existing receipts before considering the exemption. Existing databases still require verified receipts; unindexed history still requires Doctor import; a missing previously imported database still fails identity validation. Original sources remain available for deferred plugin migration.

User Impact

  • A fresh or unused configured agent with an empty legacy sessions.json and a pending deferred plugin session migration no longer deadlocks Gateway startup / openclaw update behind an unactionable "run openclaw doctor --fix" loop.

Evidence

Maintainer narrowing: the final exemption applies only to an empty source index whose owner has no database, no unindexed history in the source directory, and no existing receipt. Startup reuses Doctor's extracted transcript-directory scan and reads existing receipts through their full identity validation before considering the exemption. Two new regressions beside the original unused-owner case cover (1) unindexed history requiring Doctor import before startup succeeds and (2) a removed receipt database failing with the existing ENOENT/lstat identity error. Both failed on contributor head 19b68333b724064741a770ff665ccf3af6cd1fd2 because startup did not throw, then passed with the narrowing; the original unused-owner test still passes. The focused run passed 54 tests before and after rebasing onto current main across deferred-plugin imports, historical discovery, and startup maintenance. The contributor's commit and authorship remain intact, with the narrowing in a separate maintainer commit. node scripts/check-changed.mjs passed for all four touched files, including core/test typechecks and lint; no nested-worktree fallback was needed. Branch autoreview against origin/main is scoped-clean at P1 on 812fe61b598bb1723e24c5bbce7ceef772aeca1a.

Red/green through the real entry points — no mocks; real temporary state directories and real SQLite via withOpenClawTestState, driving runDoctorSessionSqlite and assertSessionStoreMigrationComplete directly.

Before fix (main @ 8072377b735, red)

New regression test lets startup proceed for an empty index when the owner has no database yet:

PROBE storeExists true
PROBE gateThrows SessionStoreMigrationRequiredError: Legacy session store requires migration:
  .../agents/main/sessions/sessions.json. Run "openclaw doctor --fix" against the same
  state/config before starting OpenClaw.

Doctor completed with importedEntries: 0, the empty index stayed retained on disk — and the startup gate still threw, instructing the user to run the very command that had just run. Deadlock reproduced.

After fix (this branch, green)

Same scenario: the gate passes before and after Doctor; Doctor creates no database; the empty index stays retained for the deferred plugin migration.

Test suite (commands shard, including the existing empty-index and deferred-plugin siblings)

$ node scripts/run-vitest.mjs run \
    src/commands/doctor-session-sqlite.deferred-plugin.test.ts \
    src/config/sessions/startup-migration.registry-recovery.test.ts \
    src/config/sessions/legacy-main-session-migration.startup.test.ts

Tests 27 passed (27) — 2 Vitest shards passed

tsgo / lint

$ node scripts/run-tsgo.mjs -p tsconfig.core.json                              — clean
$ node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.commands.json  — clean
$ oxlint src/config/sessions/startup-migration.ts \
    src/commands/doctor-session-sqlite.deferred-plugin.test.ts                 — 0 errors

ClawSweeper review

Both P1 findings are applied in the maintainer narrowing. ClawSweeper's completed review of 812fe61b598bb1723e24c5bbce7ceef772aeca1a confirms no remaining actionable defect and accepts the real-state startup/Doctor regressions as sufficient behavior proof.

State-skip the generic additional migration/upgrade compatibility request under the maintainer's proof ruling. This change adds no schema or stored-format change; Doctor retains import ownership and its discovery validation, and existing receipts keep their database/source identity checks. The regressions cover unused-owner startup, actual unindexed-history import, and rejection of a removed receipt database with real temporary files and SQLite. No separate live Gateway or published-driver campaign was run.

Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/35007208243 completed successfully at 812fe61b598bb1723e24c5bbce7ceef772aeca1a. A local focused run of the five empty-index cases also passed at that head.

@clawsweeper

clawsweeper Bot commented Sep 15, 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 commands Command implementations size: XS labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 2:42 PM ET / 18:42 UTC (Revision 2).

ClawSweeper review

What this changes

The PR lets unused agents pass session-migration readiness checks when their legacy index is empty, while preserving checks for historical transcripts and existing import receipts.

Merge readiness

⛔ Blocked before merge - 1 item remains

The fix remains necessary on inspected main. Both prior P1 findings are resolved, the narrowed behavior matches the recorded maintainer decision, and no remaining actionable defect was found.

Priority: P2
Reviewed head: 812fe61b598bb1723e24c5bbce7ceef772aeca1a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with both earlier blockers resolved and accepted real-state proof covering the changed contract.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The accepted production-owner harness exercises startup readiness and Doctor against real temporary files and SQLite, demonstrating the unused-owner recovery and rejection of both unsafe neighboring cases. The recorded maintainer narrowing and red/green results support this bounded proof; they do not claim a separate live Gateway or published-driver upgrade run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The accepted production-owner harness exercises startup readiness and Doctor against real temporary files and SQLite, demonstrating the unused-owner recovery and rejection of both unsafe neighboring cases. The recorded maintainer narrowing and red/green results support this bounded proof; they do not claim a separate live Gateway or published-driver upgrade run.
Evidence reviewed 8 items Narrow exemption preserves both safeguards: The current head reads and validates the receipt before checking database absence. It exempts only a zero-entry source without a receipt, database, or primary transcript file; other owners still require a source-hash-matching receipt.
Current main still has the deadlock: Inspected main requires receipts for every owner of an empty index. Doctor’s verified-import condition deliberately excludes an unused owner with no database, so running Doctor cannot satisfy that requirement.
Existing receipt validation remains authoritative: The receipt reader checks the database’s current filesystem identity and every retained source identity. A missing previously imported database throws during lstat before the new exemption can run.
Findings None None.
Security None None.

How this fits together

Doctor imports legacy session files into each agent’s SQLite database and retains originals needed by unavailable plugins. Gateway startup checks those files and import receipts before serving session history.

flowchart TD
  A[Legacy session index] --> B[Startup migration check]
  C[Deferred plugin migrations] --> B
  D[Database and import receipt] --> B
  E[Historical transcripts] --> B
  B -->|Empty unused owner| F[Allow startup]
  B -->|History needs import| G[Doctor import and verification]
  G --> B
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +20, Tests +113. Total +133 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 31 11 +20
Tests 1 113 0 +113
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 144 11 +133

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-session-sqlite-discovery.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #149263
Summary: This PR is the active candidate fix for the paired startup/Doctor deadlock issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep the narrow startup exemption and shared transcript scan, with Doctor remaining the sole importer and retained-source identity checks intact.

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

Yes. Current-main source establishes the incompatible receipt requirements, and the discussion records a failing real-state reproduction; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. The narrowed exemption repairs the existing owner’s readiness decision without changing schemas, settings, import ownership, or receipt validation.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs a concrete but narrowly conditioned startup deadlock involving an empty legacy index, an unused agent, and a deferred plugin migration.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The accepted production-owner harness exercises startup readiness and Doctor against real temporary files and SQLite, demonstrating the unused-owner recovery and rejection of both unsafe neighboring cases. The recorded maintainer narrowing and red/green results support this bounded proof; they do not claim a separate live Gateway or published-driver upgrade run.
  • proof: sufficient: Contributor real behavior proof is sufficient. The accepted production-owner harness exercises startup readiness and Doctor against real temporary files and SQLite, demonstrating the unused-owner recovery and rejection of both unsafe neighboring cases. The recorded maintainer narrowing and red/green results support this bounded proof; they do not claim a separate live Gateway or published-driver upgrade run.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • leochun92-sudo: 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-09-15T16:26:58.979Z sha 19b68333b724064741a770ff665ccf3af6cd1fd2 :: needs real behavior proof before merge. :: [P1] [P1] Check for unindexed history before skipping an owner | [P1] [P1] Validate existing receipts when their database disappears

@steipete

Copy link
Copy Markdown
Contributor

Maintainer review (landing run stopped before merge). The deadlock you describe in #149263 is real and this is the right place to fix it, but the exemption as written is wider than the case that has nothing to lose. Reproduced against the real-state fixture in doctor-session-sqlite.deferred-plugin.test.ts (probes extended from the existing #148901 cases, then reverted):

  1. Unindexed history is skipped. With an empty sessions.json and no database, but an unindexed historical transcript in the legacy session dir for that owner, assertSessionStoreMigrationComplete now lets startup proceed, while a subsequent doctor --fix imports that transcript. The gate existed for exactly this case (the comment above the line says so), so the skip must not apply when the source dir has importable history for the owner.
  2. An existing receipt is no longer validated. If a verified import receipt exists for the owner but its database has since disappeared, the fs.existsSync(destination) filter drops the owner before the receipt's database-identity check runs, so a stale receipt passes silently instead of failing closed.

Accepted narrower rule: skip the receipt demand for a deferred owner only when all three hold: the source index has zero entries, the owner has no database, and the owner has neither unindexed history in the source dir nor an existing receipt. Any receipt that exists keeps its identity validation; any history keeps the demand. Please also add the two cases above as regressions next to your no-database case (they should fail on this head and pass after). Everything else in the PR is right: the invariant comment, the real-entry-point regression, and the scope. I will land it as soon as those are in; if you would rather I take it over, say so and I will keep your authorship.

@steipete
steipete force-pushed the fix/session-empty-index-deferred-startup-gate branch from 19b6833 to 812fe61 Compare September 15, 2026 18:23
@steipete

Copy link
Copy Markdown
Contributor

I pushed narrowing commit 812fe61b598bb1723e24c5bbce7ceef772aeca1a on top of your work, preserving your commit and authorship. The empty-index exemption now applies only when the owner has no database, no unindexed history, and no existing receipt. Doctor and startup share the existing transcript-directory scan, and receipt identity validation runs before the exemption, so a removed database cannot silently bypass it.

Both new regressions failed on the original PR head because startup did not throw, then passed after the fix. The original unused-owner regression still passes. Thanks for identifying and fixing the unused-agent startup loop.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
@steipete
steipete merged commit 2f96a9d into openclaw:main Sep 15, 2026
243 of 245 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
…base (openclaw#149260)

Fix the Gateway startup and Doctor deadlock introduced by openclaw#148901 when an empty legacy session index belongs to a deferred plugin owner without a database.

Keep the contributor's unused-owner fix and the maintainer narrowing: exempt only an empty index with no database, no receipt, and no unindexed transcript history. Validate existing receipts first and share the transcript-directory scan with Doctor discovery, preserving the migration barrier for historical sessions and missing imported databases.

Regression coverage exercises the real startup assertion and Doctor import with temporary state and SQLite, including both admission failures found during review.

Fixes openclaw#149263.

Co-authored-by: Peter Steinberger <[email protected]>
@wangmiao0668000666
wangmiao0668000666 deleted the fix/session-empty-index-deferred-startup-gate branch October 28, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

Startup/doctor deadlock: empty legacy session index with a deferred plugin owner that has no database

2 participants