-
Notifications
You must be signed in to change notification settings - Fork 410
fix: propagate session permissions correctly to sub-sessions #3542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
a7c749b
f90d228
425b99a
e21bc2b
7dbcbcb
96d089e
25a6f4a
38c27a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,9 @@ func newSubSession(parent *session.Session, cfg SubSessionConfig, childAgent *ag | |
| if cfg.PinAgent { | ||
| opts = append(opts, session.WithAgentName(cfg.AgentName)) | ||
| } | ||
| if parent.Permissions != nil { | ||
| opts = append(opts, session.WithPermissions(parent.Permissions)) | ||
| } | ||
| // Merge parent's excluded tools with config's excluded tools so that | ||
| // nested sub-sessions (e.g. skill → transfer_task → child) inherit | ||
| // exclusions from all ancestors and don't re-introduce filtered tools. | ||
|
|
@@ -482,10 +485,6 @@ func (r *LocalRuntime) CurrentAgentSubAgentNames() []string { | |
| // authorises all tool calls made by the sub-agent when they approve | ||
| // run_background_agent. Callers should be aware that prompt injection in | ||
| // the sub-agent's context could exploit this gate-bypass. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this TODO looks premature. |
||
| // | ||
| // TODO: propagate the parent session's per-tool permission rules once the | ||
| // runtime supports per-session permission scoping rather than a single | ||
| // shared ToolsApproved flag. | ||
| func (r *LocalRuntime) RunAgent(ctx context.Context, params agenttool.RunParams) *agenttool.RunResult { | ||
| return r.runCollecting(ctx, params.ParentSession, SubSessionConfig{ | ||
| Task: params.Task, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -266,3 +266,28 @@ func TestSubSessionWithoutAttachedFilesOmitsBlock(t *testing.T) { | |
| assert.NotContains(t, m.Content, "<attached_files>") | ||
| } | ||
| } | ||
|
|
||
| func TestSubSessionInheritsPermissions(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| perms := &session.PermissionsConfig{ | ||
| Allow: []string{"read_*"}, | ||
| Deny: []string{"write_*"}, | ||
| Ask: []string{"edit_*"}, | ||
| } | ||
| parent := session.New(session.WithPermissions(perms)) | ||
|
|
||
| childAgent := agent.New("worker", "") | ||
| cfg := SubSessionConfig{ | ||
| Task: "refactor", | ||
| AgentName: "worker", | ||
| Title: "Refactor", | ||
| } | ||
|
|
||
| s := newSubSession(parent, cfg, childAgent) | ||
|
|
||
| require.NotNil(t, s.Permissions) | ||
| assert.Equal(t, perms.Allow, s.Permissions.Allow) | ||
| assert.Equal(t, perms.Deny, s.Permissions.Deny) | ||
| assert.Equal(t, perms.Ask, s.Permissions.Ask) | ||
|
Comment on lines
+297
to
+300
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks field copying but not that inheritance changes dispatch behaviour. Consider driving the approval path instead: a parent Deny of |
||
| } | ||
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 shares the parent's
*PermissionsConfig(and its underlying slices) with the child instead of cloning it. Every other call site clones throughclonePermissionsConfig(session.Clone,copySessionMetadatain branch.go, store.go). The aliasing is not benign: on the interactivetransfer_taskpath,handleResume'sResumeTypeApproveToolcase appends tosess.Permissions.Allow, so a child approving a tool would mutate the parent's permissions (and append to a shared slice). Suggest cloning here, for example by exposing the existingclonePermissionsConfighelper and passingsession.WithPermissions(clone).