Repository navigation
fix(dashboard): skip the context snapshot write when its read failed before restore - #18277
Conversation
…before restore _persist_context_snapshots merges context_snapshots.json into memory before it writes. A read that failed with an OSError (a Windows sharing violation) was swallowed to an empty map and latched as loaded, so the next flush replaced the file with only the live readings and destroyed every other tab's saved context reading, with no retry. ensure_context_snapshots_loaded now returns False on an OSError read and leaves the loaded flag unset. The flush skips its write and keeps the map dirty, so the next pass retries against the intact file. This holds before and after the boot restore: after restore an open tab with no fresh reading still has its reading only on disk. Content that was read but does not parse is still merged as empty and latched, so the next write repairs it instead of switching persistence off for good. Follow-up to #15735 and #17233, which apply the same rule to the open_slots.json seed read.
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that [DESIGN-REVIEWED] f11e51e Description read[DESCRIPTION-READ] 8944e4f405f0c589bf3cdd8b2b3e60a8728d9f39c72f3285271500a1990d7628 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 one trade before merge: if the snapshot file can never be read (e.g. a permanent permission error), snapshot writes stop and the only trace is a debug log on every flush. What this change shipsInventory (6 items) — 6 justifiedIntent: keep every tab's saved context reading when the snapshot file briefly can't be read, e.g. a Windows sharing violation. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] f11e51e Description read[DESCRIPTION-READ] b535685405f59dbdb2fef76c9a3970c83bd3af39a8cb22dc30cda8e1cef8710f 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 — 🔴 changes requested (blocking)GPT 6.1 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- src/kiro_crew/dashboard/dashboard_persistence.py:344 -- A decoding error terminates periodic autosaves
[BLOCK-MERGE] f11e51e Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 (fenced): the harm is silent and lasts until someone fixes the file by hand, and this PR removed the guard that used to catch it.
False positive or not applicable? A repository writer can comment: |
Problem / Motivation
_persist_context_snapshotsmergescontext_snapshots.jsoninto memory before it writes. Inensure_context_snapshots_loaded, a read that failed with anything other thanFileNotFoundErrorwas swallowed to an empty map, and the loaded flag was latchedTrue. The next flush then replaced the file with only the live readings. Every other tab's saved context reading was lost, and nothing retried the read.The common trigger is a Windows sharing violation (
WinError 32) while another handle holds the file. PR #15735 (and its backport #17233) already skips theopen_slots.jsonwrite for the same kind of seed read failure; this sidecar had no such guard.Why it matters
After a restart, a reopened tab shows its last context reading from this file. One transient read failure in the boot window erased those readings for every tab the restore had yet to rebuild. After restore it erased the reading of every open tab that had not produced a fresh reading in this process. A read failure on the slot-detail path also latched an empty map for the whole process lifetime, so no reopened tab showed its reading until restart.
Not a goal
open_slots.jsonhandling.What changed
ensure_context_snapshots_loadedreturnsbool. On anOSErrorread (content unknown, possibly intact) it returnsFalseand leaves the loaded flag unset, so the next call retries. Content that was read but does not parse (truncated or non-object JSON) is still merged as empty and latched: it holds nothing recoverable, and skipping there would switch persistence off for good on a surface that never runs a restore._persist_context_snapshotsskips its write when the load returnsFalseand keeps the map dirty. This applies before and after restore. Before restore it protects the tabs the restore has yet to rebuild; after restore it protects open tabs whose reading is still only on disk. A legacy owner override that returnsNoneis treated as loaded.DashboardState.ensure_context_snapshots_loadedpasses the result through.test/windows_sim.py: newread_text_sharing_violation, thePath.read_textcounterpart ofread_sharing_violation(patchingbuiltins.opendoes not reachread_text).docs/system-specs/modules/learn-cron-dashboard.md, "Context meter survives a reopen", states the read-failure rule.Why the split between
OSErrorand parse errors instead of skipping on any failure: the snapshot writer is atomic (temp file plus rename), so a parse error means the content is genuinely corrupt and no reader can recover it. A transientOSErrormeans the file may be intact, which is the only case where a write destroys data.Backwards compatibility
No file format change. Behaviour changes only when the file exists and cannot be read: the write is deferred to the next flush instead of replacing the file. A persistent
OSErroron read keeps the map dirty and logs at debug level on each flush; the previous behaviour in that case was to overwrite the file, which is what this PR prevents.Tests
New tests:
test/test_open_slots_persistence.py::test_context_snapshot_write_skipped_when_pre_restore_read_fails: a pre-restore flush after a failing read leaves the file byte-identical, the map stays dirty and unlatched, and the next flush writes the union.test/test_context_bar_reopen.py::test_unreadable_snapshot_file_is_not_replaced_after_restore: same after restore; the disk-only reading of an open tab survives.test/test_context_bar_reopen.py::test_slot_detail_retries_a_transiently_unreadable_snapshot_file: a failed first read from the slot-detail handler is retried on the next request.test/test_context_bar_reopen.py::test_corrupt_snapshot_file_is_repaired_not_retried_forever: a truncated file is still repaired by the next write.Without the fix, the first three fail (file replaced;
KeyError: 'context_pct') and the corrupt-file test passes, pinning that its behaviour is unchanged. With the fix all pass.Lint: flake8, isort and mypy clean on the changed files;
scripts/check_black_formatting.pypasses (test/windows_sim.pyis on the existing black baseline, and the new helper follows that file's current style).Manual verification
None beyond the tests. The Windows sharing violation is simulated in-process, the same way the existing
windows_simhelpers do it.Related Issues
Follow-up to #15735 and #17233 (backport). Same defect class as #15719. A backport to the 0.8.0 release branch is needed for 0.8.1 and will be a separate PR.
Pattern harvest
Rule candidate: a read that merges an on-disk sidecar before a full-file rewrite must not treat a transient
OSErroras "empty and loaded"; it returns an "unknown" result and the caller skips the write. Parse errors on an atomically written file may be treated as empty. Applies to every read-merge-rewrite sidecar indashboard_persistence.py.