Repository navigation
perf(acp): reuse prepared replay ledger queries - #139982
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: needs maintainer review before merge. Reviewed September 6, 2026, 5:39 AM ET / 09:39 UTC. ClawSweeper reviewWhat this changesThe PR reuses compiled SQLite queries when recording and trimming ACP replay history and avoids unnecessary byte counting for oversized cached-query inputs. Merge readiness✅ Ready for maintainer review Keep open: this implements the accepted ACP performance work that current main still lacks. No actionable correctness or security defect was found in the introduced changes. Priority: P2 Review scores
Verification
How this fits togetherThe ACP bridge records prompts and agent updates in SQLite so clients can restore session history. Its replay ledger preserves ordered events within existing retention limits and falls back to transcript history when replay is incomplete. flowchart LR
A[Prompts and agent updates] --> B[ACP replay ledger]
B --> C[Compiled queries with fresh values]
C --> D[Shared SQLite statement cache]
D --> E[Stored history and retention limits]
E --> F{Complete replay available?}
F -->|Yes| G[Ordered ACP replay]
F -->|No| H[Transcript fallback]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +148, Tests +209, Other -1. Total +356 across 5 files. View PR surface stats
Review metrics
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 replay query compilation at the connection owner while preserving fresh bindings, shared statement invalidation, and existing retention semantics. Do we have a high-confidence way to reproduce the issue? Not applicable as a correctness bug: source confirms repeated query construction on main, while the PR reports measured preparation overhead and preserved results. Is this the best way to solve the issue? Yes: using the existing prepared-query helper removes repeated work without adding a competing cache owner or changing durable replay semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f66dc27b5bf7. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Related: #139768
What Problem This Solves
ACP replay writes repeatedly rebuild the same queries and prepare native statements while appending events and enforcing the existing history limits. This adds avoidable work to every update.
Why This Change Was Made
Eleven fixed query shapes now retain their Kysely compilation per physical SQLite connection. Each invocation binds current session IDs, sequences, timestamps, metadata and payloads. Native statement retention, authorization, re-entry, size limits and invalidation remain owned by the existing bounded shared executor cache.
The raw runtime SQL in the affected append/trim operations is replaced with typed Kysely queries. The unchanged retention owner still enforces global counts, sequence gaps, session tie ordering and intermediate prompt-block eviction. No schema, configuration, cap, migration, or dependency changes are introduced.
An equivalent shared cache-admission shortcut also avoids UTF-8 scanning an obviously oversized string: when its UTF-16 code-unit length already exceeds the remaining byte budget, its UTF-8 representation cannot fit. Shorter strings still receive exact byte sizing. The cache admits exactly the same inputs as before.
User Impact
Warm ordinary appends use zero new native prepare calls and zero Kysely compilations instead of four and three respectively. Oversized payloads retain their existing uncached behavior and still require one native preparation. The trimming fixture drops from 840 native preparations to zero over 120 appends.
The first operation compiles all eleven shapes, and unchanged history-count scans can still dominate large histories. Local process-CPU samples before the shared sizing shortcut improved ordinary small writes by about 21–22% and byte trimming by about 15–23%; wall-clock samples were noisy. Final oversized-only comparisons put Node 24 roughly flat (+1.08% paired CPU) and Node 26 modestly faster (−4.25%). Both sides of those final oversized comparisons use the equivalent improved sizing helper. These are scoped local measurements, not uniform production latency claims.
Evidence
Proof uses synthetic local SQLite and the real ACP stdio/GatewayClient against a local mock WebSocket Gateway; no production provider, user data or packaged-build performance is claimed.