Skip to content

run: headless session denies are not applied to subagent or reused sessions #168

Closed

Description

@byapparov

Context

aictrl run applies its headless denies (question, plan_enter, plan_exit) only as the permission of the session it creates (cli/cmd/run.ts, sdk.session.create(... permission: rules)). #162 (for #147) makes the model request honour session-level denies, but some sessions in a headless run never get those rules:

  1. Subagent sessions. TaskTool creates the child session (tool/task.ts, Session.create) with only the todowrite/todoread/task denies. The parent session's rules are not inherited.
  2. Reused sessions. With --continue or --session, run reuses an existing session as is. With --fork, it forks one, and the fork does not get rules either.

Impact

  • Built-in subagents (general, explore) are unaffected, because the agent defaults already deny question/plan_enter/plan_exit.
  • A custom subagent, or a user permission config that allows question (this is merged into every agent), gets question offered and evaluated as allow/ask inside a headless run. A headless client has nobody to answer it.
  • A continued, resumed or forked headless session has none of the headless denies.

Proposal

  • Decide whether child sessions should inherit the parent session's ruleset, either all of it or only * denies, and apply that in TaskTool (e.g. PermissionNext.merge(parent.permission ?? [], taskDenies)).
  • In run, apply rules to reused and forked sessions too, e.g. with Session.setPermission / the SDK equivalent, merged with whatever rules the session already has.

Acceptance

  • A subagent spawned from a headless run session is not offered question/plan_enter/plan_exit, even when its agent allows them (regression test).
  • run --continue, --session and --fork sessions carry the headless denies (regression test).
  • Interactive sessions are unchanged.

Found in the review of #162 (finding: "Subagent sessions don't inherit parent session denies").

Activity

  1. added
    bugSomething isn't working
    P2Could have - Medium
    on Oct 17, 2026
  2. byapparov commented on Oct 17, 2026

    @byapparov
    MemberAuthor

    Both parts of this issue are addressed in #162. It is linked with Closes #168, so this issue closes when #162 merges.

    1. Subagent sessions: fixed. TaskTool now creates the subagent session with merge(caller session rules, subagent denies). The subagent prompt also no longer passes the legacy tools map, which used to replace the session ruleset right away. So session-level rules now apply down the subagent tree, at request time (llm.ts filters the tools by agent + session rules) and at execution time. Regression test: test/tool/task.test.ts, "applies the caller session's rules to the subagent, beneath the subagent denies".
    2. run --continue / --session / --fork: nothing remains. refactor(session): remove question and plan mode; apply session denies to requests and subagents (#147) #162 removes the question tool and plan mode (plan_enter/plan_exit, the plan agent), so run no longer creates headless deny rules, and reused or forked sessions have nothing to miss. Sessions whose history calls the removed tools still continue (regression test in test/session/prompt.test.ts). run --agent plan now fails with INVOCATION_INVALID_ARGUMENTS instead of falling back to the default agent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Could have - MediumbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions