Repository navigation
Scrub terminal backlog_metadata PII in the retention sweep (#1449) - #1681
Conversation
…1449) backlog_service.enqueue json.dumps the full drain-replay request — including user_message/user_email/system_prompt PII — into schedule_executions.backlog_metadata. Nothing reads it once a row leaves status='queued' (drain claims only queued rows; #1083/#1081 callbacks read the POST payload; canary E-04/G-04 are queued-scoped), so on a terminal row it is stale PII bounded only by the 90-day row delete. Scrub it. - New ScheduleOperations.scrub_terminal_backlog_metadata(chunk_size): chunked SELECT-ids-then-UPDATE ... SET backlog_metadata=NULL, each chunk its own txn (short write lock), mirroring prune_execution_logs — but NOT age-gated (security invariant, not a retention window). - Only _AUTHORITATIVE_TERMINALS (success/cancelled/skipped) are scrubbed. FAILED is deliberately excluded: it is resurrectable to SUCCESS via a late token-gated CAS, so its intent blob must survive; FAILED PII stays bounded by prune_execution_rows. - DatabaseManager facade delegate. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…1449) Add a guarded sub-sweep to CleanupService._sweep_retention_772 calling db.scrub_terminal_backlog_metadata(RETENTION_CHUNK_SIZE_PER_CYCLE). It runs UNCONDITIONALLY — not gated on a retention-days setting — because the scrub is a security invariant, not an operator knob; a fixed default sidesteps the #1638 floor-by-seed trap. Count-only logging (the blob carries PII, never logged). - New CleanupReport.backlog_metadata_scrubbed field, folded into total + to_dict. - Added to the _maybe_wal_checkpoint sum so a scrub-only cycle still truncates the WAL. Co-Authored-By: Claude Opus 4.8 <[email protected]>
… wiring (#1449) New tests/unit/test_1449_backlog_metadata_scrub.py asserts the actual column NULL-out through the db_harness (temp SQLite / full schema), never a mocked db (a column with no live writer is a silent lie): - authoritative terminals (success/cancelled/skipped) scrubbed; - FAILED row NOT scrubbed (resurrection guard — the load-bearing exclusion); - queued/running/pending_retry untouched; - chunk_size drains multi-pass; idempotent; chunk<=0 disabled; empty table; - canary E-04/G-04 smoke: a scrubbed terminal row is outside the queued-scoped WHERE, so the snapshot the invariants read is unaffected. Updated test_cleanup_inner_sweeps.py for the new unconditional sub-sweep: report field + WAL-sum wiring, a scrub-only-WAL regression guard, and a guard that the scrub still runs when every #772 retention window is disabled. Co-Authored-By: Claude Opus 4.8 <[email protected]>
) - requirements/infrastructure.md §12.11 (RETENTION-002): the scrub, FAILED exclusion, unconditional non-age-gated behavior, count-only logging; notes the deferred #1444 callback-persistence sibling (lands with #1081). - architecture.md Cleanup Service sweeps list: append the #1449 scrub clause. - feature-flows.md Recent Updates row. Leaves the chat_messages DDL "callback-path persistence deferred" prose as-is — persistence stays deferred to the pull single-applier work. Co-Authored-By: Claude Opus 4.8 <[email protected]>
… scrub - cleanup-service.md: Updated banner + a fourth (unconditional) retention sub-sweep documented under step 7, WAL-sum note in step 8, File Summary rows for scrub_terminal_backlog_metadata + the two test files. - feature-flows.md: repoint the #1449 Recent Updates row at cleanup-service.md (the accurate home — the scrub never touches task_execution_service.py). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…r guard (#1449) scrub_terminal_backlog_metadata filters schedule_executions.status in a WHERE clause, so the #1082 status-observability guard (_EXPECTED_UPDATE_SITES) must enumerate it as an allowed status-reading writer or the guard fails CI. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…odules lint (#1449) The bare sys.modules.pop grew the sys_modules lint baseline (0->1). Switch to the established monkeypatch.delitem(..., raising=False) idiom (auto-restores the module after the test), matching tests/unit/test_1115_schedules_summary.py and #1444. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-flows index rows Co-Authored-By: Claude Fable 5 <[email protected]>
vybe
left a comment
There was a problem hiding this comment.
Validated via /validate-pr. Clean security-invariant sweep: chunked SELECT-ids-then-UPDATE mirroring prune_execution_logs (short write locks), scoped to authoritative terminals with FAILED deliberately excluded (resurrectable via late token-gated CAS — regression-guarded), unconditional (no ops key — dodges the #1638 floor-by-seed trap), count-only logging. No schema change so no dual-track migration needed (verified). Real-DB harness tests + cleanup-cycle characterization + #1082 status-writer registration; requirements §12.11 + architecture + feature-flows all updated. Dev merge (index rows) resolved; 104 tests green on the merged tree incl. the three-way cleanup_service merge with #1616/#1578. All checks green.
Fixes #1449
What
Scrubs stale drain-replay PII from
schedule_executions.backlog_metadataonauthoritative-terminal rows.
backlog_service.enqueuejson.dumpses the fullrequest —
user_message/user_email/system_prompt— into that column so aqueued task can be reconstructed at drain. Nothing reads it once a row leaves
status='queued'(the drain claims only queued rows; the #1083/#1081 resultcallbacks read the POST payload, not the row's metadata; canary E-04/G-04 are
queued-scoped), so on a terminal row it is stale PII sitting in the DB indefinitely
— bounded only by the 90-day
execution_row_retention_daysDELETE. This NULLs it assoon as the row reaches a terminal state.
How
db.scrub_terminal_backlog_metadata(chunk_size)(db/schedules.py) — chunkedSELECT id … LIMIT N→UPDATE … SET backlog_metadata=NULL WHERE id IN (…), eachchunk its own transaction (short write lock), mirroring
prune_execution_logs.Facade delegate on
DatabaseManager.cleanup_service._sweep_retention_772— appended as an unconditionalsub-sweep (not age-gated, no ops-config key). Count feeds
CleanupReport+ theWAL-checkpoint sum; the blob itself is never logged (count-only — it carries PII).
Two load-bearing decisions
_AUTHORITATIVE_TERMINALS = success/cancelled/skipped). AFAILED row is resurrectable to SUCCESS via a late token-gated CAS (
park_expired_leasekeeps its
claim_token), so its drain-replay intent must survive. FAILED PII staysbounded by the 90-day row DELETE. (Regression-guarded by a dedicated test.)
retention window and runs every cycle even when all feat: implement execution log retention and pruning policy #772 windows are
0. A fixeddefault sidesteps the bug: retention floor (#1065) silently deletes pre-existing execution history on upgrade — currently dev-only, ships to everyone at next release #1638 floor-by-seed trap.
Migrations / schema
None. This scrubs values in an existing column — no DDL, no new table, no
column. So there is no dual-track (SQLite + Alembic) migration to add, and the
schema-parityCI job is trivially green (no schema file touched).Tests
tests/unit/test_1449_backlog_metadata_scrub.py(real DB viadb_harness, not amock): authoritative-terminal NULL-out, FAILED-exclusion resurrection guard,
queued/running/pending_retry untouched, multi-pass chunking, idempotency,
chunk_size<=0disabled, canary queued-scope smoke.tests/unit/test_cleanup_inner_sweeps.py: report field + WAL sum + "runs even whenretention disabled" guards.
tests/unit/test_schedule_status_observability.py: registers the new writer in therefactor: status-as-projection — schedule_executions.status never read as authoritative for "is running" #1082 status-writer guard.
Local run: 35 passed / 1 skipped (skip = Postgres dual-backend, no PG reachable);
canary + retention-prune regression sweep 142 passed;
sys_moduleslint green.Docs
requirements/infrastructure.md§12.11 (RETENTION-002),architecture.mdCleanupService sweep line,
feature-flows.mdRecent-Updates row, andfeature-flows/cleanup-service.mdall updated.Scope note (reviewer)
#1449 bundles two deliverables. This PR ships only the
backlog_metadataPIIscrub (a live security win with zero pull dependency). The sibling — callback/pull-path
chat-session persistence — is deferred to the #1081 single-applier work (dead
code today: the callback path is unreachable by a manual
/task, pull-mode is OFF),with the verified design captured in the plan. The original bundled "reconciliation
sweep" design was killed in review — it would double-write live in-process-drained
chat rows. If you'd rather keep #1449 open for the deferred half, drop the
FixestoRefs.