Skip to content

Commit c46fe1d

Browse files
t3dotggclaude
andcommitted
fix(web): with nothing open, triage skips a primary machine that lacks it
The palette now uses the primary machine only when it supports triage, else the first connected machine that does, as mobile does. A test covers a draft that gains user text while the handler waits. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e284222 commit c46fe1d

3 files changed

Lines changed: 51 additions & 22 deletions

File tree

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -635,25 +635,25 @@ function OpenCommandPaletteDialog(props: {
635635
const scratchTargetEnvironmentId = scratchEnvironmentId(
636636
currentProjectEnvironmentId ?? primaryEnvironmentId,
637637
);
638-
// Triage the machine the user is looking at, else the primary, else the only
639-
// capable machine. Not limited to machines that offer No project threads:
640-
// when that is missing, the action explains the terminal fallback.
641-
const triageCapableEnvironments = environments.filter(
642-
(environment) => environment.serverConfig?.environment.capabilities.triage === true,
643-
);
644-
const soleTriageEnvironmentId =
645-
triageCapableEnvironments.length === 1
646-
? (triageCapableEnvironments[0]?.environmentId ?? null)
647-
: null;
638+
// Triage the machine the user is looking at. With nothing open, the primary
639+
// if it supports triage, else the first machine that does. Not limited to
640+
// machines with No project threads: without them, the action explains the
641+
// terminal fallback.
642+
const supportsTriage = (environmentId: EnvironmentId | null) =>
643+
environments.find((environment) => environment.environmentId === environmentId)?.serverConfig
644+
?.environment.capabilities.triage === true;
648645
const triageEnvironmentId =
649646
currentProjectEnvironmentId ??
650-
primaryEnvironmentId ??
651-
soleTriageEnvironmentId ??
652-
scratchTargetEnvironmentId;
647+
(supportsTriage(primaryEnvironmentId)
648+
? primaryEnvironmentId
649+
: (environments.find(
650+
(environment) =>
651+
environment.connection.phase === "connected" &&
652+
supportsTriage(environment.environmentId),
653+
)?.environmentId ?? null));
653654
const canTriage =
654655
useAtomValue(serverEnvironment.prepareTriage.permissionAtom(triageEnvironmentId)) &&
655-
environments.find((environment) => environment.environmentId === triageEnvironmentId)
656-
?.serverConfig?.environment.capabilities.triage === true;
656+
supportsTriage(triageEnvironmentId);
657657
const currentProjectCwd = currentProjectId
658658
? (projectCwdById.get(currentProjectId) ?? null)
659659
: null;

‎apps/web/src/hooks/useHandleNewThread.test.ts‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const testState = vi.hoisted(() => {
1919
readonly threadId: string;
2020
} | null = null;
2121
let openDraftRoute: { readonly kind: "draft"; readonly draftId: string } | null = null;
22+
let draftsWithUserText = new Set<string>();
2223
const router = {
2324
state: {
2425
location: { href: "/" },
@@ -29,7 +30,7 @@ const testState = vi.hoisted(() => {
2930
}),
3031
};
3132
const draftStore = {
32-
getComposerDraft: vi.fn(() => ({})),
33+
getComposerDraft: vi.fn((draftId: string) => ({ draftId })),
3334
getDraftSessionByLogicalProjectKey: vi.fn(() => storedDraft),
3435
getDraftSession: vi.fn(() =>
3536
openDraftRoute === null
@@ -69,6 +70,11 @@ const testState = vi.hoisted(() => {
6970
removeProject() {
7071
projectRemoved = true;
7172
},
73+
hasUserText: (draft: { readonly draftId?: string } | null | undefined) =>
74+
draft?.draftId !== undefined && draftsWithUserText.has(draft.draftId),
75+
giveUserText(draftId: string) {
76+
draftsWithUserText = new Set([...draftsWithUserText, draftId]);
77+
},
7278
get openDraftRoute() {
7379
return openDraftRoute;
7480
},
@@ -87,6 +93,7 @@ const testState = vi.hoisted(() => {
8793
) {
8894
storedDraft = nextStoredDraft;
8995
openDraftRoute = null;
96+
draftsWithUserText = new Set();
9097
projectRemoved = false;
9198
connectedEnvironmentIds = ["environment-primary", "environment-ssh"];
9299
targetSettings = {
@@ -182,7 +189,8 @@ vi.mock("../composerDraftStore", () => {
182189
getState: () => testState.draftStore,
183190
});
184191
return {
185-
composerDraftHasUserContent: () => false,
192+
composerDraftHasUserContent: (draft: { readonly draftId?: string } | null | undefined) =>
193+
testState.hasUserText(draft),
186194
markPromotedDraftThreadByRef: vi.fn(),
187195
useComposerDraftStore,
188196
};
@@ -305,6 +313,28 @@ describe.each([
305313
});
306314

307315
describe("useNewThreadHandler", () => {
316+
it("keeps the text of a draft that gained some while it waited", async () => {
317+
testState.reset(null);
318+
const raced = {
319+
draftId: "draft-raced",
320+
environmentId: "environment-ssh",
321+
promotedTo: null,
322+
threadId: "thread-raced",
323+
};
324+
testState.draftStore.getDraftSessionByLogicalProjectKey
325+
.mockReturnValueOnce(null)
326+
.mockReturnValueOnce(raced as never);
327+
testState.giveUserText("draft-raced");
328+
329+
const opened = await useNewThreadHandler()(
330+
{ environmentId: "environment-ssh", projectId: "project-remote" } as never,
331+
{ prompt: "Read the playbook. " },
332+
);
333+
334+
expect(opened?.draftId).toBe("draft-raced");
335+
expect(testState.draftStore.setPrompt).not.toHaveBeenCalled();
336+
});
337+
308338
it("seeds the prompt into the empty draft that is already open", async () => {
309339
testState.reset(null);
310340
testState.openEmptyDraft("draft-open");

‎docs/user/triage.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ provider, describe what went wrong after the link, and send. T3 Code gets the
1313
source for the server's version while you write.
1414

1515
Triage runs on the machine of the thread or draft that you have open. With
16-
nothing open, web uses your primary machine, or your only machine that supports
17-
triage. Mobile uses the first connected machine that supports triage. The new
18-
thread shows the machine name, and on mobile the palette row shows it before
19-
you start. The agent runs inside that T3 Code server, so it
20-
gives you any restart steps and does not do them itself.
16+
nothing open, it uses your primary machine if that supports triage, or else the
17+
first connected machine that does. The new thread shows the machine name, and on
18+
mobile the palette row shows it before you start. The agent runs inside that T3
19+
Code server, so it gives you any restart steps and does not do them itself.
2120

2221
## In a terminal
2322

0 commit comments

Comments
 (0)