Repository navigation
fix: honor AI all-tools approvals during native permission checks - #53
Conversation
Live integration validation — passedSuccessfully reproduced and validated the fix in a real OpenCode 2.x session. Test environment:
Results:
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
left a comment
There was a problem hiding this comment.
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.
| // 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"; |
There was a problem hiding this comment.
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?
| if (grant.expiresAt <= Date.now()) nativeGrants.delete(pending); | ||
| } | ||
|
|
||
| const revision = revisions.get(event.sessionID); |
There was a problem hiding this comment.
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.
| string, | ||
| { agent: string; revision: number | undefined; expiresAt: number } | ||
| >(); | ||
| const grantLifetimeMs = 5 * 60_000; |
There was a problem hiding this comment.
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.
…piry and mutation
d65f2a1 to
c0a1a68
Compare
|
Thanks for the detailed review! I've rebased onto current main (v0.10.0) and addressed the requested changes.
Validation passed in my fork's CI: 380 tests, lint, typecheck, formatting, and build. 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
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QUBBebviXSBQtiRAmDopZ7
With reviewer.replaceDefaultPolicy from main, the allToolsNativeAsks default pushed parsePluginConfiguration over the oxlint complexity limit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QUBBebviXSBQtiRAmDopZ7
|
@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. |
Summary
Fixes native Permission required prompts appearing after AI-approved tool calls in OpenCode V2
all-toolsmode, including in subagents.tool.execute.beforereviews to nativepermission.evaluatechecks for the same tool invocation.denyrules and AIdeny/escalatedecisions.on-askbehavior.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:
Results:
tsc --noEmitpassed.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
maindirectly and is independent of reviewer-session cleanup in #50 / #51.