-
Notifications
You must be signed in to change notification settings - Fork 57
feat(desktop): enable daemon mode at runtime when terminal persistence is toggled #800
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
Conversation
…e is toggled When users enable/disable terminal persistence in settings, the daemon now starts/stops immediately without requiring an app restart. Extracts shared daemon initialization and shutdown logic for use by both startup and runtime toggle paths.
📝 WalkthroughWalkthroughThis PR adds runtime daemon mode toggling functionality to the terminal subsystem. When terminal persistence settings are updated through the settings API, the system now enables or disables daemon mode and resets the workspace runtime registry accordingly. The daemon management module gains new lifecycle functions for initialization, shutdown, and session reconciliation. Changes
Sequence DiagramsequenceDiagram
participant Settings Router
participant Terminal Manager
participant Daemon
participant Workspace Registry
Settings Router->>Terminal Manager: enableDaemonMode() or disableDaemonMode()
alt Enable Path
Terminal Manager->>Daemon: initializeDaemon()
Daemon->>Terminal Manager: daemon ready
Terminal Manager->>Terminal Manager: reconcileDaemonSessions()
Terminal Manager->>Terminal Manager: cache state
else Disable Path
Terminal Manager->>Daemon: shutdownDaemon()
Daemon->>Terminal Manager: shutdown complete
Terminal Manager->>Terminal Manager: cache state
end
Terminal Manager->>Workspace Registry: resetWorkspaceRuntimeRegistry()
Workspace Registry->>Settings Router: reset complete
Settings Router->>Settings Router: return success
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/desktop/src/main/lib/terminal/index.ts`:
- Around line 147-161: The cachedDaemonMode is set to true before
initializeDaemon() completes, so on failure the cache incorrectly indicates the
daemon is active; update enableDaemonMode to only set cachedDaemonMode = true
after await initializeDaemon() succeeds, or alternatively catch the error and
reset cachedDaemonMode = false before rethrowing; reference enableDaemonMode,
initializeDaemon, cachedDaemonMode and getActiveTerminalManager when making the
change so subsequent calls reflect the real daemon state.
| export async function enableDaemonMode(): Promise<void> { | ||
| if (cachedDaemonMode === true) { | ||
| return; | ||
| } | ||
|
|
||
| console.log("[TerminalManager] Enabling daemon mode"); | ||
| cachedDaemonMode = true; | ||
|
|
||
| try { | ||
| await initializeDaemon(); | ||
| } catch (error) { | ||
| console.error("[TerminalManager] Failed to enable daemon mode:", error); | ||
| throw error; | ||
| } | ||
| } |
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.
Cache is updated before async operation completes.
If initializeDaemon() fails, the cache remains set to true while the daemon isn't actually running. This could cause subsequent calls to getActiveTerminalManager() to return the daemon manager when the daemon isn't initialized.
Consider rolling back the cache on failure:
Proposed fix
export async function enableDaemonMode(): Promise<void> {
if (cachedDaemonMode === true) {
return;
}
console.log("[TerminalManager] Enabling daemon mode");
cachedDaemonMode = true;
try {
await initializeDaemon();
} catch (error) {
+ cachedDaemonMode = false;
console.error("[TerminalManager] Failed to enable daemon mode:", error);
throw error;
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export async function enableDaemonMode(): Promise<void> { | |
| if (cachedDaemonMode === true) { | |
| return; | |
| } | |
| console.log("[TerminalManager] Enabling daemon mode"); | |
| cachedDaemonMode = true; | |
| try { | |
| await initializeDaemon(); | |
| } catch (error) { | |
| console.error("[TerminalManager] Failed to enable daemon mode:", error); | |
| throw error; | |
| } | |
| } | |
| export async function enableDaemonMode(): Promise<void> { | |
| if (cachedDaemonMode === true) { | |
| return; | |
| } | |
| console.log("[TerminalManager] Enabling daemon mode"); | |
| cachedDaemonMode = true; | |
| try { | |
| await initializeDaemon(); | |
| } catch (error) { | |
| cachedDaemonMode = false; | |
| console.error("[TerminalManager] Failed to enable daemon mode:", error); | |
| throw error; | |
| } | |
| } |
🤖 Prompt for AI Agents
In `@apps/desktop/src/main/lib/terminal/index.ts` around lines 147 - 161, The
cachedDaemonMode is set to true before initializeDaemon() completes, so on
failure the cache incorrectly indicates the daemon is active; update
enableDaemonMode to only set cachedDaemonMode = true after await
initializeDaemon() succeeds, or alternatively catch the error and reset
cachedDaemonMode = false before rethrowing; reference enableDaemonMode,
initializeDaemon, cachedDaemonMode and getActiveTerminalManager when making the
change so subsequent calls reflect the real daemon state.
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
initializeDaemon()andshutdownDaemon()helpers used by both startup and runtime toggle pathsTest plan
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.