Skip to content

feat(cleanup): add operator_queue retention sweep (#1142) - #1592

Merged
vybe merged 1 commit into
devfrom
feature/1142-operator-queue-retention
Jul 13, 2026
Merged

vybe merged 1 commit into
devfrom
feature/1142-operator-queue-retention

Conversation

@dolho

@dolho dolho commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

operator_queue was 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 via cleared_at (a DELETE would let the 5s sync loop resurrect a row still pending in 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-DELETEs acknowledged/cancelled/expired past retention_days, and responded only 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). pending is never deleted. Age on created_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 — 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 (+ description) and facade delegator db.prune_operator_queue_terminal_items.
  • Docs: architecture.md cleanup-sweeps paragraph + the clear-resolved endpoint / operator_queue.cleared_at notes (which already pointed at "Add operator_queue retention sweep to cleanup_service #1142").

Acceptance criteria

  • Sweep wired into the cleanup cycle with a config knob + docs (architecture.md).
  • Terminal statuses purged past window; responded protected by a generous age guard (never shorter than the terminal window).
  • Capped per cycle; 0 disables.

Tests

tests/unit/test_1142_operator_queue_retention.py — 4, real-engine db_harness (SQLite + PG-capable): terminal rows purged past the window, responded protected by the 30d floor and never deleted younger than the terminal window, pending never deleted, disabled window is a no-op, per-cycle cap honored. The #1026 test_cleanup_inner_sweeps.py characterization test updated for the new sweep (mock + report/total/WAL assertions).

10 passed (new + characterization)

Run in a throwaway container off trinity-backend:latest. No schema change (reuses the existing operator_queue table).

Related to #1142

🤖 Generated with Claude Code

Fixes #1142

`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 vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr: Invariant #16 respected (iso_cutoff), pending rows never deleted, real-engine + orchestration tests; combined tree with #1589 tested locally (14 passed). Approving for merge.

@vybe
vybe merged commit 2d26fdd into dev Jul 13, 2026
22 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants