fix(core): use loadConfig() for default assistant in new conversations#1258
fix(core): use loadConfig() for default assistant in new conversations#1258
Conversation
#1172) getOrCreateConversation() read DEFAULT_AI_ASSISTANT env var directly, bypassing the config system. This meant the Settings page saved preference was ignored when creating new conversations. Now uses loadConfig() which applies the full priority chain: defaults → global config → env override. Changes: - Replace direct env var read with loadConfig() call in conversations.ts - Add config-loader mock and global config test in conversations.test.ts - Split conversations.test.ts into own bun test invocation to avoid mock pollution Fixes #1172 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🔍 Comprehensive PR ReviewPR: #1258 — fix(core): use loadConfig() for default assistant in new conversations SummaryClean, targeted single-line fix that replaces a direct Verdict: ✅
🟡 Medium Issues (No fix required before merge)
|
| Issue | Location | Suggestion |
|---|---|---|
Redundant mockConfigAssistant reset in afterEach |
conversations.test.ts:62 |
Remove dead assignment — beforeEach always overwrites it first |
| Misleading test name: "falls back to claude" | conversations.test.ts:192 |
Rename to 'uses config default assistant when codebase not found' — the value comes from loadConfig(), not a hardcoded fallback |
| Env var test comment could be expanded | conversations.test.ts:144-148 |
Add comment explaining why both process.env and mockConfigAssistant must be set in sync |
Missing explicit type annotation on mockConfigAssistant |
conversations.test.ts:15 |
Add : string for CLAUDE.md type-safety compliance |
Redundant afterEach reset (corroboration) |
conversations.test.ts:55-63 |
Same finding as first item above, independently flagged by test-coverage agent |
✅ What's Good
- Correct fix scope:
loadConfig()called withoutrepoPath— the codebase repo-level assistant override is handled separately via DB codebase lookup, so no double-application. - Caching is safe:
loadConfig()usescachedGlobalConfig; no filesystem hit on every conversation creation. - Batch split is exactly right:
conversations.test.tsnow runs in its ownbun testinvocation, correctly preventingmock.module()pollution withconfig-loader.test.ts. - New test is meaningful:
'uses saved global config defaultAssistant when no env var'directly exercises the bug — proves thatloadConfig()returning'codex'results inai_assistant_type = 'codex'in the INSERT. - Improved error detectability: Old code silently accepted any string (including invalid provider names). New code validates against the registry and throws with a descriptive message on invalid input.
- All 7 tests are outcome-based (asserting SQL parameters) — resilient to refactoring.
Reviewed by Archon comprehensive-pr-review workflow
Artifacts: ~/.archon/workspaces/coleam00/Archon/artifacts/runs/82bbb50cacf7edac3a9ae995771c017a/review/
- Add explicit `: string` type annotation to `mockConfigAssistant` (CLAUDE.md type safety) - Remove dead `mockConfigAssistant` reset from `afterEach` — `beforeEach` always overwrites it - Expand comment in env var test to explain why both `process.env` and `mockConfigAssistant` must be set in sync - Rename test 'falls back to claude when codebase not found' → 'uses config default assistant when codebase not found' to accurately describe post-fix behavior (uses config default, not a hardcoded fallback) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Self-Fix Report: Review Findings AddressedAll actionable findings from the three review agents have been addressed in commit Changes Made (
|
| Finding | Severity | Source | Action |
|---|---|---|---|
mockConfigAssistant lacks explicit : string type annotation |
LOW | error-handling | Fixed — added : string per CLAUDE.md type safety |
Redundant mockConfigAssistant reset in afterEach |
LOW | code-review + test-coverage | Fixed — removed dead assignment; replaced with clarifying comment (beforeEach owns the reset) |
| Env var test comment needs expansion | LOW | code-review | Fixed — expanded comment to explain why both process.env and mockConfigAssistant must be set in sync |
| Misleading test name: "falls back to claude when codebase not found" | LOW | code-review | Fixed — renamed to 'uses config default assistant when codebase not found' |
Skipped
| Finding | Severity | Reason |
|---|---|---|
loadConfig() throws not logged at call site (conversations.ts:76) |
MEDIUM | The review agent itself recommended leaving as-is (Option B). Fail-fast design is intentional per CLAUDE.md — loadConfig() throws produce descriptive messages; a catch-and-rethrow wrapper would violate YAGNI/KISS without meaningful benefit. |
Validation
All checks pass after the fixes:
bun run type-check: ✅ All 10 packagesbun run lint: ✅ No warningsbun run test: ✅ All tests pass
Replace misleading `process.env.DEFAULT_AI_ASSISTANT ?? 'claude'` module-level initializer with a plain `'claude'` literal (beforeEach always resets it before any test runs, so the env-var read was dead code). Condense a five-line explanation comment into two lines without losing meaning. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Archon PR Validation ReportVerdict: ✅ APPROVE SummaryThis PR correctly fixes a bug where Bug Confirmation
Fix Quality: 5/5
IssuesNo blocking issues found. Validated by archon-validate-pr workflow |
Summary
getOrCreateConversation()readprocess.env.DEFAULT_AI_ASSISTANT ?? 'claude'directly, completely bypassing the config system. The default assistant saved via the Settings page was never consulted when creating new conversations.getOrCreateConversation()now callsloadConfig(), which applies the full priority chain: defaults → global config file (Settings page) → env var override. TheDEFAULT_AI_ASSISTANTenv var still wins when set.UX Journey
Before
After
Architecture Diagram
Before
After
Connection inventory:
conversations.tsprocess.envconversations.tsconfig-loader.tsloadConfig()call addedLabel Snapshot
risk: lowsize: XScorecore:dbChange Metadata
bugcoreLinked Issue
Validation Evidence (required)
'uses saved global config defaultAssistant when no env var'verifies the fix explicitly.Security Impact (required)
Compatibility / Migration
DEFAULT_AI_ASSISTANTenv var still takes highest priority viaapplyEnvOverrides()insideloadConfig().Human Verification (required)
bun run validate)Side Effects / Blast Radius (required)
getOrCreateConversation()is called from web routes, orchestrator, CLI, and platform adapters — all now read the correct assistant type on first creation.loadConfig()reads~/.archon/config.yamlon first call (subsequent calls hit in-memory cache); negligible overhead.loadConfig()throws on invalid provider config, surfacing misconfiguration early.Rollback Plan (required)
git revert 8a4b8a75— single-commit revert restores the direct env var read.ai_assistant_type(visible in API response or DB).Risks and Mitigations
loadConfig()adds a (cached) file read on every new conversation creation.loadGlobalConfig()is memoized; the overhead is a cache lookup after the first call. Acceptable given it only runs at conversation creation time, not on every message.