Skip to content

Stop command for run button#2740

Merged
Kitenite merged 2 commits into
mainfrom
kitenite/align-stop-behavior
Mar 22, 2026
Merged

Stop command for run button#2740
Kitenite merged 2 commits into
mainfrom
kitenite/align-stop-behavior

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Mar 22, 2026

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

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.

  • Bug Fixes
    • Reuse the live terminal for new runs by writing the command after attach, avoiding restarts and flicker.
    • Recover panes reliably: reattach if the shell is alive; if the session is gone, restart with the stored command or show an exited state. Added tests.
    • Better error handling when stopping/starting: treat “not found/not alive” as exited and surface errors via toasts.

Written for commit a9d8029. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Added a “Force Stop” action in the workspace run menu and a flag to enable it
    • Track and surface pending workspace-run launches so UI reflects launch-in-progress
  • Bug Fixes

    • Improved terminal command termination and write/restart behavior
    • Enhanced error handling and clearer stopped/restarted state transitions
    • Better terminal session recovery and reconnection logic
  • Tests

    • Expanded test coverage for terminal session recovery and restart scenarios

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 22, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Refactors 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

Cohort / File(s) Summary
Workspace run command & control
apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/useWorkspaceRunCommand.ts
Added launchWorkspaceRunInPane, send Ctrl+C via terminal.write for stop, added pending-launch tracking integration, unified restart/new-pane launch flow, added try/catch with toast on failures, and exported canForceStop + forceStopWorkspaceRun.
Terminal lifecycle & command write
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalLifecycle.ts
Added writeWorkspaceRunCommand, defer writing run commands until after attach, allow reusing attached sessions by writing command directly, improved error handling for write failures and attach scheduling.
Session recovery logic
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/workspaceRun.ts
recoverWorkspaceRunPane now queries terminal.getSession for liveness and attaches if alive; startAttach accepts optional commandToRunAfterAttach; resolveWorkspaceRunAttachMode returns restartCommand and uses pending-launch flag to decide if new.
Tests for recovery behavior
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/workspaceRun.test.ts
Updated tests to expect session queries for stopped-by-user panes and added coverage for live-session reattach, null session handling, and getSession rejection fallback behaviors.
UI: Workspace run controls
apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/TopBar/components/WorkspaceRunButton/WorkspaceRunButton.tsx
Added canForceStop / forceStopWorkspaceRun usage, new “Force Stop” dropdown item and separator, plus related imports and event handler.
Store: pending launches
apps/desktop/src/renderer/stores/tabs/workspace-run.ts
Added pendingWorkspaceRunLaunches set with exported markPaneWorkspaceRunLaunchPending, clearPaneWorkspaceRunLaunchPending, and isPaneWorkspaceRunLaunchPending.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I nudged the keys with a gentle paw,
Ctrl+C whispers — no noisy law.
I hop between panes, pending and bright,
Reattach if alive, else show the light.
Cheer for runs that stop with grace tonight!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description uses only the template placeholders without substantial content. The actual changes are documented in the auto-generated cubic summary, not in the description fields. Fill in the Description section with a summary of the changes; identify the related issue(s); select the Type of Change; and describe the testing performed.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main objective: adding a stop command feature for the run button with improved stopping behavior (Ctrl+C instead of kill).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kitenite/align-stop-behavior

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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 running panes, but there's no corresponding test for stopped-by-user panes when getSession throws. This would verify the fallback to startAttach() behavior added in workspaceRun.ts lines 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

📥 Commits

Reviewing files that changed from the base of the PR and between dd8c47d and 37af7d9.

📒 Files selected for processing (4)
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/useWorkspaceRunCommand.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalLifecycle.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/workspaceRun.test.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/workspaceRun.ts

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Kitenite Kitenite merged commit d470865 into main Mar 22, 2026
5 of 7 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

@Kitenite Kitenite deleted the kitenite/align-stop-behavior branch March 25, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant