Repository navigation
fix: keep three stores intact when a rewrite cannot read them - #31998
Conversation
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. Each rewrite now refuses to write when its read fails, which fixes the mechanism behind #24607 for these three modules. The Inventory (7 items) — 7 justifiedIntent: stop three stores (crewmate opt-in, app dependency ledger, mint manifest) from being wiped when a read fails for a moment. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] ddcffa2 Description read[DESCRIPTION-READ] ec21ccce48c22790170b28c1236237a60764dc7b808cbde15931699b43162c99 That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The change adds a strict read only on the four rewrite paths, and every caller of the changed returns is listed and handled. Notes
[DESIGN-REVIEWED] ddcffa2 Description read[DESCRIPTION-READ] e23fbf7ff5f4d58e6eaf4642ad389f581dfc823909e819cdef9d42b31d9a80d5 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 |
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 crewmate opt-in store, the app dependency ledger and the connection mint manifest were each rewritten from a reader that answers an empty document on any OSError, so a transient EACCES or EIO published an empty file over every other entry. Each reader gains a strict mode for the base of a rewrite: only a missing file reads as empty. reserve_offer raises (the card is refused with 503 opt_in_unrecorded), _record_mint_spec returns False (the mint fails as before), and the two ledger rewrites leave the file as it was and log a warning. An install whose ownership was not recorded reports that dependency as failed, so a later install or enable records it instead of a later uninstall treating another app as its sole owner. The remaining sites in these modules write only after changing an entry the read found, and the ratchet records that reason for them. Part of #24607
e333b65 to
ddcffa2
Compare
[operator: bolichen97] |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved for the on-call. Review lanes pass on ddcffa2, no conflict, no open change request.
The crewmate opt-in store, the app dependency ledger and the connection mint manifest were each rewritten from a reader that answers an empty document on any OSError, so a transient EACCES or EIO published an empty file over every other entry. Each reader gains a strict mode for the base of a rewrite: only a missing file reads as empty. reserve_offer raises (the card is refused with 503 opt_in_unrecorded), _record_mint_spec returns False (the mint fails as before), and the two ledger rewrites leave the file as it was and log a warning. An install whose ownership was not recorded reports that dependency as failed, so a later install or enable records it instead of a later uninstall treating another app as its sole owner. The remaining sites in these modules write only after changing an entry the read found, and the ratchet records that reason for them. Part of #24607 (cherry picked from commit 7a4830a)
Problem / Motivation
Goal: A store that exists but cannot be read for a moment (
EACCES,EIO) is never overwritten with an empty one by the crewmate opt-in card, an app dependency install or uninstall, or a connection mint.Each of these rewrites reads its file through a reader that answers
{}on anyOSError, then writes the whole file back. When the read fails for a moment, the write replaces every other entry with nothing, and because the write succeeds nothing reports the loss. These are the 11 sites #24607 lists inmate_tool_access.py,apps/dependency_ledger.pyandconnections/mint.py.Why it matters
tool-access.jsondrops every crewmate's opt-in record, so each one is asked the Preview opt-in again.Not a goal
mcp_config_entries,dev_mode,pidfile,stale_reap,autonudge_selfarm, the app builtins,push_guard_record) and the further sites in its 2026-11-02 comment: later PRs, one module group each.self./cls.calls.What changed (motivation → approach → change)
These rewrites now leave an unreadable file exactly as it was. The cause is one shape, a lenient reader feeding a whole-file write, so each of the three readers gets a
strictmode: only a missing file reads as empty and any otherOSErrorpropagates. Display reads keep the lenient answer.~/.kiro/mates/tool-access.jsonreserve_offer503 opt_in_unrecordedrecord_installFalse, so the install or enable lists that dependency as failedclassify_and_clean_for_uninstall_record_mint_specFalse, which the mint already turns into a failed ConnectThe ledger callers keep going instead of failing.
resolve_dependenciesis documented as non-blocking, so a dependency whose owner was not recorded is reported failed, not installed: the missing owner is shown instead of hidden, and a later install or enable records it. The uninstall's dependency step runs after the onUninstall script, past the point where that handler ever aborts.The other seven sites (
settle,bind_card,release_offer,take_held,record_uninstall,_forget_mint_spec,_sweep_mint_specs) write only after changing an entry the read found, so an empty read writes nothing. The ratchet's_KNOWNrecords that reason for them instead of "not audited" and drops the four fixed sites. The ledger spec (app-kit-platform.md) and the opt-in card spec (crew-mode.md) say what an unreadable store does.Backwards compatibility
Compatible: every changed path runs only when a store exists but cannot be read, where main wrote an empty store over it; a missing file still starts empty, and display reads (
entry,get_entry,list_by_app,classify_for_uninstall, the mint sweep) still read an unreadable file as empty.Reader: src/kiro_crew/dashboard/handlers/member_self.py:_raise_opt_in -- crew page -- its
exceptalready answers503 opt_in_unrecordedand raises no card; test_an_unreadable_store_refuses_the_offer_and_keeps_every_recordReader: src/kiro_crew/connections/mint.py:_write_mint_agent_spec -- chat --
not _record_mint_spec(...)already raisesOSErrorbefore any spec is written; test_a_manifest_that_cannot_be_read_records_nothing_and_keeps_its_rowsReader: src/kiro_crew/apps/dependencies.py:resolve_dependencies -- app --
record_installreturnsFalse, so the dependency goes tofailedand the loop goes on; test_unreadable_ledger_reports_dependency_failedReader: src/kiro_crew/apps/routes_uninstall.py:_run_uninstall -- app -- the classification comes back with nothing removable, so no dependency is cleaned and Step 5 runs; test_an_unreadable_ledger_is_left_as_it_was_and_removes_nothing
Tests
test_an_unreadable_store_refuses_the_offer_and_keeps_every_record: anEACCESontool-access.jsonmakesreserve_offerraise and leaves the file byte-identical.test_an_unreadable_ledger_is_left_as_it_was_and_removes_nothing: with the ledger unreadable, an install and an uninstall both return normally, nothing is removable, and the file is byte-identical.test_unreadable_ledger_reports_dependency_failed: with the ledger unreadable, a second app's successful install is reported failed, not installed, and the ledger is byte-identical.test_a_manifest_that_cannot_be_read_records_nothing_and_keeps_its_rows:_record_mint_specreturnsFalseand the manifest keeps its rows.test_lenient_read_rewrite_ratchet.py: four sites leave_KNOWN, seven carry the found-only reason.Determinism: the three first-round tests passed 20 runs at
-n0, 10 runs at-n 4 --dist loadgroup --max-worker-restart=2besidetest_dependency_ledger.pyandtest_connections_mint.py, and the three touched files in a shuffled order (seed 9943, 70 tests).test_unreadable_ledger_reports_dependency_failedpassed 20 runs at-n0, 10 runs at-n 4 --dist loadgroup --max-worker-restart=2besidetest_dependency_ledger.pyandtest_dependency_ledger_decode.py, and those three files in a shuffled order (seed 18437, 96 tests). None uses a clock, sleep or port.Proof: PROVEN test/test_connections_mint_spec_files.py::test_a_manifest_that_cannot_be_read_records_nothing_and_keeps_its_rows, test/test_dependencies.py::TestCapabilitySeamResolution::test_unreadable_ledger_reports_dependency_failed, test/test_dependency_ledger_decode.py::test_an_unreadable_ledger_is_left_as_it_was_and_removes_nothing, test/test_lenient_read_rewrite_ratchet.py::test_no_new_rewrite_starts_from_a_lenient_read, test/test_mate_tool_access.py::test_an_unreadable_store_refuses_the_offer_and_keeps_every_record (head ddcffa2)
Manual verification
N/A — unit coverage sufficient: each test forces the read error on the real store file and compares its bytes before and after.
Screenshots / video
N/A — no frontend file changes and nothing user-visible is drawn differently.
Related Issues
Part of #24607
Sibling sweep
Swept: python -m pytest test/test_lenient_read_rewrite_ratchet.py (its AST scan of src/ lists every lenient read that feeds a write)
Sibling: src/kiro_crew/dashboard/handlers/mcp_config_entries.py -- tracked in #24607
Sibling: src/kiro_crew/apps/dev_mode.py -- tracked in #24607
Sibling: src/kiro_crew/apps/backend_runtime/pidfile.py -- tracked in #24607
Sibling: src/kiro_crew/apps/backend_runtime/stale_reap.py -- tracked in #24607
Sibling: src/kiro_crew/autonudge_selfarm.py -- tracked in #24607
Sibling: src/kiro_crew/apps/builtins/meetings/backend/providers/tasks.py -- tracked in #24607
Sibling: src/kiro_crew/apps/builtins/pptx_maker/backend/routes.py -- tracked in #24607
Sibling: src/kiro_crew/apps/builtins/spec_builder/backend/repository.py -- tracked in #24607
Sibling: src/kiro_crew/builtin_skills/kirocrew-dev/kirocrew-prepare-pr/scripts/push_guard_record.py -- tracked in #24607
Sibling: src/kiro_crew/aws_consent.py -- tracked in #24607
Sibling: src/kiro_crew/irq.py -- not affected -- load_state documents a lost state as one duplicate wake
Sibling: src/kiro_crew/ledger_wake.py -- not affected -- _read_rate documents a lost map as one extra wake
Pattern harvest
Not generalizable: the class already has its rule, the lenient-read ratchet in test/test_lenient_read_rewrite_ratchet.py, and this PR only shrinks its frozen list.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.