Repository navigation
fix(ops-mission-control): prune the stalest of tied ledger entries - #21825
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that every writer stores [DESIGN-REVIEWED] 3a52ce1 Description read[DESCRIPTION-READ] 5b368056ce773397d4c3dbd22f57202a9bd44b59f52dbdbb1be4cf3f6e191fc0 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 Check that nothing reads the ledger's file order as its age. Tied entries are now written newest first instead of oldest first. What this change shipsInventory (3 items) — 3 justifiedIntent: when the ledger is full and two entries are equally valuable, keep the one someone just used and drop the stale one. This is a FIX (#21719).
[FIRST-PRINCIPLES-REVIEWED] 3a52ce1 Description read[DESCRIPTION-READ] 3d04a9a5f0bfe2b98ba147f98853c8baf356b8306faf1f9225bc9c24af68272a 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: |
The hygiene prune sorted `last_used` ascending, so among entries tied on net uses, trust and confidence it kept the one used longest ago and pruned the freshest. That contradicts the `MAX_LEDGER_ENTRIES` contract (least used, weakest confidence, oldest go first). Sort most recently used first, then stably by value, so ties keep the freshest entry and the stalest is pruned. Closes #21719
2d3f9a4 to
3a52ce1
Compare
|
[operator: bolichen97]
|
|
[operator: bolichen97]
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (2 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: the ledger prune sorts by recency first so the stalest of tied entries is pruned; test covers both file orders.
Problem / Motivation
Goal: When the ledger hygiene prune must drop one of two otherwise-equal entries, it drops the one used longest ago and keeps the freshest.
The comment on
MAX_LEDGER_ENTRIESsays the prune drops "least used, weakest confidence, oldest" first. The code did the opposite on a tie: two entries equal in net uses, trust and confidence, cap reached, and the recently used one was pruned while the stale one stayed.Why it matters
Once a team ledger reaches its cap, every hygiene pass threw away the lesson someone had just relied on and kept one nobody had needed for weeks. That is silent knowledge loss in the part of the ledger that is most current.
Not a goal
dedupedis always 0 #21715 is its own PR).What changed (motivation → approach → change)
Symptom: on a tie, the prune kept the stalest entry and dropped the freshest.
Root cause: the last key of the prune sort in
backend/ledger.pywaslast_usedascending, so the oldest timestamp sorted first and was kept bydeduped[:MAX_LEDGER_ENTRIES].Change: the pass sorts by
last_usednewest first, then runs the existing value sort (now withoutlast_used), which is stable. Ties keep their newest-first order, so the stalest tied entry sits last and is pruned.last_usedis an ISO string, so it cannot be negated inside one key. The code now matches theMAX_LEDGER_ENTRIEScomment, so no comment or SOP text changes.Backwards compatibility
Compatible: the summary keys and the cap are the same. Only which entry is dropped on an exact value tie changes, and tied entries are written newest first instead of oldest first.
Reader:
src/kiro_crew/apps/builtins/ops_mission_control/backend/ledger.py:match-- entry: crew page, cron (investigations) -- ranks by its own key and keeps file order only on an exact tie there, so after a pruning pass tied matches list the most recently used first; the existing ops-mission-control match tests are green.Tests
test_prune_drops_the_stalest_of_tied_entriesintests/test_store_and_gate_ledger.py: two entries equal in everything butlast_used(20 and 2 days old, both inside the decay window), cap patched to 1, run in both file orders. Only the newer one survives,prunedis 1,decayedis 0. Red onorigin/mainin both orders (['older'] != ['newer']). The same test pins that recency only breaks ties: an older entry with 3 uses still beats a fresh entry with none.Determinism: the test file ran 5 times in a row serially and once under
-n 2, all green. The ops-mission-control tests (1119 passed) and the local gate's related backend set (22501 passed) are green.Manual verification
N/A — unit coverage sufficient: the prune is a pure pass over a real ledger file under an isolated
KIROCREW_HOME, and the test drives it end to end.Related Issues
Closes #21719
Pattern harvest
Not generalizable: a single tie-break key written in the wrong direction against its own documented contract; the regression test pins this one.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)