Skip to content

feat(home): add auto-run toggle to quick actions#2987

Open
k11kirky wants to merge 5 commits into
mainfrom
posthog-code/home-quick-action-auto-mode
Open

feat(home): add auto-run toggle to quick actions#2987
k11kirky wants to merge 5 commits into
mainfrom
posthog-code/home-quick-action-auto-mode

Conversation

@k11kirky

Copy link
Copy Markdown
Contributor

What

Adds an auto-run toggle to Home-tab quick actions. When a quick action has auto-run enabled, the server-side classifier will launch it as a cloud task whenever a workstream lands in that action's situation (deduped against already-running tasks).

This PR is the config + UI half in posthog/code. It's harmless on its own — the flag is just stored in the workflow config until the backend honors it. The backend auto-run (the evaluate-code-workstreams worker + dedup) ships in a companion posthog/posthog PR.

Changes

  • packages/core/src/workflow/schemas.ts — add auto?: boolean to workflowAction (the schema is .strict(), so the field is required for it to round-trip on save). Type propagates to all consumers.
  • ActionEditorPanel.tsx — add an "Auto-run" Switch to the quick-action editor.
  • SituationStation.tsx — auto-enabled actions show a filled lightning glyph (instead of the sparkle) on the config map so they're visible at a glance.
  • TestsworkflowEditorStore round-trips the auto flag and marks the draft dirty.

How it works (full picture)

auto rides along inside the CodeWorkflowConfig.bindings JSON. The server worker reads the per-user bindings, and for a workstream's primary situation fires any bound action with auto: true — once per workstream+action, and only when no task is already running on that workstream.

Test plan

  • pnpm --filter @posthog/core typecheck
  • pnpm --filter @posthog/ui typecheck
  • pnpm --filter @posthog/ui test (973 passing, incl. new auto-flag test)
  • biome lint on changed files

🤖 Generated with Claude Code

Adds an `auto` flag to `WorkflowAction` and an "Auto-run" toggle in the
quick-action editor. When enabled, the server-side classifier
(evaluate-code-workstreams worker) auto-runs the action as a cloud task
whenever a workstream's primary situation matches the binding — gated so
it never piles onto a workstream that already has a running task.

This change is the config/UI half (harmless until the backend honors the
flag): the `auto` field round-trips through the workflow config bindings,
the editor exposes a Switch, and auto-enabled actions show a lightning
glyph on the config map. Backend auto-run lands in posthog/posthog.

Generated-By: PostHog Code
Task-Id: e40b189a-6d1a-4de5-a228-79e681402b35
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit f3e63f0.

@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(home): add auto-run toggle to quick..." | Re-trigger Greptile

<Switch
size="1"
checked={action.auto ?? false}
onCheckedChange={(checked) => patch({ auto: checked })}

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.

P1 When auto-run is toggled off, patch({ auto: false }) spreads auto: false onto the action. JSON.stringify serialises false explicitly, so the resulting string differs from the baseline (which has no auto key at all). This leaves dirty === true even after a round-trip enable → disable, falsely prompting the user to save a semantically-unchanged config.

Using checked || undefined keeps the field absent when the toggle is off, matching the original serialisation and letting the dirty flag clear correctly.

Suggested change
onCheckedChange={(checked) => patch({ auto: checked })}
onCheckedChange={(checked) => patch({ auto: checked || undefined })}

Comment on lines +121 to +128
it("toggles the auto flag and marks dirty", () => {
store().beginEdit(makeConfig({ ci_failing: [makeAction({ id: "a" })] }));
store().updateAction("ci_failing", "a", { auto: true });
expect(store().draft?.bindings.ci_failing[0].auto).toBe(true);
expect(store().dirty).toBe(true);
store().updateAction("ci_failing", "a", { auto: false });
expect(store().draft?.bindings.ci_failing[0].auto).toBe(false);
});

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 test verifies that toggling auto to false leaves dirty as true, but it never checks whether the dirty flag clears after a round-trip (enable → disable back to the original state). A test that calls updateAction with { auto: true } then { auto: false } and asserts dirty === false would have caught the serialisation mismatch noted in ActionEditorPanel.tsx.

Keeps the frontend validationDiagnostic enum in sync with the backend
workflow-config validator, which now rejects a non-boolean `auto` flag.
The save-result parse is strict, so the code must be enumerated here or a
returned diagnostic would fail to parse.

Generated-By: PostHog Code
Task-Id: e40b189a-6d1a-4de5-a228-79e681402b35
k11kirky added 3 commits June 29, 2026 18:00
- Collapse the Auto-run Field to a single helper-text line with a state
  ternary, matching the Skill/Model field pattern (drops the one-off
  Flex wrapper and inline-label Text).
- Document that `action_auto_not_bool` is emitted only by server-side save
  validation, so it isn't mistaken for dead surface and removed (it must
  stay listed for server-returned diagnostics to parse via saveResult).
- Apply Biome formatting the original commits missed (multi-line
  @radix-ui/themes import, wrapped Lightning element) — fixes the red
  `quality` check.

Generated-By: PostHog Code
Task-Id: e40b189a-6d1a-4de5-a228-79e681402b35
Toggling auto-run off wrote an explicit `auto: false`, which serializes
differently from the baseline (which has no `auto` key), so an enable →
disable round-trip left `dirty === true` and falsely prompted an
unsaved-changes save. The editor now sends `checked || undefined`, keeping
the field absent when off so the serialization matches baseline and the
dirty flag clears.

Adds a store test covering the enable → disable round-trip clears dirty.

Addresses Greptile review feedback on the PR.

Generated-By: PostHog Code
Task-Id: e40b189a-6d1a-4de5-a228-79e681402b35
Removes the explanatory comments on the `auto` field and the
`action_auto_not_bool` diagnostic code per review feedback — the intent is
clear from the field/code names.

Generated-By: PostHog Code
Task-Id: e40b189a-6d1a-4de5-a228-79e681402b35
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.

1 participant