Skip to content

Commit ea3767b

Browse files
shivamhwpPR Batch Testerclaudemaria-rcks
authored
fix(web): scheduled task editor shows the destination thread (#26658)
Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 3e42e66 commit ea3767b

2 files changed

Lines changed: 60 additions & 3 deletions

File tree

‎apps/web/src/components/settings/ScheduledTasksSettings.browser.test.tsx‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ProjectId,
77
ProviderInstanceId,
88
ScheduledTaskId,
9+
ThreadId,
910
type ScheduledTask,
1011
} from "@t3tools/contracts";
1112
import { describe, expect, it, vi } from "vite-plus/test";
@@ -24,7 +25,7 @@ const task: ScheduledTask = {
2425
enabled: true,
2526
schedule: { type: "interval", everyMs: 60_000 },
2627
projectId,
27-
threadId: null,
28+
threadId: ThreadId.make("older-thread"),
2829
workspaceStrategy: { type: "root" },
2930
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
3031
runtimeMode: "full-access",
@@ -40,6 +41,12 @@ const task: ScheduledTask = {
4041
runCount: 0,
4142
};
4243

44+
// Stands in for the thread family read the editor makes when the shell lacks the bound thread.
45+
const threadFamilyRead = {
46+
snapshotSequence: 1,
47+
threads: [{ id: task.threadId, title: "Fix login bug" }],
48+
};
49+
4350
const state = vi.hoisted(() => ({ connected: true, tasksLoaded: true, secondary: false }));
4451
const secondaryId = EnvironmentId.make("secondary");
4552
const permissions = new Map<string, Atom.Writable<boolean>>();
@@ -102,11 +109,21 @@ vi.mock(import("../../state/server"), async (original) => {
102109
},
103110
};
104111
});
112+
vi.mock(import("../../state/threads"), async (original) => {
113+
const actual = await original();
114+
return {
115+
...actual,
116+
threadFamilies: { ...actual.threadFamilies, familyAtom: (() => threadFamilyRead) as never },
117+
};
118+
});
105119
// Mirrors the real query: a null request (disconnected environment) has no data.
106120
vi.mock(import("../../state/query"), async (original) => ({
107121
...(await original()),
108122
useEnvironmentQuery: ((request: unknown) => ({
109-
data: request === null ? null : { tasks: state.tasksLoaded ? [task] : [] },
123+
data:
124+
request === null || request === threadFamilyRead
125+
? request
126+
: { tasks: state.tasksLoaded ? [task] : [] },
110127
error: null,
111128
isPending: false,
112129
refresh: vi.fn(),
@@ -166,6 +183,7 @@ describe("ScheduledTasksSettings", () => {
166183
it("keeps a linked task's unsaved edits across a disconnect and reconnect", async () => {
167184
setup();
168185
await using screen = await render(<ScheduledTasksSettings taskId={task.id} />);
186+
await expect.element(page.getByRole("dialog").getByText("Fix login bug")).toBeVisible();
169187
const name = page.getByRole("dialog").getByRole("textbox", { name: "Name" });
170188
await expect.element(name).toHaveValue("Review issues");
171189
await userEvent.fill(name, "Review stale issues");

‎apps/web/src/components/settings/ScheduledTasksSettings.tsx‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ import {
5959
useEnvironmentHttpBaseUrl,
6060
type EnvironmentPresentation,
6161
} from "../../state/environments";
62-
import { useProjects } from "../../state/entities";
62+
import { useProjects, useThreadShell } from "../../state/entities";
63+
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
6364
import { environmentAtomList, environmentIdsKey } from "../../state/environmentAtomList";
6465
import { formatEnvironmentQueryError, useEnvironmentQuery } from "../../state/query";
6566
import { EMPTY_SERVER_PROVIDERS, serverEnvironment } from "../../state/server";
67+
import { threadFamilies } from "../../state/threads";
6668
import { useAtomCommand } from "../../state/use-atom-command";
6769
import { WorktreeBaseBranchPicker } from "../WorktreeBaseBranchPicker";
6870
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
@@ -1120,6 +1122,38 @@ function ScheduledTaskEditorDialog({
11201122
);
11211123
}
11221124

1125+
function ScheduledTaskDestination({
1126+
environmentId,
1127+
threadId,
1128+
}: {
1129+
readonly environmentId: EnvironmentId;
1130+
readonly threadId: ThreadId | null;
1131+
}) {
1132+
const ref = threadId === null ? null : scopeThreadRef(environmentId, threadId);
1133+
const shell = useThreadShell(ref);
1134+
// The shell can omit older settled threads; their family read still carries the title.
1135+
const family = useEnvironmentQuery(
1136+
ref !== null && shell === null ? threadFamilies.familyAtom(environmentId, ref.threadId) : null,
1137+
);
1138+
const thread = shell ?? family.data?.threads.find((row) => row.id === threadId);
1139+
return (
1140+
<Field label="Destination">
1141+
{ref === null ? (
1142+
<p className="text-sm text-muted-foreground">
1143+
Each run starts a new thread with the workspace and model below.
1144+
</p>
1145+
) : (
1146+
<div className="space-y-1 text-sm">
1147+
<p className="wrap-anywhere">{thread?.title.trim() || `Thread ${ref.threadId}`}</p>
1148+
<p className="text-muted-foreground">
1149+
Each run continues this conversation, in its workspace and with its current model.
1150+
</p>
1151+
</div>
1152+
)}
1153+
</Field>
1154+
);
1155+
}
1156+
11231157
function ScheduledTaskEditorForm({
11241158
initialEnvironmentId,
11251159
task,
@@ -1396,6 +1430,11 @@ function ScheduledTaskEditorForm({
13961430
/>
13971431
</Field>
13981432

1433+
<ScheduledTaskDestination
1434+
environmentId={environmentId}
1435+
threadId={draft.threadId ? (draft.threadId as ThreadId) : null}
1436+
/>
1437+
13991438
<div className="grid gap-3 sm:grid-cols-2">
14001439
<Field label="Project" htmlFor="scheduled-task-project">
14011440
<Select

0 commit comments

Comments
 (0)