Skip to content

perf(sqlite): stop no-op startup repair from blocking Gateway writes - #115193

Merged
steipete merged 1 commit into
mainfrom
codex/skip-noop-state-schema-repair
Jul 28, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/skip-noop-state-schema-repair

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where routine CLI startup could hold the shared SQLite writer lock for roughly two seconds even when the database schema was already current. Repeated status and automation commands could then make Gateway writes wait behind no-op schema repair and turn lightweight CLI reads into multi-second operations.

Why This Change Was Made

Automatic legacy migration now performs a read-only canonical-schema gate first and enters the existing exclusive repair path only when a migration, schema mismatch, unreadable database, or other uncertainty is detected. Explicit Doctor repair remains exhaustive, including integrity checks and index repair.

User Impact

Routine CLI commands no longer run a full shared-state integrity/repair transaction on every new process. This reduces startup latency and avoids unnecessary contention with a running Gateway while preserving fail-closed repair behavior for old, damaged, or noncanonical databases.

Evidence

  • Production-sized baseline: 142 no-op schema repair transactions took about 1.8 seconds each and caused 668 shared-state write lock waits in one day; three read-only cron-status probes took 4.32s, 3.89s, and 3.93s.
  • Added a writer-held-open regression proving current-schema automatic migration stays read-only instead of waiting for or failing on the writer slot.
  • Added a metadata regression proving the no-op path does not rewrite schema_meta.updated_at.
  • pnpm test src/state/openclaw-state-db.test.ts src/infra/state-migrations.test.ts — 164 passed on Blacksmith Testbox tbx_01kymapw8km35a2c99t050tnyb.
  • pnpm check:changed — passed core production/test typechecks, targeted lint, formatting, schema guards, import-cycle checks, and repository guards on the same Testbox.
  • Autoreview (gpt-5.6-sol, high) — clean; no accepted/actionable findings.

@steipete steipete self-assigned this Jul 28, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Jul 28, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 28, 2026, 10:38 AM ET / 14:38 UTC.

ClawSweeper review

What this changes

This PR makes automatic shared-SQLite migration read the schema first and skip exclusive repair when the database is already current, reducing CLI startup contention with Gateway writes.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

The PR remains necessary: current main still runs the exclusive shared-state schema repair during automatic migration, while this branch adds a read-only canonical-schema gate before preserving the existing repair fallback. The patch has focused regression coverage and no concrete correctness or security defect surfaced from the available source and PR evidence; the maintainer label means it should remain open for human maintainer review rather than automated cleanup.

Priority: P2
Reviewed head: 816d323a26d128d1c799c46784fa53d64f06699a

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, fallback-preserving state-database repair with targeted lock-contention and metadata regressions; it awaits normal maintainer review rather than contributor proof.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless supplies production contention observations and focused Testbox regression results.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless supplies production contention observations and focused Testbox regression results.
Evidence reviewed 5 items Current-main behavior remains unoptimized: The current shared-state database implementation exposes the unconditional repairOpenClawStateDatabaseSchema repair path, and the new conditional helper is absent from the current-main source inspected for this review; the central contention problem is therefore not already fixed on main.
Focused fallback-preserving implementation: The proposed helper opens an existing database read-only, checks supported version, schema version, pending migrations, and runtime schema shape, then routes any mismatch or read failure back through the existing exhaustive repair function.
Automatic versus explicit repair boundary: Automatic migration uses the conditional gate, while the doctorOnlyStateMigrations path retains the full repair call; this matches the stated design that explicit Doctor repair remains exhaustive.
Findings None None.
Security None None.

How this fits together

OpenClaw stores shared runtime state in a SQLite database used by both CLI processes and the Gateway. Automatic startup migration currently invokes schema repair before normal work; this change decides whether repair is needed without first taking the writer path.

flowchart LR
  A[CLI or automation startup] --> B[Automatic state migration]
  B --> C[Read-only schema gate]
  C -->|Canonical and current| D[Continue without repair]
  C -->|Legacy damaged or uncertain| E[Exclusive schema repair]
  D --> F[Gateway and state writes]
  E --> F
Loading

Before merge

  • Add real behavior proof - Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless supplies production contention observations and focused Testbox regression results.
  • Complete next step (P2) - The patch appears focused and correct, but the protected maintainer label requires explicit maintainer handling instead of an automated repair or close action.
Agent review details

Security

None.

PR surface

Source +39, Tests +46. Total +85 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 43 4 +39
Tests 2 46 0 +46
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 89 4 +85

Review metrics

None.

Stored data model

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

Technical review

Best possible solution:

Land the focused read-only gate after a maintainer confirms that the current-main state-schema invariants remain complete and the branch is refreshed against current main as needed.

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

Yes, at source level: the added regression holds a SQLite writer transaction open and verifies that automatic migration of a current schema completes without waiting for that writer. The supplied Testbox result reports the focused tests passing, but this read-only review did not rerun them.

Is this the best way to solve the issue?

Yes. A narrow read-only canonical-schema gate preserves the existing exhaustive repair fallback for migration, malformed, unreadable, and noncanonical databases while removing avoidable contention on the known-current path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3fa4805563eb.

Labels

Label changes:

  • add P2: The PR addresses a bounded but real shared-database contention path that can delay Gateway writes and routine CLI work without indicating data loss or a service outage.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless supplies production contention observations and focused Testbox regression results.

Label justifications:

  • P2: The PR addresses a bounded but real shared-database contention path that can delay Gateway writes and routine CLI work without indicating data loss or a service outage.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless supplies production contention observations and focused Testbox regression results.

Evidence

What I checked:

  • Current-main behavior remains unoptimized: The current shared-state database implementation exposes the unconditional repairOpenClawStateDatabaseSchema repair path, and the new conditional helper is absent from the current-main source inspected for this review; the central contention problem is therefore not already fixed on main. (src/state/openclaw-state-db.ts:293, 3fa4805563eb)
  • Focused fallback-preserving implementation: The proposed helper opens an existing database read-only, checks supported version, schema version, pending migrations, and runtime schema shape, then routes any mismatch or read failure back through the existing exhaustive repair function. (src/state/openclaw-state-db.ts:293, 816d323a26d1)
  • Automatic versus explicit repair boundary: Automatic migration uses the conditional gate, while the doctorOnlyStateMigrations path retains the full repair call; this matches the stated design that explicit Doctor repair remains exhaustive. (src/infra/state-migrations.doctor.ts:1348, 816d323a26d1)
  • Regression coverage: The branch adds a writer-held-open test for automatic migration and a metadata test that confirms the no-op path does not rewrite schema_meta.updated_at. The PR reports 164 focused tests and changed checks passing on Blacksmith Testbox. (src/infra/state-migrations.test.ts:512, 816d323a26d1)
  • Maintainer routing signal: The PR conversation identifies the branch as maintainer-authored, self-assigned, and labeled maintainer; repository policy keeps protected-label PRs open for explicit maintainer handling. (816d323a26d1)

Likely related people:

  • steipete: The PR is marked maintainer-authored, was self-assigned by steipete, and its only commit implements the state-database migration change. (role: current area contributor and assigned review owner; confidence: medium; commits: 816d323a26d1; files: src/state/openclaw-state-db.ts, src/infra/state-migrations.doctor.ts)

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 2cbbb00 into main Jul 28, 2026
126 of 132 checks passed
@steipete
steipete deleted the codex/skip-noop-state-schema-repair branch July 28, 2026 15:18
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 28, 2026
* origin/main:
  test(codex): de-flake attempt turn-watch timing tests (#115258)
  fix: preserve retryable ACPX lease ownership (#115247)
  fix: serialize ACPX lease ownership transitions
  fix: retain ACPX leases across wrapper reconnects
  refactor: parse ACPX lease command identity
  fix: preserve OpenClaw profile env in macOS launch-at-login plist (#99752)
  refactor(config): retire compaction truncateAfterCompaction gate (#115206)
  improve(ui): reduce duplicate chat startup work (#114743)
  fix(ui): keep reconnects, browser tabs, and localized search consistent (#115221)
  perf(pr): cache complete small file lists (#115199)
  perf(sqlite): skip no-op automatic schema repair (#115193)
  docs(browser): correct Docker sandbox setup (#115254)
  fix(ui): avoid duplicate session refreshes during startup (#114764)

# Conflicts:
#	ui/src/pages/agents/panels-tools-skills.browser.test.ts
vincentkoc added a commit that referenced this pull request Jul 28, 2026
* origin/main:
  test(codex): de-flake attempt turn-watch timing tests (#115258)
  fix: preserve retryable ACPX lease ownership (#115247)
  fix: serialize ACPX lease ownership transitions
  fix: retain ACPX leases across wrapper reconnects
  refactor: parse ACPX lease command identity
  fix: preserve OpenClaw profile env in macOS launch-at-login plist (#99752)
  refactor(config): retire compaction truncateAfterCompaction gate (#115206)
  improve(ui): reduce duplicate chat startup work (#114743)
  fix(ui): keep reconnects, browser tabs, and localized search consistent (#115221)
  perf(pr): cache complete small file lists (#115199)
  perf(sqlite): skip no-op automatic schema repair (#115193)
  docs(browser): correct Docker sandbox setup (#115254)
  fix(ui): avoid duplicate session refreshes during startup (#114764)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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