Skip to content

Commit f8d8fc4

Browse files
committed
fix(channels): refresh workspace cache so repo prompt clears on no-repo task
The synthetic scratch workspace was correct server-side, but the client's workspace.getAll query is only invalidated after workspace.create — which repo-less channel tasks skip. So the cached (empty) result kept repoPath null and the "Select a repository folder" prompt stayed up over the running task. - Provision the scratch dir before onTaskReady so it exists when the task view mounts. - Invalidate workspace.getAll after a no-repo task is created so the view refetches the synthetic scratch workspace, resolves its cwd, and shows the running session instead of the repo prompt. Generated-By: PostHog Code Task-Id: 9c51d9dc-d108-41b2-abdd-0be442a5e36d
1 parent 882676c commit f8d8fc4

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

packages/core/src/task-detail/taskCreationSaga.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,22 @@ export class TaskCreationSaga extends Saga<
204204

205205
const shouldStartCloudRun = workspaceMode === "cloud" && !task.latest_run;
206206

207+
// Channels "generic chat box": a repo-less local/worktree task still starts
208+
// an agent, in a per-task scratch dir. Provision it before signalling the
209+
// task is ready so the task view resolves the scratch dir as its cwd (a
210+
// synthetic local workspace) instead of showing the repo-picker prompt.
211+
let scratchCwd: string | null = null;
212+
if (
213+
!repoPath &&
214+
!input.taskId &&
215+
workspaceMode !== "cloud" &&
216+
input.allowNoRepo
217+
) {
218+
scratchCwd = await this.readOnlyStep("scratch_dir", () =>
219+
this.deps.host.ensureScratchDir(task.id),
220+
);
221+
}
222+
207223
if (!hasProvisioning && !shouldStartCloudRun && this.deps.onTaskReady) {
208224
this.deps.onTaskReady({ task, workspace });
209225
}
@@ -319,16 +335,11 @@ export class TaskCreationSaga extends Saga<
319335
}
320336

321337
const isCloudCreate = !input.taskId && workspaceMode === "cloud";
322-
let agentCwd = workspace?.worktreePath ?? workspace?.folderPath ?? repoPath;
323-
324-
// Channels "generic chat box": a repo-less local/worktree task still starts
325-
// an agent, in a per-task scratch dir. The agent decides at runtime whether
326-
// it needs a repo and clones one into the scratch dir only if so.
327-
if (!isCloudCreate && !agentCwd && input.allowNoRepo) {
328-
agentCwd = await this.readOnlyStep("scratch_dir", () =>
329-
this.deps.host.ensureScratchDir(task.id),
330-
);
331-
}
338+
const agentCwd =
339+
workspace?.worktreePath ??
340+
workspace?.folderPath ??
341+
repoPath ??
342+
scratchCwd;
332343

333344
const shouldConnect = !isCloudCreate && (!!input.taskId || !!agentCwd);
334345

packages/ui/src/features/task-detail/hooks/useTaskCreation.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type { ExecutionMode, Task } from "@posthog/shared/domain-types";
1919
import { useTaskInputPrefillStore } from "@posthog/ui/features/task-detail/stores/taskInputPrefillStore";
2020
import { navigateToTaskPending } from "@posthog/ui/router/navigationBridge";
2121
import { openTask, openTaskInput } from "@posthog/ui/router/useOpenTask";
22-
import { useQuery } from "@tanstack/react-query";
22+
import { useQuery, useQueryClient } from "@tanstack/react-query";
2323
import { useCallback, useState } from "react";
2424
import { useConnectivity } from "../../../hooks/useConnectivity";
2525
import { toast } from "../../../primitives/toast";
@@ -154,6 +154,7 @@ export function useTaskCreation({
154154
const [isCreatingTask, setIsCreatingTask] = useState(false);
155155
const hostClient = useHostTRPCClient();
156156
const trpc = useHostTRPC();
157+
const queryClient = useQueryClient();
157158
const defaultAdditionalDirectoriesQuery = useQuery(
158159
trpc.additionalDirectories.listDefaults.queryOptions(),
159160
);
@@ -306,6 +307,15 @@ export function useTaskCreation({
306307
if (result.success) {
307308
setAdditionalDirectoriesOverride(null);
308309
void trackTaskCreated(input, selectedDirectory, hostClient);
310+
// Repo-less channel tasks create no workspace row (the agent runs in
311+
// a scratch dir surfaced as a synthetic workspace), so the normal
312+
// workspace.create invalidation never fires. Refresh the workspace
313+
// cache so the task view resolves its cwd and skips the repo prompt.
314+
if (allowNoRepo) {
315+
void queryClient.invalidateQueries({
316+
queryKey: trpc.workspace.getAll.queryKey(),
317+
});
318+
}
309319
}
310320

311321
if (!result.success) {
@@ -366,6 +376,8 @@ export function useTaskCreation({
366376
invalidateTasks,
367377
onTaskCreated,
368378
hostClient,
379+
trpc,
380+
queryClient,
369381
taskService,
370382
],
371383
);

0 commit comments

Comments
 (0)