Skip to content

feat(config): tolerate invalid config.toml sections instead of failing startup#689

Merged
liruifengv merged 3 commits into
mainfrom
start-for-config
Jun 12, 2026
Merged

feat(config): tolerate invalid config.toml sections instead of failing startup#689
liruifengv merged 3 commits into
mainfrom
start-for-config

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Problem

A single typo in config.toml (e.g. a wrong value type in [loop_control]) made the app fail to start entirely — including dropping the user into a crash even though their providers, models, and login state were perfectly fine. Mutating settings (/provider, kimi provider) on top of a broken file crashed with an unhandled rejection dumping raw validation JSON.

Changes

Lenient runtime loading (loadRuntimeConfigSafe):

  • Schema errors drop only the offending sections — single entries for providers/models, the whole top-level section otherwise — with a warning. Login state survives a typo elsewhere in the file.
  • TOML syntax errors (file entirely unusable) still fail startup fast with the parse location: defaults-only would look like a fresh install, which is worse than an actionable error.
  • Mid-run reloads keep the last good config when the file breaks, instead of degrading a live session.
  • A broken KIMI_MODEL_* env overlay is skipped with a warning instead of throwing.

Warning surfacing via the new getConfigDiagnostics API: startup notice in the TUI, stderr in print mode, status bar after /new.

Write paths stay strict — read-merge-write must never use a salvaged config as its base, or rewriting would silently drop the user's broken-but-fixable sections. They now fail with a short actionable message ("fix it first, run kimi doctor") instead of raw validation JSON, and:

  • the /provider TUI flow reports errors in the status bar instead of crashing on a dangling promise;
  • the kimi provider CLI prints one line and exits 1 instead of an unhandled-rejection stack dump;
  • OAuth token resolution (resolveManagedAuth) reads leniently so a broken section elsewhere doesn't break OAuth-backed sessions.

Testing

  • New unit tests: salvage granularity, fileError semantics, keep-last-good reloads, write rejection message and file integrity, CLI error boundary.
  • Full suite green (6808 tests), typecheck and oxlint clean.
  • Manual smoke: broken [loop_control] with a real OAuth login starts with a warning and a working session; [[[ fails fast with the parse location; kimi provider remove on a broken file prints one actionable line.

…g startup

Schema errors now drop only the offending sections (single entries for
providers/models) with a warning, so a typo no longer prevents startup or
drops the login state. TOML syntax errors still fail fast with the parse
location. Mid-run reloads keep the last good config when the file breaks.

Warnings surface via the new getConfigDiagnostics API: as a startup notice
in the TUI, on stderr in print mode, and in the status bar after /new.

Write paths stay strict so a broken file is never silently rewritten, and
now fail with a short actionable message instead of raw validation JSON;
the /provider TUI flow and the kimi provider CLI report these errors
instead of crashing on an unhandled rejection.
@changeset-bot

changeset-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0e6a451

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code-sdk Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@0e6a451
npx https://pkg.pr.new/@moonshot-ai/kimi-code@0e6a451

commit: 0e6a451

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf480fc0ab

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/config/toml.ts Outdated
…sues

A providers/models entry with several validation issues was deleted by the
first issue, and the remaining issues from the same safeParse pass then
escalated to deleting the entire section — one badly-typed custom provider
could drop every provider, including the managed OAuth login. Issues on
entry-keyed sections now only ever target the entry itself; once it is
gone, later issues are no-ops.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: ce3427f8d8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@liruifengv liruifengv merged commit 8d251f8 into main Jun 12, 2026
8 checks passed
@liruifengv liruifengv deleted the start-for-config branch June 12, 2026 07:56
@github-actions github-actions Bot mentioned 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

Development

Successfully merging this pull request may close these issues.

1 participant