fix(core): bound event log compaction - #36710
Conversation
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
bef5885 to
04954f8
Compare
|
Rebased onto current Fresh production evidence from today: Verification on the rebased branch:
The branch is current, clean, mergeable, and CI is green. Maintainer review would be appreciated. |
|
Any timeline on this getting merged? My local |
|
I'll try Discord and see if I can get a maintainer to look at this. Mine got up to 84gb. |
|
Production-scale dry-run validation at exact head Safety boundaryI did not point this PR CLI directly at the live database. Snapshot:
Verification
{
"events": 7894217,
"payloadBytes": 79722946429,
"compactableEvents": 7571556,
"recommended": true
}Session-scoped dry-run: opencode db compact-events --session ses_05c8c577dffe3gCA4gW5hlPzUH --limit 1000Completed in All-scope dry-run: opencode db compact-events --all --limit 1000Produced no report before being terminated after
Post-run invariants on the clone remained unchanged: ConclusionThe dry-run mutation guard itself held, and session-scoped execution works against this dataset. However, AI assistance disclosure: OpenAI GPT-5.6-sol via OpenCode was used to inspect the implementation, run the isolated validation, analyze the SQLite query plan, and draft this report. Chris Huber reviewed and is responsible for the submitted findings. |
AI assistance: OpenAI GPT-5.6-sol via OpenCode updated and validated the branch integration. Chris Huber reviewed and is responsible for the change.
Replace global event-log grouping with aggregate and sequence cursors, strengthen projection checks, and route inspection commands through a read-only database layer. AI assistance: OpenAI GPT-5.6-sol via OpenCode analyzed the production query plan, implemented the bounded compaction and read-only path, and ran clone validation. Chris Huber reviewed and is responsible for the change.
|
Updated the PR at Repair
Verification
Production-clone results on a
A byte-for-byte fixture test confirms the read-only layer leaves the main DB unchanged and creates no sidecars for a rollback-journal database. Against the WAL production clone, dry-run left the main DB and WAL unchanged; SQLite updated the existing SHM lock-coordination file mtime, which is expected for a concurrent read-only WAL connection. Full clone compaction was intentionally stopped after 200,215 rewrites because APFS copy-on-write consumed about 17 GB during mutation and completing all 7.5M snapshots would exhaust local disk. This is a clone-storage constraint, not a query or integrity failure. AI assistance disclosure: OpenAI GPT-5.6-sol via OpenCode analyzed the production query plan, implemented and reviewed the resumable/read-only repair, ran tests and typechecks, and validated it against the production clone. Chris Huber reviewed and is responsible for the submitted changes and evidence. |
Add exclusive run-to-completion compaction, cursor-interval accounting, verified VACUUM INTO recovery copies, integrity checks, and physical source vacuuming. AI assistance: OpenAI GPT-5.6-sol via OpenCode designed and implemented the maintenance workflow, reviewed concurrency safety, and validated exact source/backup parity on a production-derived fixture. Chris Huber reviewed and is responsible for the change.
|
Added the complete maintenance workflow at The PR now owns the entire operation: opencode db compact-events \
--all --apply --limit 10000 --until-done \
--backup /absolute/path/to/recovery.sqlite \
--vacuumSafety properties:
Validation on a production-derived 100-session fixture:
Verification:
AI assistance disclosure: OpenAI GPT-5.6-sol via OpenCode designed, implemented, reviewed, and production-fixture-tested the exclusive maintenance, backup verification, and vacuum workflow. Chris Huber reviewed and is responsible for the submitted changes and evidence. |
Replace repeated aggregate JSON grouping with one maintenance-locked event scan, indexed latest-snapshot lookups, durable batch cursors, and bulk checkpoint updates. AI assistance: OpenAI GPT-5.6-sol via OpenCode implemented and reviewed the indexed compaction path and validated production-derived throughput and crash-safety cases. Chris Huber reviewed and is responsible for the change.
Issue for this PR
Closes #33356
Type of change
What does this PR do?
Adds read-only event-log status plus explicit, dry-run-by-default bounded compaction (
--sessionor--all,--apply, maximum 10,000 rows). Apply verifies latest message/part projection contents, batches in one immediate transaction, and only writes checkpoints for aggregates with no workspace or sync owner. Sync has no marker version negotiation, so synced/owned aggregates are reported and rejected.How did you verify your code works?
bun test test/session-event-log-compaction.test.ts test/event.test.tsbun typecheck(30 packages)Screenshots / recordings
Not applicable; database maintenance CLI.
Checklist
AI assistance