Skip to content

fix(config): make flattening deterministic for duplicate keys - #2298

Open
WitteShadovv wants to merge 1 commit into
safing:developmentfrom
WitteShadovv:fix/config-deterministic-flatten
Open

WitteShadovv wants to merge 1 commit into
safing:developmentfrom
WitteShadovv:fix/config-deterministic-flatten

Conversation

@WitteShadovv

@WitteShadovv WitteShadovv commented Oct 16, 2026 •

Copy link
Copy Markdown

When a config file defines the same option both nested and flattened, e.g. {"core": {"devMode": true}, "core/devMode": false}, flattenMap iterated over the map in Go's random order, so the value in use changed between restarts. This happens easily when config files with different spellings are merged.

This iterates over the keys in sorted order. A flattened key sorts after its nested parent (core < core/devMode), so the flattened spelling consistently takes precedence.

Testing: added TestFlattenDuplicateKeys, which fails reliably without the fix; go test ./base/config/ and go vet pass, and service/sync (the other user of Flatten) builds

Summary by CodeRabbit

  • Bug Fixes
    • Configuration options now resolve consistently when the same setting is provided in both nested and flattened forms. The flattened setting takes precedence, so the selected value no longer depends on inconsistent processing order. This makes configuration behavior predictable when these forms conflict.

When a config file defines the same option both nested and flattened,
e.g. {"core": {"devMode": true}, "core/devMode": false}, flattenMap
iterated over the map in random order, so the value in use changed
between restarts.

Iterate over the keys in sorted order. A flattened key sorts after its
nested parent ("core" < "core/devMode"), so the flattened spelling
consistently takes precedence.
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2bfbb3c4-5d61-4641-b761-47e6710a6424
📥 Commits

Reviewing files that changed from the base of the PR and between e0b7d27 and 03a6b19.

📒 Files selected for processing: 2
  • base/config/persistence.go
  • base/config/persistence_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

📝 Walkthrough

flattenMap now processes map keys in sorted order, so a flattened key takes precedence over its nested equivalent. A test repeats conversion 100 times and checks this precedence.

Changes: Configuration key flattening

Layer / File(s) Summary
Deterministic key conflict resolution
base/config/persistence.go, base/config/persistence_test.go
flattenMap processes keys in sorted order. The test checks 100 conversions where the nested and flattened core/devMode keys have conflicting values.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 03a6b

Conflicting configuration entries now resolve consistently in favor of the flattened key. No actionable merge-blocking risk is evident.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: deterministic config flattening for duplicate keys.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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