Repository navigation
perf(knowledge): release database locks during Git checkpoints - #184789
Conversation
Keep Git outside write transactions, settle each checkpoint and receipt atomically, and reuse per-drain request facts and statements. Label ingest transaction owners while preserving publication and recovery semantics.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR runs Knowledge Git checkpoints outside SQLite write transactions and atomically records each checkpoint result afterward. Example: Knowledge drains 10 queued checkpoints containing 25 documents each.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: current main still holds the SQLite writer during Git checkpoints, and this focused change removes that hold without a definite introduced defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherKnowledge's serialized storage worker publishes vault content, queues exact snapshots in SQLite, sends those snapshots to local Git, and records checkpoint results in publication receipts. flowchart TD
A[Knowledge operation] --> B[Serialized storage worker]
B --> C[Publication and SQLite outbox]
C --> D[Ordered checkpoint drain]
D --> E[Local Git checkpoint]
E --> F[Atomic job and receipt settlement]
Technical reviewBest possible solution: Keep Git work in the existing serialized storage owner and use short atomic transactions solely to settle each job and its receipt. Do we have a high-confidence way to reproduce the issue? Current-main source directly shows Git subprocess work inside an IMMEDIATE transaction, and the PR reports a second-connection writer probe failing on the base and passing on the candidate; this review ran no target code. Is this the best way to solve the issue? The change addresses the lock's owning boundary with the existing worker, outbox, and idempotent Git refs; the added benchmark and two distinct regression checks are proportionate to the transaction change. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c5d77b74ab19. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +12, Tests +39, Docs +2, Other +298. Total +351 across 7 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 26, 2026, 12:33 PM ET / 16:33 UTC. |
…law#184789) Keep Git outside write transactions, settle each checkpoint and receipt atomically, and reuse per-drain request facts and statements. Label ingest transaction owners while preserving publication and recovery semantics.
What Problem This Solves
Knowledge Git checkpoints held an IMMEDIATE SQLite write transaction while running Git subprocesses and filesystem work. Even an empty checkpoint queue acquired a write transaction. Slow transaction logs could not distinguish this work from publication, observation, or attachments.
User Impact
Knowledge keeps its operational database writer free during Git checkpoints. Exact content, search behavior, publication atomicity, checkpoint order, and crash recovery are unchanged. No schema, configuration, retention, or migration changes.
Why This Change Was Made
The storage worker already serializes operations, and the durable Git checkpoint ref already makes replay idempotent. Drain one retained batch at a time outside the transaction, then acknowledge its job and publication receipt together in a short transaction after checking current access. Reuse prepared statements and derive the publication-token lookup once per synchronous drain instead of once per job. Empty drains do no transactional work. Label attachment, acceptance, publication/recovery, observation, and Git settlement transactions.
The plugin has no embedding stage. Record preparation already runs in the storage worker; keyword reconciliation is incremental and search-driven. Atomic publication batches remain capped at 25 items / 1 MiB. Filesystem validation in acceptance/publication/observation remains intact. The new labels will distinguish residual slow work there; this PR does not claim that every previously unlabeled slow transaction was Git.
Runtime production delta: +12 lines across the three storage modules. Growth preserves atomic per-job acknowledgement and current-authority checks after removing the encompassing transaction. There is no new long-lived cache or compatibility path. The separate benchmark is tooling, with an exact Knip entry; the shared performance README is unchanged.
Evidence
Acceptance: remove the database writer hold during real Git work, eliminate empty-drain transactions, preserve exact stored Git blobs and receipts, and reduce owner CPU/allocation without a demonstrated adverse result. Synthetic owner benchmark on macOS/Node 26.12.1, baseline
e0b550b0ababbf011ec2aaee40c00a228070562a, 2,000 archived jobs and publication receipts. Five timing runs per arm; two separate allocation runs per arm. Each invocation is a small single-process run; no live service load was started.CPU excludes Git children; allocation includes collected JavaScript objects, not native SQLite/Git memory. Every run verifies all 250 document blob hashes and all checkpoint receipts. Timing median/range: empty drains 2,557 [2,489–2,974] → 2,473 [2,291–2,692] ms; checkpoints 1,634 [1,511–1,831] → 1,842 [1,439–1,947] ms. Host one-minute load per timing arm: base 25.6/20.4/19.3/18.1/17.2; candidate 24.5/24.2/19.6/18.7/17.6. No latency-tail claim from these small samples. Maximum checkpoint transaction per timing run: base 1607/1815/1676/1617/1494 ms; candidate 3.73/3.59/2.68/6.93/1.98 ms (one vs ten transactions per run).
GC was collected in two additional untraced AB/BA pairs after fixing the benchmark's observer queue drain. Empty drains: 7 → 5 collections per run, paired mean total 8.88 → 8.46 ms per 2,000 calls; maxima base 1.79/1.43 ms, candidate 1.96/3.98 ms. Checkpoint drains: one collection (1.65/1.77 ms) → zero. These tiny counts are context only. Those extra checkpoint timing windows were highly variable: base 2.15/7.09 s, candidate 3.19/1.93 s; none were discarded. The earlier timing/allocation results remain valid, but their original GC fields were not used.
Mean post-operation RSS: empty 295.6 → 290.0 MiB; queued 303.3 → 292.2 MiB. Transient heap: empty 89.4 → 76.3 MiB; queued 70.7 → 75.8 MiB with fewer collections. These are owner-process observations, not retained Gateway heap measurements.
Reproduce with
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/knowledge-git-transactions.ts; use--sampleseparately for allocation. The script header documents baseline source selection and workload options.Validation:
7d7740ca093a1f98a0471d953f0135bf5d923d43; requiredopenclaw/ci-gatechecks passed. No CI reruns.database is locked, passes on candidate.git-history.test.ts,publication.test.ts, andingestion.test.ts: 46 passed, final runner exit 0, 96.6 s wall time. These include process death, FIFO catch-up, filesystem conflicts, immutable sources, and scope isolation. An earlier run passed assertions but was rejected because source changed before runner verification; only the frozen rerun is counted.pnpm tsgo:extensions;git diff --check: passed.Gaps: owner proof follows the scoped fast-path protocol; no ten-minute whole-Gateway stress or live ingest mutation. The reported main-thread heap increase remains unattributed: full parsed catalogs/plans live in the storage worker, and this change does not establish a Gateway heap-retention fix. Hosted CI supplies broad validation. The standalone unused-file analysis was not run under the local compute limit; the benchmark has an exact Knip entry.