feat: allow session permission updates#22070
Merged
rekram1-node merged 7 commits intoanomalyco:devfrom Apr 11, 2026
Merged
Conversation
Expose `permission` on `PATCH /session/:sessionID` and normalize API-provided rulesets before storing them. This keeps session create and update behavior aligned, so `~/` and `$HOME` patterns sent through the API are expanded the same way config-based permissions already are. - export `Permission.expandRuleset()` for API ruleset normalization - expand permission rules on session create and update routes - expose `Session.setPermission()` through the public session helpers - regenerate the v2 SDK so update requests accept `permission` - add focused permission expansion tests
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search results, I found a potentially related PR: Related PR:
This PR #15118 may be a predecessor or related attempt to implement similar functionality. You may want to check if it was closed or merged, and if there are any insights from that PR that could inform the current implementation. |
Preserve existing session permission rules when `PATCH /session/:sessionID` receives additional rules. This keeps API updates additive instead of replacing the stored ruleset, while still normalizing `~/` and `$HOME` patterns before they are persisted.
Drop the extra permission normalization work from this branch and keep the change focused on session updates. The remaining behavior change is limited to allowing `PATCH /session/:sessionID` to accept `permission` and merge the new rules into the existing session ruleset.
Simplify the session update route by always loading the current session up front. This keeps the permission merge path straightforward and avoids the extra conditional state handling around `Session.get()`. EOF && git push
Add a Bun script that starts the local server, updates a session through the HTTP route, and verifies an attached `opencode run` can read an external file after the permission patch. The script uses a local fake OpenAI-compatible server so the full serve -> session.update -> run flow can be exercised without external credentials. EOF && git push
Drop the temporary Bun script used to validate the route manually. Keep the branch focused on the session permission update itself without carrying the extra verification script. EOF && git push
Collaborator
|
/review |
Contributor
|
lgtm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #15116
Closes #15118
Type of change
What does this PR do?
PATCH /session/{sessionID}now acceptspermissionand merges the new rules into the existing session ruleset.This makes session permission updates possible without replacing previously stored rules.
How did you verify your code works?
bun test test/permission/next.test.tsbun run typecheckinpackages/opencodebun run typecheckinpackages/sdk/jspnpm dev serve --hostname 127.0.0.1 --port 4097pnpm dev run --attach http://127.0.0.1:4097 --session <id> -m anthropic/claude-sonnet-4-20250514 'Read /Users/morse/.zshrc and tell me only how many lines it has. Do not quote or summarize the file contents.'failed withpermission requested: external_directory (/Users/morse/*); auto-rejectingpermission: [{ permission: \"external_directory\", pattern: \"/Users/morse/*\", action: \"allow\" }, { permission: \"read\", pattern: \"/Users/morse/.zshrc\", action: \"allow\" }]pnpm dev run --attach ... --session ...command and confirmed it succeeded by reading/Users/morse/.zshrcand returning the line countScreenshots / recordings
N/A - no UI changes
Checklist