Skip to content

improve: speed up transcript migration and Doctor scans - #133127

Merged
steipete merged 1 commit into
mainfrom
codex/streamline-migration-hot-path
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/streamline-migration-hot-path

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large upgrades still spent avoidable time importing transcript events and scanning already-current session histories during Doctor. This follows the earlier profiling work in #133068 and #133100.

Why This Change Was Made

The existing synchronous transcript batch now carries forward the projection facts it just persisted, removing redundant reads and query construction between events. Single appends and replacement writes still start with fresh facts. Doctor reuses prepared read statements within its existing read-only database pass, without caching results or retaining a cursor across repairs.

Statement reuse also requires clearing a native SQLite iterator error before reading the next session. A real SQLite regression reproduced that failure in three iterator paths before the cleanup fix; the original read error remains visible. No schema, indexes, durability settings, transaction boundaries, configuration, or persisted data contracts change.

User Impact

Imports and repeated Doctor checks do less work while preserving transcript contents, deduplication, active branches, search projections, recency, and restart behavior. This does not change background update channel selection or plugin capability consent.

Evidence

Matched Node profiling and fresh-process import runs against main 63f265c0ddb9ec80dd0c54bf7b6c76f3c005f6f6, three interleaved runs per variant and shape:

Fixture Before median After median Less elapsed time
Deep history, 100,001 events 15.383 s 12.426 s 19.2%
100 short histories, 10,100 events 1.298 s 1.072 s 17.4%
100 branched histories, 10,200 events 1.875 s 1.715 s 8.5%

These are local synthetic measurements with timing noise, not a guarantee for every machine. A separate 10,001-event trace removed 19,999 queries (120,033 → 100,034); all twelve reported write shapes retained identical counts, including every per-event watermark write.

On a separate unchanged 20,000-session / 500,000-event fixture, full Doctor header detection fell from 404.63 to 203.58 ms (49.7%) and label detection from 1,043.50 to 882.67 ms (15.4%). Each side has nine observations across three fresh processes. Initial label measurements overlapped local review scanning and are retained separately; the reported label result is the quiet confirmation. The database SHA-256 stayed identical.

Native SQLite error isolation: three iterator regressions failed before cleanup, then all four cases passed. All 102 focused tests passed across 11 files, covering imports, active projections, classification convergence, replacements, message cuts, recovery, parent forks, and Doctor repairs. The exact-head packaged Docker lane passed on its first attempt: stable 2026.7.1-2 → candidate tarball at 2ef1cee326e2aa3a3fa8689b9e9582733a364e81, with 4,800 sessions, 1,227,946 transcript events, and 10,000 cron jobs. Five exhaustive volume assertions passed, including automatic migration immediately after the update command and before standalone Doctor/plugin consent. Eight Gateway history samples (600 returned messages) were identical across restart. Repeat Doctor took 39 seconds against a 60-second budget; the complete lane took 533 seconds, excluding package build.

Exact-head CI passed, including production/test types, Windows, and SQLite lifecycle. Docker proof run returned wrapper exit 0; its delegated lease was stopped after evidence collection. Local aggregate test typing encountered the existing shared-install pako mismatch, which the clean CI install did not reproduce. Final changed-file lint, core typing, and focused reruns passed.

Reproduction: run node scripts/test-docker-all.mjs in Testbox with OPENCLAW_DOCKER_ALL_LANES=published-upgrade-survivor, OPENCLAW_UPGRADE_SURVIVOR_BASELINE_SPECS=2026.7.1-2, OPENCLAW_UPGRADE_SURVIVOR_SCENARIOS=sqlite-volume, OPENCLAW_UPGRADE_SURVIVOR_VOLUME_SESSIONS=4800, OPENCLAW_UPGRADE_SURVIVOR_VOLUME_EVENTS_PER_SESSION=257, and OPENCLAW_UPGRADE_SURVIVOR_VOLUME_CRON_JOBS=10000. This explicitly selects the candidate package; it proves automatic migration during update, not unattended stable-to-main channel switching. Fixture plugin capability consent remains explicit.

The latest ClawSweeper review found no actionable or security defect and listed no Rank-up moves. Its remaining exact-head CI/maintainer-review step is satisfied by the linked CI, local owner review, and fresh committed-patch Codex autoreview.

Production LOC: +238/-218 (net +20). Tests: +76/-3 (net +73). The growth gives the existing batch a bounded projection-fact owner and gives reused read statements explicit native-error cleanup; there is no second index/repair path or persistent cache. Codex autoreview of the complete owner/caller/test evidence found no actionable findings.

The change is bounded query/read reuse under the existing owners. It adds no persistent representation and does not alter the operating model described in docs/reference/database-schemas.md. Planner-statistics work (#119884) and credential-retention work (#129689) remain separately owned; this PR does not claim to resolve them.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: L maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 06:45
@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 Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 2:53 AM ET / 06:53 UTC.

ClawSweeper review

What this changes

The PR reuses SQLite statements during Doctor transcript scans and carries projection state across synchronous transcript batches to eliminate repeated reads and query construction.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. The fetched current main still uses the earlier per-call projection and reader behavior, so this remains a distinct optimization; it is also maintainer-authored and must not be auto-closed.

Priority: P2
Reviewed head: 2ef1cee326e2aa3a3fa8689b9e9582733a364e81

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, owner-bound performance refactor with meaningful native-error and projection coverage; no actionable correctness finding was identified.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal performance refactor is exempt from the external-contributor proof gate; its body additionally supplies benchmark and SQLite regression evidence correlated with the changed read and batch owners.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal performance refactor is exempt from the external-contributor proof gate; its body additionally supplies benchmark and SQLite regression evidence correlated with the changed read and batch owners.
Evidence reviewed 7 items Changed projection owner: The new closure retains only one batch's projection watermark, marks ambiguous paths dirty, and otherwise advances the same active-branch projection in the existing write transaction.
Caller boundary: Batch appends create one cursor for a synchronous iterator and retain fresh behavior for exported single-event appends; this keeps cached sequence and projection facts inside one transaction-bound batch.
Doctor reader behavior: Header and label health checks each create a reader for their read-only database pass, enumerate session IDs before guarded repairs, and reuse statements only within that pass.
Findings None None.
Security None None.

How this fits together

Doctor scans agent SQLite transcripts and makes guarded repairs, while the transcript store appends events and maintains the active-history search projection. This PR optimizes both internal paths without changing the stored schema or public configuration.

flowchart LR
  A[Stored transcript events] --> B[Doctor scan]
  B --> C[Read-only transcript reader]
  C --> D[Guarded repair]
  A --> E[Transcript batch append]
  E --> F[Active-history projection]
  F --> G[Session history and search]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed because no discrete patch defect was found; normal exact-head CI and maintainer review remain.
Agent review details

Security

None.

PR surface

Source +20, Tests +73. Total +93 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 238 218 +20
Tests 3 76 3 +73
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 314 221 +93

Review metrics

Metric Value Why it matters
Production versus test LOC production +20, tests +73 The small production increase establishes bounded batch/read-pass ownership; the additional tests cover native iterator cleanup and active-projection convergence.

Stored data model

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

Technical review

Best possible solution:

Retain the single synchronous-batch projection owner and per-read-pass statement reuse, with the existing dirty-projection reconciliation as the sole fallback path.

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

Not applicable as a user bug report. The relevant technical scenario is directly reproducible in node:sqlite and covered by the added healthy-session-after-error regression test.

Is this the best way to solve the issue?

Yes. The caching is confined to the synchronous transaction batch or one read-only Doctor pass, while ambiguous projections still use the established dirty-and-reconcile owner rather than a parallel path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 357078cf7087.

Labels

Label changes:

  • add P2: This is a bounded performance improvement to session migration and Doctor maintenance paths without evidence of an urgent user-facing regression.
  • 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: This maintainer-authored internal performance refactor is exempt from the external-contributor proof gate; its body additionally supplies benchmark and SQLite regression evidence correlated with the changed read and batch owners.

Label justifications:

  • P2: This is a bounded performance improvement to session migration and Doctor maintenance paths without evidence of an urgent user-facing regression.
  • 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: This maintainer-authored internal performance refactor is exempt from the external-contributor proof gate; its body additionally supplies benchmark and SQLite regression evidence correlated with the changed read and batch owners.

Evidence

What I checked:

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.

@steipete
steipete merged commit 348ad76 into main Aug 30, 2026
315 of 316 checks passed
@steipete
steipete deleted the codex/streamline-migration-hot-path branch August 30, 2026 07:02
@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

commands Command implementations 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: L 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