-
Notifications
You must be signed in to change notification settings - Fork 341
fix(tabs): allow an agent to have zero AI tabs #1349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,11 +203,18 @@ export function useSessionRestoration(): SessionRestorationReturn { | |
| session = { ...session, createdAt: backfill }; | ||
| } | ||
|
|
||
| // Sessions must have aiTabs - if missing, this is a data corruption issue | ||
| // Create a default tab to prevent crashes when code calls .find() on aiTabs | ||
| if (!session.aiTabs || session.aiTabs.length === 0) { | ||
| // An agent may legitimately have zero AI tabs as long as some other tab kind | ||
| // is still open (the user closed the last chat but kept a terminal around). | ||
| // Only a session with no tabs whatsoever is treated as data corruption - | ||
| // recovering the zero-AI-tab case would wipe the tabs the user still has. | ||
| const restoredTabCount = | ||
| (session.aiTabs?.length ?? 0) + | ||
| (session.filePreviewTabs?.length ?? 0) + | ||
| (session.terminalTabs?.length ?? 0) + | ||
| (session.browserTabs?.length ?? 0); | ||
| if (restoredTabCount === 0) { | ||
|
Comment on lines
+206
to
+215
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Count only terminal tabs that survive restoration. A session with zero AI tabs and one terminal tab without Count only terminal tabs with a startup command here, or repeat the empty-session recovery check after transient terminal tabs are removed. 🤖 Prompt for AI Agents |
||
| logger.error( | ||
| '[restoreSession] Session has no aiTabs - data corruption, creating default tab:', | ||
| '[restoreSession] Session has no tabs of any kind - data corruption, creating default tab:', | ||
| undefined, | ||
| session.id | ||
| ); | ||
|
|
@@ -249,6 +256,12 @@ export function useSessionRestoration(): SessionRestorationReturn { | |
| }; | ||
| } | ||
|
|
||
| // Normalize a missing aiTabs array so the rest of the app can keep calling | ||
| // .find()/.map() on it. Zero AI tabs is a valid state; undefined is not. | ||
| if (!session.aiTabs) { | ||
| session = { ...session, aiTabs: [] }; | ||
| } | ||
|
Comment on lines
+259
to
+263
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Clear stale AI selection during zero-AI restoration. This normalization accepts an empty Use an empty string when no reset AI tab exists. Proposed fix const restoredActiveTabId = validAiTabIds.has(correctedSession.activeTabId)
? correctedSession.activeTabId
- : resetAiTabs[0]?.id || correctedSession.activeTabId;
+ : resetAiTabs[0]?.id || '';🤖 Prompt for AI Agents |
||
|
|
||
| // Fix inconsistency: activeFileTabId should only be set in AI mode. | ||
| // If inputMode is 'terminal' but a file tab is still active, clear it to prevent | ||
| // rendering a file preview without a tab bar (orphaned file preview bug). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the last AI tab is closed beside an ordinary terminal and Maestro restarts, this check counts that terminal and skips recovery before the terminal is later discarded for lacking a startup command, causing the session to open with no usable tabs and a blank AI workspace.