Skip to content

Improve project action terminal readiness#3175

Open
Quicksaver wants to merge 6 commits into
pingdotgg:mainfrom
Quicksaver:split/terminal-backed-project-actions
Open

Improve project action terminal readiness#3175
Quicksaver wants to merge 6 commits into
pingdotgg:mainfrom
Quicksaver:split/terminal-backed-project-actions

Conversation

@Quicksaver

@Quicksaver Quicksaver commented Jun 19, 2026

Copy link
Copy Markdown

Summary

This changes project actions to use stable action-specific terminal sessions and wait until the target terminal is ready before writing the action command.

It also improves terminal subprocess detection so idle POSIX login shells are not treated as busy work, which lets action terminals be reused once they are actually sitting at a prompt.

What Changed

  • Added stable action-* terminal IDs for project scripts, including suffix allocation when existing action terminals are busy.
  • Added prompt-readiness detection that strips ANSI/OSC control sequences and waits for common shell prompt endings before writing project-action input.
  • Updated ChatView project-script execution to prefer reusable action terminals, wait for readiness when needed, and only allocate regular terminals when explicitly requested.
  • Added a client runtime command for waiting on action terminal readiness through the existing terminal attach stream.
  • Updated POSIX terminal subprocess inspection to read descendant command names, treat idle shell children as not busy, and report the first non-shell descendant as the running subprocess.
  • Added readable labels for project action terminal IDs, such as Action: lint.
  • Added focused tests for action terminal ID selection, prompt readiness, idle-shell detection, and action terminal labels.

Why

When running a custom action, the terminal can open and receive the inserted action before the shell is ready. Once the terminal later becomes ready, it may no longer be able to receive that action. This change makes action execution wait for an input-ready prompt and improves terminal reuse so the action is sent to a usable shell session.

Validation

  • pnpm exec vp check
  • pnpm exec vp run typecheck
  • pnpm exec vp test run apps/web/src/projectScriptTerminals.test.ts apps/server/src/terminal/Layers/Manager.test.ts packages/shared/src/terminalLabels.test.ts

Proof

  • No screenshots, screencasts, or log files were added.

Note

Medium Risk
Changes terminal busy-state semantics on POSIX and the project-script write path; behavior is covered by new tests but misclassification could still affect reuse or premature command injection.

Overview
Project scripts now target stable action-* terminal sessions, wait for a shell prompt before sending the command, and reuse idle action terminals instead of always opening a new tab when the active one looks busy.

Client: New helpers pick action terminal IDs (with suffixed fallbacks when busy), detect prompt readiness from terminal output (ANSI/OSC stripped), and block on the attach stream until ready or timeout. ChatView uses these for script runs and only allocates a regular term-* when preferNewTerminal is set. A runtime command exposes the wait step over the existing RPC path.

Server: POSIX subprocess polling now reads ps command names, walks the process tree, treats idle interactive shells as not busy, and surfaces the first non-shell descendant as the running command—so an action terminal sitting at bash can be reused.

Labels: action-* terminal IDs render as readable Action: names in the UI.

Reviewed by Cursor Bugbot for commit 777cece. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Improve project action terminal readiness by targeting stable terminal IDs and awaiting prompt detection

  • Introduces stable action-specific terminal IDs (e.g. action-build, action-build-2) in projectScriptTerminals.ts, with logic to pick an idle terminal or allocate the next available suffix.
  • Adds prompt readiness detection by stripping control chars and matching trailing prompt patterns ($, #, %, >); exposes both Stream-based and API-based wait utilities.
  • Updates ChatView.tsx to skip busy terminals when selecting a target, wait for a prompt in reusable shells before writing, and only set terminal dimensions for new server-side sessions.
  • Extends POSIX subprocess inspection in Manager.ts to traverse the full process tree, treating idle interactive shells as having no running subprocess and reporting the first non-shell descendant as the active process.
  • Adds Action: <suffix> human-readable labels for action-* terminal IDs in terminalLabels.ts.

Macroscope summarized 777cece.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5843cd19-d98b-4667-a467-9f03dc54bbe6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jun 19, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 777cece. Configure here.

});
}
if (isInteractiveShellCommand(normalized)) {
return { hasRunningSubprocess: false, childCommand: null, processIds: [] };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PS failure misreports busy shell

High Severity

When the full ps process-table pass fails after the direct PTY child is classified as an interactive shell, POSIX subprocess inspection returns idle (hasRunningSubprocess: false) without walking descendants. A command still running under that shell can be missed, so the UI may treat the action terminal as free and send a project script while work is still active.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 777cece. Configure here.

);
if (idleActionTerminal) {
return idleActionTerminal;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Action terminal prefix steals sessions

High Severity

resolveProjectActionTerminalId treats any action-{scriptId}-* id as a fallback for script {scriptId}. A script whose id is build-2 uses primary terminal action-build-2, but when build runs while action-build is busy the same id is reused. Different project actions can share one PTY and send commands to the wrong session.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 777cece. Configure here.

@macroscopeapp

macroscopeapp Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces new terminal readiness detection and selection logic for project actions, representing significant new runtime behavior. Two high-severity unresolved review comments identify potential bugs in subprocess detection and terminal ID resolution that could cause commands to be sent to incorrect terminals.

You can customize Macroscope's approvability policy. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant