Skip to content

fix(FR-2355): handle duplicate TOML keys in config.toml parsing#6107

Open
ironAiken2 wants to merge 1 commit intomainfrom
03-23-fix_fr-2355_handle_duplicate_toml_keys_in_config_parsing
Open

fix(FR-2355): handle duplicate TOML keys in config.toml parsing#6107
ironAiken2 wants to merge 1 commit intomainfrom
03-23-fix_fr-2355_handle_duplicate_toml_keys_in_config_parsing

Conversation

@ironAiken2
Copy link
Copy Markdown
Contributor

@ironAiken2 ironAiken2 commented Mar 23, 2026

Resolves #6091 (FR-2355)

Summary

  • smol-toml throws on duplicate keys in TOML, but the previous code silently swallowed the error, causing all config options to fall back to defaults without any indication to the user
  • Change fetchAndParseConfig return type from RawTomlConfig | null to { config, error } to distinguish fetch failures (network error, non-200, SPA fallback) from parse failures (invalid TOML)
  • Add configParseErrorState Jotai atom to store parse errors so other hooks can access them
  • Surface parse errors on the diagnostics page as a critical alert with the raw error message displayed in a <pre> code block, remediation instructions, and early return (skip remaining config checks since rawConfig is null)
  • Log parse errors via useBAILogger (replaces console.warn)
  • Update call sites (loginSessionAuth.ts, EduAppLauncher.tsx) for the new return type
  • Update all tests for the new return type and add test cases for duplicate keys and parse failure
  • Add i18n keys (ConfigParseError, ConfigParseErrorDesc, ConfigParseErrorFix) across all 21 languages

Test plan

  • Add duplicate keys in config.toml (e.g., debug = false and debug = true under [general]), open the diagnostics page, and verify a critical alert is shown with the parse error message in a code block
  • Verify config values are applied correctly when config.toml is valid
  • Verify the app falls back to defaults without errors when config.toml is missing (404)
  • pnpm run test — all 35 useWebUIConfig tests pass

🤖 Generated with Claude Code

@github-actions github-actions bot added the size:L 100~500 LoC label Mar 23, 2026
Copy link
Copy Markdown
Contributor Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • flow:merge-queue - adds this PR to the back of the merge queue
  • flow:hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 2026

Coverage report for ./react

St.
Category Percentage Covered / Total
🔴 Statements
8.26% (+0.01% 🔼)
1406/17031
🔴 Branches
7.43% (-0.01% 🔻)
883/11884
🔴 Functions
5.41% (-0% 🔻)
258/4767
🔴 Lines
7.95% (+0.01% 🔼)
1319/16589
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / useWebUIConfig.ts
21.93% (+0.98% 🔼)
12.73% (-0.48% 🔻)
11.76% (-0.74% 🔻)
22.12% (+0.97% 🔼)

Test suite run success

775 tests passing in 36 suites.

Report generated by 🧪jest coverage report action from 26193ea

@ironAiken2 ironAiken2 marked this pull request as ready for review March 23, 2026 09:40
Copilot AI review requested due to automatic review settings March 23, 2026 09:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens config.toml loading in the React WebUI so duplicated keys generated by the webserver don’t cause TOML parsing to fail silently and revert all config options to defaults.

Changes:

  • Add a TOML text preprocessor intended to remove duplicate keys within a section before parsing.
  • Change fetchAndParseConfig() to return { config, error } so callers can distinguish success vs failure paths.
  • Replace console.warn with useBAILogger logging on config load failures and update call sites/tests accordingly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
react/src/hooks/useWebUIConfig.ts Adds deduplication + new fetch/parse result shape, and switches failure logging to useBAILogger.
react/src/hooks/useWebUIConfig.test.ts Updates tests for new return type and adds a duplicate-key handling test.
react/src/helper/loginSessionAuth.ts Updates call site to new { config } return shape.
react/src/components/EduAppLauncher.tsx Updates call site to new { config } return shape.

@ironAiken2 ironAiken2 force-pushed the 03-23-fix_fr-2355_handle_duplicate_toml_keys_in_config_parsing branch from 02f0efd to 1ce5c97 Compare March 23, 2026 09:51
@ironAiken2 ironAiken2 force-pushed the 03-23-fix_fr-2355_handle_duplicate_toml_keys_in_config_parsing branch from 1ce5c97 to 21872b9 Compare March 24, 2026 02:25
@ironAiken2 ironAiken2 requested a review from yomybaby March 24, 2026 02:25
@ironAiken2 ironAiken2 force-pushed the 03-23-fix_fr-2355_handle_duplicate_toml_keys_in_config_parsing branch from 21872b9 to dbb22ff Compare March 24, 2026 04:16
@github-actions github-actions bot added area:ux UI / UX issue. area:i18n Localization labels Mar 24, 2026
The Backend.AI webserver generates config.toml with duplicate keys
(e.g. two `debug = true` lines), which causes smol-toml to throw.
The error was silently swallowed, falling back to defaults and
making all config options appear disabled.

- Add deduplicateTomlKeys() preprocessing to remove duplicate keys
  before TOML parsing (keeps last occurrence)
- Change fetchAndParseConfig return type to { config, error } to
  distinguish fetch failure from parse failure
- Add useBAILogger-based error logging for parse failures
- Update all call sites for new return type
- Add test for duplicate key handling
@ironAiken2 ironAiken2 force-pushed the 03-23-fix_fr-2355_handle_duplicate_toml_keys_in_config_parsing branch from dbb22ff to 26193ea Compare March 24, 2026 08:17
Copy link
Copy Markdown
Contributor

@nowgnuesLee nowgnuesLee left a comment

Choose a reason for hiding this comment

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

LGTM

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

Labels

area:i18n Localization area:ux UI / UX issue. quick-capture size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Login config.toml options not applied after Lit-to-React migration

4 participants