Skip to content

fix(logbook): index frame and batch queries - #129570

Merged
vincentkoc merged 1 commit into
mainfrom
fix/logbook-sqlite-indexes
Aug 25, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/logbook-sqlite-indexes

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Audit: https://gist.github.com/vincentkoc/10826f918dde7e23020cf2f390af95d3

What Problem This Solves

Fixes an issue where Logbook capture, batch analysis, observation replacement,
and frame cleanup scan or sort growing SQLite tables on normal paths.

Why This Change Was Made

Adds four indexes for global capture timestamps, completed-batch frame reads,
batch-owned observations, and card keyframe foreign-key maintenance. Logbook
continues to use schema version 1; its canonical schema runs idempotently on
open, so existing databases receive the indexes without a migration bump.

This is a bounded query-plan improvement under the SQLite review checkpoint.
The timestamp index is justified by the hot lastFrame() path, not by an
unmeasured retention claim.

User Impact

Periodic capture and batch processing avoid table-wide scans as Logbook history
grows. Frame cleanup no longer scans every card to maintain keyframe references.

Evidence

  • pnpm test:extension logbook: 66 passed.
  • Planner coverage proves the four indexes and rejects unindexed scans or
    temporary ordering where relevant.
  • Schema-1 reopen coverage drops all four indexes, reopens the store, and proves
    restoration without changing the version.
  • Manual 400,000-row benchmarks:
    • batch frame read: 11.485 ms -> 0.802 ms, 14.3x
    • observation replace/delete: 10.507 ms -> 2.841 ms, 3.70x
    • keyframe FK maintenance: 21.624 ms -> 0.0197 ms, 1098x
    • latest frame lookup: 11.697 ms -> 0.005 ms, 2339x
  • Measured build/storage cost:
    • batch index: 5.84 MB, 106 ms
    • observation index: 4.26 MB, 83 ms
    • keyframe index: 4.39 MB, 83 ms
    • captured-at index: 4.76 MB, about 94 ms
  • Production delta: +4 SQL lines. Tests: +109.

AI-assisted: yes. The implementation, benchmarks, and review findings were
independently verified before push.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@vincentkoc vincentkoc self-assigned this Aug 25, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 25, 2026 19:27
@openclaw-barnacle openclaw-barnacle Bot added plugin: logbook Logbook automatic work journal plugin size: S maintainer Maintainer-authored PR labels Aug 25, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 25, 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:

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision: accepted.

I accept the same-version four-index rollout and its measured build/storage tradeoff. The representative 400k-row fixture added about 19.25 MB and took about 366 ms aggregate to build the indexes. Measured query improvements were about 14.3x for batch lookup, 3.7x for observation replacement, 1098x for keyframe lookup, and over 2000x for latest-frame lookup.

Focused Logbook extension tests, query-planner assertions, and reopen/persistence coverage pass. This is the intended performance/storage tradeoff for this PR.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

This PR adds four SQLite indexes to Logbook and planner/reopen tests to avoid table scans during capture, batch analysis, observation replacement, and frame cleanup.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer review: the focused Logbook index change appears technically sound, but it changes persistent-store disk and open-time behavior without a linked accepted design record required by repository policy.

Priority: P2
Reviewed head: 5dc2e8b9dc2474653436fe0deea0dc45379eb03d
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The owner-local implementation and upgrade coverage are strong; merge still needs the required persistent-store decision record.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored internal database performance change is exempt from the external-contributor proof gate; the PR body nonetheless supplies benchmark and planner evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored internal database performance change is exempt from the external-contributor proof gate; the PR body nonetheless supplies benchmark and planner evidence.
Evidence reviewed 5 items Current-main gap: Current main contains the capture, batch-frame, observation-delete, and pruning query paths but not the four proposed indexes, so the PR remains necessary.
Schema owner and upgrade path: The proposed indexes are in the Logbook canonical schema, which is executed whenever the store opens; the added reopen test verifies restoration while user_version remains 1.
Runtime callers: Capture calls lastFrame, analysis calls batchFrames and replaceObservations, and pruning deletes frames through the same store that owns the new indexes.
Findings None None.
Security None None.

Live Verification

Command: pnpm test:extension logbook

Result: PASS (completed)

$ node --import tsx scripts/test-extension.mts logbook
[test-extension] Running 5 test files for logbook

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129570-vloGvk/target

 ✓  extensions  extensions/logbook/src/store.test.ts (26 tests) 392ms
 ✓  extensions  extensions/logbook/src/node-host.test.ts (2 tests) 9ms
 ✓  extensions  extensions/logbook/src/analyze.test.ts (27 tests) 2205ms
     ✓ preserves local wall-clock time across a DST transition  2051ms
 ✓  extensions  extensions/logbook/src/service.test.ts (8 tests) 122ms
 ✓  extensions  extensions/logbook/index.test.ts (3 tests) 4ms

 Test Files  5 passed (5)
      Tests  66 passed (66)
   Start at  21:04:24
   Duration  12.15s (transform 19.85s, setup 3.82s, import 21.51s, tests 2.73s, environment 1ms)
$ node --import tsx scripts/test-extension.mts logbook
[test-extension] Running 5 test files for logbook

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129570-vloGvk/target

 ✓  extensions  extensions/logbook/src/store.test.ts (26 tests) 336ms
 ✓  extensions  extensions/logbook/src/node-host.test.ts (2 tests) 11ms
 ✓  extensions  extensions/logbook/src/analyze.test.ts (27 tests) 1171ms
     ✓ preserves local wall-clock time across a DST transition  1073ms

Assertions:

  • PASS expect_output: store.test.ts

How this fits together

Logbook stores captured frames, derived observations, and timeline cards in a plugin-owned SQLite database. Capture, analysis, and pruning read or update those records, with frame deletion also maintaining card keyframes.

flowchart LR
A[Screen capture] --> B[Logbook SQLite store]
C[Batch analysis] --> B
B --> D[Indexes select query paths]
D --> E[Observations and cards]
E --> F[Timeline output]
Loading

Decision needed

Question Recommendation
Should existing Logbook databases create these four indexes on their next open, accepting the documented one-time disk and build cost? Accept the indexed schema: Record acceptance of the one-time index build, storage cost, and same-version reopen path, then merge after exact-head checks are green.

Why: This changes a plugin-owned persistent representation and has stated disk and open-time costs, so repository policy requires maintainer acceptance before merge.

Before merge

  • Resolve merge risk (P1) - Existing Logbook databases would create four persistent indexes on their next open; the PR reports about 19.25 MB of added storage and roughly 366 ms of aggregate build time at 400,000 rows, but no accepted maintainer design record is linked.
  • Complete next step (P2) - A maintainer must accept the persistent-store trade-off before this member-authored protected-label PR can proceed.
Agent review details

Security

None.

PR surface

Source +4, Tests +109. Total +113 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 0 +4
Tests 1 109 0 +109
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 113 0 +113

Review metrics

Metric Value Why it matters
Production versus test delta production +4, tests +109 Four schema statements modify a plugin-owned SQLite store; test growth covers query plans and same-version reopening.
Reported index cost 4 indexes; about 19.25 MB and 366 ms at 400,000 rows This is the merge-relevant storage and startup trade-off requiring an accepted persistent-store decision.

Stored data model

Persistent data-model change detected: database schema: extensions/logbook/src/store.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Record the persistent-store decision (recommended)
    Link maintainer acceptance of the existing-database index build, disk footprint, and same-version reopen behavior before merge.
  2. Defer the indexes
    Pause this PR if maintainers do not want current Logbook stores to absorb the documented one-time build and storage cost at open.

Technical review

Best possible solution:

Record acceptance of the Logbook index lifecycle, disk footprint, startup cost, and same-version reopen behavior, then merge this owner-local schema and test change.

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

Yes, from source: current main has the relevant Logbook queries and foreign-key cleanup path without these supporting indexes; the PR adds direct planner coverage for them.

Is this the best way to solve the issue?

Yes technically: indexes belong in the canonical Logbook store schema that owns these queries; merge remains contingent on maintainer acceptance of the persistent-store trade-off.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded performance and persistent-store maintenance change in a bundled plugin.
  • add merge-risk: 🚨 compatibility: Existing Logbook databases acquire new persistent indexes when opened without a schema-version change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded performance and persistent-store maintenance change in a bundled plugin.
  • merge-risk: 🚨 compatibility: Existing Logbook databases acquire new persistent indexes when opened without a schema-version change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Introduced the Logbook feature and later maintained the shared SQLite boundary used by this store. (role: feature introducer and adjacent SQLite contributor; confidence: high; commits: c730d8f1f1bb, 1e93465a2a92; files: extensions/logbook/src/store.ts, src/infra/node-sqlite.ts)
  • Vincent Koc: Appears in prior merged history affecting the Logbook store as well as the current focused proposal. (role: recent Logbook-area contributor; confidence: medium; commits: c9abc7588493; files: extensions/logbook/src/store.ts, extensions/logbook/src/store.test.ts)

Rank-up moves

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

  • Link maintainer acceptance of the documented index build and storage trade-off.

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.

@vincentkoc
vincentkoc merged commit f21c707 into main Aug 25, 2026
154 of 162 checks passed
@vincentkoc
vincentkoc deleted the fix/logbook-sqlite-indexes branch August 25, 2026 21:30
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR plugin: logbook Logbook automatic work journal plugin size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant