Skip to content

feat(settings): auto-publish cloud runs toggle in advanced settings#3217

Open
k11kirky wants to merge 2 commits into
mainfrom
posthog-code/auto-publish-cloud-runs-setting
Open

feat(settings): auto-publish cloud runs toggle in advanced settings#3217
k11kirky wants to merge 2 commits into
mainfrom
posthog-code/auto-publish-cloud-runs-setting

Conversation

@k11kirky

@k11kirky k11kirky commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

Cloud runs are review-first by default: the sandbox agent stops with local changes and won't push or open a PR unless explicitly asked. For most users the PR is the deliverable of a cloud run, so this default costs an extra round trip on nearly every run. We want this to be user-configurable, and on by default.

Changes

  • New Settings → Advanced toggle "Always create pull requests for cloud runs" (autoPublishCloudRuns, default on, persisted).
  • The setting is threaded through task creation (cloudAutoPublish on TaskCreationInputautoPublish run option → auto_publish in the run-creation request body), and carried across resume runs from the previous run's state like pr_authorship_mode.
  • agent-server accepts a new --autoPublish flag: when set, shouldAutoPublishCloudChanges() returns true for manual (non-Slack/signal) origins too, so the cloud system prompt switches to the push-and-open-a-draft-PR variant (including no-repository mode). --createPr false still disables publishing, and manual runs keep the "PostHog Code" PR attribution.

Requires the backend side to accept and forward the new field: PostHog/posthog#68864 adds auto_publish to the run-creation API and passes --autoPublish to the sandbox.

Known follow-up: warm-pool runs launch their agent-server before the first message arrives, so a warm-run activation currently keeps review-first behavior regardless of the setting.

How did you test this?

  • turbo typecheck on shared/core/ui/api-client/agent — clean.
  • vitest full core suite and agent-server suite pass. New tests: auto-PR prompt for manual runs with autoPublish (incl. attribution), createPr=false still wins, no-repo mode variant, and saga threading of cloudAutoPublishautoPublish.
  • Biome clean on changed files.

Automatic notifications

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

Created with PostHog Code

Adds a default-on "Always create pull requests for cloud runs" setting. When enabled, cloud task runs are created with auto_publish, and the sandbox agent-server (via the new --autoPublish flag) prompts the agent to push its work and open a draft PR on completion instead of stopping with local changes.

Generated-By: PostHog Code
Task-Id: 49d73463-ec66-491c-b645-f6116972bd02
@trunk-io

trunk-io Bot commented Jul 7, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 27dbf15.

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(settings): auto-publish cloud runs ..." | Re-trigger Greptile

Comment on lines 1990 to +2017
delete process.env.POSTHOG_CODE_INTERACTION_ORIGIN;
});

it("returns auto-PR prompt for manual runs when the user opted into auto-publish", () => {
const s = createServer({ autoPublish: true });
const prompt = (s as unknown as TestableServer).buildCloudSystemPrompt();
expect(prompt).toContain("gh pr create --draft");
expect(prompt).not.toContain("stop with local changes ready for review");
// Manual runs keep the PostHog Code attribution.
expect(prompt).toContain(
"Created with [PostHog Code](https://posthog.com/code?ref=pr)",
);
});

it("keeps review-first prompt when auto-publish is on but createPr is false", () => {
const s = createServer({ autoPublish: true, createPr: false });
const prompt = (s as unknown as TestableServer).buildCloudSystemPrompt();
expect(prompt).toContain("stop with local changes ready for review");
expect(prompt).not.toContain("gh pr create --draft");
});

it("auto-publishes in no-repository mode when the user opted in", () => {
const s = createServer({ repositoryPath: undefined, autoPublish: true });
const prompt = (s as unknown as TestableServer).buildCloudSystemPrompt();
expect(prompt).toContain("Cloud Task Execution — No Repository Mode");
expect(prompt).toContain("without waiting to be asked");
expect(prompt).not.toContain("unless the user explicitly asks for that");
});

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 Prefer parameterised tests for similar cases

The three new tests all exercise the autoPublish: true path and share a common assertion structure (checking for/against "gh pr create --draft" and "stop with local changes ready for review"). Tests 1 and 2 are especially close — they differ only in createPr: false and expected prompt content — and could be folded into an it.each block alongside the existing origin-based parameterised tests just below. The no-repo test (test 3) shares the "draft PR" assertion with test 1 and could similarly be grouped. Using it.each here would make the full matrix of (autoPublish, createPr, mode) behaviour easier to scan and extend.

Context Used: Do not attempt to comment on incorrect alphabetica... (source)

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!

Inline the one-ternary getCloudAutoPublish helper, pass the option value through in the request body builder, take a single settings snapshot in useTaskCreation, and split the no-repo cloud prompt into per-mode blocks mirroring the repository branch.

Generated-By: PostHog Code
Task-Id: 49d73463-ec66-491c-b645-f6116972bd02
@k11kirky k11kirky marked this pull request as ready for review July 7, 2026 11:11
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "chore(settings): simplify auto-publish t..." | Re-trigger Greptile

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.

2 participants