Skip to content

fix(sessions): add cancel control to cloud initializing screen#2621

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/cloud-initializing-cancel
Draft

fix(sessions): add cancel control to cloud initializing screen#2621
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/cloud-initializing-cancel

Conversation

@posthog

@posthog posthog Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Problem

Users running cloud tasks could get permanently stuck on the "Getting things ready…" screen with no way to stop, cancel, or resume — forcing them to abandon their work (customer ticket #1581). During provisioning, SessionView renders CloudInitializingView as its only child: a full-screen spinner with zero interactive controls. The only Stop button lives in PromptInput, which isn't mounted in the isInitializing branch. If the SSE stream never delivers a status transition (cloudStatus stays null/queued), the task displays this message indefinitely.

Changes

  • CloudInitializingView now accepts an optional onCancel handler and renders a Cancel button (with a "Cancelling…" pending state to prevent double-clicks).
  • SessionView wires that to the existing onCancelPrompt callback, which routes through cancelPromptcancelCloudPrompt and already sends a cancel command over tRPC for non-terminal (null/queued/in_progress) runs, reusing the existing TASK_RUN_CANCELLED analytics.

No service behavior changed — the cloud cancel command cancels the current turn (mirroring local cancelPrompt), so the fix is a localized UI affordance rather than an optimistic status transition.

How did you test this?

  • Added CloudInitializingView.test.tsx covering: the Cancel control renders while provisioning when onCancel is provided, it is omitted otherwise, and clicking invokes onCancel exactly once while showing the disabled "Cancelling…" label. All 3 tests pass via vitest run.
  • pnpm --filter @posthog/ui typecheck passes; Biome lint clean on the touched files.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code from an inbox report.

A provisioning cloud task renders CloudInitializingView as a full-screen
spinner with no interactive controls. If the SSE stream never delivers a
status transition, the task is stuck on "Getting things ready…" with no way
to stop, cancel, or resume.

Surface a Cancel button during the initializing render path, wired to the
existing onCancelPrompt callback (cancelPrompt -> cancelCloudPrompt), which
already sends a `cancel` command over tRPC for null/queued/in_progress runs
and reuses the TASK_RUN_CANCELLED analytics.

Generated-By: PostHog Code
Task-Id: 677a6fa9-0f43-4d72-aa8a-12dd3a008619
@github-actions

Copy link
Copy Markdown

React Doctor could not complete this scan.

No React dependency found in /tmp/react-doctor-baseline-4M8xjv/package.json. Add "react" to dependencies (or peerDependencies) and re-run.

Reviewed by React Doctor for commit fd8ed37.

@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
packages/ui/src/features/sessions/components/CloudInitializingView.tsx:51-55
The `if (cancelling) return` guard is redundant — React does not fire `onClick` on a `disabled` button, so the check can never be reached once `cancelling` is `true`. The "Cancelling…" label and `disabled` attribute on the button are already the single point of protection. This violates the "no superfluous parts" simplicity rule, and the duplicate guard also means the same invariant is expressed in two places (once in the handler, once in the JSX).

```suggestion
  const handleCancel = () => {
    setCancelling(true);
    onCancel?.();
  };
```

### Issue 2 of 3
packages/ui/src/features/sessions/components/CloudInitializingView.tsx:44-55
`cancelling` is never reset to `false`. If `onCancel` is invoked but the underlying request fails (and the component stays mounted in the initialising state), the button is permanently locked in "Cancelling…" with no retry path. Because `onCancel` is typed as `() => void`, the caller can't surface a failure back here. Consider widening the signature to `onCancel?: () => Promise<void>` and resetting `cancelling` in a `catch`, or at minimum resetting it in `finally`, so a failed cancel attempt doesn't permanently disable the control.

### Issue 3 of 3
packages/ui/src/features/sessions/components/CloudInitializingView.test.tsx:23-46
The first two tests cover the same boolean condition (`onCancel` provided vs omitted) and their assertions mirror each other. Per the team's parameterised-test preference these could be collapsed into a single `it.each`, e.g. `[[null, true], [undefined, false]]` — keeping the shared setup in one place and making it easy to add more `cloudStatus`/`onCancel` combinations later.

Reviews (1): Last reviewed commit: "fix(sessions): add cancel control to clo..." | Re-trigger Greptile

Comment on lines +51 to +55
const handleCancel = () => {
if (cancelling) return;
setCancelling(true);
onCancel?.();
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The if (cancelling) return guard is redundant — React does not fire onClick on a disabled button, so the check can never be reached once cancelling is true. The "Cancelling…" label and disabled attribute on the button are already the single point of protection. This violates the "no superfluous parts" simplicity rule, and the duplicate guard also means the same invariant is expressed in two places (once in the handler, once in the JSX).

Suggested change
const handleCancel = () => {
if (cancelling) return;
setCancelling(true);
onCancel?.();
};
const handleCancel = () => {
setCancelling(true);
onCancel?.();
};
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ui/src/features/sessions/components/CloudInitializingView.tsx
Line: 51-55

Comment:
The `if (cancelling) return` guard is redundant — React does not fire `onClick` on a `disabled` button, so the check can never be reached once `cancelling` is `true`. The "Cancelling…" label and `disabled` attribute on the button are already the single point of protection. This violates the "no superfluous parts" simplicity rule, and the duplicate guard also means the same invariant is expressed in two places (once in the handler, once in the JSX).

```suggestion
  const handleCancel = () => {
    setCancelling(true);
    onCancel?.();
  };
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines 44 to +55
const [revealed, setRevealed] = useState(false);
const [cancelling, setCancelling] = useState(false);
useEffect(() => {
const timer = setTimeout(() => setRevealed(true), REVEAL_DELAY_MS);
return () => clearTimeout(timer);
}, []);

const handleCancel = () => {
if (cancelling) return;
setCancelling(true);
onCancel?.();
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 cancelling is never reset to false. If onCancel is invoked but the underlying request fails (and the component stays mounted in the initialising state), the button is permanently locked in "Cancelling…" with no retry path. Because onCancel is typed as () => void, the caller can't surface a failure back here. Consider widening the signature to onCancel?: () => Promise<void> and resetting cancelling in a catch, or at minimum resetting it in finally, so a failed cancel attempt doesn't permanently disable the control.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ui/src/features/sessions/components/CloudInitializingView.tsx
Line: 44-55

Comment:
`cancelling` is never reset to `false`. If `onCancel` is invoked but the underlying request fails (and the component stays mounted in the initialising state), the button is permanently locked in "Cancelling…" with no retry path. Because `onCancel` is typed as `() => void`, the caller can't surface a failure back here. Consider widening the signature to `onCancel?: () => Promise<void>` and resetting `cancelling` in a `catch`, or at minimum resetting it in `finally`, so a failed cancel attempt doesn't permanently disable the control.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +23 to +46
it("renders a cancel control while provisioning when onCancel is provided", () => {
render(
<Theme>
<CloudInitializingView cloudStatus={null} onCancel={() => {}} />
</Theme>,
);
reveal();
expect(screen.getByText("Getting things ready…")).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "Cancel" }),
).toBeInTheDocument();
});

it("omits the cancel control when no handler is provided", () => {
render(
<Theme>
<CloudInitializingView cloudStatus="queued" />
</Theme>,
);
reveal();
expect(
screen.queryByRole("button", { name: "Cancel" }),
).not.toBeInTheDocument();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The first two tests cover the same boolean condition (onCancel provided vs omitted) and their assertions mirror each other. Per the team's parameterised-test preference these could be collapsed into a single it.each, e.g. [[null, true], [undefined, false]] — keeping the shared setup in one place and making it easy to add more cloudStatus/onCancel combinations later.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ui/src/features/sessions/components/CloudInitializingView.test.tsx
Line: 23-46

Comment:
The first two tests cover the same boolean condition (`onCancel` provided vs omitted) and their assertions mirror each other. Per the team's parameterised-test preference these could be collapsed into a single `it.each`, e.g. `[[null, true], [undefined, false]]` — keeping the shared setup in one place and making it easy to add more `cloudStatus`/`onCancel` combinations later.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants