Skip to content
Prev Previous commit
fix(team): carry delegated ceilings into current subagent spawning
  • Loading branch information
SivanCola committed Nov 3, 2026
commit 017da790e534c256eca2839424a64d9715d79237
9 changes: 7 additions & 2 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ func (a *Agent) readOnlyExecutionBlock(ctx context.Context, visible tool.Tool, r
if readOnlyExecutionMCPDestructive(visible) {
return block("execute a destructive MCP capability")
}
if h, ok := visible.(tool.ReadOnlyExecutionHostMutation); ok && h.ReadOnlyExecutionHostMutation() && !readOnlyExecutionAllowsMCPStartup(visible) && !a.readOnlyCeilingAllowsTeamCoordination(ctx, visible) {
if a.blocksReadOnlyHostMutation(ctx, visible) {
return block("start or mutate a host capability")
}
return toolOutcome{}, false
Expand Down Expand Up @@ -1737,7 +1737,7 @@ func (a *Agent) readOnlyExecutionBlock(ctx context.Context, visible tool.Tool, r
if readOnlyExecutionMCPDestructive(resolved.Target) {
return block("execute a destructive MCP capability")
}
if h, ok := resolved.Target.(tool.ReadOnlyExecutionHostMutation); ok && h.ReadOnlyExecutionHostMutation() && !readOnlyExecutionAllowsMCPStartup(resolved.Target) && !a.readOnlyCeilingAllowsTeamCoordination(ctx, resolved.Target) {
if a.blocksReadOnlyHostMutation(ctx, resolved.Target) {
return block("start or mutate a host capability")
}
return toolOutcome{}, false
Expand All @@ -1746,6 +1746,11 @@ func (a *Agent) readOnlyExecutionBlock(ctx context.Context, visible tool.Tool, r
}
}

func (a *Agent) blocksReadOnlyHostMutation(ctx context.Context, t tool.Tool) bool {
h, ok := t.(tool.ReadOnlyExecutionHostMutation)
return ok && h.ReadOnlyExecutionHostMutation() && !readOnlyExecutionAllowsMCPStartup(t) && !a.readOnlyCeilingAllowsTeamCoordination(ctx, t)
}

func (a *Agent) readOnlyCeilingAllowsTeamCoordination(ctx context.Context, t tool.Tool) bool {
if a.readOnlyExecution || SubagentDepth(ctx) > 0 || tool.ExecutionCeiling(ctx) != "read-only" || !t.ReadOnly() {
return false
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/spawn_readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type forceReadOnlySpawnKey struct{}

func forceReadOnlySpawn(ctx context.Context) bool {
forced, _ := ctx.Value(forceReadOnlySpawnKey{}).(bool)
return forced || PlanModeFromContext(ctx) || planmode.Active(ctx)
return forced || PlanModeFromContext(ctx) || planmode.Active(ctx) || tool.ExecutionCeiling(ctx) == "read-only"
}

// A resolved read-only invocation carries its own restriction through Execute.
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (t *SubagentRunner) RunProfileSpec(ctx context.Context, spec ProfileExecSpe
if spec.Sched.RunInBackground || spec.Context.ContinueFrom != "" {
return "", fmt.Errorf("background and continuation are retired; use spawn_agents")
}
spec.Grant.ReadOnly = spec.Grant.ReadOnly || PlanModeFromContext(ctx)
spec.Grant.ReadOnly = spec.Grant.ReadOnly || forceReadOnlySpawn(ctx)
// One progress owner publishes each child terminal after resource cleanup.
trk := newSubagentProgressTracker(ctx, subSink(ctx))
parentCtx := ctx
Expand Down
53 changes: 53 additions & 0 deletions internal/agent/team_spawn_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package agent

import (
"context"
"testing"

"deepzora/internal/capability"
"deepzora/internal/event"
"deepzora/internal/provider"
"deepzora/internal/tool"
)

func TestTeamCeilingForcesReadOnlySpawnAcrossEntrances(t *testing.T) {
for _, entrance := range []string{"direct", "capability", "runner"} {
t.Run(entrance, func(t *testing.T) {
p := &spawnProvider{run: func(ctx context.Context, req provider.Request) error {
if tool.ExecutionCeiling(ctx) != "read-only" {
t.Error("child lost delegated ceiling")
}
for _, schema := range req.Tools {
if schema.Name == "write_file" {
t.Error("delegated child received writer schema")
}
}
return nil
}}
spawner := spawnFixture(t, p)
ctx := tool.WithExecutionCeiling(testTaskContext(), "read-only")
if entrance == "runner" {
if _, err := spawner.runner.RunProfileSpec(ctx, ProfileExecSpec{Task: TaskSpec{Objective: "inspect"}}); err != nil {
t.Fatal(err)
}
} else {
reg := tool.NewRegistry()
reg.Add(spawner)
call := provider.ToolCall{ID: "team-spawn", Name: SpawnToolName, Arguments: `{"tasks":[{"title":"read","task":"inspect"}]}`}
if entrance == "capability" {
reg.Add(NewUseCapabilityTool(context.Background(), nil, nil, reg, capability.NewLedger(), nil, nil))
call.Name = "use_capability"
call.Arguments = `{"action":"call","capability_id":"tool:spawn_agents","arguments":` + call.Arguments + `}`
}
a := New(nil, reg, NewSession(""), Options{}, event.Discard)
out := a.executeOne(ctx, &a.turn, call)
if out.blocked || out.errMsg != "" {
t.Fatalf("delegated spawn failed: %+v", out)
}
}
if p.calls != 1 {
t.Fatalf("child calls = %d", p.calls)
}
})
}
}
Loading