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#29784EClinick wants to merge 1 commit into
Conversation
…or dropping them An invalid file in agent/ threw ConfigInvalidError and aborted the whole load (no agents loaded); the same file in mode/ was silently dropped with no error. Both loaders now log, publish a session error, and skip just the bad file while loading the rest. Fixes anomalyco#27133
|
The following comment was made by an LLM, it may be inaccurate: I found a potentially related PR: #29208: fix(config): catch parse errors gracefully during startup This PR appears to address a similar issue — handling parse errors gracefully during startup. It may be related to your PR's goal of reporting invalid agent/mode configs instead of crashing. You should verify whether this PR already addresses the issue or if there's overlap in the fixes. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Improves config loading resilience by reporting invalid agent/mode markdown files as user-visible errors while continuing to load valid configs.
Changes:
- Added event-based error reporting for agent/mode config parsing failures.
- Updated agent/mode loaders to skip invalid entries instead of crashing or silently dropping them.
- Added tests to ensure invalid files are reported and don’t block valid files.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/opencode/src/config/agent.ts | Adds a report() helper and updates agent/mode loaders to emit error events on parse failures. |
| packages/opencode/test/config/config.test.ts | Adds tests and a helper to subscribe to error events and assert invalid configs are reported. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function subscribeErrors(pattern: string, timeoutMs = 500) { | ||
| const errors: string[] = [] | ||
| const matched = Promise.withResolvers<void>() | ||
| Bus.subscribe(Session.Event.Error, (evt) => { | ||
| const data = evt.properties.error?.data | ||
| if (!data || !("message" in data) || typeof data.message !== "string") return | ||
| errors.push(data.message) | ||
| if (data.message.includes(pattern)) matched.resolve() | ||
| }) | ||
| const wait = Promise.race([matched.promise, Bun.sleep(timeoutMs)]) | ||
| return { errors, wait } | ||
| } |
| errors.push(data.message) | ||
| if (data.message.includes(pattern)) matched.resolve() | ||
| }) | ||
| const wait = Promise.race([matched.promise, Bun.sleep(timeoutMs)]) |
| const parsed = Schema.decodeUnknownExit(Info)(config, { errors: "all", propertyOrder: "original" }) | ||
| if (Exit.isFailure(parsed)) { | ||
| await report("agent", item, `Failed to parse agent ${item}`, parsed.cause) | ||
| continue | ||
| } |
Issue for this PR
Closes #27133
Type of change
What does this PR do?
packages/opencode/src/config/agent.tshad two near-identical loaders that handled invalid files differently.load()calledConfigParse.schema()which throws, so one bad agent file aborted the whole load and startup failed withConfigInvalidError.loadMode()usedSchema.decodeUnknownExitwith anif (Exit.isSuccess)and noelse, so a bad mode silently disappeared with no error.Now both decode the same way and on failure they log, publish a
Session.Event.Error, and skip just the bad file while continuing to load the rest. The shared log + publish logic moved into a smallreport()helper to avoid duplicating it across both functions.How did you verify your code works?
test/config/config.test.tsthat exercise the repro from [BUG]: Invalid agent/mode config files: agent crashes startup, mode silently disappears #27133 at the API level. Both fail onorigin/dev(agent test throwsConfigInvalidError; mode test fails the "error was reported" assertion) and pass with the fix.bun test test/config test/agent: 212/212 passing.bun typecheckfor the opencode package andoxlinton both changed files: clean.bun dev <dir>against the four-file fixture from [BUG]: Invalid agent/mode config files: agent crashes startup, mode silently disappears #27133): before the fix, startup crashes as described; after, opencode starts cleanly, thegoodentries appear in the agent cycler, and the broken ones are reported viaSession.Event.Errorinstead of crashing or vanishing.Screenshots / recordings
N/A — not a UI change.
Checklist