Repository navigation
fix(agent): retire settled run journals so agent.db stays bounded - #891
Merged
Merged
Conversation
Every run kept its raw event journal forever, and ~95% of it is per-token deltas the transcript has already folded into entries and message blocks. One session's journal reached 8 GB (17.8M rows, 4 GB of payload), and `prune_run_events` existed but had no caller. A settled run's journal is only read while a client can still attach to (or reconnect to) it, so each run now retires the journals of settled runs beyond the newest two (`SETTLED_RUN_JOURNALS_KEPT`). The prune is awaited on the blocking pool before the run starts - the run cannot race its own cleanup - and is never fatal: a failure leaves the bytes for the next run or the startup compaction. Ordering uses the run markers' timestamps (`started_at_ms`, falling back to `completed_at_ms`), because `runs.run_sequence` is NULL on the plain prompt path; runs with no timestamp, the live run, and session-scoped rows (empty run id) are never touched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
run_eventswas effectively append-only: nothing ever deleted a settled run's rows, and ~95% of the table is per-token deltas (thinking_delta,tool_delta) that the transcript has already folded intoentries/message_blocks. In the field oneagent.dbreached 8 GB (17.8M rows, 4 GB of payload, 96% of it from a single day), andprune_run_events- RPC, store method and tests - had no production caller.What
SqliteStore::prune_settled_runs(session, keep)deletes the journals of a session's settled runs beyond the newestkeepin one transaction, then reclaims the freed pages like the existingprune_events/deletepaths.!is_ephemeral, and never fatal: a failed prune leaves the bytes for the next run or the startup compaction.SETTLED_RUN_JOURNALS_KEPT = 2: the run that just settled and the one before stay replayable for reconnect. The live run,running/unknownrows, undated rows, and session-scoped rows (run_id = '') are never touched.started_at_ms, falling back tocompleted_at_ms);runs.run_sequenceturned out to be NULL on the plain prompt path, which the first iteration of this fix tripped over (caught by the new end-to-end test).Tests
settled_run_retention_keeps_the_newest_journals(store level): keeps the newest two, retires the older settled runs, never the undated or live rows; second pass is a no-op.later_runs_retire_the_journals_of_settled_older_runs(end-to-end): four prompts; run 1's journal is gone, runs 2-4 remain replayable.cargo fmt -p future-agent --check,cargo clippy -p future-agent --all-targets -- -D warnings,cargo test -p future-agent: green (2082 lib tests, all integration targets).Docs: one caveat in
docs/internals/desktop/ER.md+ zh-CN twin, since the GUI's cursor replay is now bounded to recent Runs.