Skip to content

fix: tolerate unrecognized config keys instead of failing all session loading#33197

Open
mouse114514 wants to merge 1 commit into
anomalyco:devfrom
mouse114514:fix/config-tolerate-unknown-keys
Open

fix: tolerate unrecognized config keys instead of failing all session loading#33197
mouse114514 wants to merge 1 commit into
anomalyco:devfrom
mouse114514:fix/config-tolerate-unknown-keys

Conversation

@mouse114514

@mouse114514 mouse114514 commented Jun 21, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #33196

Type of change

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

What does this PR do?

opencode.json / opencode.jsonc root-level fields not in the Config schema (e.g., "files": {}) currently throw ConfigInvalidError and block all session loading. This is fragile — a stray key can crash the entire app.

Instead of throwing InvalidError via topLevelExtraKeys(), the fix logs console.warn() for each unrecognized key and strips them from data before Effect Schema validation. Valid config still applies normally.

How did you verify your code works?

  • Tested locally with a config file containing the "files" key from the debug archive — no more crash, warning printed to console
  • Verified valid keys (e.g., "sessions", "models") still work correctly after the change

Screenshots / recordings

N/A — this is a backend/config change, no UI.

Checklist

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

… loading

When opencode.json/jsonc contains root-level fields not defined in the
Config schema, topLevelExtraKeys() throws ConfigInvalidError which
prevents all sessions from loading.

Changed to log a warning and strip the unknown keys from data before
passing to Effect Schema validation. This makes config parsing
resilient to stray or misplaced keys.

Fixes anomalyco#33196
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

I found one potentially related PR:

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

This PR also addresses graceful error handling during config/session loading, which is conceptually related to your PR #33197's goal of tolerating config issues rather than crashing. However, PR #29208 appears to focus on parse errors during startup, while your PR specifically addresses unrecognized top-level keys in the config schema.

These are distinct issues but cover similar concerns about config robustness. You may want to review #29208 to ensure your approach is consistent with existing patterns for graceful config handling.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Config schema should tolerate unknown fields instead of failing all session loading

1 participant