Skip to content

perf(doctor): snapshot SQLite migration validation - #125361

Merged
steipete merged 2 commits into
mainfrom
fix/batch-session-archive-publish
Aug 17, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/batch-session-archive-publish

Conversation

@steipete

@steipete steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes large JSONL→SQLite upgrades timing out during Doctor's post-import safety validation. After import completed, Doctor validated every legacy session by reopening SQLite, loading and parsing the full session table, and issuing a separate transcript-count query for each record. With 4,800 sessions this made validation quadratic in session rows and performed thousands of database opens before archival could complete.

Why This Change Was Made

Doctor now opens each target database once and takes a read-only validation snapshot containing session entries keyed by exact stored key plus transcript counts grouped by session ID. Import validation, explicit validation, and already-migrated transcript checks use map lookups while preserving the existing sessionId, exact-key, malformed-prefix, count, idempotence, and archive gating semantics.

The earlier 4 → 256 pending-archive publication change was removed after the combined packaged stress disproved it as the update timeout's cause. The final PR does not alter archive publication behavior.

Production LOC: +138/-127 (net +11) | Tests: +57/-0. The small production growth is the target-level snapshot/error contract replacing two per-record query APIs. The focused regression compares one-session and three-session real imports at the SQLite-open boundary, proving target-bounded validation reads without timing assertions or a production-only test seam.

User Impact

Large stable-to-current upgrades no longer spend the bounded update window repeatedly scanning the same SQLite rows after migration. Validation remains fail-closed before source archival.

Evidence

  • Pre-fix focused cardinality regression failed for the intended reason: one session made 4 read-only target opens while three sessions made 8 (expected 8 to be 4). With the fix both cardinalities are equal and all entries/events import and archive successfully.
  • After-fix packaged [email protected] → [email protected] survivor passed with 4,800 sessions, 23,890 transcript events, and 2,200 cron jobs: migration Doctor 21s, idempotence Doctor 20s, Gateway startup 14s, then health/readiness/status passed. All 62 recorded phases passed. The rebased production files are byte-identical to the packaged candidate's reviewed production head; the new head adds only the regression test.
  • Full src/commands/doctor-session-sqlite.test.ts: 84 passed, 2 skipped.
  • Full changed-file gate passed all selected ratchets, formatting, dead-export scans, core/core-test typechecks, Oxlint, database-first, import-cycle, and guard checks on the rebased head.
  • oxfmt --check and git diff --check passed.
  • Fresh Codex autoreview on rebased head f803757dc7ebf997b60b979a2c82714130be46db: no accepted/actionable P0–P2 findings; patch correct at 0.9 confidence.
  • Node 24.15.0 with provider/channel requests disabled for this performance proof; no live provider or channel request was made.

Provenance

The per-record helpers came from #98236 (0a8e3604ba24, 2026-07-11), authored by @jalehman and merged by @steipete. They were correct for small stores but made the later all-record post-import validation path quadratic at realistic volume.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 5:54 PM ET / 21:54 UTC.

ClawSweeper review

What this changes

This PR snapshots SQLite session entries and grouped transcript counts once per Doctor migration target, replacing repeated validation reads and adding a multi-session bounded-read regression.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No actionable patch defect found. The prior multi-record regression gap is addressed; this maintainer-authored, protected PR should remain open for normal exact-head CI and human merge handling.

Priority: P2
Reviewed head: f803757dc7ebf997b60b979a2c82714130be46db

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, preserves the archive gate in source, and addresses the prior cardinality-proof finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The PR body and follow-up describe an after-fix packaged upgrade run and a real SQLite migration regression with bounded reads and successful migration results.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The PR body and follow-up describe an after-fix packaged upgrade run and a real SQLite migration regression with bounded reads and successful migration results.
Evidence reviewed 5 items Snapshot owner boundary: The new reader opens the target SQLite database once, loads session entries and grouped transcript counts, and closes it before callers use immutable maps.
Archive-gate preservation: Import still validates all records before archival and only archives when validation adds no issue.
Focused regression: The added test uses real temporary legacy stores and the production SQLite opener, compares one versus three sessions, and requires equal read-only target-open counts with successful import totals.
Findings None None.
Security None None.

How this fits together

Doctor imports legacy JSONL session data into per-agent SQLite, validates the resulting rows, then archives legacy sources only after validation passes. The snapshot sits in the validation phase between import and archival.

flowchart LR
  A[Legacy session files] --> B[Doctor import]
  B --> C[SQLite session store]
  C --> D[Read-only validation snapshot]
  D --> E[Validation checks]
  E --> F[Archive gate]
  F --> G[Legacy source archive]
Loading

Before merge

  • Resolve merge risk (P1) - This modifies fail-closed validation before legacy session files are archived; exact-head CI should complete before merge.
  • Resolve merge risk (P1) - The local sparse checkout could not independently inspect the base/current-main objects because its promisor remote was unreachable.
  • Complete next step (P2) - The prior proof finding is resolved, but the protected maintainer item should proceed through exact-head CI and normal human merge handling rather than an automated repair lane.
Agent review details

Security

None.

PR surface

Source +11, Tests +57. Total +68 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 138 127 +11
Tests 1 57 0 +57
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 195 127 +68

Review metrics

Metric Value Why it matters
Production versus test delta production +11 net, tests +57 The production growth consolidates two repeated validation-reader paths into one snapshot contract, while the test adds multi-session scaling coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-session-sqlite-readers.ts, migration/backfill/repair: src/commands/doctor-session-sqlite.test.ts, serialized state: src/commands/doctor-session-sqlite.test.ts, unknown-data-model-change: src/commands/doctor-session-sqlite-readers.ts, unknown-data-model-change: src/commands/doctor-session-sqlite.test.ts, unknown-data-model-change: src/commands/doctor-session-sqlite.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Land after exact-head migration checks (recommended)
    Accept the bounded-read implementation once the current head’s required checks finish green, preserving the existing manual review of session migration and archive behavior.

Technical review

Best possible solution:

Keep one target-level snapshot reader and retain the existing validate-before-archive contract, with the new cardinality regression guarding against per-record read growth.

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

Yes, source provides a focused current-head real SQLite migration regression comparing one and three session imports; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Moving repeated reads into one target-owned snapshot preserves the existing validation and archive boundary without adding a fallback or a test-only production seam.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0b75ea3cefcd.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body and follow-up describe an after-fix packaged upgrade run and a real SQLite migration regression with bounded reads and successful migration results.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body and follow-up describe an after-fix packaged upgrade run and a real SQLite migration regression with bounded reads and successful migration results.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded Doctor migration performance and reliability repair.
  • merge-risk: 🚨 session-state: Incorrect validation could affect whether legacy session and transcript sources are archived during SQLite 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 (logs): The PR body and follow-up describe an after-fix packaged upgrade run and a real SQLite migration regression with bounded reads and successful migration results.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and follow-up describe an after-fix packaged upgrade run and a real SQLite migration regression with bounded reads and successful migration results.

Evidence

What I checked:

Likely related people:

  • jalehman: The related merged storage-flip work established the Doctor SQLite migration and validation boundary this PR optimizes. (role: introduced the SQLite migration surface; confidence: medium; commits: 0a8e3604ba24; files: src/commands/doctor-session-sqlite.ts, src/commands/doctor-session-sqlite-readers.ts)
  • steipete: The supplied related-PR provenance identifies this person as merger of the original storage migration and author of the current repair proposal. (role: recent area contributor and merger; confidence: medium; commits: f803757dc7eb; files: src/commands/doctor-session-sqlite.ts, src/commands/doctor-session-sqlite-readers.ts)

Rank-up moves

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

  • Allow the exact-head required checks to complete before manual merge review.

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 (2 earlier review cycles)
  • reviewed 2026-08-17T18:01:36.299Z sha ffff961 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-17T19:20:03.114Z sha 340b1e4 :: found issues before merge. :: [P2] Add a multi-record snapshot regression

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 17, 2026
@steipete steipete changed the title fix(sessions): avoid update stalls while publishing transcript archives perf(doctor): snapshot SQLite migration validation Aug 17, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 17, 2026
@steipete
steipete force-pushed the fix/batch-session-archive-publish branch from 340b1e4 to f803757 Compare August 17, 2026 21:48

Copy link
Copy Markdown
Contributor Author

Addressed the review's two proof gaps on exact head f803757dc7ebf997b60b979a2c82714130be46db:

  • Added a real multi-session cardinality regression at the SQLite-open boundary. Reversing the production fix makes it fail for the intended scaling reason (1 session: 4 read-only target opens; 3 sessions: 8; expected 8 to be 4). On the fixed head both runs use equal target-bounded reads while all entries/events import and archive.
  • The full Doctor file passes: 84 passed, 2 skipped. The complete changed-file gate and fresh Codex autoreview are clean.
  • The after-fix packaged [email protected] → [email protected] survivor passed 4,800 sessions, 23,890 events, and 2,200 cron jobs: Doctor 21s, idempotence Doctor 20s, Gateway 14s, all 62 phases passed. The rebased production files byte-match that packaged candidate's reviewed production head.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@steipete
steipete merged commit 27cb5d0 into main Aug 17, 2026
228 checks passed

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

commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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: M 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.

2 participants