Repository navigation
fix(database): make unbounded retention portable to PostgreSQL - #183044
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 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 reuses ordered sessions and deletion byte totals during ACP replay eviction. Example: Sessions a, b, and c each contain 130 events with 64 KiB text and tied timestamps.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this maintainer-authored PR open: it removes identifiable repeated work that remains on current main, and no definite introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe ACP bridge sends session starts and updates to the shared-state worker, which persists bounded replay history and returns complete replay or an incomplete result that selects transcript fallback. flowchart LR
A[ACP stdio client] --> B[Bridge translator]
B --> C[Replay ledger facade]
C --> D[Shared state worker]
D --> E[Transactional retention]
E --> F[Replay tables]
F --> G[Replay or transcript fallback]
Technical reviewBest possible solution: Keep the owner-local optimization and land it once its performance acceptance rule and required database checks are satisfied. Do we have a high-confidence way to reproduce the issue? Yes: current-main source repeats both reads per eviction batch, and the submitted baseline reports 11 budget reads through real ACP stdio and an isolated Gateway; this review ran no target code. Is this the best way to solve the issue? Carrying the existing deletion totals and bounded session order within their owning transaction is the smallest complete optimization, preserving the stored clamp without introducing a cache or another state owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ad2172d77e26. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +20, Tests +157, Other +188. Total +365 across 6 files. Added test files: 1. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 24, 2026, 9:17 PM ET / October 25, 2026, 01:17 UTC. |
e554c36 to
afc4115
Compare
8749adb to
afc4115
Compare
Use the engine-owned unbounded row limit for ACP, channel ingress, and resolved suggestions. Preserve offset ordering, protected slots, and batch behavior; express ACP byte clamping with CASE. Real SQLite and PostgreSQL regressions cover all three owners.
afc4115 to
d0ecc55
Compare
…law#183044) Fix PostgreSQL retention failures in ACP replay, channel ingress, and resolved session suggestions by using the database engine-owned unbounded LIMIT expression. Preserve each owner's ordering, offsets, protected rows, and batching. Express ACP byte-accounting subtraction with the same portable zero clamp. Synthetic owner regressions reproduce seven PostgreSQL failures before the repair and pass all fourteen SQLite/PostgreSQL cases with the fix. No schema, policy, transaction, or worker-request change.
What Problem This Solves
PostgreSQL rejects three retention queries with SQLSTATE
2201W(LIMIT must not be negative). ACP replay session retention, channel-ingress capacity retention, and resolved session-suggestion pruning all used SQLite'sLIMIT -1spelling. ACP byte trimming also used SQLite's scalarmaxform.What Changed
One database-engine helper supplies the unbounded limit expression:
-1on SQLite andALLon PostgreSQL. The three owners keep their existing OFFSET, ordering, predicates, and batching. ACP uses a Kysely CASE expression for the same zero-clamped subtraction.No schema, retention policy, transaction, cache, identity, or worker-request change. ACP byte-budget optimization is deliberately separate and will follow in another PR.
Evidence
The synthetic real-owner tests pass 7/7 on SQLite and fail 7/7 on PostgreSQL before the fix, all with SQLSTATE
2201W. With this repair, 14/14 pass on SQLite and real PostgreSQL 17. They exercise:Changed-file type-aware lint and
git diff --checkpass. The independent Codex P0–P2 review is scoped-clean, and the committed tree matches the reviewed tree. PostgreSQL maintainer review is approved for this exact head. Exact-head CI passed, including all three PostgreSQL conformance shards, production/test types, type-aware lint, source contracts, and baseline ratchets.The local T1 and dialect ratchets, format, mock exports, and other completed contract checks passed. Local typecheck setup rejected the campaign-required external dependency store; CI supplies the passing typecheck and lint evidence. The duplicate local full-core lint was stopped after CI passed. All three local Knip comparisons exactly match the original base: production 72/72, full-tree 86/86, scripts 1,136/1,136, with zero added or removed findings.
Class Audit
The shared helper repairs all three unguarded negative-LIMIT sites:
src/acp/event-ledger.worker.ts,src/channels/message/ingress-queue.kernel.ts, andsrc/config/sessions/session-suggestion-store.kernel.ts(the latter usedeb.lit(-1)). The remaining negative sentinel insession-accessor.transcript-range.worker.tsis explicitly inside the SQLite-only!postgresrecursive branch; PostgreSQL has its own outer limit. All 13 other OFFSET chains use nonnegative limits.Open-PR Compatibility
Base-only versus base-plus-candidate merge-tree comparison across 80 overlapping open PRs adds no conflicting paths or conflict markers. Existing conflicts are not counted as new ones.
Compared PRs
#183114, #183069, #182971, #182951, #182329, #182216, #182104, #180832, #180026, #178768, #178124, #178033, #177356, #177351, #175345, #175029, #174317, #174235, #173557, #173026, #170160, #169723, #169504, #169438, #169241, #169081, #168522, #168434, #167221, #167090, #166166, #165710, #165583, #164935, #164843, #164721, #164551, #163835, #163655, #163239, #162989, #162583, #162565, #162530, #161997, #161410, #160908, #160851, #159478, #159326, #159255, #158502, #158244, #157693, #157557, #157427, #156634, #155630, #154904, #153907, #153856, #151648, #150078, #149882, #149241, #148533, #146847, #146326, #145839, #141239, #141004, #140609, #139620, #136474, #129388, #126224, #124337, #121204, #107366, #93952
Portability head:
d0ecc5533d4b1f56fedf9db9d030eaad42870ac8. All seven files are byte-identical to the reviewed and tested prerequisite. The three optimization-only proof changes have moved out of this PR.