Skip to content

fix: honor AI all-tools approvals during native permission checks - #53

Merged
dyoshikawa merged 14 commits into
dyoshikawa:mainfrom
thisfilipe:fix/v2-all-tools-native-permissions
Oct 23, 2026
Merged

dyoshikawa merged 14 commits into
dyoshikawa:mainfrom
thisfilipe:fix/v2-all-tools-native-permissions

Conversation

@thisfilipe

@thisfilipe thisfilipe commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes native Permission required prompts appearing after AI-approved tool calls in OpenCode V2 all-tools mode, including in subagents.

  • Bridges successful tool.execute.before reviews to native permission.evaluate checks for the same tool invocation.
  • Scopes temporary approvals to the exact session, agent, message, and tool-call ID.
  • Handles multiple native permission checks without a second AI review.
  • Preserves explicit native deny rules and AI deny/escalate decisions.
  • Clears grants after tool completion or failure, with expiration for abandoned calls.
  • Invalidates grants when user intent changes.
  • Preserves existing on-ask behavior.

Fixes during validation

The initial validation revealed two lint warnings concerning function scoping. Both were corrected by moving reusable helpers to module scope.

A subsequent run exposed an actual edge case: a native permission evaluation from a different agent correctly returned ask, but unintentionally removed the legitimate agent's temporary approval.

This was fixed so mismatched agents cannot consume or invalidate another agent's grant. User-intent changes still invalidate the original approval.

The corresponding regression test now passes.

Validation

Successfully ran the following commands against the updated PR branch:

pnpm cicheck
pnpm build

Results:

  • Vitest: 296/296 tests passed across 16 test files, including all 31 V2 tests.
  • Formatting: Passed.
  • Lint: 0 warnings, 0 errors.
  • TypeScript: tsc --noEmit passed.
  • CSpell: 0 issues.
  • Secretlint: Passed.
  • Build: ESM and CJS bundles and TypeScript declarations generated successfully.

The build emitted only non-blocking warnings concerning experimental TypeScript 7 and mixed CJS exports.

Remaining validation: A live integration test with an actual OpenCode subagent is still pending. The automated tests verify the authorization logic, but the disappearance of the native permission dialog has not yet been confirmed in a real session.

Scope

This PR targets main directly and is independent of reviewer-session cleanup in #50 / #51.

@thisfilipe
thisfilipe marked this pull request as ready for review October 16, 2026 21:19
@thisfilipe
thisfilipe marked this pull request as draft October 16, 2026 21:56
@thisfilipe

Copy link
Copy Markdown
Contributor Author

Live integration validation — passed

Successfully reproduced and validated the fix in a real OpenCode 2.x session.

Test environment:

  • Plugin loaded from the local build of this PR, confirmed by opencode plugin list.
  • Test project configured with native shell: ask.
  • Main agent delegated to the explore subagent.
  • Subagent executed ls -la /tmp/opencode-pr53-test.

Results:

  • Without the plugin loaded, OpenCode displayed the native Permission required dialog for the command.
  • With the patched plugin loaded, the subagent executed the same command successfully without any interactive permission prompt.
  • Command completed with exit code 0 and returned the expected directory listing.
  • An additional shell verification by the main agent also completed without a permission prompt.

This confirms the reported behavior is resolved in the reproduced scenario.

Automated validation: 296/296 tests passed; lint, TypeScript, formatting, content checks, and build all passed.

@dyoshikawa dyoshikawa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for digging into this and for the live validation — the call-id scoping and the tests are careful work. I can't merge it in its current form, though, for three reasons.

First, it's a policy change rather than a pure fix. Today all-tools means AI review plus whatever native ask rules the user configured, so someone with "git push*": "ask" still gets a human prompt. With this PR one AI allow satisfies every native ask inside that call, and the user's mandatory checkpoint quietly disappears on upgrade. README (the modes table and the paragraph saying only on-ask touches permission.evaluate) isn't updated either. I'd want this behind an opt-in option, documented, with the V1 asymmetry called out.

Second, the branch conflicts with main in src/v2.ts. Main replaced the per-session revisions map with createIntentTracker keyed on the root session (so a prompt in the parent revokes subagent approvals). The grant needs to store the ReviewIntent from tracker.begin() and check intent.changed() in the evaluate hook; restoring revisions would let a child-session grant survive the user typing "stop" in the root session. A test for that case would be great.

Third, the grant covers more than the reviewer saw (inline comments below). Happy to look again once it's rebased and opt-in.

Comment thread src/v2.ts Outdated
// Core has already rejected explicit native deny rules before this hook.
// The reviewer approval covers all native assertions within this call
// (e.g. external_directory followed by shell), without reviewing twice.
event.effect = "allow";

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This flips any native ask carrying this call id, regardless of event.action / event.resources. The reviewer only saw event.input, but e.g. external_directory is asked about the resolved path (a symlink inside the repo can point outside), and a tool can call ctx.ask for resources it only learns at run time. Could the grant be limited to the actions the reviewed tool is expected to assert, and send anything else (at least external_directory) through the normal on-ask style review with its resources visible?

Comment thread src/v2.ts Outdated
if (grant.expiresAt <= Date.now()) nativeGrants.delete(pending);
}

const revision = revisions.get(event.sessionID);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Main no longer has revisions — it uses tracker.begin(event.sessionID) / intent.changed() resolved on the root session. When rebasing, please store that intent in the grant and drop the grant in the evaluate hook once intent.changed() is true, so a new prompt in the parent session revokes a subagent's grant.

Comment thread src/v2.ts Outdated
string,
{ agent: string; revision: number | undefined; expiresAt: number }
>();
const grantLifetimeMs = 5 * 60_000;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Native asserts happen right after execute.before, so five minutes is a much wider window than needed. Something like 30–60 s would do. Also worth noting: other execute.before hooks (core's input repair, other plugins) can still mutate input after ours, and the grant would cover the mutated call. Storing the reviewed tool + an input digest and checking it at least in execute.after (or a comment acknowledging the hook-order trust) would help.

@thisfilipe
thisfilipe force-pushed the fix/v2-all-tools-native-permissions branch from d65f2a1 to c0a1a68 Compare October 22, 2026 15:16
@thisfilipe

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review! I've rebased onto current main (v0.10.0) and addressed the requested changes.

  • Native permission bridging is now opt-in, using allToolsNativeAsks: "review". The default preserves existing native human checkpoints.
  • V1 behavior remains unchanged.
  • Grants use the root-session intent tracker, so new user prompts invalidate outstanding subagent approvals.
  • Grants expire after 45 seconds and are scoped to the exact tool invocation and agent.
  • Additional native permission actions, especially external_directory, receive a separate review using their actual resolved resources.
  • Added post-execution detection for tool-input mutations, with its limitations documented.
  • Added regression tests for these scenarios.

Validation passed in my fork's CI: 380 tests, lint, typecheck, formatting, and build.

https://github.com/thisfilipe/opencode-auto-approval-plugin/actions/runs/39804860950

The earlier live integration test still documents the original issue and its resolution. The revised implementation has passed automated tests but has not yet undergone a fresh live integration test.

I'd appreciate another review!

Keep both config tests: the cleanupSessions one from dyoshikawa#51 and the
allToolsNativeAsks one from this PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QUBBebviXSBQtiRAmDopZ7
@dyoshikawa
dyoshikawa merged commit 7914e27 into dyoshikawa:main Oct 23, 2026
1 check passed
@dyoshikawa

Copy link
Copy Markdown
Owner

@thisfilipe Thank you! I merged main into the branch twice (a test-only conflict with #51, then a complexity lint after #65) and collected the remaining follow-ups in #68.

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