Repository navigation
fix(dispatch): two #37 follow-ups — undo loses detached agents; rehydrate stale focus - #39
Merged
Merged
Conversation
closeTab in actions/tab.ts kills both grid panes AND detached dispatch agents associated with the project tab (the detached records carry projectTabId, so the tab is the natural lifetime owner). The undo path restored only the grid panes — detachedEntries weren't captured, so Cmd+Shift+T silently dropped every parked dispatch agent the user had in that project. Big trust hit: the user thought "undo close" meant "give me back the entire tab" but actually got "tile-tree only, everything else is gone." Fix: - lib/undoClose.ts: extend ClosedTab with optional detachedEntries, each carrying SessionMeta (for respawn) + the original detachedAt (so the dispatch row's age display doesn't snap to "just now" on undo — a 4-hour-old detached agent restored in the same minute should still read as 4 hours old). Optional because tab closes before the detached-sessions feature shipped, or tabs that simply had no detached agents, won't carry the field. - actions/tab.ts: capture detachedEntries at close time. Defensive flatMap skips any record whose SessionMeta has gone missing — should never happen, but an undo entry referencing a non-existent meta would throw at restore time. - actions/undoClose.ts: in the tab branch, after rebuilding the tile tree, re-spawn each detached entry and rebuild DetachedSessionRecord entries pointing at the restored tab's NEW id (the old tab id is gone). Same restore-what-we-can policy as the tile-tree spawn loop: failed spawns are skipped silently. SessionMeta lands in state.sessions through sessionActions.spawn's own setState, so the setState here only needs to merge the DetachedSessionRecord entries. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dispatchMode.focusedSessionId is a SessionId that, like every other persisted SessionId in the workspace (tab leaves, buried records, detached records), needs to be remapped through the rehydrate idMap. Without this remap the field carries a pre-restart sessionId past restart, so the dispatch UI's selectActiveRow silently falls back to grid focus or first row, and any command that targets dispatch focus operates on the wrong visible row. Fall back to undefined when the old id failed to respawn (or wasn't in the idMap for any reason). Better to clear the focus than to pretend a dead id is still selectable — the dispatch UI's first-row fallback handles undefined cleanly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs surfaced by review of PR #37 (dispatch detached sessions). Both are session-id lifecycle holes in the new detached model. Small, targeted, no behavior change beyond closing the holes.
Commit map
Bug 1 — `undo close` silently dropped detached agents
`closeTab` killed both grid panes and detached agents associated with the tab (their `projectTabId` makes the tab the natural lifetime owner), but the undo entry only captured grid leaf metas. Cmd+Shift+T restored the tile tree and silently lost every parked dispatch agent — big trust hit because the user reasonably expects "undo close" to mean "give me back the entire tab."
Fix:
Bug 2 — rehydrate kept stale dispatch focus
`rehydrate.ts` spread `persisted.dispatchMode` directly while every other persisted SessionId (tab leaves, buried, detached) went through `idMap`. After restart, `dispatchMode.focusedSessionId` still pointed at a pre-restart sessionId, so `selectActiveRow` silently fell back to grid focus or first row. No crash, but commands that target dispatch focus operated on the wrong row.
Fix: pass `focusedSessionId` through `idMap.get(...)`, fall back to `undefined` if the old id didn't respawn. The dispatch UI's first-row fallback handles `undefined` cleanly.
Verification
Test plan
🤖 Generated with Claude Code