Skip to content

fix(dashboard): keep the open-tab reopen seed across restarts (release/0.8.0) - #17233

Merged
bolichen97 merged 1 commit into
release/0.8.0from
fix/bp15735-open-tab-seed-0.8
Oct 8, 2026
Merged

bolichen97 merged 1 commit into
release/0.8.0from
fix/bp15735-open-tab-seed-0.8

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On 0.8, a restart keeps idle sessions in the active sidebar list and keeps each session's saved context-window reading, instead of dropping every session into "older sessions" and showing 0% context everywhere.

Backport of #15735 to release/0.8.0. At startup start_flush_loop() arms the 5s periodic flush before the open-tab restore runs, and several awaits separate the two. A flush landing in that gap sees a _slots the restore has not populated yet (empty, or only a tab opened during boot) and writes it over open_slots.json, so the next restart has an empty or partial seed and every other session lands in "older sessions". _persist_context_snapshots has the same hazard: it prunes context_snapshots.json down to set(_slots), so once the seeded tabs are gone their stored context readings go with them and each reopened session renders a 0% meter until its next turn.

Why it matters

Stable Toolbox users on 0.8.0.x report exactly this after an update or restart: all sessions show 0% context window (used ~0) and the active-session set is gone. Every abrupt restart turns into a tab-by-tab recovery with no context reading to trust.

Not a goal

  • No change to restore_window_minutes or the "older sessions" grouping.
  • No change to how a fork seeds its context meter (a fork is a new slot key with no reading until its first turn; separate, pre-existing).

What changed (motivation → approach → change)

Where What
src/kiro_crew/dashboard/state.py New open_slots_restored latch, False until the boot open-tab restore has run
src/kiro_crew/dashboard/chat_persistence.py Both restore drivers set the latch in a finally (missing file, early return and raise included)
src/kiro_crew/dashboard/dashboard_persistence.py Before the latch flips, _persist_open_slots MERGES the on-disk seed into the live keys instead of pruning, and skips the write on a transient seed read failure; _persist_context_snapshots writes the union without pruning in the same window. Both prune as before once restore has run
test/test_open_slots_persistence.py, test/test_context_bar_reopen.py main's tests, applied unchanged
docs/system-specs/modules/learn-cron-dashboard.md main's two spec sentences

Cherry-pick of c4fd3a446c. All five source and test files applied cleanly. The one conflict was in the spec: main's hunk sits beside the chat_api/ composition paragraph that does not exist on this branch (it came with #16427), so the branch's structure was kept and only the two sentences #15735 changed were applied.

Backwards compatibility

Compatible: no field, type, kind or key is rejected, renamed or removed. The change only suppresses two disk writes during a window where their result was never authoritative; the on-disk formats of open_slots.json and context_snapshots.json are unchanged.

Tests

  • Before the fix (tests applied, the three source files reverted to the release tip aa37ae70a1): test_two_boot_restart_keeps_idle_sessions_active, test_flush_before_restore_does_not_wipe_seed and test_context_snapshot_prune_skipped_before_restore fail (3 failed).
  • With the fix: test_open_slots_persistence.py + test_context_bar_reopen.py: 105 passed, the same count as on main.
  • isort and flake8 clean on the changed files. black reports only pre-existing lines in test_open_slots_persistence.py that this PR does not touch (identical on main).

Manual verification

N/A — the unit tests reproduce the pre-restore flush and the two-boot restart deterministically, which a manual abrupt-restart repro cannot.

Related Issues

Fixes #15719 on release/0.8.0. Backport of #15735.

The periodic flush loop is armed before the startup open-tab restore, so a
flush firing in the pre-restore gap snapshotted an empty/partial open_slots.json
over a good seed, dropping idle sessions into "older sessions" after a restart.

Before the restore latch flips, _persist_open_slots now MERGES the on-disk seed
into the live keys instead of pruning, so a pre-restore crash keeps both the
seeded tabs and any boot-time tab; the sibling _persist_context_snapshots writes
the union (no prune) in the same window. A transient seed read failure (e.g. a
Windows sharing violation) now SKIPS the whole write rather than merging an empty
read, preserving the seed for the next flush. The open_slots_restored latch, set
by both restore drivers on every exit, flips the writers back to pruning once the
live set is authoritative.

Covered by two-boot / pre-restore-crash / transient-read-failure regression tests.

Co-authored-by: kirocrew-agent <agent@kirocrew.local>
(cherry picked from commit c4fd3a4)
@bolichen97
bolichen97 requested a review from a team as a code owner October 6, 2026 04:35
@bolichen97
bolichen97 requested review from dodgeblaster and removed request for a team October 6, 2026 04:35
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of a8958c4be8eb6ac4a45da5e94ab595ab90dd36b5 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify the hand-resolved spec conflict in learn-cron-dashboard.md carries main's two sentences verbatim — the only hunk of this cherry-pick that was merged by hand.

[DESIGN-REVIEWED] a8958c4

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of a8958c4be8eb6ac4a45da5e94ab595ab90dd36b5 — 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: PASS

Verify the "3 failed on release tip aa37ae70a1" claim by running the three named tests with the source files reverted — the one assertion here that reading cannot check.

What this change ships

Inventory (7 items) — 7 justified

Intent: FIX — backport #15735 so a restart on 0.8 no longer drops idle sessions into "older sessions" or zeroes every context meter (fixes #15719; failing-on-base tests named).

  1. Restart keeps idle sessions in the active sidebar; a pre-restore flush no longer wipes the reopen seed — justified
  2. Saved context-window readings survive a restart; the snapshot prune waits for restore — justified
  3. Pre-restore flush writes the union of seed, boot-time tab and live readings, so a crash in that window loses nothing — justified
  4. A transient seed read failure skips that flush's write instead of shrinking the file — justified
  5. New internal open_slots_restored latch — justified (2 counted consumers: dashboard_persistence.py:252,363; set by both drivers, and the boot path server.py:6812 reaches one)
  6. Headless/no-restore surfaces keep persisting (merge mode, never suppressed) — justified
  7. Spec sentences updated in the same commit — justified (AGENTS.md mandate)

[FIRST-PRINCIPLES-REVIEWED] a8958c4

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging a8958c4be8eb6ac4a45da5e94ab595ab90dd36b5. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/dashboard/dashboard_persistence.py:363 -- transient snapshot read failure still destroys saved readings

prune = bool(getattr(owner, "open_slots_restored", False))
WinError 32 during pre-restore load -> empty fallback -> flush replaces saved snapshots with only live readings.
Anchor: residual/crash-data-loss-corruption
Fix: Before restore, skip the write when loading existing snapshots fails.
[GPT-REVIEWED] a8958c4
[BLOCK-MERGE] a8958c4

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

F1 — harm rung: HIGH (saved per-tab context readings for every other tab are replaced by the live subset, with no retry once latched).
Conditions confirmed: a non-FileNotFoundError read failure of context_snapshots.json is swallowed to raw = {} at src/kiro_crew/dashboard/dashboard_persistence.py:325-330 and _context_snapshots_loaded is latched True at :340, so no later call re-reads (:316-318); the dirty flag the write requires is set on any ordinary live reading at :312; the write then replaces the file from memory alone at :390-395. Recovery path: none for the destroyed entries — the only self-correction is a new reading once a provider is live again (:303-312), and a reopened tab with no live provider falls back to snapshot is None → no stale bar (chat_handlers.py:1771-1774).
Real fix cost: small and already-patterned — the same None-sentinel skip this PR added for the symmetric seed read (:182-211, :252-263) applied to the snapshot load; no new module coordination, no hot-path state. Rarity argument for FLAG cannot be completed: the PR's own guard treats a transient sharing-violation read failure on a sibling file in the same directory as plausible, and a truncated/corrupt JSON from a prior crash reaches the identical branch, so the condition combination is ordinary rather than extreme.

[ADJUDICATION] a8958c4 total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] a8958c4
[ADJUDICATION-FENCED] a8958c4 fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/dashboard/dashboard_persistence.py:363 -- A non-FileNotFound read failure is latched as "loaded empty" (:325-340) and the ensuing write replaces the saved snapshot file from memory alone (:390-395), and that failure class is the same one this PR's own sibling guard treats as plausible, so the condition combination is ordinary rather than extreme.
[GPT-ADJUDICATED-FENCED] a8958c4

False positive or not applicable? A repository writer can comment:
/ai-review override gpt a8958c4be8eb6ac4a45da5e94ab595ab90dd36b5: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed a8958c4be8eb6ac4a45da5e94ab595ab90dd36b5 — this comment is updated in place on each push.

Review details

Nothing blocks; the open-tab persistence latch never flips on the headless API surface, and the edited spec sentence points at a file that does not exist.

FINDING — src/kiro_crew/dashboard/dashboard_persistence.py:252 — if not getattr(owner, "open_slots_restored", False): never becomes True on a surface that runs no restore (start_api_server, headless --slack-only, which also never arms the flush loop; the sole restore_open_slots_async call site is start_dashboard at server.py:6812), so the shutdown write via save_all_slots_to_history → _persist_open_slots always takes the merge branch and can never REMOVE a key — open_slots.json grows monotonically across every headless run (where it previously pruned to the live set), as does context_snapshots.json under the same latch (prune = bool(... "open_slots_restored" ...)), and each accumulated key costs a metadata read plus transcript walk on the next dashboard boot restore → Fix: have the surface that owns its live set from construction set open_slots_restored = True (an edit in server.py, outside this diff), so False means "a restore is pending" rather than "merge forever".

FINDING — docs/system-specs/modules/learn-cron-dashboard.md:2435 — the changed sentence redirects seedContextUsage to `website/src/store/chat/slotCache.ts`, a path that does not exist (website/src/store/ has no chat/ subdirectory); the function is at website/src/store/chatSlice.ts:2368 → Fix: restore the pointer to website/src/store/chatSlice.ts.

FINDING — docs/system-specs/modules/learn-cron-dashboard.md:2435 — the same changed line still asserts context_snapshots.json is "pruned to the open-slot set on every write" while the clause added immediately before it states the prune is now gated on open_slots_restored, so the paragraph documents two contradictory persistence invariants → Fix: reword to "pruned to the open-slot set once the boot restore has run".

[OPUS-REVIEWED] a8958c4

Verdict parsed from the review's SHA-scoped output markers for commit a8958c4be8eb6ac4a45da5e94ab595ab90dd36b5.

False positive or not applicable? A repository writer can comment:
/ai-review override fable a8958c4be8eb6ac4a45da5e94ab595ab90dd36b5: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 6, 2026
@bolichen97
bolichen97 merged commit c36cfce into release/0.8.0 Oct 8, 2026
20 of 23 checks passed
@bolichen97
bolichen97 deleted the fix/bp15735-open-tab-seed-0.8 branch October 8, 2026 21:44
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 8, 2026
bolichen97 pushed a commit that referenced this pull request Oct 9, 2026
…before restore (#18277)

_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.

Co-authored-by: kirocrewcaptain <kirocrewcaptain@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants