Skip to content

Commit 831fc5b

Browse files
sheetsyncclaude
andcommitted
fix(web): action ports stay with the thread that ran them
- Stop a reserved-port action if the thread changes while its port is requested, since terminal actions follow the newly selected thread. - Show "Already running" when the action runs in another thread for the same checkout, matching mobile. - Require terminal operate scope to reserve ports. - Share one toggle row across the action editor's switches. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cf819d6 commit 831fc5b

4 files changed

Lines changed: 72 additions & 53 deletions

File tree

‎apps/server/src/auth/RpcAuthorization.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ describe("RPC authorization scopes", () => {
191191
}
192192
});
193193

194+
it("reserves action ports only for clients that can run actions", () => {
195+
expect(requiredScopeForRpcMethod(WS_METHODS.projectsGetScriptPorts)).toBe(
196+
AuthTerminalOperateScope,
197+
);
198+
});
199+
194200
it("rejects unknown RPC method names", () => {
195201
for (const method of ["server.notRegistered", "toString", "constructor"]) {
196202
expect(() => requiredScopeForRpcMethod(method)).toThrow(

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export const RPC_REQUIRED_SCOPES = {
144144
[WS_METHODS.projectsReadFile]: AuthFilesystemReadScope,
145145
[WS_METHODS.projectsSearchContents]: AuthFilesystemReadScope,
146146
[WS_METHODS.projectsSearchEntries]: AuthFilesystemReadScope,
147-
[WS_METHODS.projectsGetScriptPorts]: AuthOrchestrationReadScope,
147+
[WS_METHODS.projectsGetScriptPorts]: AuthTerminalOperateScope,
148148
[WS_METHODS.projectsWriteFile]: AuthFilesystemWriteScope,
149149
[WS_METHODS.projectsEnsureScratch]: AuthOrchestrationOperateScope,
150150
[WS_METHODS.projectsCreateNew]: AuthOrchestrationOperateScope,

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,9 @@ export default function ChatView(props: ChatViewProps) {
34653465
return;
34663466
}
34673467
previewPort = result.value.ports[script.id];
3468+
// Terminal actions follow the newly selected thread, so a switch during the request
3469+
// would run this thread's script in the other one.
3470+
if (currentRouteThreadKeyRef.current !== routeThreadKey) return;
34683471
}
34693472
const baseTerminalId =
34703473
previewPort !== undefined
@@ -3503,6 +3506,14 @@ export default function ChatView(props: ChatViewProps) {
35033506
if (runningScriptTerminal) {
35043507
if (runningScriptTerminal.target.threadId === activeThreadId) {
35053508
storeEnsureTerminal(activeThreadRef, baseTerminalId, { open: true, active: true });
3509+
} else {
3510+
toastManager.add(
3511+
stackedThreadToast({
3512+
type: "info",
3513+
title: "Already running",
3514+
description: `${script.name} is running in another thread for this checkout.`,
3515+
}),
3516+
);
35063517
}
35073518
} else {
35083519
const launched = terminalActions.launchTerminal({

‎apps/web/src/components/projectScriptEditor.tsx‎

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,33 @@ export function ProjectScriptEditorDialog({
238238
);
239239
}
240240

241+
function ActionToggle({
242+
checked,
243+
disabled = false,
244+
onCheckedChange,
245+
children,
246+
}: {
247+
checked: boolean;
248+
disabled?: boolean;
249+
onCheckedChange: (checked: boolean) => void;
250+
children: React.ReactNode;
251+
}) {
252+
return (
253+
<label
254+
className={`flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035] ${
255+
disabled ? "opacity-60" : ""
256+
}`}
257+
>
258+
<span>{children}</span>
259+
<Switch
260+
checked={checked}
261+
disabled={disabled}
262+
onCheckedChange={(next) => onCheckedChange(Boolean(next))}
263+
/>
264+
</label>
265+
);
266+
}
267+
241268
function ProjectScriptEditorForm({
242269
environmentId,
243270
editScope,
@@ -517,62 +544,37 @@ function ProjectScriptEditorForm({
517544
Open this URL in the in-app preview when this action runs.
518545
</p>
519546
</div>
520-
<label className="flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035]">
521-
<span>Run automatically on worktree creation</span>
522-
<Switch
523-
checked={runOnWorktreeCreate}
524-
onCheckedChange={(checked) => setRunOnWorktreeCreate(Boolean(checked))}
525-
/>
526-
</label>
527-
<label
528-
className={`flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035] ${
529-
runOnWorktreeCreate ? "" : "opacity-60"
530-
}`}
547+
<ActionToggle checked={runOnWorktreeCreate} onCheckedChange={setRunOnWorktreeCreate}>
548+
Run automatically on worktree creation
549+
</ActionToggle>
550+
<ActionToggle
551+
checked={waitForSetup}
552+
disabled={!runOnWorktreeCreate}
553+
onCheckedChange={setWaitForSetup}
531554
>
532-
<span>Wait for it to finish before the agent starts</span>
533-
<Switch
534-
checked={waitForSetup}
535-
disabled={!runOnWorktreeCreate}
536-
onCheckedChange={(checked) => setWaitForSetup(Boolean(checked))}
537-
/>
538-
</label>
539-
<label className="flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035]">
540-
<span>Run in the thread's worktree when the thread settles</span>
541-
<Switch
542-
checked={runOnSettle}
543-
onCheckedChange={(checked) => setRunOnSettle(Boolean(checked))}
544-
/>
545-
</label>
546-
<label
547-
className={`flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035] ${
548-
previewUrl.trim().length === 0 ? "opacity-60" : ""
549-
}`}
555+
Wait for it to finish before the agent starts
556+
</ActionToggle>
557+
<ActionToggle checked={runOnSettle} onCheckedChange={setRunOnSettle}>
558+
Run in the thread's worktree when the thread settles
559+
</ActionToggle>
560+
<ActionToggle
561+
checked={reservePort}
562+
disabled={previewUrl.trim().length === 0}
563+
onCheckedChange={setReservePort}
550564
>
551-
<span>
552-
Reserve a port
553-
<span className="mt-1 block text-xs text-muted-foreground">
554-
Sets the command's <code>T3CODE_PREVIEW_PORT</code> environment variable. Use{" "}
555-
<code>{"${T3CODE_PREVIEW_PORT}"}</code> in the Preview URL.
556-
</span>
565+
Reserve a port
566+
<span className="mt-1 block text-xs text-muted-foreground">
567+
Sets the command's <code>T3CODE_PREVIEW_PORT</code> environment variable. Use{" "}
568+
<code>{"${T3CODE_PREVIEW_PORT}"}</code> in the Preview URL.
557569
</span>
558-
<Switch
559-
checked={reservePort}
560-
disabled={previewUrl.trim().length === 0}
561-
onCheckedChange={(checked) => setReservePort(Boolean(checked))}
562-
/>
563-
</label>
564-
<label
565-
className={`flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035] ${
566-
previewUrl.trim().length === 0 ? "opacity-60" : ""
567-
}`}
570+
</ActionToggle>
571+
<ActionToggle
572+
checked={autoOpenPreview}
573+
disabled={previewUrl.trim().length === 0}
574+
onCheckedChange={setAutoOpenPreview}
568575
>
569-
<span>Open preview automatically when this action runs</span>
570-
<Switch
571-
checked={autoOpenPreview}
572-
disabled={previewUrl.trim().length === 0}
573-
onCheckedChange={(checked) => setAutoOpenPreview(Boolean(checked))}
574-
/>
575-
</label>
576+
Open preview automatically when this action runs
577+
</ActionToggle>
576578
{validationError && <p className="text-sm text-destructive">{validationError}</p>}
577579
</fieldset>
578580
</form>

0 commit comments

Comments
 (0)