Skip to content

feat(autonudge): quarantine a row with an unsafe addressing field instead of dropping it - #11154

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:split/autonudge-quarantine-sidecar
Sep 20, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:split/autonudge-quarantine-sidecar

Conversation

@rnoack1

@rnoack1 rnoack1 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Problem / Motivation

When the auto-nudge store is loaded, a persisted row whose addressing field holds a value the
service cannot safely use was dropped. The row vanished with only a log line behind it, so
there was nothing left to inspect and no way to tell a corrupt write from a row that had never
existed. A partially-vetted load could then be persisted back, overwriting the rows it had
failed to read.

Why it matters

Silent loss is the worst outcome for a store that is the only record of a user's armed loops.
A row that cannot be vetted is evidence, not garbage: preserving it is what makes the failure
diagnosable, and refusing to persist over an unvetted load is what stops one bad read from
destroying the rows it could not parse.

What changed

A quarantine sidecar. A row with an unsafe addressing field is now held out of the live
loop set and written to a sidecar file next to the store, instead of being discarded:

  • _write_quarantine_sidecar / _read_quarantine_sidecar persist and recover held rows, keyed
    by _quarantine_row_key so a repaired row keeps its held-aside copy.
  • _compact_quarantine_sidecar prunes entries that no longer apply. A compaction failure
    after the main store has committed does not report the landed write as failed.
  • _move_aside_unreadable_sidecar preserves an unreadable sidecar rather than truncating it, so
    recovery can never end the process at boot.
  • _refuse_writes_and_preserve_sidecar latches a persist refusal when the last load could not
    vet the store, raising AutoNudgeStoreUnvetted from both the persist entry point and the
    timer fire path.

This PR is one unit of a split of the oversized #7996, cut to be reviewable on its own. It
carries redact_store_value as an identical copy also present in #10967 — that duplication is
deliberate, and is what lets each unit compile and test independently rather than imposing a
merge order between them.

Tests

test/test_autonudge_quarantine_sidecar.py — 20 tests, all passing, covering the sidecar
write path, id-colliding held rows, recovery from an unreadable sidecar at startup, and the
write refusal being reachable with rows already in memory.

The tests are extracted from the parent change and were baselined against it: each one passes
at the parent head before extraction, so a failure here would be an extraction defect rather
than a pre-existing one. flake8 is clean on both changed files.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 16, 2026
@dwu96

dwu96 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@rnoack1
rnoack1 marked this pull request as ready for review September 16, 2026 10:36
@rnoack1
rnoack1 requested review from a team and CrysisDeu September 16, 2026 10:36
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 16, 2026
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — 🟡 CONCERNS

Design-level review of af37d3edd6befdbe5bfd3303f4c26336d26d5d47 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Undescribed in-flight-cycle claim schema ships with no producer: _delivering_claim is never populated, yet inflight_cycle/inflight_undelivered become persisted contract here.

Watch

Scope smuggled from the #7996 split: the diff adds _delivering_claim, _unreconciled_claim, _undelivered_claim, persisted keys inflight_cycle/inflight_undelivered, and a load branch that deactivates a loop with stopped_reason = "interrupted_cycle" — but nothing on the fire path ever writes a claim ("Persisted but rolled back in memory for the delivery window" has no code behind it), and the description's "What changed" names only the sidecar. The persisted owed-vs-spent cycle contract gets committed with its writer half unreviewed, and the reconciliation branch is reachable only via hand-edited or future-build stores until the sibling unit lands.
Clears when: the claim scaffolding moves to the split unit that adds its fire-path producer, or the description states the deliberate reader-before-writer sequencing and links that sibling PR.

Suggestions

  • The quarantine core (vet → hold aside → refuse unvettable persists) would stand alone if _serialized_loops dropped its claim lines — a cleaner extraction boundary for the split.

[DESIGN-REVIEWED] af37d3e

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings (all downgraded on adjudication)

Reviewed af37d3edd6befdbe5bfd3303f4c26336d26d5d47 via the fork AI-review pipeline; updated in place on each push.

Opus 4.8 adjudication downgraded every blocking finding to advisory. Adjudication downgraded all 1 blocking finding(s) to advisory: the remedy each one requires is disproportionate to the harm it prevents. Read them as advice, not as merge conditions.

Review details

BLOCKING -- src/kiro_crew/autonudge.py:1277 -- quarantine retention is unbounded
self._quarantined.append(deepcopy(raw))
Distinct unsafe persisted rows -> _load retains complete arbitrary rows -> memory/disk exhaustion.
Anchor: a-bound-bounds-every-field-it-retains
Fix: Bound row count and every retained string/container before copying.

FINDING -- src/kiro_crew/autonudge.py:1227 -- "inflight_cycle" deactivates loops on restart, adding undeclared delivery semantics outside quarantine scope -> Fix: remove the claim-state changes from this PR.

[BLOCK-MERGE-DOWNGRADED] af37d3e
[GPT-REVIEWED] af37d3e

Adjudication (Opus 4.8) — is blocking on each finding proportionate?

I've reviewed the finding against the diff (the changed lines) and the surrounding base code.

F1 — quarantine retention unbounded (autonudge.py:1277, self._quarantined.append(deepcopy(raw))).

Conditions the failure requires:

  • A row is only quarantined when an addressing field (id/slot_key) is credential-shaped or non-printable — _addressing_value_unsafe_why (patch:54-67) gating the quarantine append (patch:296-317). Normal operation generates these fields internally and never trips it; unsafe values require hand-editing/corruption of autonudge.json, a plain file under the agent's own data home. To exhaust memory/disk you need many distinct such rows.
  • Accumulation across restarts depends on the sidecar union that de-dups only by whole-row key (_write_quarantine_sidecar_locked, patch:714-745), and the pre-existing store already retains whole loop dicts with no row cap (no MAX_*LOOP/bound anywhere; add has none, autonudge.py:1556).

Recovery / visibility: sidecar and store are ordinary files; repairing or deleting them clears the set, and compaction retires enumerated+held rows (_compact_quarantine_sidecar_locked, patch:752-781). Failure is visible as disk usage and fully recoverable — none silent, none irreversible.

Harm rung: LOW — a recoverable, visible degradation gated on an operator-corrupted store, bounded by a store whose row count is already unbounded independent of this PR. The proposed remedy ("bound row count and every retained string/container before copying") directly contradicts the PR's central invariant — rows are held VERBATIM so an operator can repair them (patch:130-132, _write_quarantine_rows docstring patch:783-806) — so truncating/dropping would reintroduce exactly the data-loss this change exists to prevent. Remedy cost clearly exceeds the harm.

[ADJUDICATION] af37d3edd6befdbe5bfd3303f4c26336d26d5d47 total=1 uphold=0 downgrade=1
DOWNGRADE F1 src/kiro_crew/autonudge.py:1277 reason=disproportionate-remedy
[GPT-ADJUDICATED] af37d3edd6befdbe5bfd3303f4c26336d26d5d47

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed af37d3edd6befdbe5bfd3303f4c26336d26d5d47 via the fork AI-review pipeline; updated in place on each push.

Review details

No blocking findings; one advisory.

FINDING — src/kiro_crew/autonudge.py:~5317 — the new if self._load_refused: fire-refusal guard is placed AFTER the is_structured_monitor_loop(loop) branch (which returns at the end of its block), so it only gates the legacy _on_fire path; the comment claims it is "reached before either dispatch" but a structured monitor loop bypasses it entirely → once _refuse_writes_and_preserve_sidecar latches _load_refused at runtime, the monitor loop keeps ticking through _on_monitor_tick → MonitorController.tick; in the claimed-wake retry path (wake_delivery is BUSY) _dispatch_claimed delivers the wake at self._dispatch(...) and only then calls record_monitor_dispatched → _write_state, which now raises AutoNudgeStoreUnvetted and is swallowed by the tick's except Exception, so the same unattended wake is re-delivered on every re-armed tick with no durable record — the exact harm the guard was added to prevent, left uncovered for monitor loops → Fix: move the if self._load_refused: … return check above the is_structured_monitor_loop(loop) branch in _timer.

[OPUS-REVIEWED] af37d3e

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

Premise-level review of af37d3edd6befdbe5bfd3303f4c26336d26d5d47 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The in-flight cycle-claim machinery rides along undeclared with zero producers — nothing writes inflight_cycle, so its load arm and "interrupted_cycle" hold are dead code.

Not justified as shipped

  • Item 9 — undeclared, zero producers: the description ("A quarantine sidecar…") never mentions _delivering_claim, _unreconciled_claim, _undelivered_claim, the inflight_cycle load arm, or the claim lines in _serialized_loops; grepped inflight_cycle|inflight_undelivered|_delivering_claim across src/ — 0 matches on base, and in the diff _delivering_claim is only initialized/reset, never populated, so the marker this code reads can only come from a hand-edit or the unmerged parent test(autonudge): verify redaction rendering in the popover projection #7996.
    Subtraction: delete the three claim attributes, the inflight_cycle/inflight_undelivered handling in _load and _serialized_loops, and stopped_reason = "interrupted_cycle"; defer them to the split unit that ships the fire-path writer.
    Clears when: the test(autonudge): verify redaction rendering in the popover projection #7996 unit that populates _delivering_claim (writes inflight_cycle) merges, or the apparatus is deleted from this unit.

What this change ships

Inventory (10 items) — 8 justified

Intent: stop the auto-nudge store silently losing rows it cannot vet, by holding them aside for repair instead of dropping or overwriting them — a FIX to silent data loss, though the addressing vetting itself is new against base (the "was dropped" behavior exists only in unmerged parent #7996).

  1. A loop whose id/slot_key is credential-shaped or non-printable no longer arms; it is held in a new autonudge.quarantine.json sidecar — justified
  2. A load-time warning names each held row and where to move the repaired copy — justified
  3. A store with a non-object root or non-list loops arms nothing and refuses writes, instead of crashing boot or deleting rows on the next rewrite — justified
  4. Persisting after a refused load raises AutoNudgeStoreUnvetted instead of overwriting the store — justified
  5. Loops do not fire while persistence is refused — justified
  6. A row _load cannot parse now survives store rewrites verbatim instead of being deleted — justified
  7. An unreadable sidecar is moved aside as .corrupt-<ts> and writes refuse until restart — justified
  8. A new autonudge.quarantine.json.lock file appears beside the store — undeclared, harm-free infrastructure for items 1/7
  9. Loops loaded with a persisted inflight_cycle marker are held stopped as "interrupted_cycle"; rows can carry inflight_cycle/inflight_undelivered — undeclared, zero producers (dead until another test(autonudge): verify redaction rendering in the popover projection #7996 unit lands)
  10. Store writes are dir-synced after commit; a post-commit sync/compaction failure logs rather than reporting the landed write failed — justified

(One smaller item over the cap: load-path log lines now pass store values through redact_store_value — justified, named boundary.)

[FIRST-PRINCIPLES-REVIEWED] af37d3e

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Sep 16, 2026
@rnoack1
rnoack1 force-pushed the split/autonudge-quarantine-sidecar branch from 240a803 to 4cf8013 Compare September 18, 2026 11:59
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 18, 2026
…tead of dropping it

A loaded row whose addressing field cannot be vetted is now held out of the live loop
set and written to a sidecar file, so the operator can still see and correct it.
@rnoack1
rnoack1 force-pushed the split/autonudge-quarantine-sidecar branch from 4cf8013 to af37d3e Compare September 18, 2026 13:04
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 18, 2026

@cixuuz cixuuz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Large but carefully reasoned fail-closed persistence design for a real data-loss bug (a corrupt/unsafe row was silently dropped, and a partially-vetted load could then overwrite the rows it failed to read). The quarantine sidecar keeps held-aside rows durable and out of every serving/egress path (addressing fields are exempt from the display scrub, which is exactly why an unsafe row must never be armed). Write ordering (sidecar synced before the main store swap, dir-fsync after commit, compaction only after a successful write) prevents the crash-window data loss the docstrings describe. Verified PlatformCompositionError/redact_log_via_context exist in kiro_crew.platform. 21 tests target exactly the failure modes named (fsync-before-compact ordering, compaction-failure survival, corrupt-root refusal). Deliberate duplication of redact_store_value with #10967 is disclosed and justified (independent compilability of a deliberate split of oversized #7996).

@bolichen97
bolichen97 merged commit 0c8a093 into kirodotdev:main Sep 20, 2026
82 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 20, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…tead of dropping it (kirodotdev#11154)

A loaded row whose addressing field cannot be vetted is now held out of the live loop
set and written to a sidecar file, so the operator can still see and correct it.
@rnoack1
rnoack1 deleted the split/autonudge-quarantine-sidecar branch November 5, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants