fix(config): drop malformed top-level fields instead of crashing the load#26611
Closed
kitlangton wants to merge 1 commit intodevfrom
Closed
fix(config): drop malformed top-level fields instead of crashing the load#26611kitlangton wants to merge 1 commit intodevfrom
kitlangton wants to merge 1 commit intodevfrom
Conversation
…load
Reported by Ben Matthews on Discord against v1.14.45: a `skills:` field
shaped as an array (rather than the schema's `{paths?, urls?}` object)
caused the entire config load to fail with ConfigInvalidError, the
server returned 500, and the desktop app couldn't start.
Per Kit:
> for all of these things that we load from the user's computer, they
> should be kind of tolerant. We can have warnings that we log
> somewhere, but Jesus. It shouldn't break opencode.
This makes `ConfigParse.effectSchema` field-tolerant:
- Unknown top-level keys are stripped (with a warning log) instead of
throwing `unrecognized_keys`.
- Top-level fields whose value fails decoding are dropped (with a
warning log naming the field + the issue summary), the rest of the
config decodes normally.
- Root-level errors (e.g. data is not an object at all) and post-strip
failures still throw the original `InvalidError` so we don't silently
swallow truly broken configs.
Three new tests cover the reported shape (skills as array), unknown
keys, and multi-bad-field cases. Two existing tests that asserted the
strict-throw behavior were updated to the new tolerant contract.
Pre-fix: opencode unstartable for users with malformed configs.
Post-fix: opencode starts, the bad field is ignored, the user sees a
warning in the log naming what was dropped.
Contributor
Author
|
Closing — talked to @AidenCline; opencode has always hard-failed on invalid configs by design, since day 1. The intentional behavior is to surface bad configs loudly so users fix them, not silently strip them. The reported user's correct path is to fix their |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
Reported by Ben Matthews on Discord against v1.14.45: a `skills:` field shaped as an array (rather than the schema's `{paths?, urls?}` object) made the entire config load throw `ConfigInvalidError`, the server returned 500, and the desktop app couldn't start.
What this does
Makes `ConfigParse.effectSchema` field-tolerant:
Each drop emits a `log.warn("ignoring invalid config fields", { source, fields, summary })` line so users (and we) can see what was ignored and fix it.
Test
Three new red→green tests for the reported shape (skills-as-array), unknown keys, and multi-bad-field configs. Two existing tests that asserted strict-throw behavior were updated to the new tolerant contract.
`bun test test/config/config.test.ts` — 84/84 PASS.
`bun typecheck` — clean.
Why this is the right shape
Same architectural insight as today's other regressions: anything we load from the user's filesystem (config, sessions, cached state) should be tolerant on read, strict on write. We've now applied this to `/config` HTTP responses (#26584 SDK Error wrap), session diffs (#26574, #26579 legacy summary_diffs), and now the config loader itself. Each one closes a "user can't start opencode because one bad byte on disk" failure mode.
Followup worth considering