Skip to content

Commit 1a35024

Browse files
IM.codesclaude
andcommitted
fix: restore watchers for live sub-sessions on daemon restart
restoreFromStore was skipping all deck_sub_* sessions entirely, so codex/gemini/CC watchers for sub-sessions were lost on daemon restart. Now: skip restart/respawn for sub-sessions (still managed by rebuild), but restore JSONL watchers for live ones. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6fbda46 commit 1a35024

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

src/agent/session-manager.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,28 @@ export async function restoreFromStore(): Promise<void> {
211211
// 1. Restart store sessions missing from tmux; start jsonl-watcher for live ones
212212
for (const s of all) {
213213
if (s.state === 'stopped') continue;
214-
// Sub-sessions (deck_sub_*) are managed by rebuildSubSessions triggered by the browser.
215-
// Their JSONL watcher uses a specific file path via startWatchingFile.
216-
// Handling them here would fall back to directory scan (startWatching), stealing the main
217-
// session's JSONL file since sub-sessions have no ccSessionId in the session-store.
218-
if (s.name.startsWith('deck_sub_')) continue;
214+
// Sub-sessions (deck_sub_*): skip restart/respawn (managed by rebuildSubSessions),
215+
// but still restore watchers if the tmux session is alive.
216+
if (s.name.startsWith('deck_sub_')) {
217+
if (!live.includes(s.name)) continue; // dead sub-session, skip
218+
// Restore watcher for live sub-sessions
219+
if (s.agentType === 'claude-code' && s.ccSessionId && s.projectDir && !isWatching(s.name)) {
220+
startCCWatcher(s.name, s.projectDir, s.ccSessionId);
221+
} else if (s.agentType === 'codex' && s.codexSessionId && !isCodexWatching(s.name)) {
222+
findRolloutPathByUuid(s.codexSessionId).then((rolloutPath) => {
223+
if (rolloutPath) {
224+
startCodexWatchingFile(s.name, rolloutPath).catch(() => {});
225+
} else {
226+
startCodexWatchingById(s.name, s.codexSessionId!).catch(() => {});
227+
}
228+
}).catch(() => {});
229+
} else if (s.agentType === 'gemini' && !isGeminiWatching(s.name)) {
230+
if (s.geminiSessionId) {
231+
startGeminiWatching(s.name, s.geminiSessionId);
232+
}
233+
}
234+
continue;
235+
}
219236

220237
// Always backfill missing CC session UUID from the tmux pane command, even if
221238
// a watcher is already active. Otherwise sessions.json can stay permanently

0 commit comments

Comments
 (0)