Skip to content

fix(web): project actions stay on the thread that started them - #36714

Closed
StiensWout wants to merge 5 commits into
pingdotgg:mainfrom
StiensWout:t3/preserve-script-target
Closed

StiensWout wants to merge 5 commits into
pingdotgg:mainfrom
StiensWout:t3/preserve-script-target

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

Switching threads while a project action opens its terminal can send the command to the newly selected thread. When that thread has no matching terminal, the write fails and the action stays idle.

Bind the write to the terminal launch result, preserving its initiating thread and environment. Recheck terminal permission for that environment immediately before writing. Script buttons, shortcuts, and chat shell commands share this path; other terminal launch callers are unchanged. Mobile uses a separate path.

Found by the bughunt and independently confirmed by Claude Opus 5.5 on main. The lead reproduced it again before implementing the fix. Wrong-shell execution was not observed: the real-app base rejected the wrong-target write.

Validation

  • Focused browser hook tests cover cross-environment navigation, access revocation, and normal launches.
  • pnpm exec vp run scenarios:prove scripts/scenarios/project-action-runs-on-its-thread.e2e.ts --base 8cb551a3ce fails on base and passes on head. The scenario holds terminal open, navigates to B, asserts the write targets A, and waits for the marker while remaining on B.
  • Primary shared Browser verification independently held open across navigation and observed the initiating target and marker creation.
  • pnpm exec vp run check:changed passes.
  • Local cubic found no issues; fork-specific repository context was unavailable.

Small fast-lane change: terminal ownership fix with no storage, new UI flow, or cross-package interface. Existing error and interrupted-open handling stays intact.

Captures

Base: the write is rejected and the initiating terminal stays idle. Head: the action runs in the initiating terminal. Machine prompts are redacted.

Base Head
Base Head

Council review

Reviewer Round 1
GPT 6.1 Sol 8/10
Claude Opus 5.5 9/10

Sol's scenario timing finding is fixed: completion is now observed while still on B, and the outgoing target is asserted. Opus's optional control-test and comment nits were retained: the control guards normal launches and the comment states the ownership invariant. Mean 8.5; no second round required by the fix-thread brief.

Created with GPT 6.1 Sol in Codex and Claude Opus 5.5 in Claude, through T3 Code.

Closes #36713

StiensWout and others added 3 commits November 14, 2026 13:05
A project action or chat code block typed its command through a stable
write that read the latest thread, so switching threads while the
terminal was opening sent the command to the other thread's terminal.
The launch now returns a write bound to the thread that opened it, which
still checks terminal access when it runs.

Co-authored-by: GPT 6.1 Sol <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: GPT 6.1 Sol <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Nov 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR changes the test suite by +2 test cases (browser +2, unit 0, server 0).

New browser test files: apps/web/src/components/chat/useChatTerminalActions.browser.test.tsx.
Each browser test file costs CI seconds of module loading before its first test runs; a unit test costs milliseconds.

Keep tests that would fail for a real reason, and test logic below the UI where it can be. See Testing.

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Nov 14, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 18f1986

Macroscope's review found this PR approvable — Project-script terminal input now stays bound to the thread and environment that launched it, even if navigation occurs while the terminal opens. Existing permission checks remain in place, and the change does not broaden command execution capabilities.

Notes:

  • All code in this push has already been reviewed. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 14, 2026
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Project-script execution now writes through the terminal handle returned at launch. Browser and end-to-end tests cover navigation while terminal opening is pending, plus loss of terminal access before opening completes.

Changes: Project action terminal targeting

Layer / File(s) Summary
Bind writes to the launched terminal
apps/web/src/components/chat/useChatTerminalActions.ts, apps/web/src/components/terminal/useThreadTerminalActions.ts
launchTerminal returns a permission-checked write function bound to the launching thread and terminal. Project-script execution uses this function instead of a separate terminal-ID write action. The hook input types now specify only the fields this hook uses.
Validate writes during navigation
apps/web/src/components/chat/useChatTerminalActions.browser.test.tsx, scripts/scenarios/project-action-runs-on-its-thread.e2e.ts
Browser tests check that pending launches write to the original thread and environment, and that no write occurs if terminal access is lost. The end-to-end scenario checks that the action command runs on its original thread after navigation.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to 18f19

Project actions now run on the thread that started them, even if the user switches threads while the terminal is opening. No remaining merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: project actions now run on the thread that started them, instead of a thread the user switched to. It follows the conventional commit format with the fix(web) scope. I…
Description check Passed The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section states the bug and the failure. The Change section explains binding the write to the launch…
Linked Issues check Passed Issue #36713 requires that a project action started on thread A writes its command to A's terminal, even after navigation to thread B. At head, launchTerminal in `apps/web/src/components/terminal/us…
Out of Scope Changes check Passed All changed files relate to issue #36713. useThreadTerminalActions.ts changes the write path, and removes the writeToTerminal action that caused the wrong-target write. useChatTerminalActions.ts…
Full details: Title check

Explanation

The title names the main change: project actions now run on the thread that started them, instead of a thread the user switched to. It follows the conventional commit format with the fix(web) scope. It matches the raw summary, which covers binding the terminal write to the launching thread and environment, and the PR objectives, which describe the same race fix.

Full details: Description check

Explanation

The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section states the bug and the failure. The Change section explains binding the write to the launch result and rechecking permission. The Scope section links issue #36713. The Verification section gives focused browser hook tests, a scenario that fails on base and passes on head, and a check:changed run. Screenshots are included for the UI behavior. The description does not state the reproduction environment in full, and it lists a council review table and tool names that the template does not request. Those extras do not block the check.

Full details: Linked Issues check

Explanation

Issue #36713 requires that a project action started on thread A writes its command to A's terminal, even after navigation to thread B. At head, launchTerminal in apps/web/src/components/terminal/useThreadTerminalActions.ts returns a write(data) closure. The closure captures the launch-time threadRef.environmentId, threadRef.threadId, and terminalId. The write therefore no longer depends on the active thread at write time. write calls canWrite() before each write, and canWrite reads terminal operate scope for the launching environment. Access revocation returns null and blocks the write, which matches the PR requirement to recheck permission for that environment. Hook tests (useChatTerminalActions.browser.test.tsx) and the scenario project-action-runs-on-its-thread.e2e.ts cover cross-environment navigation, revocation, and normal launches, per the PR summary. Changes since the previous reviewed head (aac61a19) do not touch the two source files. The incremental diffs for useThreadTerminalActions.ts and useChatTerminalActions.ts are empty. The incremental diff for the scenario file also returned no content, so the Sol timing fix in the scenario is not confirmed from the diff. The prior conclusion on the source code remains supported. I did not execute the tests.

Full details: Out of Scope Changes check

Explanation

All changed files relate to issue #36713. useThreadTerminalActions.ts changes the write path, and removes the writeToTerminal action that caused the wrong-target write. useChatTerminalActions.ts narrows activeThread and activeProject to the fields it uses, and switches to the bound write. The browser test and e2e scenario verify the fix. The comment update documents the ownership invariant. Changes since the previous reviewed head touch only test and comment content, and no unrelated source change appears. The PR states that other terminal launch callers and mobile are unchanged. Removal of writeToTerminal could affect other callers. I did not confirm absence of other references by search. The PR reports that pnpm exec vp run check:changed passes, which would catch remaining references through type checking. I did not independently verify this result.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between aac61a1 and 18f1986.

Files selected for processing: 1

  • apps/web/src/components/chat/useChatTerminalActions.browser.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

The cross-environment case covers the regression; the same-thread case
only mirrored the normal path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@macroscopeapp
macroscopeapp Bot dismissed their stale review November 14, 2026 12:15

Dismissing prior approval to re-evaluate 18f1986

@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Real web app, Chromium, 1280×800, light theme, fresh synthetic state on each commit. Run the project action on saved thread A, hold its terminal-open response, navigate to B, release while on B, then return to A.

Before After
Commit 13a6782a6c 18f1986116
Result Unknown terminal thread; A idle; action-ran absent Command completed in A; action-ran created
B selected while A opens Before: B selected After: B selected
Return to A Before: rejected write and idle A terminal After: action completed in A terminal
Recording Before video After video

Scenario and seed · Plain-prompt shell helper

scenarios:prove exited 0: failed on base and passed on head. Captures and recordings visually inspected.

Not shown:

  • Terminal-access revocation during terminal opening was not exercised; this scenario covers navigation between saved threads with terminal access retained.
  • Navigation to another environment was not exercised; both threads belonged to one environment.

@juliusmarminge juliusmarminge added takeover:needs-julius Takeover done; route gate says Julius decides and removed takeover:in-progress A takeover lead is working on this PR labels Nov 14, 2026
@StiensWout StiensWout closed this Nov 29, 2026
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). takeover:needs-julius Takeover done; route gate says Julius decides vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Switching threads while a project action opens changes its command target

2 participants