GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): harden PermissionPolicy algebra and unattended hook checks by hearnadam · Pull Request #65945 · anomalyco/opencode

Conversation

@hearnadam

@hearnadam hearnadam commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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:

  1. 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.
  2. Universal wildcard patterns (isUniversalPattern): recognizes *, **, and * * (/^\*+(?: \*)?$/) across reachableEffects, restrict, and scopedRules instead of checking literal === "*".
  3. 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.
  4. 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.
  5. 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.

All reactions
@hearnadam
fix(core): address @tear/pbt findings in PermissionPolicy
59b4ae7
@github-actions github-actions Bot added the contributor label Nov 24, 2026
opencodejr[bot]
opencodejr Bot reviewed Nov 24, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread packages/core/test/permission.test.ts
{ action: "skill", resource: "browser" },
]),
Permission.Policy.fromRules([rule("skill", "*", "allow")]),
// fallback left/right identity & secondary denial reachability

@opencodejr opencodejr Bot Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

All reactions
@hearnadam
hearnadam merged commit 84e357e into anomalyco:dev Nov 24, 2026
11 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
📊 AI CLI 工具社区动态日报 2026-11-24 litang9/big_model_radar#751
Open
beyondChang pushed a commit to beyondChang/opencode that referenced this pull request Nov 24, 2026
@hearnadam @beyondChang
fix(core): harden PermissionPolicy algebra and unattended hook checks (…
a79a15c
…anomalyco#65945)
@hearnadam
hearnadam deleted the policy-pbt-fixes branch November 24, 2026 21:02
@Edo771977 Edo771977 mentioned this pull request Nov 25, 2026
chore: merge upstream/dev into the fork Edo771977/opencode#101
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

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.

1 participant

@hearnadam
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.