Skip to content

Agent .md files with invalid YAML frontmatter are silently skipped without warning #45876

Closed

Description

@zhouksh

Description

When a custom agent markdown file (for example .opencode/agents/test.md or ~/.config/opencode/agents/test.md) contains invalid YAML frontmatter — such as an indentation error — the file is silently skipped. The user sees no warning, no error, and no indication that the agent failed to load.

This is inconsistent with skill loading, which logs an error and publishes a Session.Event.Error when a skill file fails to parse.

Reproduction steps

  1. Create .opencode/agents/test.md with malformed frontmatter indentation:

    ---
     name: test
      description: test agent
    ---
    
    You are a helpful assistant.
  2. Start OpenCode or run opencode agent list.

  3. Observe that test does not appear, and no warning or error is shown.

Root cause

In packages/opencode/src/config/agent.ts, the parse result is swallowed:

const md = await ConfigMarkdown.parse(item).catch(() => undefined)
if (!md) continue

Any FrontmatterError thrown by ConfigMarkdown.parse() is discarded, and the agent is simply omitted.

Expected behavior

At minimum, a warning should be logged so the user knows:

  • which file failed
  • why it failed
  • that the agent was skipped

Ideally, this should behave similarly to skill parse failures: log the error with context and, when possible, surface it to the user.

Related

Environment

  • OpenCode version: current dev branch
  • Bun 1.3+

Activity

  1. iceteaSA commented on Oct 22, 2026

    @iceteaSA

    This continues to occur on OpenCode 2.1.1 and on dev at 27cdf5fb. The V2 code is in packages/core, and it has the same silent returns:

    A duplicate key is one more cause. gray-matter 4.0.3 throws duplicated mapping key, and sanitize does not change duplicate keys, so the retry also throws. For example, this file does not load and the log has no entry for it:

    ---
    description: Test agent
    mode: subagent
    mode: primary
    ---
    Reply with OK.

    We found this when four agent files were missing from the agent list on 2.1.1. Each file had one key two times in its frontmatter, and nothing showed which files were missing or why. A warn log entry that names the file and the parse or schema error can show this.

  2. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the report. I reproduced this on 2.2.0, and it still happens on the latest dev (506ac20c).

    What I did:

    1. In a fresh project, added three files to .opencode/agents/: a valid good.md, badindent.md with the mis-indented frontmatter from your report, and dupkey.md with mode: set twice (the example from the comment above).
    2. Ran opencode debug agents --standalone --log-level debug --print-logs.
    3. Only good is listed. The other two are missing, and no log line mentions either file, even at debug level.

    The same loader does log a warning when an agent uses unsupported fields, but a file that fails to parse is dropped silently. The script below reproduces it on the release and from source.

    Related:

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Repro for #45876: agent .md files with invalid YAML frontmatter are dropped silently.
    # Usage: ./repro.sh            -> uses `opencode` from PATH
    #        OC_DEV=/path/to/repo ./repro.sh -> runs CLI from a source checkout
    set -u
    P=$(mktemp -d /tmp/opencode/agentrepro.XXXX)
    export HOME="$P/home" XDG_CONFIG_HOME="$P/home/.config" XDG_DATA_HOME="$P/home/.local/share" XDG_STATE_HOME="$P/home/.local/state" XDG_CACHE_HOME="$P/home/.cache"
    mkdir -p "$HOME" "$P/proj/.opencode/agents"
    cd "$P/proj" && git init -q
    
    # good agent (control)
    cat > .opencode/agents/good.md <<'EOF'
    ---
    description: good agent
    mode: subagent
    ---
    You are fine.
    EOF
    # bad indentation
    cat > .opencode/agents/badindent.md <<'EOF'
    ---
     name: test
      description: test agent
    ---
    
    You are a helpful assistant.
    EOF
    # duplicated key
    cat > .opencode/agents/dupkey.md <<'EOF'
    ---
    description: Test agent
    mode: subagent
    mode: primary
    ---
    Reply with OK.
    EOF
    
    if [ -n "${OC_DEV:-}" ]; then
      oc() { bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js" "$OC_DEV/packages/cli/src/index.ts" "$@"; }
    else
      oc() { opencode "$@"; }
    fi
    oc --version
    echo "=== debug agents (stdout+stderr, log-level debug, print-logs) ==="
    if [ -n "${OC_DEV:-}" ]; then
      # --standalone re-spawns without the preload from source, so run a server explicitly
      export OPENCODE_PASSWORD=repro
      oc serve --port 4611 --log-level debug --print-logs > "$P/out.txt" 2>&1 & SRV=$!
      sleep 12
      oc debug agents --server http://127.0.0.1:4611 >> "$P/out.txt" 2>&1
      echo "exit: $?"; kill $SRV
    else
      oc debug agents --standalone --log-level debug --print-logs > "$P/out.txt" 2>&1
      echo "exit: $?"
    fi
    echo "--- agent ids in output:"
    grep -oE '\b(good|badindent|dupkey)\b' "$P/out.txt" | sort | uniq -c
    echo "--- any log line mentioning the bad files:"
    grep -nE 'badindent|dupkey' "$P/out.txt" || echo "(none)"
    echo "--- warnings/errors in output:"
    grep -niE 'warn|error|yaml|frontmatter' "$P/out.txt" | head -20 || true
    echo "full output: $P/out.txt"

    Run it: bash repro.sh

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions