Repository navigation
fix(doctor): judge the LLM provider the way the daemon does - #1575
Conversation
The no-llm-provider-key check counted six key names on its own, while the daemon decides through detectLlmProviderKind. With OPENAI_API_KEY and OPENAI_API_KEY_FOR_LLM=false doctor reported the key as found although the daemon runs in noop mode, and with AGENTMEMORY_ALLOW_AGENT_SDK=true and no key it failed and opened the editor while the daemon had an LLM. Drop placeholder keys from the env file, pass the rest to detectLlmProviderKind and list only the keys it would use for the LLM. Doctor now parses the env file with the daemon's parser, so a line uncommented from .env.example keeps its trailing comment out of the value in both. On the same .env doctor reaches the daemon's verdict, except that placeholder keys still count as missing. Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
|
@dmazhukov is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Merge Risk:
|
The daemon resolves provider keys through getMergedEnv(), where process.env wins over ~/.agentmemory/.env. The provider check read the file only, so an exported key, or OPENAI_API_KEY_FOR_LLM=false in the shell, made doctor report the opposite of what the daemon does. The check now merges the environment over the file. It takes the environment from before hydrateProcessEnvFromFile() copied the file into process.env: the copied values go stale once the file is edited, so merging live process.env would keep a pasted key failing on re-check after the editor fix. Keys found only in the environment are marked in the detail, since a daemon started elsewhere does not see them. Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
getMergedEnv() merges the file under process.env and treats a missing file as empty, so a daemon started with ANTHROPIC_API_KEY exported and no ~/.agentmemory/.env resolves an LLM provider. The provider check returned early on the missing file and reported the opposite. The check now reads the environment regardless; env-missing stays the diagnostic that reports an absent file. With neither a file nor a key the detail still points at the env-missing fix, since the editor fix has nothing to open. Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
The caveat about a daemon started from another environment sat in moreInfo, which runDoctor prints only through the interactive "more" action on a failing check. On a passing one it printed just the detail, so the one configuration the caveat was written for never showed it. The detail now carries it whenever a named key comes from the environment, and a key the environment overrides is marked too, not only one the file lacks. An undefined environment value no longer blanks the file's key. env-missing no longer claims BM25-only when a key is exported, and the key list names GOOGLE_API_KEY, which both detectLlmProviderKind and realProviderKeys already accept. Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
| ok: real.length > 0, | ||
| detail: real.length > 0 ? `found: ${real.join(", ")}` : "no provider key set", | ||
| }; | ||
| for (const k of placeholderProviderKeys(env)) delete env[k]; |
There was a problem hiding this comment.
🔴 Placeholder Gemini key masks valid alias
With placeholder GEMINI_API_KEY and real GOOGLE_API_KEY, no-llm-provider-key passes after dropping the placeholder. The daemon's detectProvider selects GEMINI_API_KEY first, so Gemini calls use the placeholder instead.
Learn more
The provider check removes placeholder values from its copy of the merged environment. The actual detectProvider does not remove them: it treats any nonempty value as a real key and prefers GEMINI_API_KEY over its GOOGLE_API_KEY alias. As a result the doctor's positive result does not correspond to the key the daemon will send to Gemini. The same discrepancy can affect which provider wins when a higher-priority provider has a placeholder.
Example: Put GEMINI_API_KEY=your-key-here and GOOGLE_API_KEY=real-google-key in the file. Doctor says found: GOOGLE_API_KEY; the worker builds its Gemini provider with your-key-here and requests fail.
Recommended fix: Check the actual selected provider and its selected credential against placeholder values, rather than deleting placeholder keys before provider selection. Account for the Gemini alias precedence and the priority order in detectProvider.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Main gives the same verdict for this env (found: GOOGLE_API_KEY). The placeholder is picked on the daemon side, src/providers/index.ts:98 (GEMINI_API_KEY || GOOGLE_API_KEY), which this PR does not touch.
There was a problem hiding this comment.
The daemon side is now #1588: a placeholder GEMINI_API_KEY no longer shadows a real GOOGLE_API_KEY, and doctor and the daemon share one placeholder rule.
| const real = realProviderKeys(env).filter( | ||
| (k) => | ||
| detectLlmProviderKind({ | ||
| [k]: env[k], | ||
| OPENAI_API_KEY_FOR_LLM: env.OPENAI_API_KEY_FOR_LLM, | ||
| }) === "llm", | ||
| ); |
There was a problem hiding this comment.
🟡 Unused provider keys reported as active
When several keys exist, no-llm-provider-key reports each as usable despite the daemon selecting only one. detectProvider stops at the first provider, so the verdict misidentifies the active key.
Learn more
The provider-kind helper answers whether a given configuration has any LLM route; it does not say which route wins. Running it once per key treats all valid keys as used, even though detectProvider selects the first provider in its priority order. The result is misleading when debugging which credential a running worker uses, especially when one key exists only in the shell.
Example: With OPENAI_API_KEY=sk-openai-real and ANTHROPIC_API_KEY=sk-ant-real, doctor reports both as found. The worker picks OpenAI; it never uses the Anthropic key for its primary provider.
Recommended fix: Derive the displayed active key from the same provider-selection priority and alias logic as detectProvider, while retaining a separate check for whether any working route exists.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Main prints the same list for this env (found: ANTHROPIC_API_KEY, OPENAI_API_KEY); this PR does not change what the detail lists. Naming only the key detectProvider picks would be a separate change.
Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
The daemon loads AGENTMEMORY_ENV_FILE when it is set, so doctor judged the provider key from a file the daemon does not read. Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
|
Merged main to clear the conflict with #1592. Since #1592 the daemon loads Left alone: the |
| function buildDoctorEffects(): DoctorEffects { | ||
| return { | ||
| envFileExists: () => existsSync(join(homedir(), ".agentmemory", ".env")), | ||
| envFileExists: () => existsSync(doctorEnvPath()), |
There was a problem hiding this comment.
🟡 Missing custom env file remains unfixed
When AGENTMEMORY_ENV_FILE points to a missing file, env-missing fails but its fix creates the default file. runInit ignores the custom path, so doctor reports a successful fix while the custom file remains missing.
Learn more
The env-missing check now inspects the path selected by AGENTMEMORY_ENV_FILE. Its fix invokes runInit, but runInit always targets the default file. As a result, the fix can create an unrelated file, or do nothing when that default file already exists, and the re-check still fails.
Example: Set AGENTMEMORY_ENV_FILE=/tmp/agent.env with neither /tmp/agent.env nor ~/.agentmemory/.env present. Choose Fix for env-missing. Doctor creates ~/.agentmemory/.env, then reports that /tmp/agent.env is still missing.
Recommended fix: Pass ctx.envPath to the env-missing fix and copy the template to that path with the same exclusive-create behavior as runInit; keep standalone init's default-path behavior unchanged.
Was this helpful? React with 👍 or 👎 to provide feedback.
| baseUrl: getBaseUrl(), | ||
| viewerUrl: getViewerUrl(), | ||
| envPath: join(homedir(), ".agentmemory", ".env"), | ||
| envPath: doctorEnvPath(), |
There was a problem hiding this comment.
The
no-llm-provider-keydoctor check now asksdetectLlmProviderKind, which the daemon uses, instead of its own list of six key names, and lists only the keys it would use for the LLM. Doctor also reads.envwith the daemon's parser. Placeholder keys still count as missing.With the built CLI,
OPENAI_API_KEYplus theOPENAI_API_KEY_FOR_LLM=falseline from.env.examplepassed as "found: OPENAI_API_KEY" while the daemon ran noop, andAGENTMEMORY_ALLOW_AGENT_SDK=truewithout a key failed and opened the editor while the daemon ran agent-sdk.Provider PRs #558, #1111, #1355 and #1554 extend
detectLlmProviderKind, so doctor follows them; a key-name list cannot express Azure's key-plus-endpoint rule. #1111, #1355 and #1554 will conflict textually here.A missing
.envalso counts: the daemon treats an absent file as empty, so a key exported in the shell resolves a provider without one.env-missingstays the check that reports the absent file.Where a named key comes from the environment, the verdict says so in its own line rather than in
more info, which a passing check never prints.Embedding checks and the
cli.tshint are unchanged.The check also merges the shell environment over
.env, asgetMergedEnvdoes, so its verdict describes a daemon started from the same environment, and keys found only there are marked(environment). It takes the environment from beforehydrateProcessEnvFromFile(), so a key pasted in through the editor fix passes the re-check.Fixes #1572
Summary by CodeRabbit
.envfiles, with environment values taking precedence. Placeholder values are treated as missing.