Repository navigation
improve: reduce audit event persistence overhead - #150243
Conversation
|
🦞👀 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: blocked before merge. Reviewed September 16, 2026, 9:51 PM ET / September 17, 2026, 01:51 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR reuses compiled audit insert and reread queries per SQLite connection and closes the test database before removing temporary directories. Merge readiness⛔ Blocked before merge - 1 item remains The optimization remains useful and has no actionable findings. The previous migration-proof blocker does not apply: the introduced changes preserve the existing stored format and persistence semantics. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s audit writer queues run, tool, and enabled message metadata for storage in the shared SQLite database. The audit store persists and prunes these records before returning them for operational inspection. flowchart TD
A[Run and tool events] --> C[Audit writer queue]
B[Enabled message events] --> C
C --> D[State write transaction]
D --> E[Compiled queries with fresh values]
E --> F[SQLite audit ledger]
F --> G[Prune and reread]
G --> H[Recorded audit event]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +66, Tests +1. Total +67 across 3 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep compiled query reuse inside the audit store’s existing transaction and native execution lifecycle, preserving all persisted values and reread semantics. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug: this is a performance improvement, and current-main source confirms repeated compilation while the supplied experiment measures its cost. Is this the best way to solve the issue? Yes. Reusing the existing prepared-query helper removes repeated compilation without introducing a competing statement owner or changing database compatibility. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1fbb41545ec5. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
* improve: reduce audit event persistence overhead * refactor: isolate prepared audit event queries
Closes #150239
What Problem This Solves
The default audit ledger rebuilds the same INSERT and exact post-prune SELECT for every run or tool event, adding avoidable work to its writer queue.
User Impact
Reduces audit persistence overhead. The real tool-event writer improved 6.67% at the paired median in a fixed component experiment; message-event gains were smaller. No configuration, schema, durability, or retention change.
Why This Change Was Made
Retain the two compiled query shapes with each physical SQLite connection in an audit query sibling using the existing prepared-query helper. Every write still binds fresh fields and runs the same native operations, transaction, HMAC projection, pruning, sequence validation, and authoritative reread.
Validation also exposed a pre-existing Windows fixture cleanup error. The writer test now closes the shared database before removing its temporary directory in one teardown hook; assertions and deadlines are unchanged.
Evidence
These are modest component results on a shared Windows host, not whole-Gateway gains. Slower pairs are retained (worst 8.39% slower). Invalid initial harness runs are preserved separately: fixture rowid restoration and an unreferenced writer-readiness wait were corrected before the complete fixed cohort; production code was unchanged.
Focused Windows validation: 116 tests passed across the audit store (58), writer (12), and Gateway subscription (46) suites. The unchanged baseline reproduced the writer cleanup failure before the fixture repair. Formatting and diff whitespace checks passed.
Independent reviews passed through P2 with no actionable findings, including the follow-up sibling extraction. Targeted type-aware lint and formatting passed for the extracted owner and query module. The initial CI run caught a newly enforced 700-line cap; the extracted owner now has 699 nonblank lines, with no suppression or baseline change. Hosted CI passed on revised head 1f3c488, including the required openclaw/ci-gate, line-cap ratchet, types, lint, and selected runtime suites.
The 116 local test passes and benchmark cohort preceded the mechanical module extraction. The revised head has now passed hosted CI. No new local benchmark or local runtime pass is claimed after extraction. Native review, prepare, and merge completed on a fresh Blacksmith Testbox. Landed as 8c959de; main ancestry and exact landed source hashes were verified. Native recovery receipts were transferred and verified before the owned lease was stopped.
Data-model compatibility: the reviewed diff changes only the audit store, its new query sibling, and writer test teardown. It changes no schema, migration, generated database types, schema version, defaults, persisted fields, indexes, durability, or retention. The query sibling imports the existing generated table type and compiles the same INSERT/SELECT with all 30 fresh values; it executes no DDL. Existing database files require no migration and use the unchanged schema/bootstrap owners. The full-owner experiment checked identical SQL/method/bindings and close/reopen behavior; revised-head CI is green. The automated 'database schema: src/audit/audit-event-queries.ts' classification is a path-based false positive, so no migration-specific gate applies to this diff.