Repository navigation
feat(cleanup): add operator_queue retention sweep (#1142) - #1592
Merged
Merged
Conversation
`operator_queue` was the one #772-adjacent table with no automatic retention — terminal rows (acknowledged/cancelled/expired) accumulated forever; #1017's Clear All only *hid* them via `cleared_at`. Add the automatic complement. - `db/operator_queue.prune_terminal_items(retention_days, responded_retention_days, limit)`: hard-DELETE acknowledged/cancelled/expired past `retention_days`; `responded` only past a more generous floor (they still carry an operator answer the 5s write-back loop must deliver — a stopped agent picks it up on restart); `pending` never deleted. Age on `created_at`; select-ids-then-delete (portable SQLite/PG), capped per cycle. Disabled window prunes nothing. - `cleanup_service._sweep_operator_queue_retention`: reads `operator_queue_retention_days` (default 90, `0`=off), passes the fixed `OPERATOR_QUEUE_RESPONDED_MIN_RETENTION_DAYS=30` floor, 5000/cycle cap; wired into the cycle and the WAL-checkpoint trigger. New `operator_queue_pruned` report field. - Setting `operator_queue_retention_days` (default 90) + description; facade delegator `db.prune_operator_queue_terminal_items`. - Docs: architecture.md cleanup-sweeps + operator_queue schema/endpoint notes. Tests: `test_1142_operator_queue_retention.py` (4, real-engine db_harness) — terminal purged past window, `responded` protected by the floor (and never shorter than the terminal window), `pending` never deleted, disabled=no-op, per-cycle cap honored. The #1026 characterization test updated for the new sweep. Related to #1142 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
vybe
pushed a commit
that referenced
this pull request
Jul 13, 2026
…lap with #1592 (operator_queue retention) Union resolution: both the #1581 volume-reclaim and #1142 operator_queue retention sweeps kept in cleanup_service.py (constants, CleanupReport fields, total, to_dict) and in the architecture.md sweeps paragraph. Co-Authored-By: Claude Fable 5 <[email protected]>
Merged
4 tasks done
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.
Problem
operator_queuewas the one #772-adjacent table with no automatic retention — terminal rows (acknowledged/cancelled/expired) accumulate forever. #1017 added a manual Clear All (POST /operator-queue/clear-resolved), but it only hides rows viacleared_at(a DELETE would let the 5s sync loop resurrect a row stillpendingin the agent file). Unbounded growth should be handled automatically like the other tables.Fix (mirrors the #772/#834/#918 pattern)
db/operator_queue.prune_terminal_items(retention_days, responded_retention_days, limit)— hard-DELETEsacknowledged/cancelled/expiredpastretention_days, andrespondedonly past a more generous floor (those rows still carry an operator answer the write-back loop must deliver; a stopped agent picks it up on restart).pendingis never deleted. Age oncreated_at; select-ids-then-delete so the LIMIT is portable across SQLite + PostgreSQL; capped per cycle. Disabled window (<=0) prunes nothing.cleanup_service._sweep_operator_queue_retention— readsoperator_queue_retention_days(default 90,0=off), passes the fixedOPERATOR_QUEUE_RESPONDED_MIN_RETENTION_DAYS=30floor, 5000/cycle cap; wired into the cycle and the WAL-checkpoint trigger. Newoperator_queue_prunedreport field.operator_queue_retention_days(+ description) and facade delegatordb.prune_operator_queue_terminal_items.clear-resolvedendpoint /operator_queue.cleared_atnotes (which already pointed at "Add operator_queue retention sweep to cleanup_service #1142").Acceptance criteria
respondedprotected by a generous age guard (never shorter than the terminal window).0disables.Tests
tests/unit/test_1142_operator_queue_retention.py— 4, real-enginedb_harness(SQLite + PG-capable): terminal rows purged past the window,respondedprotected by the 30d floor and never deleted younger than the terminal window,pendingnever deleted, disabled window is a no-op, per-cycle cap honored. The #1026test_cleanup_inner_sweeps.pycharacterization test updated for the new sweep (mock + report/total/WAL assertions).Run in a throwaway container off
trinity-backend:latest. No schema change (reuses the existingoperator_queuetable).Related to #1142
🤖 Generated with Claude Code
Fixes #1142