GeezerVison is showing github.com — fix(core): harden PermissionPolicy algebra and unattended hook checks by hearnadam · Pull Request #65945 · anomalyco/opencode
Conversation
Issue for this PR
Follow-up fix for #65907 (addressing @tear/pbt findings)
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Fixes the five algebra bugs and two surfaced pre-existing bugs found by @tear/pbt against #65907:
- Unified abstract interpretation (
reachableEffects): computes a sound over-approximation of reachable effects (allow / ask / deny) across rules, override, restrict, and fallback.
isActionDenied now handles fallback.secondary when base cannot allow (fixes fallback(empty, denyAll)), and fallback simplifies left/right empty identities.
hasDeny now clears overridden denies after a universal non-deny ([*, *, deny], [shell, *, allow]) and skips unreachable fallback.secondary branches when base cannot ask.
- Universal wildcard patterns (
isUniversalPattern): recognizes *, **, and * * (/^\*+(?: \*)?$/) across reachableEffects, restrict, and scopedRules instead of checking literal === "*".
- Immutable & monotone
restrict: defensively copies denies so caller mutations cannot alter the policy, and hoists inner restrict above override and fallback so restrictions cannot be undone.
relevant and scopedRules precedence: places fallback.secondary before base (and omits it when base cannot ask) and resets accumulated scopedRules on universal patterns so dead overridden denies cannot resurrect in AutomationCode.run.
- Empty
Permission.Unattended vs. permission:evaluate hooks: when a hook downgrades allow to ask, Permission.Service evaluates PermissionPolicy.fromRules(unattended) directly rather than override(effective, unattended) so Unattended = [] cannot inherit the pre-hook allow.
How did you verify your code works?
- Added regression tests in
packages/core/test/permission.test.ts covering every shrunk counterexample (universal wildcards, fallback identities/secondary denial, overridden/unreachable hasDeny, restrict copy + monotonicity under override/fallback, relevant/scopedRules precedence, and stateful Permission.Service with Unattended = [] + hook forcing ask).
- Ran 5,000 randomized policy PBT trials (45,000 concrete evaluations) with 0 violations of Galois soundness,
isActionDenied, hasDeny, fallback identities, and restrict monotonicity.
- Ran
packages/core suites (223 pass, 0 fail), packages/simulation/test/simulated-provider.test.ts (7 pass, 0 fail), bun typecheck, oxlint, prettier --check, and bun run lint:changed upstream/dev.
Screenshots / recordings
Not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks sound. On the base I reproduced the fallback(empty, denyAll), overridden-deny hasDeny, ** wildcard and dead-scoped-deny counterexamples with a probe against policy.ts; all four are fixed here. The PR's permission tests fail twice on the base and pass with the change (140/140). Automation and shell suites pass, and tsc -b is clean.
I checked how callers are affected:
restrict currently has no callers outside policy.ts, so hoisting it above override only changes behaviour in the tests.
- The new
hasDeny makes ShellPermissions skip UnverifiableError when every shell deny is overridden by a later universal rule. That is the intended behaviour.
- In
Permission.Service, a hook that downgrades allow → ask is now settled only by Unattended. So any unattended ruleset that doesn't explicitly allow the request now denies, not just Unattended = [] (plugin/server automations.create). AutomationCode and the MCP automation always include an explicit allow, so they're unaffected. This matches the PR's intent.
Public API: Permission.Policy gains the exported helpers isUniversalPattern and reachableEffects (additive, internal to core). There are no changes to the SDK, HTTP API, config or plugin API.
Minor points:
- The
tool.ts change only renames permissions → input and can be dropped to keep the diff focused.
- See the inline note on the test.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
{ action: "skill", resource: "browser" },
|
|
|
]),
|
|
|
Permission.Policy.fromRules([rule("skill", "*", "allow")]),
|
|
|
// fallback left/right identity & secondary denial reachability
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This single test now checks about eight unrelated properties: fallback identities, universal patterns, hasDeny, restrict copy/monotonicity, and relevant/scopedRules precedence. A failure won't say which law broke. Could you split it into a few small named tests, one per fixed bug, and keep only the core assertion for each (e.g. the five isUniversalPattern literal checks can go, since the restrict/scopedRules cases with ** already cover them)?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|