Skip to content

fix(agent): prompt for destructive PostHog exec sub-tools in auto mode#3514

Closed
skoob13 wants to merge 1 commit into
mainfrom
fix/posthog-exec-gate-auto-mode
Closed

fix(agent): prompt for destructive PostHog exec sub-tools in auto mode#3514
skoob13 wants to merge 1 commit into
mainfrom
fix/posthog-exec-gate-auto-mode

Conversation

@skoob13

@skoob13 skoob13 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Problem

The PostHog MCP exec destructive gate (#1991) re-gates update / partial-update / delete / destroy sub-tools at sub-tool granularity — but it short-circuits to a silent allow when the session permission mode is auto, not just bypassPermissions.

The posthog_ai web surface creates runs in auto mode and relies on its client-side policy (products/posthog_ai/frontend/policy/toolPolicy.ts in PostHog/posthog) to auto-approve safe permission_requests and show an approval card for destructive ones. Because the gate never emits a request in auto mode, that card never triggers.

The result is exactly backwards in auto mode: non-destructive exec calls (e.g. call insight-create) are not in the auto-allowed tool set and exec is annotated readOnlyHint: false, so they fall through to the default permission flow and do prompt — while destructive calls are the only exec calls that run with no permission request at all.

Changes

  • canUseTool: the destructive PostHog exec gate now only skips prompting in bypassPermissions mode. In auto mode it consults persisted allow_always sub-tool approvals and otherwise goes through handlePostHogExecApprovalFlow, emitting a permission_request the client can decide on.
  • This matches the advertised scope of auto mode ("Auto-approve file edits and shell commands") and the existing intent that "auto stays narrower than bypassPermissions" for MCP tools.

Behavior on other surfaces:

  • Desktop PostHog Code in Auto Mode now prompts once per destructive sub-tool (silenceable via "always allow").
  • Slack-origin runs: the request is answered by the backend permission broker, which fails closed on non-read-only tools unless the run is full_auto.
  • Background-mode cloud runs: the cloud client still auto-selects the first allow option, so no behavior change and no hang.

How did you test this?

  • Flipped the "bypasses the PostHog exec gate in auto mode" unit test to assert the new prompting behavior (gate consulted, requestPermission called with the PostHog-specific title, no approval persisted on allow_once).
  • pnpm vitest run src/adapters/claude/permissions/ src/adapters/claude/hooks.test.ts — 86 tests pass.
  • biome check clean on changed files; repo-wide pnpm typecheck passes via the pre-commit hook.

Automatic notifications

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

🤖 Generated with Claude Code

Auto mode only promises hands-off file edits and shell commands, but the PostHog exec destructive gate short-circuited to silent allow in auto mode, so update/delete/destroy sub-tools were the only exec calls that never produced a permission_request. Non-destructive exec calls already prompt in auto mode (and web clients auto-approve them client-side), which made the gate exactly backwards on the cloud surface: safe calls asked, destructive ones ran silently.

Keep the bypass for bypassPermissions only; persisted allow_always sub-tool approvals still skip the prompt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Jul 16, 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

@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Security Review

A destructive PostHog exec call can still be silently allowed in an auto-mode cloud session without a connected desktop because the cloud permission client selects the first allow option.

Reviews (1): Last reviewed commit: "fix(agent): prompt for destructive PostH..." | Re-trigger Greptile

) {
// "auto" deliberately does NOT skip this gate: the mode only promises
// hands-off file edits and shell commands, and destructive PostHog
// sub-tools must still surface a permission prompt to the client.

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 security Cloud Auto Mode Still Fails Open

When an auto-mode cloud session has no desktop connected, this branch reaches the approval flow, but the cloud permission client falls through to selecting the first option, allow. An unapproved destructive PostHog sub-tool therefore still executes without presenting a permission request, so the changed gate does not protect that reachable auto-mode path.

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 2bc55f2.

@skoob13 skoob13 closed this Jul 16, 2026
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