Skip to content

fix(config): catch schema validation errors in agent scanning loop#27998

Open
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/agent-scan-error-handling
Open

fix(config): catch schema validation errors in agent scanning loop#27998
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/agent-scan-error-handling

Conversation

@kagura-agent
Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #27988

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

ConfigAgent.load() iterates over all {agent,agents}/**/*.md files using a for...of loop. The markdown parsing step (ConfigMarkdown.parse) is wrapped in a .catch() that logs the error and continues, but the subsequent ConfigParse.schema() call has no error handling. When any agent file fails schema validation (e.g. invalid frontmatter types), the thrown InvalidError propagates up and aborts the entire loop.

Since glob returns files in alphabetical order, every agent file sorted after the failing one is silently dropped. This explains the symptom in #27988: 184 files exist but only ~119 register, with the missing ones clustering at the alphabetical tail.

The fix wraps ConfigParse.schema() in a try/catch that mirrors the existing error handling pattern for ConfigMarkdown.parse(): publish a Session.Event.Error, log the failure with the file path, and continue loading remaining agents.

How did you verify your code works?

  • bun test test/config/ — 163 pass, 0 fail
  • bun test test/agent/ — 47 pass, 0 fail
  • Reviewed that loadMode() already handles this correctly via Schema.decodeUnknownExit + Exit.isSuccess check, confirming this is specifically a load() gap

Screenshots / recordings

N/A — no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When ConfigParse.schema() throws for an agent .md file with invalid
frontmatter, the unhandled exception crashes the entire for-loop in
ConfigAgent.load(). Since glob returns files in alphabetical order,
all agents sorted after the failing file are silently dropped.

Wrap the schema validation in try/catch matching the existing error
handling pattern for ConfigMarkdown.parse() above it: publish a
Session.Event.Error, log the failure, and continue loading the
remaining agents.

Closes anomalyco#27988
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.

Agent scanning from .opencode/agents/ silently drops files — only ~119 of 184 register

1 participant