Skip to content

fix: guard initConfig against silent config reset on empty file load#36

Open
bob56621517 wants to merge 1 commit into
ZeR020:mainfrom
bob56621517:fix/initconfig-guard-empty-config
Open

fix: guard initConfig against silent config reset on empty file load#36
bob56621517 wants to merge 1 commit into
ZeR020:mainfrom
bob56621517:fix/initconfig-guard-empty-config

Conversation

@bob56621517

@bob56621517 bob56621517 commented Jun 4, 2026

Copy link
Copy Markdown

Problem

initConfig() in src/config.ts can silently reset the entire CONFIG to hardcoded defaults when loadConfigFromPaths() returns an empty object {}. This happens when the global config file is transiently inaccessible (I/O contention, file lock, race condition).

When triggered, buildConfig({}) fills all fields with defaults (768D Xenova/nomic-embed-text-v1), then Object.assign(CONFIG, ...) overwrites the correctly initialized CONFIG — silently breaking user-configured embedding model, dimensions, and API endpoint.

The Web UI migration detection then reports a false dimension mismatch because CONFIG values no longer match shard metadata.

Fix

Add a guard in initConfig() — when both global and project config sources are empty, skip the CONFIG rebuild entirely and preserve the existing values from module-level initialization.

if (Object.keys(globalConfig).length === 0 && Object.keys(projectConfig).length === 0) {
    return;
}

Testing

  • Syntax check: node --check passes
  • Existing initConfig behavior is unchanged when config files are present
  • When config files are temporarily inaccessible, CONFIG preserves its originally loaded values instead of resetting to defaults

Closes #35

Summary by CodeRabbit

  • Bug Fixes
    • Corrected a critical configuration handling issue where existing user settings could be unexpectedly lost and replaced with default values when project or global configuration files were absent. The system now intelligently preserves your configuration settings in these scenarios.

When global or project config files are transiently inaccessible
(I/O contention, race condition, missing files), loadConfigFromPaths()
returns {}. Calling buildConfig({}) fills all fields with hardcoded
defaults, then Object.assign(CONFIG, ...) overwrites the correctly
initialized CONFIG singleton — silently breaking user-configured
embedding model, dimensions, and API endpoint.

The Web UI migration detection (/api/migration/detect) reads
CONFIG.embeddingDimensions and CONFIG.embeddingModel to compare
against shard metadata, so the reset manifests as a false dimension
mismatch warning.

Fix: skip CONFIG rebuild entirely when both config sources are empty.

Closes ZeR020#35
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 60be30c8-83af-4edc-9667-05aa009cf12c

📥 Commits

Reviewing files that changed from the base of the PR and between 01fefff and cf6a494.

📒 Files selected for processing (1)
  • src/config.ts

📝 Walkthrough

Walkthrough

initConfig() now guards against silent CONFIG reset by detecting when both global and project config files are missing, returning early to preserve existing user-configured values instead of rebuilding CONFIG with hardcoded defaults.

Changes

Config Guard Against Silent Reset

Layer / File(s) Summary
initConfig guard clause for missing config files
src/config.ts
Adds an early-return guard that detects when neither the global config nor the project config files were loaded (both empty objects), preventing CONFIG rebuild that would replace user-configured embedding model, dimensions, and API endpoint with hardcoded defaults.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hops through config lands,
Where guards now stand with steady hands—
No more default cascades fall,
User settings safe from all! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: guarding initConfig against silent config reset when empty config files are loaded.
Description check ✅ Passed The description comprehensively covers the problem, fix implementation, and testing approach, matching the repository template structure.
Linked Issues check ✅ Passed The PR implementation fully addresses issue #35's objectives: guards initConfig against silent config reset by returning early when both global and project configs are empty, preserving user-configured values.
Out of Scope Changes check ✅ Passed The code changes are narrowly scoped to the specific bug fix in src/config.ts with no unrelated modifications outside the guard implementation for handling empty config files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@deepsource-io

deepsource-io Bot commented Jun 4, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 01fefff...cf6a494 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Jun 4, 2026 7:22a.m. Review ↗
Secrets Jun 4, 2026 7:22a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@bob56621517

Copy link
Copy Markdown
Author

@ZeR020 This PR is ready for review. It fixes a bug where silently resets CONFIG to hardcoded defaults when the global config file is transiently inaccessible, causing false dimension mismatch warnings in the Web UI.

Changes: Single-file fix in — adds a guard to skip CONFIG rebuild when config sources are empty.

CI note: The DeepSource JavaScript failure appears pre-existing (not from this change — only 11 lines of guard logic added). CodeRabbit skipped. Secrets check passed.

Please review when available. Thanks!

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.

fix: initConfig() silently resets CONFIG to defaults when global config file is transiently inaccessible

1 participant