Repository navigation
fix(dashboard): settle undecidable strReplace before-snapshots at flush - #11394
DcXiaoBing wants to merge 1 commit into
Conversation
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Canonical-path dedup now merges every multi-spelling write into one chip for all writes, not just ambiguous strReplace — confirm that collapse is wanted. What this change shipsInventory (9 items) — 9 justifiedIntent: FIX — the file-change card stops counting an unchanged file as fully added when a strReplace snapshot is ambiguous (#11387), by settling the before at turn end.
Lens 4/5 checks: identity tables ( [FIRST-PRINCIPLES-REVIEWED] f692e5b Description read[DESCRIPTION-READ] f4f6ede96960c1cd4481fdaa639cfce49a147f74a75b04be6c815eae72689691 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Reproduce issue #11387 once against a live kiro-cli turn: every verification replays synthetic dispatcher event orders, never the real frame sequence. [DESIGN-REVIEWED] f692e5b Description read[DESCRIPTION-READ] 10462c0ba94f6568a900db67de8862e52aa2bd3adece26b64a2895c4fa44f3ad 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 |
GPT 5.6 Review (fork) — 🔴 changes requested (blocking)Reviewed 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands. BLOCKING -- src/kiro_crew/dashboard/chat_runner.py:3271 -- Unobserved shell restore fabricates the before-snapshot
Adjudication (Opus 5) — is blocking on each finding proportionate?Harm: UNBOUNDED-class per the fence (silent fabrication of persisted before-state). Conditions confirmed: only [ADJUDICATION] f692e5b total=0 uphold=0 downgrade=0 |
Opus 5 Review (fork) — ✅ no blocking findingsReviewed |
1b01e6e to
d2035ad
Compare
90d3c3c to
569b045
Compare
569b045 to
1af8823
Compare
1af8823 to
d8a362c
Compare
f9a3215 to
71e043f
Compare
|
71e043f to
d2a5c6b
Compare
|
|
|
span=db37e66c9e96
|
|
span=6dd7854a8bdf
|
|
span=e48125549479
|
Resolve ambiguous strReplace snapshots at turn flush using capped hypotheses and completed tool outcomes. Correlate snapshots only when the turn first-source tracker proves a redacted tool ID names one call; ambiguous IDs bind and settle as unidentified. Scope a recorded terminal outcome and a bound pending payload to one call occurrence: a tool_call frame that reuses an id retires both before the new call is snapshotted, so a write cancelled before its terminal frame never binds a stale completed, and a second write under the reused id never settles the first call's payload against the file it restored. Bound the outcome map by _MAX_TCID_SOURCES, the constant that already bounds the identified-id population it is keyed on. Carry the canonical path on every snapshot from the off-thread snapshot step, so the flush buckets spellings of one file without resolving paths on the event loop. Void a held pending payload when the accumulator collapses a repeat write from another tool call, since that dropped snapshot is the second writer the flush cannot see. Keep the fragment fallback for multiple writers, changed-again files, truncated ambiguity, and non-completed writes. Cover both event orderings, redaction-colliding writer IDs, and id reuse with turn-loop tests, and align the owning system specification.
|
span=db37e66c9e96
|
|
span=6dd7854a8bdf
|
|
span=e48125549479
|
|
span=75b5323a637d
|
|
span=1f8ede687911
|
|
span=d8b12062375b
|
|
Triage note (automated PR-overlap scan, inspected Rebase needed. This branch (merge base Coordination: two other open PRs also change No breaking change or P0 found: the persisted |
|
This fix has been taken forward in #17367, a same-repo branch rebased onto current |
Problem / Motivation
Goal: Show the true pre-write content in a file chip when a strReplace leaves the on-disk state ambiguous at snapshot time.
A one-line
strReplacecan make the dashboard file-change card report the removed line against the entire post-edit file, such as-1 +55instead of-1 +0. The race occurs when the disk snapshot is valid as both the pre-write and post-write state.Why it matters
The card's stat badge is the first summary users see. Counting an unchanged file as newly added makes a safe shell configuration edit look destructive and undermines trust in the recorded diff.
Not a goal
What changed (motivation → approach → change)
The card resolves the full-file before only when one completed tool call can be identified without ambiguity.
_classify_str_replace_beforeandpending_str_replace_tcid_identity_keyonly when_tcid_first_sourceand_tcid_collapsedprove the redacted ID names one raw call. An absent, over-long, or redaction-collapsed ID binds and settles as unidentified._flush_file_changesvalidate_file_pathreturns, so two spellings of one file are one path. Resolve exactly one completed writer against the turn-end file. Multiple writers, failed or missing outcomes, changed-again files, and truncated ambiguity keep the safe fragment fallback.tool_callframe reusing an id retires both (_retire_write_tool_outcome) before the new call is snapshotted, so a write cancelled before its terminal frame never binds a stalecompleted, and a second write under the reused id never settles the first call's payload against the file it restored. Bound_write_tool_outcomesby_MAX_TCID_SOURCES, the constant that already bounds the identified-id population it is keyed on, and clear it per turn; document the bounded hypotheses, completion gate, and fail-closed identity rule.The implementation is contained in
src/kiro_crew/dashboard; the owning system specification and snapshot tests describe and verify the same contract.The ACP
oldTextforstrReplaceis a fragment, while the card needs a full-file before. For substring-shaped replacements, the snapshot race leaves two valid interpretations. Turn-end content distinguishes them only after the write reports completion.Two distinct raw tool-call IDs can redact to the same displayed constant. Treating that constant as one writer lets a second write satisfy the single-writer gate and persist a fabricated before-state. The existing first-source/collapsed verdict now gates both snapshot bind sites and terminal outcome settlement, so an ambiguous identity cannot resolve pending evidence.
This fix covers only the recoverable ambiguous-strReplace class (the undecidable seam); the other decline branches of
_classify_str_replace_beforekeep the fragmentoldTextand its badge, by design. Deferred resolution observes write tools only: a shell command that restores the file in the same turn is not a writer the flush can see, so a completed ambiguous strReplace followed by such a restore can still resolve tobefore_if_post; the owning specification records this residual as accepted.No product-shape change is introduced. The card reports the full-file comparison it is designed to show.
Backwards compatibility
Compatible: persisted
file_changesentries retain their existing{path, before, after}shape and truncation flags. Pending hypotheses, outcome state, and writer identity stamps remain turn-local.Tests
test/test_file_change_snapshots.pycovers pre-write and post-write snapshots, both substring directions, both tool-result event orders, completion/refusal/cancellation, repeated snapshots, multiple writers, capped payloads, capped outcome state, changed-again files, and truncation.TestPendingStrReplaceThroughTheTurnLoop::test_redaction_colliding_write_ids_keep_fragmentdrives two distinct raw IDs that redact to one value through_run_chat, restores the original file with the second write, and proves the fragment is kept. Removing the bind and settlement gates makes this test fail by persisting a fabricated full-file before.TestPendingStrReplaceResolution::test_later_write_under_another_spelling_keeps_fragmentrestores the file through adir/./rcspelling of the same path and proves the two writes share one bucket and keep the fragment. Keying by the raw path makes this test fail with two entries and a fabricated before.TestPendingStrReplaceThroughTheTurnLoop::test_a_reused_id_does_not_inherit_the_earlier_calls_outcomedrives a completed call and a later write that reuse one raw ID through_run_chat, ends the turn before the write's terminal frame, and proves the fragment is kept. Removing the retirement at thetool_callsite makes this test fail by persistingbefore_if_post, a before that was never on disk.TestPendingStrReplaceResolution::test_outcome_map_is_cappedpins the shared_MAX_TCID_SOURCESbound and the absence of a second constant.TestPendingStrReplaceThroughTheTurnLoop::test_a_second_write_reusing_the_id_cannot_settle_the_firstdrives two completed writes that reuse one raw ID through_run_chat, restores the file with the second write, and proves the fragment is kept. Removing the pending-payload walk in_retire_write_tool_outcomemakes this test fail by persistingbefore_if_post.Hand-built second-writer entries in the resolution tests carry
canonical_pathlike every runner-produced snapshot, so the flush buckets them with the first writer on a host whose temp directory realpath differs from its spelling (Windows 8.3 names).test/test_chat_runner_coverage.pypins the classifier's decline paths.Manual verification
N/A — the turn-loop tests replay the dispatcher event order and disk transitions that produce the card metadata; no frontend renderer changes.
Screenshots / video
N/A — this backend correction changes the accuracy of existing card data without changing the rendered component or layout.
Related Issues
Fixes #11387
Pattern harvest
Rule candidate: review-prompt
Pattern: before/after inference must not correlate operations through an identifier that redaction can collapse.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)