Skip to content

fix(agent): v2 permissions: silently discarded when frontmatter has a stray v1 key - #51669

Closed
Kirytho wants to merge 1 commit into
anomalyco:devfrom
Kirytho:fix/agent-frontmatter-legacy-detection
Closed

Kirytho wants to merge 1 commit into
anomalyco:devfrom
Kirytho:fix/agent-frontmatter-legacy-detection

Conversation

@Kirytho

@Kirytho Kirytho commented Sep 27, 2026

Copy link
Copy Markdown

Problem

A Markdown agent was classified as v1 whenever its frontmatter contained any key absent from the v2 schema:

const legacy = Object.keys(markdown.data).some((key) => !agentKeys.has(key))

That test is far too broad, and the consequence is not "unknown key ignored" — it is a valid v2 permissions: block being silently discarded and shipped to the model provider as a junk request param.

The chain:

  1. legacy becomes true from a single stray key.
  2. ConfigAgentV1.AgentSchema is a Schema.StructWithRest(..., [Record(String, Any)]), so it accepts anything.
  3. v1's normalize moves every key not in v1's KNOWN_KEYS into options. permissions is not in that set.
  4. migrateAgent does request: { body: { ...info.options } }.

So the v2 permissions array lands in request.body.permissions and the agent's real permission list ends up empty.

Observed on 2.0.18:

_with_tools     permissions=[]  request.body={'tools': {...}, 'permissions': [...]}
_without_tools  permissions=[browser* deny, sqlite_* allow]  request.body={}

The agent keeps every tool it was written to restrict, with no warning. tools: is the most damaging trigger precisely because the v1 → v2 migration guide tells users to carry it over, so the natural migrated agent is the broken one. name: triggers it too. Reported in #50598, #50149, #32787.

Fix

Classify as v1 only when a key that exists solely in v1 is present, and let an explicit v2 permissions: key always win:

const legacyKeys = new Set(["permission", "prompt", "disable", "maxSteps", "options", "temperature", "top_p", "tools"])
const legacy =
  markdown.data.permissions === undefined && Object.keys(markdown.data).some((key) => legacyKeys.has(key))

Notes on the shape of the fix:

  • tools stays in legacyKeys, so a genuine v1 agent that only carries tools: still takes the legacy path and keeps its tools → permission → v2 permissions mapping. Dropping it would have been a silent behaviour regression.
  • The permissions === undefined guard is what stops a v2 agent from being dragged down the v1 path, and it also makes the intent explicit: an explicit v2 key wins over the guess.
  • agentKeys is now unused and removed.
  • A v1 file whose only non-v2 key was something inert (e.g. name:) is now parsed as v2. That is harmless: v1's own migration ignored name too, so the resulting agent is equivalent.

Tests

Two fixtures in loads legacy file-based agents from config directories: a v2 agent with a stray tools: and one with a stray name:. Both assert the rules are applied and that nothing leaks into request.body.

Verified failing on the parent commit and passing with the fix.

 5 pass 1 fail   <- parent commit, new assertions fail
 6 pass 0 fail   <- with fix

Full suites: bun test test/config test/agent test/permission → 68 pass / 0 fail. packages/schema v1-isolation → 2 pass. tsgo --noEmit clean. oxlint back to the 2 pre-existing warnings on that file.

Open question for maintainers

name: is documented as accepted-but-unsupported and "ignored with a warning", but no warning is emitted. Now that stray keys no longer change parsing, would you want a warning for unrecognized frontmatter keys in general? It would have surfaced both name: and this bug immediately.

…v1 key

A Markdown agent was classified as v1 whenever its frontmatter contained
any key absent from the v2 schema:

    const legacy = Object.keys(markdown.data).some((key) => !agentKeys.has(key))

That is far too broad. The v1 schema is a `StructWithRest`, so it accepts
any unknown key, and its `normalize` folds everything not in v1's
`KNOWN_KEYS` into `options`. `migrateAgent` then forwards `options` as
`request.body`. So a perfectly valid v2 agent that happened to carry a
`name:` or `tools:` key had its entire `permissions:` block moved to
`options` and shipped to the model provider as a junk `request.body`
param, while the agent's real permission list stayed empty.

Effect: the agent keeps every tool it was meant to restrict, with no
warning. `tools:` is the worst trigger because the v1 -> v2 migration
guide tells users to carry it over, so the natural migrated agent is the
one that breaks.

Classify as v1 only when a key that exists solely in v1 is present
(`permission`, `prompt`, `disable`, `maxSteps`, `options`, `temperature`,
`top_p`, `tools`), and let an explicit v2 `permissions:` key always win.
v1 files that only carry `tools:` still take the legacy path, so their
tool gating is preserved.

Regression tests cover a v2 agent with a stray `tools:` and with a stray
`name:`; both assert the rules are applied and that nothing leaks into
`request.body`. Verified failing before the fix and passing after.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Sep 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant