Skip to content

fix(opencode): skip invalid agent config files instead of crashing startup#31992

Open
NumerousJLs wants to merge 1 commit into
anomalyco:devfrom
NumerousJLs:fix/agent-load-graceful-skip
Open

fix(opencode): skip invalid agent config files instead of crashing startup#31992
NumerousJLs wants to merge 1 commit into
anomalyco:devfrom
NumerousJLs:fix/agent-load-graceful-skip

Conversation

@NumerousJLs

Copy link
Copy Markdown

Issue for this PR

Closes #31481
Closes #27133

Type of change

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

What does this PR do?

Skips an invalid agent or mode config file instead of crashing startup or dropping it without an explanation.

Before this change, load() validated each agent file with ConfigParse.schema(), which throws whenever a file does not match the schema. A single malformed file, such as a Cursor-format agent where tools is a YAML array instead of an object, would throw partway through the loop, so none of the agents loaded and startup failed with "4 of 5 requests failed". The loadMode() function right next to it already skipped invalid files, but it did so silently, so a broken mode would just disappear with no explanation (#27133).

This switches both functions to decode with Schema.decodeUnknownExit and skip an invalid file with a warning that names it, instead of throwing or dropping it silently. Valid agents and modes still load normally. I left ConfigParse.schema() itself unchanged, since throwing is the right behavior for a single config file like opencode.json.

How did you verify your code works?

  • bun typecheck (clean)
  • oxlint (0 warnings, 0 errors)
  • git diff --check (clean)
  • bun test test/config test/agent (233 pass, 3 skip, 0 fail)
  • added test/config/agent.test.ts with a valid + invalid file; it throws on the current code and passes after the fix

Screenshots / recordings

N/A

Checklist

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

…artup

load() validated each agent file with ConfigParse.schema(), which throws on a
schema mismatch. A single invalid file (e.g. a Cursor-format agent with a
YAML-array tools field) aborted the whole loop, so no agents loaded and startup
failed with "4 of 5 requests failed". loadMode() already skipped invalid files
via Exit.isSuccess, but silently (anomalyco#27133).

Both functions now skip an invalid file with a warning naming it, so one bad
file no longer takes down the rest and the user can see why a file was dropped.

Closes anomalyco#31481
Closes anomalyco#27133
@github-actions

Copy link
Copy Markdown
Contributor

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

Based on my search, I found two related PRs that address similar issues:

Related PRs:

  1. PR fix(config): catch parse errors gracefully during startup #29208 - fix(config): catch parse errors gracefully during startup

    • Addresses the same problem of catching parse errors during config loading
  2. PR fix(opencode): report invalid agent/mode configs instead of crashing or dropping them #29784 - fix(opencode): report invalid agent/mode configs instead of crashing or dropping them

    • Very closely related; appears to address the exact same issue of reporting invalid agent/mode configs instead of crashing or silently dropping them

These PRs appear to be attempting to solve the same problem that PR #31992 addresses. You should verify whether these earlier PRs were merged, closed, or abandoned, and confirm that #31992 is not a duplicate effort of #29784 in particular, which has an almost identical title and purpose.

NumerousJLs added a commit to NumerousJLs/su26-ai301-contribution that referenced this pull request Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant