Skip to content

Invalid YAML in agent .md frontmatter silently ignored — agent loads with degraded config #24181

Closed as not planned

Description

@MaxImum2509

Description

Description

When an agent .md file contains invalid YAML frontmatter, OpenCode loads the
agent anyway — but all frontmatter is silently discarded. The agent loads
with its filename-derived name and without its prompt, permissions, or tool
configuration. No error is shown to the user.

## Root cause

gray-matter (the YAML frontmatter parser) does not throw on invalid
YAML by default. When js-yaml fails (e.g., skill:true without space),
gray-matter returns the raw frontmatter as a string in md.data instead
of a parsed object.
This means:

  • ConfigMarkdown.parse() never throws → the catch block in loadAgent
    is never reached → no Session.Event.Error is published
  • { ...md.data } spreads a string → garbage instead of config
  • The explicit name: agentName (from filename) survives, masking the error

Relevant code

packages/opencode/src/config/markdown.ts:71-89

export async function parse(filePath: string) {
    const template = await Filesystem.readText(filePath)
    try {
        const md = matter(template)
        return md   // ← returns with md.data as string on YAML error
    } catch { ... }
}

packages/opencode/src/config/config.ts:219-231

const config = {
    name: agentName,        // ← "my-agent" from filename
    ...md.data,             // ← string spread → garbage, loses frontmatter name
    prompt: md.content.trim(),
}
const parsed = Agent.safeParse(config)
if (parsed.success) {
    result[config.name] = parsed.data   // ← key is still the filename-based name
}

Suggested fix

Validate that md.data is actually parsed structured data, not a raw string
fallback:

const md = matter(template)
if (typeof md.data === "string") {
    // gray-matter returned raw string: YAML parse failed
    throw new FrontmatterError(...)
}

Or pass { language: "yaml", strict: true } to matter() so it throws on
invalid YAML instead of silently returning a raw string.

Plugins

none

OpenCode version

1.14.23

Steps to reproduce

  1. Create .opencode/agents/my-agent.md:
    ---
    name: myAgent
    mode: primary
    permission:
      "*": deny
      read: allow
      grep: allow
      skill:true       # ← missing space after colon
    ---
    You are an expert...
  2. Start opencode server
  3. Run opencode agent list or open the TUI agent picker
  4. Agent appears as my-agent (filename-based) instead of myAgent
  5. The prompt and permissions from the frontmatter are not applied

Screenshot and/or share link

No response

Operating System

Windows 11

Terminal

windows terminal

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 24, 2026
  2. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  3. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions