Repository navigation
fix(autonudge): set a damaged self-arm record aside before an arm rewrites it - #36206
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. The fix stays inside the lock-held read-modify-write, adds one opt-in keyword, and reuses the existing quarantine-name helper. Notes
[DESIGN-REVIEWED] 5219448 Description read[DESCRIPTION-READ] c21355153a6d5ddc44f645bc54da5bb4eb07e7d5bb32af4c1344d079b5903677 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 blocks. The fix works at the root of the bug: the arm used to read a damaged file as empty and then write over it. Its one test fails on base, so the defect is proven. What this change shipsInventory (4 items) — 4 justifiedIntent: when a loop is armed over a cut-off or wrong-shaped self-arm record, the other loops' entries can still be recovered instead of being destroyed. FIX.
[FIRST-PRINCIPLES-REVIEWED] 5219448 Description read[DESCRIPTION-READ] 447b32ae8364da2d8f13cbd9764cff1c921ab8e750c430769f15f12945410575 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: |
Code change approver recommendation: ApproveWhy: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. record_self_arm now reads through _read_record_for_update. If the record opens but is cut off or has the wrong shape, it is moved to a .corrupt- file using the existing reserve_quarantine_name and replace_with_retry helpers, and a failed move deletes the reserved placeholder. Only then is the record rewritten. Paths that are not damaged-but-openable behave exactly as on main: a missing record creates it, a readable record keeps its entries, a record that can't be opened (EACCES/EIO) is still rewritten, and a failed set-aside still rewrites it. forget_self_arm only writes after finding its entry, so it can't destroy a damaged record. The fire-time readers still treat a damaged record as "not recorded", which refuses the fire. The set-aside file stays inside the trust/ subtree, which is protected as a whole directory, and nothing enumerates that directory. The new cut-off-record test fails on main, and the ratchet _KNOWN entries are consistent with the code. No regression or trust-boundary change found. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed the whole diff at 4f35d74, tests included. Most of it is good, and one part needs to change.
Good: a record that opens but is cut off or has the wrong shape is moved to a .corrupt-<utc> file and the arm carries on, so one damaged file no longer drops every other loop's entry and the arm still succeeds. That keeps the arm working where main also works, and I have no concern with it. The ratchet entry change is fine too.
Needs to change: _read_record_for_update now raises OSError when the record cannot be opened (a transient EACCES or EIO), and record_self_arm lets it out. On main the same call goes ahead and arms the loop. So this adds a new condition under which an arm fails where main lets it pass. It is a refusal even though its purpose is to protect the other loops' entries, and test_arming_over_a_record_that_cannot_be_opened_keeps_it_and_refuses pins it. The change should not make a self-arm fail where main arms.
Suggested direction, either of which keeps main's behavior by default:
- On an unopenable record, log a warning and carry on as main does, keeping the corrupt-set-aside part for the cut-off case. Or
- If the failing behavior is wanted, put it behind a setting that is off by default, so the default path arms as main does.
The test for the unopenable case would change to match whichever you pick. Everything else can stay as it is. I am not approving until that part is changed. The author's auto-merge is left alone.
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (3 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: arming a self-arm loop no longer rewrites the record from an empty read when the file cannot be opened; a cut-off record is set aside first. Tests added.
|
A follow-up to my review at 4f35d74, with a third option for the unopenable-record case that protects the data without a refusal. When the record cannot be opened (a transient EACCES or EIO), That keeps the data protection this change is after and adds no condition under which an arm fails where main arms. The cut-off and wrong-shape case can stay as written (set aside as |
|
This review found no blocking defect at head 4f35d74. It cannot approve while the maintainer change request on this head is open. A maintainer decides how an arm should behave when the self-arm record cannot be opened. What the review checked on this head:
Done well: the tests drive a real record in a temporary data home and read it back through For the change request decision:
Optional:
|
|
Thanks, agreed: this read should never refuse an arm.
The unopenable-case test now pins that the arm succeeds, and a new test pins the same for a set-aside that fails. Both pass on main, which is the point. The set-aside test is the only one that fails on main. |
ac392d9 to
47bb927
Compare
|
Rebased: |
47bb927 to
9c32e0a
Compare
|
The First Principles note is right, and |
record_self_arm read autonudge-self-armed.json with a reader that turns an unopenable or cut-off file into an empty table, then wrote back only the new entry. Every other loop's entry was gone, and each of those loops was refused at every fire although it had been armed by its own session. The rewrite reads through a strict reader. Only a missing file is empty. A file that cannot be opened raises OSError and stays as it is, which the authorizer already answers with "self-arm record unavailable". A file that opens but is cut off or has the wrong shape is moved to a timestamped .corrupt- file and the record starts again, so one damaged file does not stop every later self-arm. The lenient-read ratchet drops record_self_arm and marks forget_self_arm audited: it writes only after finding the entry.
9c32e0a to
1f99b05
Compare
|
Rebased: onto main |
…e read An unopenable record reads as empty and the arm proceeds, and a damaged record that cannot be set aside is logged and the arm proceeds too, so this read never refuses an arm that would succeed without it. A cut-off or wrong-shaped record is still moved to a timestamped .corrupt- file first, so its bytes are kept. The lenient-read ratchet lists record_self_arm again, with that reason.
1f99b05 to
5219448
Compare
|
The First Principles note is right, and |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed the whole diff at 5219448, tests included. This supersedes my earlier request for changes.
A damaged self-arm record (cut off or the wrong shape) is now moved to a .corrupt-<utc> file before the arm rewrites it, so its bytes are kept, and a failed set-aside is logged and does not stop the arm. A record that cannot be opened reads as empty, as on main, so an arm never fails on it. The change adds no new refusal: every case still arms, and the tests cover the cut-off record, the unopenable record, a set-aside that cannot happen and the no-record case. The unopenable-record path loses no more than main does.
One non-blocking idea for a follow-up: when the record cannot be opened, skipping the write with a warning would also keep the other loops' entries, which main loses today.
All checks that are live are green. The four cancelled runs on this head each have a newer passing run. The author holds auto-merge, so I approve without it.
Problem / Motivation
Goal: arming a self-armed loop over a damaged record keeps the damaged record's bytes, and an arm never fails where it succeeds today.
autonudge-self-armed.jsonholds one entry per loop a session armed for itself, and the fire-time guard refuses a self-armed loop whose entry is missing.record_self_armread the record with_read_record, which answers an empty table for a file that is cut off or has the wrong shape, then wrote back only the new entry. The old bytes were replaced, so every other loop's entry was gone with no copy left to recover it from.Why it matters
A refused fire looks like a loop that stopped working for no reason. With the damaged record set aside, the entries it held can still be read back by hand instead of being overwritten.
Not a goal
.corrupt-<utc>file beside it.forget_self_arm, which writes only after finding the entry it removes.What changed (motivation → approach → change)
Symptom → cause: the read-modify-write started from a read that turns a damaged file into an empty one and then writes over it.
src/kiro_crew/autonudge_selfarm.py:record_self_armreads through_read_record(set_aside_damaged=True), the same reader the checks use, with one new keyword. With it, a record that opens but is cut off or has the wrong shape moves to a.corrupt-<utc>name reserved by the existingsqlite_quarantine.reserve_quarantine_name(throughreplace_with_retry; a move that fails removes the reserved placeholder) before the arm writes the new record. A record that cannot be opened reads as empty, and a set-aside that fails is logged; in both cases the arm goes ahead, so this read never refuses an arm. Without the keyword the reader answers exactly as before.test/test_lenient_read_rewrite_ratchet.py:record_self_armstays listed in_KNOWN, now with the reason above, andforget_self_armis marked_FOUND_ONLY.test/test_autonudge_self_arm_unreadable_rewrite.py: new.Backwards compatibility
Compatible: every arm that succeeds today still succeeds, and a readable record and a missing one behave as before. The one change is that a cut-off or wrong-shaped record is moved aside to a
.corrupt-<utc>file before the arm rewrites it, instead of being overwritten. Removes nothing.Tests
b9ddf797c7, 1 of the 4 new tests fails: arming over a cut-off record sets it aside. The other 3 pass on main and pin behavior that must not change: an arm over a record that cannot be opened still arms, an arm whose set-aside fails still arms, and an arm with no record yet creates it.test/test_autonudge*.pyfiles: 2074 passed.flake8,isortandmypypass on the changed files, and the repo's black gate (scripts/check_black_formatting.py) passes.python -m pytest test/test_autonudge_self_arm_unreadable_rewrite.py -n0Manual verification
N/A: the tests drive
record_self_armon a real record in a temporary data home and read it back throughis_recorded_self_arm.Sibling sweep
Swept: the
_KNOWNsites intest/test_lenient_read_rewrite_ratchet.pymarked "matches the shape; not audited".Sibling:
src/kiro_crew/autonudge_selfarm.py-- changed hereSibling:
src/kiro_crew/apps/backend_runtime/pidfile.py-- not affected -- fixed in #36012Sibling:
src/kiro_crew/apps/dev_mode.py-- not affected -- fixed in #35910Pattern harvest
Rule candidate: review-prompt
Pattern: a writer of an authorization record replaces a file it could not parse, so the bytes that held every other entry are gone.
Related Issues
None filed; found while auditing the unaudited sites of the lenient-read ratchet.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement