Repository navigation
fix(ops-mission-control): count and compact duplicate ledger lines in hygiene - #21787
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] 955c76f Description read[DESCRIPTION-READ] ed48537144b06a72bf715f2e380afa804f28e359f47362300b334d2bc24c97a1 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. What this change shipsInventory (5 items) — 5 justifiedIntent: let operators trust ledger hygiene to report and remove duplicate ledger lines left by git merges. FIX (Closes #21715; new tests fail on base).
[FIRST-PRINCIPLES-REVIEWED] 955c76f Description read[DESCRIPTION-READ] 9a282637abe97042548235e280389143b2e9f95cebe7124c482b7e4cacfbed4d That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
[operator: bolichen97] The red |
|
[operator: bolichen97]
|
|
[operator: bolichen97] Correction: the main red is issue #21790, and its fix is PR #21792. The other red, |
… hygiene The hygiene pass read entries through the reconciling reader, so every id was already unique and its own dedupe loop could never merge anything: `deduped` was always 0 and duplicate lines from a git merge stayed on disk. The strict read now also returns how many duplicate lines it collapsed. Hygiene reports that as `deduped`, rewrites the file when it is non-zero, and drops the unreachable merge loop so `_reconcile` stays the only merge. Closes #21715
120efb2 to
955c76f
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (4 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: ledger hygiene now counts duplicate lines collapsed by the read and compacts them, reusing the one reconcile merge; tests added.
Problem / Motivation
Goal: The ledger hygiene pass reports how many duplicate ledger lines it collapsed and rewrites the file without them.
POST /ledger/hygienealways returneddeduped: 0. When a git merge left two copies of the same entry in the ledger file, the pass said there were no duplicates and left both lines on disk.Why it matters
The hygiene SOP tells the agent the pass dedupes and returns
deduped: N, so a merged team ledger looked clean when it was not. The duplicate lines stayed in the file and in the synced team repo until some unrelated decay or prune forced a rewrite.Not a goal
_reconcilestays the one merge rule.What changed (motivation → approach → change)
Symptom:
dedupedwas always 0 and merged duplicate lines were never removed.Root cause: hygiene read the ledger through
read_entries_for_update, which already merges duplicate ids with_reconcile. Every id it saw was unique, so its own merge loop never ran and "before minus after" was always 0.Change: in
backend/ledger.py, the strict read moves into_read_counted_for_update, which also counts the duplicate lines it collapsed (valid lines minus unique ids; a malformed line is skipped, not counted).read_entries_for_updatewraps it unchanged. Hygiene reports that count asdedupedand rewrites the file when it is non-zero. The unreachable merge loop is gone. Theledger-hygiene.mdSOP step 1 now says whatdedupedcounts. ThePOST /ledger/hygienehandler already countsdedupedtowardchanged, so a compacting pass now writes itsledger_hygieneaudit row and is reported.Backwards compatibility
Compatible: the response keys and types are the same;
dedupedis now the real count, and a ledger with merge duplicates gets one rewrite to one line per entry with the same merged values reads already returned.Removes nothing: the deleted merge loop in
_hygiene_lockedcould never run, and reads, merges and the route contract are unchanged.Tests
In
tests/test_store_and_gate_ledger.py:test_hygiene_counts_and_compacts_duplicate_lines: two entries, every line duplicated; hygiene reportsdeduped: 2, the file has 2 lines and 2 unique ids, and a second pass reports 0. Red onorigin/main(0 != 2).test_hygiene_compaction_keeps_the_merged_counters: two raw lines of one id with different counters and fingerprints; the rewritten line keeps the maxuse_count, the maxmiss_countand both fingerprints. Red onorigin/main(0 != 1).test_hygiene_does_not_count_a_malformed_line_as_a_duplicate: a broken line and a blank line givededuped: 0and no rewrite.tests/test_ledger_index.pyandtest_a_failed_mutation_read_refuses_instead_of_truncatingpatch_read_counted_for_update, the read hygiene now starts from, so the race and refused-read tests still drive hygiene.Determinism: both test files ran 5 times in a row serially and once under
-n 2in reversed file order, all green. The ops-mission-control tests (1121 passed) and the local gate's related backend set (22515 passed) are green.Manual verification
N/A — unit coverage sufficient: the change is a pure file-level ledger pass and the tests drive it on a real file under an isolated
KIROCREW_HOME.Related Issues
Closes #21715
Pattern harvest
Rule candidate: review-prompt
Pattern: a second dedupe/merge pass over data an upstream reader already deduplicated, so its counter is always zero.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)