Repository navigation
feat(security): add archive-wide bulk secret-candidate scan - #3486
Conversation
Problem: polylogue ops scan-secrets required --session, so an operator with no prior signal had no way to discover secret candidates archive-wide; nothing kept coverage current as new sessions were ingested (polylogue-layg.1). What changed: - polylogue/security/secret_scan.py: scan_archive_for_secret_candidates is a bounded, checkpointed sweep over sessions not yet covered by a new ops-tier secret_scan_status table at the current SECRET_SCAN_VERSION. Coverage rows commit together with their session's findings, so an interrupted sweep never leaves a session covered without its candidates recorded, and resuming re-derives the pending set from the coverage table instead of restarting or duplicating findings. A scanner-version bump invalidates all existing coverage and schedules an intentional rescan. - polylogue/storage/sqlite/archive_tiers/ops.py: additive secret_scan_status DDL (disposable ops tier -- losing it only means re-scanning, never lost candidates, since findings live durably in user.db). - polylogue/cli/commands/scan_secrets.py: --session is no longer required; --all drains the full pending backlog across bounded pages, --limit bounds one page, --origin scopes the sweep, --status reports pending coverage without scanning. - polylogue/daemon/secret_scan_sweep.py: a plain asyncio periodic loop (not a ConvergenceStage -- convergence_stages.py's own retro verdict is "refactor before adding a fourth stage", docs/retro/2026-05-24-1498-cascade.md) draining one bounded page every 15 minutes, registered as a one-line addition to daemon/cli.py's periodic_loops list. Verification: - python -m devtools test tests/unit/security/test_secret_scan.py tests/unit/cli/test_scan_secrets.py tests/unit/daemon/test_secret_scan_sweep.py -> 38 passed - python -m devtools verify --quick -> exit 0 (ruff format/check, mypy --strict, render all --check, layering, closure-matrix, schema policy checks) - docs/plans/layering-surface-baseline.json: added one baselined entry for secret_scan_sweep.py's sqlite_locking import, mirroring the identical existing entry for fts_orphan_audit.py (same sweep shape). Ref polylogue-layg.1 Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 43 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…jtc, bvnz, 5vbs) Reconciliation pass driven by devtools lab probe bead-pr-reconciliation: verified each bead's own acceptance criteria against the actual diff/AC matrix of its referencing merged PR(s), not just the PR's self-description. Closed (AC fully satisfied): - polylogue-bvnz: PR #3504, all 5 AC items satisfied. - polylogue-5vbs: PR #3439, AC's detection/repair branch satisfied via new daemon/fts_orphan_audit.py sweep. Left open with progress notes (partial, residual scope named): - polylogue-layg.1: PR #3486 satisfies 6/8 AC items; scale fixture + coverage manifest update still missing. - polylogue-hjpx: PR #3485 confirms AC1-5 satisfied (mostly by pre-existing landed work whose ancestry the bead's own stale note had missed), but bd close refuses on open child polylogue-yla8 (the live closure-gate audit AC1-5 doesn't substitute for). - polylogue-6j9c, polylogue-9kjtc: PR #3511 satisfies 2/3 AC items each; live-archive reprice pass over existing session_profiles rows still outstanding for both. Ref polylogue-93xe Co-Authored-By: Claude <[email protected]>
Summary
polylogue ops scan-secretsrequired--session <id>, so an operator with noprior signal had no way to discover secret candidates archive-wide, and
nothing kept coverage current as new sessions were ingested. This adds a
bounded, resumable archive-wide sweep (CLI
--all+ a daemon catch-up loop)on top of the existing per-session scanner and non-injectable
SECRET_CANDIDATEassertion write path.Problem
polylogue/cli/commands/scan_secrets.py:22had--sessionasrequired=Truewith no bulk mode, and no daemon convergence/maintenance loop ever called
scan_session_for_secret_candidates— the regex/entropy rules and writechokepoint existed but only ran when an operator already knew a specific
session id to scan (polylogue-layg.1, filed against the security/privacy
covenant epic polylogue-kwsb after the polylogue-27m per-session fix round
shipped with zero archive-wide callers).
Solution
polylogue/security/secret_scan.py:scan_archive_for_secret_candidatesis a bounded page of the archive-wide sweep. It selects sessions not yet
covered by a new ops-tier
secret_scan_statustable at the currentSECRET_SCAN_VERSION(select_pending_secret_scan_session_ids,count_pending_secret_scan_sessions), scans each with the same rules andwrite chokepoint as the existing single-session path, and commits a
session's findings together with its coverage row in the same
user.db/ops.dbtransaction pair. This makes resumption exact: aninterrupted sweep never leaves a session "covered" without its candidates
recorded, and a fresh call re-derives the still-pending set from the
coverage table itself (no separate cursor row, and no duplicate findings —
the write chokepoint's deterministic assertion ids are already idempotent).
A
SECRET_SCAN_VERSIONbump invalidates every existing coverage row andschedules an intentional rescan.
polylogue/storage/sqlite/archive_tiers/ops.py: additivesecret_scan_statusDDL. Ops tier is disposable by design — losing thistable only means re-scanning (idempotent), never lost candidates, since
findings themselves live durably in
user.db.polylogue/cli/commands/scan_secrets.py:--sessionis no longerrequired.
--alldrains the full pending backlog across as many boundedpages as needed;
--limit Nbounds one invocation to a single page;--originscopes the sweep to one origin token;--statusreportspending-coverage count without scanning anything.
polylogue/daemon/secret_scan_sweep.py: a new plainasyncioperiodicloop (
periodic_secret_scan_sweep, 15-minute cadence, 50 sessions/tick)draining one bounded page per tick so newly ingested sessions get
incremental coverage without operator action. Deliberately not a
ConvergenceStage—docs/retro/2026-05-24-1498-cascade.md(mandatoryreading before touching
convergence_stages.py/daemon/cli.py) recordsthat file's own verdict as "refactor before adding a fourth stage"; this
follows the same shape as the existing
fts_orphan_audit.py/periodic_fts_identity_drift_recomputesweeps instead. Registration indaemon/cli.pyis a two-line addition (one import, one line in theperiodic_loopslist) next to the other maintenance loops, to stay clearof the startup-auth and raw-materialization-drain regions other lanes are
touching concurrently.
Acceptance-criteria matrix (polylogue-layg.1)
--all(full drain),--limit(bounded page),--origin(scope).since_msscoping exists in the Python API (scan_archive_for_secret_candidates(..., since_ms=...)) but is not yet exposed as a CLI flagperiodic_secret_scan_sweep, 50 sessions/15mintest_interrupt_and_resume_covers_all_sessions_exactly_onceSECRET_SCAN_VERSION; seetest_scanner_version_bump_schedules_intentional_rescanrecord_secret_candidates/upsert_assertionchokepoint unchangedBulkSecretScanResult/SecretScanSweepResultcarry scanned/candidates/errors/remaining counts; CLI--statusand--all --jsonsurface themmax_sessions=2over 5-6 sessions) prove the mechanism is page-bounded, not a scale/perf assertion. Follow-up if the operator wants a benchmark gatedocs/plans/security-privacy-coverage.yamlis unchanged; flagging as remaining scope rather than claiming it hereVerification
python -m devtools test tests/unit/security/test_secret_scan.py tests/unit/cli/test_scan_secrets.py tests/unit/daemon/test_secret_scan_sweep.py→38 passedpython -m devtools verify --quick→exit_code: 0(ruff format/check, mypy --strict, render all --check, layering, closure-matrix, schema-versioning policy, schema promotion audit)python -m devtools render all --check→ all surfacessync OK, including the regenerateddocs/plans/topology-target.yamlfor the newpolylogue/daemon/secret_scan_sweep.pymoduleAnti-vacuity: the production dependency exercised is the real
scan_text_for_secret_candidatesregex/entropy rules and the realupsert_assertionwrite chokepoint (author_kind="detector"coercingstatus=CANDIDATE/non-injectable), run against a real multi-sessionindex.dbfixture with planted AWS-key-shaped spans. Reverting the bulkscanner to skip a session batch (e.g. stopping after one page without
checking
more_pending, or a query that fails to anti-joinsecret_scan_status) failstest_full_sweep_covers_every_session_and_finds_every_planted_secretbecause it asserts every seeded session — not just one — ends up covered
with a recorded candidate and
remaining_pending == 0.Not merging
Ref polylogue-layg.1 — leaving this PR open per instruction; not merging or
closing the bead from this branch.