-
Notifications
You must be signed in to change notification settings - Fork 287
feat: Persist and restore active session id (resume in last open sess… #714
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
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 |
|---|---|---|
|
|
@@ -71,6 +71,12 @@ export interface SessionStoreActions { | |
| */ | ||
| setActiveSessionId: (id: string) => void; | ||
|
|
||
| /** | ||
| * Set the active session ID from persisted state on startup. | ||
| * Updates local state only — does not write back to disk. | ||
| */ | ||
| hydrateActiveSessionId: (id: string) => void; | ||
|
|
||
| /** | ||
| * Set the active session ID without resetting cycle position. | ||
| * Used internally by session cycling (Cmd+J/K). | ||
|
|
@@ -198,7 +204,16 @@ export const useSessionStore = create<SessionStore>()((set) => ({ | |
| }), | ||
|
|
||
| // Active session | ||
| setActiveSessionId: (id) => set({ activeSessionId: id, cyclePosition: -1 }), | ||
| setActiveSessionId: (id) => { | ||
| set({ activeSessionId: id, cyclePosition: -1 }); | ||
| // Fire-and-forget: persist to disk for restore on next launch. | ||
| // Not awaited — UI state must update synchronously; if the write | ||
| // fails the only consequence is the session won't be pre-selected | ||
| // on next launch (falls back to first session). | ||
| window.maestro?.sessions?.setActiveSessionId(id); | ||
|
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C3 'getActiveSessionId|setActiveSessionId|ipcRenderer\.invoke|ipcMain\.handle' \
src/renderer/global.d.ts \
src/main/preload/settings.ts \
src/main/ipc/handlers/persistence.tsRepository: RunMaestro/Maestro Length of output: 7348 🏁 Script executed: cat -n src/renderer/stores/sessionStore.ts | sed -n '195,220p'Repository: RunMaestro/Maestro Length of output: 876 Add explicit
Line 209 is more problematic: the IPC call sits inside a Zustand state setter callback ( 🤖 Prompt for AI Agents |
||
| }, | ||
|
|
||
| hydrateActiveSessionId: (id) => set({ activeSessionId: id, cyclePosition: -1 }), | ||
|
|
||
| setActiveSessionIdInternal: (v) => | ||
| set((s) => ({ activeSessionId: resolve(v, s.activeSessionId) })), | ||
|
|
||
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.
setActiveSessionIdpersists during initial load, potentially overwriting a valid saved IDWhen the saved
activeSessionIdisn't found in the restored sessions (e.g., that session was deleted), the code falls back torestoredSessions[0]?.id.setActiveSessionIdis then called, which immediately fireswindow.maestro?.sessions?.setActiveSessionId(id)and overwrites the persisted ID with the fallback.This is correct behavior for the deletion case, but it also means that if sessions haven't fully migrated yet (unlikely but possible), the fallback ID is permanently stored before the next app run can attempt a re-match. A clarifying comment here would help future maintainers understand this intentional overwrite.