Repository navigation
perf(gateway): retain history readers across agent switches - #150519
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 16, 2026, 11:26 PM ET / September 17, 2026, 03:26 UTC (Revision 2). ClawSweeper reviewWhat this changesRetain up to 64 history database connections across agent switches, with least-recently-used eviction, tracked cleanup, and idle worker retirement. Merge readiness✅ Ready for maintainer review This remains a useful performance improvement: current main still closes the previous connection when switching agents. No actionable correctness or security findings were identified, and all five touched files match the previously reviewed head. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway serves conversation history through a serialized worker that reads per-agent SQLite databases. This change reuses database connections while preserving fresh snapshots and per-request admission checks. flowchart TD
A[History or presence request] --> B[Parent database custody]
B --> C[Serialized history worker]
C --> D[Retained connection pool]
D --> E[Identity and admission checks]
E --> F[Fresh database read]
F --> G[History or presence result]
D --> H[Eviction or joined worker cleanup]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +44, Tests +67, Docs +1. Total +112 across 5 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep connection reuse inside the existing serialized history worker, with bounded retention and the existing per-read validation and joined cleanup owners. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction: this optimizes existing behavior. Current-main source confirms connection churn on target switches, and the supplied entry-point census measures it. Is this the best way to solve the issue? Yes. Extending the existing worker's connection retention avoids a parallel reader owner and preserves the established snapshot, admission, and cleanup contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9843b937e354. LabelsLabel 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)
|
9a7ef99 to
5c29949
Compare
|
Merged via squash.
|
Related: #145579
What Problem This Solves
Reading conversation history across multiple agents repeatedly closes and reopens their databases, even though the history worker stays alive for 30 minutes.
User Impact
History reads across agents reuse open connections while preserving current database admission and committed-data visibility. No configuration or stored-data migration is required. The single history worker retains at most 64 database connections, evicts the least recently used target at capacity, and closes its connections after 30 minutes without pending history work. This is a worker idle timeout; activity for another agent can keep retained connections open.
Why This Change Was Made
Keep successful per-target read scopes in the existing serialized worker and report confirmed closures to the existing parent resource owner. Missing stores consume no retained slots. Explicit database cleanup and worker failures still revoke custody and join native worker exit. An empty worker created by missing-store reads also expires after 30 minutes without inventing database custody.
The tradeoff is additional open handles: the 32-agent fixture observed 223 file descriptors versus 192 after warmup; both returned to 44 after owned cleanup. RSS varied across fresh processes and does not isolate the connection cost. Persistent storage, schema, row selection and read transaction boundaries are unchanged.
Evidence
13c6d9e: for 128 warm reads, alternating targets went from 127 physical opens to zero; rotating 32 targets went from 128 to zero. Full result checksums matched and an external append remained visible after switching targets. Both census processes exited successfully and their groups/fixtures were absent.Updated onto main at
26d2daa2c294b4f260187e4edb5ecea224ce876c, which includes the landed Qwen CI repair #150523. All files in this PR retain their previously reviewed and tested bytes; the duplicate local clock-fixture change is removed. Fresh exact-head checks validate the updated base.