This issues is from AI agent !
Bug Description
initConfig() in src/config.ts:613-622 can silently reset the entire CONFIG to hardcoded defaults when loadConfigFromPaths(CONFIG_FILES) returns an empty object {}. This occurs when the global config file is transiently inaccessible (I/O contention, file lock, race condition at process startup).
Impact
When triggered, all configuration values are reset to hardcoded defaults:
embeddingModel → "Xenova/nomic-embed-text-v1" (user had configured Ollama qwen3-embedding:0.6b)
embeddingDimensions → 768 (user had configured 1024)
embeddingApiUrl → undefined (user had configured http://localhost:11434/v1)
embeddingApiKey → undefined (user had configured "ollama")
This causes the Web UI migration detection (/api/migration/detect) to report a false dimension mismatch, because it compares the (now-default) CONFIG values against shard metadata that was written with the correct user-configured values.
Root Cause
In initConfig() (line 613-622):
export function initConfig(directory: string): void {
const globalConfig = loadConfigFromPaths(CONFIG_FILES);
const projectConfig = loadConfigFromPaths(projectPaths);
const merged = deepMerge(globalConfig, projectConfig);
Object.assign(CONFIG, buildConfig(merged)); // ← BUG: buildConfig({}) fills ALL defaults
}
When globalConfig is {} and projectConfig is {}, buildConfig({}) rebuilds the entire config with every hardcoded default, then Object.assign overwrites the existing CORRECT CONFIG.
Reproduction
- Configure opencode-mem0 with Ollama embedding API (non-default model/dimensions)
- Start opencode — CONFIG initializes correctly at module load time (line 593)
- Open a new session in a project without
.opencode/opencode-mem0.jsonc
initConfig(projectDir) is called
- If
loadConfigFromPaths(CONFIG_FILES) returns {} (transient I/O failure), CONFIG is reset to defaults
- Web UI at
http://localhost:4747 shows: 模型不匹配:配置使用 768D (Xenova/nomic-embed-text-v1),但2 个分片具有不同的维度。
Proposed Fix
Add a guard in initConfig() — when both global and project configs are empty, skip the CONFIG rebuild entirely:
export function initConfig(directory: string): void {
const projectPaths = [...];
const globalConfig = loadConfigFromPaths(CONFIG_FILES);
const projectConfig = loadConfigFromPaths(projectPaths);
// Guard: if neither config file was found, preserve existing CONFIG values.
// Rebuilding from defaults here would silently break user-configured
// embedding model, dimensions, and API endpoint.
if (Object.keys(globalConfig).length === 0 && Object.keys(projectConfig).length === 0) {
return;
}
const merged = deepMerge(globalConfig, projectConfig);
Object.assign(CONFIG, buildConfig(merged));
}
Environment
- opencode-mem0 v2.16.2
- Node.js v18+
- Windows 11
This issues is from AI agent !
Bug Description
initConfig()insrc/config.ts:613-622can silently reset the entire CONFIG to hardcoded defaults whenloadConfigFromPaths(CONFIG_FILES)returns an empty object{}. This occurs when the global config file is transiently inaccessible (I/O contention, file lock, race condition at process startup).Impact
When triggered, all configuration values are reset to hardcoded defaults:
embeddingModel→"Xenova/nomic-embed-text-v1"(user had configured Ollamaqwen3-embedding:0.6b)embeddingDimensions→768(user had configured1024)embeddingApiUrl→undefined(user had configuredhttp://localhost:11434/v1)embeddingApiKey→undefined(user had configured"ollama")This causes the Web UI migration detection (
/api/migration/detect) to report a false dimension mismatch, because it compares the (now-default) CONFIG values against shard metadata that was written with the correct user-configured values.Root Cause
In
initConfig()(line 613-622):When
globalConfigis{}andprojectConfigis{},buildConfig({})rebuilds the entire config with every hardcoded default, thenObject.assignoverwrites the existing CORRECT CONFIG.Reproduction
.opencode/opencode-mem0.jsoncinitConfig(projectDir)is calledloadConfigFromPaths(CONFIG_FILES)returns{}(transient I/O failure), CONFIG is reset to defaultshttp://localhost:4747shows:模型不匹配:配置使用 768D (Xenova/nomic-embed-text-v1),但2 个分片具有不同的维度。Proposed Fix
Add a guard in
initConfig()— when both global and project configs are empty, skip the CONFIG rebuild entirely:Environment