Skip to content

feat(agent-guard): refuse a vetted-op --caller the running skill does not use - #2352

Open
Harp404 wants to merge 4 commits into
apache:mainfrom
Harp404:feat/agent-guard-caller-check
Open

Harp404 wants to merge 4 commits into
apache:mainfrom
Harp404:feat/agent-guard-caller-check

Conversation

@Harp404

@Harp404 Harp404 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Step 1 of #2124: an agent-guard rule that checks --caller against the skill that is actually running.

The vetted-ops policy grants operations per caller, but --caller is whatever the agent writes, so a skill whose own caller is refused can rerun the operation under another skill's caller. That's what #2124 recorded: the ID-allocation skill writing under --caller security-issue-sync.

New bundled rule, vetted-ops-caller, for every vetted-op* launch (vetted-op, vetted-op-read, vetted-op-tracker, vetted-op-tracker-batch, vetted-op-tracker-batch-unprompted, vetted-op-git):

  1. Which skills are running. Claude Code's hook input carries transcript_path. The rule reads the transcript's tail (at most 32 MiB) for every skill invoked across the user's last 10 prompts, stopping early at a prompt that is a slash command starting a skill. A skill counts if it came from a Skill tool call or a slash command that names it. So a skill that runs another and carries on keeps its own caller, also after the user answers in between (security-issue-fix runs security-issue-sync, the user confirms its corrections, and issue-fix goes on writing). Claude Code repeats each tool call in bookkeeping entries of other types, so only assistant entries count. Tool results and injected messages aren't prompts, and built-in commands like /model don't start a skill.
  2. Which callers they use. It collects the --caller <name> values written in those skills' own files (plugin skill dir, the bare name or plugin:name, the skills/ link name, or magpie-<link name> as snapshot and self-adoption installs expose it). There's no name guessing. Each shipped skill names exactly one caller, for example magpie-security:cve-allocate → security-cve-allocate.
  3. Refuse any other caller. The message names the running skills, their callers, and says to stop and ask for a policy grant rather than borrow another skill's.

On your three open questions, I picked the safe defaults and they're easy to change:

  • Allow when unsure. No transcript, another harness, no skill invoked, a skill it doesn't know, or a skill that names no caller: all allowed, as today. Only Claude Code's own hook passes a transcript. Codex shares that handler but writes its own format, so it gets none.
  • Subagents. A gatherer subagent passes its parent skill's caller. When its own transcript (<session>/subagents/agent-*.jsonl) has no skill call, the parent session's transcript is read. That removes the need for a separate security-issue-sync-gatherer caller.
  • Mapping. It comes from the skill's own files rather than the skill name, since names don't map uniformly (issue-sync → security-issue-sync, prepare → release-prepare).

Override. MAGPIE_ALLOW_ANY_CALLER=1 is honoured only from the hook's environment, like MAGPIE_GUARD_OFF. The other guards also accept it inline, but written inline here it would be the agent picking its own grants. Happy to change that if you prefer the usual pattern.

Not a boundary. The agent chooses its own Skill calls, so the rule catches an accidental caller swap (the #2124 case), not a deliberate one. The per-caller split is still not an authorisation boundary, and both READMEs and the spec say so.

Type of change

  • New feature

Test plan

  • New tests/test_vetted_caller.py, 34 tests on synthetic transcripts in Claude Code's line format:
    • another skill's caller refused, own caller allowed, --caller= form, bare and plugin: names;
    • an outer skill keeps its caller after running another (Skill(issue-fix) then Skill(issue-sync), then --caller security-issue-fix is allowed); an outer skill keeps its caller after the user confirms the inner one (Skill(issue-fix), Skill(issue-sync), prompt "yes, apply"); a skill keeps its caller across the user's answers; a skill expires after 10 prompts; every vetted-op* entry point is checked, including the two batch ones; a tool result doesn't start a turn; an unknown skill in the turn allows; the magpie-<link> name is known; a repeated bookkeeping copy isn't counted; a slash command naming a skill counts, /model doesn't;
    • a prompt quoting <command-name> isn't an invocation;
    • must keep allowing: no or missing transcript, no skill invoked, unknown skill, skill naming no caller, malformed lines, adversarial-review and gh commands;
    • a subagent reads its parent session; the hook-env override allows, the inline one doesn't;
    • main() denies end to end; Codex isn't passed a transcript;
    • against the real skill tree: magpie-security:cve-allocate → security-cve-allocate, and the vetted-ops: --caller is self-declared, so per-skill grants are not enforced #2124 case (--caller security-issue-sync) is refused.
  • test_codex.py: the dispatch stub takes the new transcript_path argument and asserts Codex passes None.
  • agent-guard suite: 915 passed.
  • Plugin copies synced with check-family-plugins.py --fix. The isolated-setup fingerprint was regenerated by its own hook. prek run on the changed files passes.

Docs

  • tools/agent-guard/README.md: a vetted-ops-caller row in the bundled-guards table, plus a note that its override is read from the hook environment only.
  • tools/vetted-ops/README.md: under "The boundary is the entry point, not --caller", what is now checked and what still isn't.
  • tools/spec-loop/specs/vetted-command-surface.md: the rule, its fail-open cases and its hook-env-only override, beside vetted-ops-spelling.

Linked issues

Part of #2124 (step 1, the guard).

Was generative AI tooling used to co-author this PR?

  • Yes — Claude Code (Opus 5.5)

I made this with help from Claude Code (Opus 5.5). I checked every line and tested it myself.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 08:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot added family:setup setup-* skills family:tools tools/* family:docs Docs, MISSION.md, READMEs capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) substrate:sandbox Tool substrate: agent isolation, egress control, settings audit substrate:action-guard Tool substrate: deterministic pre-tool-use command guards labels Nov 26, 2026

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, reading the transcript for the running skill is a neat way to catch a borrowed caller, and injected text can't fake a skill switch there. Before this can merge: a skill that runs another one first (security-issue-fix runs security-issue-sync) gets its own later writes refused, and the branch needs a rebase (only the generated fingerprint conflicts).

The branch currently conflicts with main and needs a rebase before this can merge.

nested-skill-false-refusal (tools/agent-guard/src/agent_guard/__init__.py:2571)

The running skill is the latest Skill tool call, or slash command naming a skill, in the session transcript

    skill = running_skill(transcript_path)

'Latest Skill call' is not 'the running skill' when one skill runs another and then continues. security-issue-fix says (plugins/magpie-security/skills/issue-fix/SKILL.md:134) "It always runs security-issue-sync first"; when the agent does that with the Skill tool, every later issue-fix write under its own --caller security-issue-fix (tracker update, rollup, labels) is refused, because the latest Skill call is now issue-sync, whose files name only security-issue-sync. The refusal then tells the agent to stop and ask for a policy grant the policy already has. This hits the main security pipeline, and no test covers an outer skill that resumes after an inner one. Allow the union of callers of every skill invoked since the last user turn (or the last N skills), not only the latest one; at minimum also accept the caller of the skill invoked just before the latest one. Add a test: transcript with Skill(issue-fix) then Skill(issue-sync), then a launch with --caller security-issue-fix must be allowed.

Smaller observations

  • tools/agent-guard/src/agent_guard/__init__.py — tools/spec-loop/specs/vetted-command-surface.md describes the sibling agent-guard rules vetted-ops-spelling and vetted-ops-source. The new vetted-ops-caller rule, its fail-open cases and its hook-env-only override are not recorded there. Add the rule to vetted-command-surface.md beside the other two vetted-ops guards.
  • See inline comments on tools/vetted-ops/README.md:149, tools/agent-guard/src/agent_guard/__init__.py:2446, tools/agent-guard/tests/test_vetted_caller.py:1.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. After you've
addressed the points above and pushed an update, an Apache Magpie
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.

More on how Apache Magpie handles maintainer review:
Contributing guide.

return None # the dispatcher itself refuses a launch with no caller
if _truthy(os.environ.get(GLOBAL_OFF_ENV)) or _truthy(os.environ.get(CALLER_OVERRIDE_ENV)):
return None
skill = running_skill(transcript_path)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nested-skill-false-refusal

The running skill is the latest Skill tool call, or slash command naming a skill, in the session transcript

'Latest Skill call' is not 'the running skill' when one skill runs another and then continues. security-issue-fix says (plugins/magpie-security/skills/issue-fix/SKILL.md:134) "It always runs security-issue-sync first"; when the agent does that with the Skill tool, every later issue-fix write under its own --caller security-issue-fix (tracker update, rollup, labels) is refused, because the latest Skill call is now issue-sync, whose files name only security-issue-sync. The refusal then tells the agent to stop and ask for a policy grant the policy already has. This hits the main security pipeline, and no test covers an outer skill that resumes after an inner one. Allow the union of callers of every skill invoked since the last user turn (or the last N skills), not only the latest one; at minimum also accept the caller of the skill invoked just before the latest one. Add a test: transcript with Skill(issue-fix) then Skill(issue-sync), then a launch with --caller security-issue-fix must be allowed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, you're right. Fixed in d69e49f.

The rule now allows the callers of every skill invoked since the user's last prompt, plus the one that was running when that prompt came in. That second part keeps a skill's caller after the user answers a question the skill asked. A prompt that is itself a slash command naming a skill starts that skill alone. Tool results and isMeta messages don't count as a prompt.

Your case is test_an_outer_skill_keeps_its_caller_after_running_another: Skill(issue-fix) then Skill(issue-sync), and a launch with --caller security-issue-fix is allowed. There are also tests for the turn boundaries: a skill keeps its caller across the user's answers, a skill from an earlier turn expires, and a tool result doesn't start a turn.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same-turn nesting works now, but not when the user answers in between, which is how issue-fix runs issue-sync (issue-fix SKILL.md Step 1: "apply the state corrections the user confirms there"). Walking back from the confirmation, the first skill found is issue-sync, the loop stops (__init__.py, the if turn_began and skill: break), and issue-fix is no longer counted, so every later --caller security-issue-fix write is refused.

Suggest carrying every skill that was running across a prompt (stop only at a slash-command prompt or a fixed cap of turns): the guard catches accidental swaps only, so a wider set is a cheaper error than a false refusal in the security pipeline. Please add a test: Skill(issue-fix), tool result, Skill(issue-sync), tool result, prompt "yes, apply", then --caller security-issue-fix must be allowed; and update the README row and spec sentence to match.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, agreed: a wider set is the cheaper mistake here. Fixed in 23537ce.

Every skill invoked across the user's last 10 prompts now counts. A prompt that is a slash command starting a skill still stops the walk, and nothing before it counts.

Your case is test_an_outer_skill_keeps_its_caller_after_the_user_confirms_the_inner_one: Skill(issue-fix), tool result, Skill(issue-sync), tool result, prompt "yes, apply", and --caller security-issue-fix is allowed. test_a_skill_expires_after_the_turn_cap pins the limit. The README row and the spec sentence say the same.

I also rebased on main, which now has vetted-op-tracker-batch and vetted-op-tracker-batch-unprompted (#2369). The rule already covered them, since it checks every vetted-op* entry point, and they're now in the docs and in a test. agent-guard suite: 915 passed.

Comment thread tools/vetted-ops/README.md Resolved
@Harp404
Harp404 force-pushed the feat/agent-guard-caller-check branch from 71b488c to d69e49f Compare November 26, 2026 18:34
Harp404 added a commit to Harp404/magpie that referenced this pull request Nov 26, 2026
…kill

Review of apache#2352. The latest Skill call is not the running skill when
one skill runs another and carries on: security-issue-fix runs
security-issue-sync first, so its own later writes were refused.

- Allow the callers of every skill invoked since the user's last
  prompt, plus the one running when it was sent (so a skill that asks
  the user a question keeps its caller). A prompt that is itself a
  slash command naming a skill starts that skill alone. Tool results
  and injected messages do not start a turn.
- Recognise the magpie-<skills/ link> names that snapshot and
  self-adoption installs give their skills.
- Say in both READMEs and the vetted-command-surface spec that the
  agent chooses its own Skill calls, so the rule catches an accidental
  caller swap, not a deliberate one.
- test_vetted_caller.py is no longer executable.

Generated-by: Claude Code (Opus 5.5)
@Harp404

Harp404 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @potiuk. All points are addressed in d69e49f:

  • Nested skills: the callers of every skill invoked since the user's last prompt, plus the one running when it came in, are allowed. Your issue-fix → issue-sync case is a test.
  • Not a boundary: both READMEs and the spec now say the rule catches an accidental caller swap, not a deliberate one.
  • magpie-<name> links: recognised, with a test.
  • Spec: vetted-command-surface.md describes the rule, its fail-open cases and its hook-env-only override, right after vetted-ops-spelling.
  • Test file mode: 100644.
  • Rebased on main. The isolated-setup fingerprint was regenerated by its hook.

agent-guard suite: 911 passed (30 in test_vetted_caller.py). I've updated the description to match.

@github-actions github-actions Bot added the family:dev Repo dev: .asf.yaml, spec-loop specs, Node manifests, .claude/settings.json label Nov 26, 2026

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the wording, the magpie-<name> names, the spec entry and the file mode are all fixed, and same-turn nesting now works. One case is still refused, and it is the main pipeline's normal flow: only the newest skill survives a user prompt, so once the user confirms issue-sync's proposed corrections in a chat reply, issue-fix's own --caller security-issue-fix writes are refused for the rest of the run (see the reply on the nested-skill thread).


This review was drafted by an AI-assisted tool and
confirmed by an Apache Magpie maintainer. The maintainer
requesting changes on this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Apache Magpie handles maintainer review:
Contributing guide.

… not use

The vetted-ops policy grants operations per caller, but --caller is
whatever the agent writes, so a skill whose own caller is refused can
rerun the operation under another skill's caller (apache#2124).

Add a vetted-ops-caller rule for vetted-op, vetted-op-read,
vetted-op-tracker and vetted-op-git launches. Under Claude Code the
hook input carries transcript_path; the rule reads the transcript's
tail for the latest Skill tool call (or a slash command naming a
skill), takes the --caller values written in that skill's own files,
and refuses any other caller. A subagent transcript falls back to its
parent session's.

It allows whenever it cannot tell: no transcript, another harness
(Codex writes its own format, so it is not passed one), no skill
invoked, or a skill it does not know or that names no caller. The
override, MAGPIE_ALLOW_ANY_CALLER=1, is read from the hook's
environment only: written inline it would be the agent choosing its
own grants.

Generated-by: Claude Code (Opus 5.5)
CodeQL flagged the bare `except OSError: pass` in _skill_names.

Generated-by: Claude Code (Opus 5.5)
…kill

Review of apache#2352. The latest Skill call is not the running skill when
one skill runs another and carries on: security-issue-fix runs
security-issue-sync first, so its own later writes were refused.

- Allow the callers of every skill invoked since the user's last
  prompt, plus the one running when it was sent (so a skill that asks
  the user a question keeps its caller). A prompt that is itself a
  slash command naming a skill starts that skill alone. Tool results
  and injected messages do not start a turn.
- Recognise the magpie-<skills/ link> names that snapshot and
  self-adoption installs give their skills.
- Say in both READMEs and the vetted-command-surface spec that the
  agent chooses its own Skill calls, so the rule catches an accidental
  caller swap, not a deliberate one.
- test_vetted_caller.py is no longer executable.

Generated-by: Claude Code (Opus 5.5)
Second review of apache#2352. issue-fix runs issue-sync, the user confirms
issue-sync's corrections in a chat reply, and issue-fix carries on
with its own writes; only the newest skill survived that prompt, so
--caller security-issue-fix was refused for the rest of the run.

Count every skill invoked across the user's last 10 prompts, stopping
early at a prompt that is a slash command starting a skill. The rule
catches accidental swaps only, so the wider set is a cheaper error than
a false refusal in the security pipeline.

Generated-by: Claude Code (Opus 5.5)
@Harp404
Harp404 force-pushed the feat/agent-guard-caller-check branch from d69e49f to 23537ce Compare November 27, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) family:dev Repo dev: .asf.yaml, spec-loop specs, Node manifests, .claude/settings.json family:docs Docs, MISSION.md, READMEs family:setup setup-* skills family:tools tools/* substrate:action-guard Tool substrate: deterministic pre-tool-use command guards substrate:sandbox Tool substrate: agent isolation, egress control, settings audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants