Stop command for run button#2740
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughRefactors workspace-run command launching and stopping: introduces pending-launch tracking, sends Ctrl+C to stop runs instead of killing PTY, defers writing run commands until after attach, queries session liveness during recovery, and exposes a force-stop API plus error handling and toast reporting. Changes
Sequence Diagram(s)sequenceDiagram
participant Renderer
participant ElectronTrpc as electronTrpcClient.terminal
participant PTY as Terminal PTY
rect rgba(100, 200, 100, 0.5)
Note over Renderer,ElectronTrpc: Launching a workspace run (new or reused pane)
Renderer->>ElectronTrpc: createOrAttach(paneId, allowKilled: true)
ElectronTrpc->>PTY: create/attach session
PTY-->>ElectronTrpc: session ready
ElectronTrpc-->>Renderer: success
Renderer->>ElectronTrpc: write(command, paneId)
ElectronTrpc->>PTY: write command
PTY-->>ElectronTrpc: ack
ElectronTrpc-->>Renderer: success
end
rect rgba(200, 100, 100, 0.5)
Note over Renderer,ElectronTrpc: Graceful stop (force-stop flow uses kill as fallback)
Renderer->>ElectronTrpc: write(CTRL_C_INPUT, paneId)
ElectronTrpc->>PTY: send Ctrl+C
PTY-->>ElectronTrpc: signal processed / exit
ElectronTrpc-->>Renderer: success
alt write fails
Renderer->>ElectronTrpc: kill(paneId)
ElectronTrpc->>PTY: kill PTY
end
end
rect rgba(100, 100, 200, 0.5)
Note over Renderer,ElectronTrpc: Recovery path for non-running pane
Renderer->>ElectronTrpc: getSession.query(paneId)
ElectronTrpc->>PTY: check session status
PTY-->>ElectronTrpc: {isAlive: true/false}
ElectronTrpc-->>Renderer: session status
alt Session Alive
Renderer->>Renderer: startAttach(commandToRunAfterAttach?)
Renderer->>ElectronTrpc: createOrAttach / attach flow
else Session Dead
Renderer->>Renderer: showExitedState("stopped-by-exit")
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 Tip CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/workspaceRun.test.ts (1)
161-201: Consider adding test coverage for the session query error path.The existing test at lines 161-201 covers the error path for
runningpanes, but there's no corresponding test forstopped-by-userpanes whengetSessionthrows. This would verify the fallback tostartAttach()behavior added inworkspaceRun.tslines 89-98.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/workspaceRun.test.ts` around lines 161 - 201, Add a new unit test in workspaceRun.test.ts that mirrors the existing "falls back to attach when session inspection fails for running panes" case but uses a pane workspaceRun.state of "stopped-by-user"; mock the getSession call (mockGetSessionQuery) to reject (e.g., new Error("transport down")), call recoverWorkspaceRunPane with the same mocks (xterm, done, startAttach, setExitStatus, refs), and assert that the function returns true, startAttach was called, and xterm.writeln / done / setExitStatus were not called to confirm the fallback-to-attach behavior for stopped-by-user panes when getSession fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/workspaceRun.test.ts`:
- Around line 161-201: Add a new unit test in workspaceRun.test.ts that mirrors
the existing "falls back to attach when session inspection fails for running
panes" case but uses a pane workspaceRun.state of "stopped-by-user"; mock the
getSession call (mockGetSessionQuery) to reject (e.g., new Error("transport
down")), call recoverWorkspaceRunPane with the same mocks (xterm, done,
startAttach, setExitStatus, refs), and assert that the function returns true,
startAttach was called, and xterm.writeln / done / setExitStatus were not called
to confirm the fallback-to-attach behavior for stopped-by-user panes when
getSession fails.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e1cd81cb-79ab-4e39-bb3a-7f110eabfda9
📒 Files selected for processing (4)
apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/useWorkspaceRunCommand.tsapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalLifecycle.tsapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/workspaceRun.test.tsapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/workspaceRun.ts
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalLifecycle.ts">
<violation number="1" location="apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalLifecycle.ts:549">
P1: Initial attach for `isNewWorkspaceRun` no longer sends the run command, so a restored/newly-starting workspace-run pane can attach to an idle shell instead of executing its configured command.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Description
Related Issues
Type of Change
Testing
Screenshots (if applicable)
Additional Notes
Summary by cubic
Updated the Run/Stop button: Stop sends Ctrl+C, and a Force Stop option is available if needed. Runs exit cleanly and the shell stays open for the next command.
Written for commit a9d8029. Summary will update on new commits.
Summary by CodeRabbit
New Features
Bug Fixes
Tests