Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: detect env-var provider credentials in readiness (#4612)

[._.]/ Adam Eivy60599246792e
diff --git a/client/src/pages/AIProviders.jsx b/client/src/pages/AIProviders.jsx
index 4b6b9e738a..7ad6cca0be 100644
--- a/client/src/pages/AIProviders.jsx
+++ b/client/src/pages/AIProviders.jsx
@@ -376,13 +376,25 @@ export default function AIProviders() {
const { providersById, runtimeByProviderId, cardStateByProviderId, providersBySection } = useMemo(() => {
const byId = Object.fromEntries(providers.map(p => [p.id, p]));
const runtimeById = Object.fromEntries(providers.map(p => [p.id, runtimeForProvider(p)]));
- const readinessById = Object.fromEntries(providers.map(p => [p.id, providerCardState(p, {
- runtime: runtimeById[p.id],
- status: statuses[p.id],
- // `providers` is the authoritative list, so a sibling that is absent from
- // it was deleted — the wrapper has no key to inherit, which is `false`,
- // not "unknown". (Nothing here runs before the list loads.)
- orcaRouterKeySet: Boolean(byId.orcarouter?.hasApiKey),
+ const readinessById = Object.fromEntries(providers.map((provider) => [provider.id, providerCardState(provider, {
+ runtime: runtimeById[provider.id],
+ status: statuses[provider.id],
+ keySetFor: (id) => {
+ const referenced = byId[id];
+ // The list is authoritative once this memo runs. A missing sibling was
+ // deleted, so the wrapper has no inherited key; an unknown lookup is
+ // reserved for callers that genuinely cannot determine the state.
+ if (!referenced) return false;
+ return typeof referenced.hasApiKey === 'boolean' ? referenced.hasApiKey : null;
+ },
+ envVarSet: (name) => {
+ if (!Object.hasOwn(provider.envVars || {}, name)) return null;
+ const value = provider.envVars[name];
+ // Secret values arrive as `***`; only an explicitly empty configured
+ // value is a definite missing credential.
+ if (value === '***' || typeof value !== 'string') return null;
+ return value !== '';
+ },
})]));
// The default provider floats to the top of whichever section it sits in, so
// "which one runs by default" stays a one-glance answer after grouping.
diff --git a/client/src/utils/providers.js b/client/src/utils/providers.js
index 4dcd109353..7e74a27041 100644
--- a/client/src/utils/providers.js
+++ b/client/src/utils/providers.js
@@ -980,6 +980,81 @@ export const isOllamaBackedProvider = (provider) => {
*/
export const isOrcaRouterBackedProvider = (provider) => provider?.orcarouterBacked === true;
+// Environment variables whose names are conventionally credentials. The
+// explicit secretEnvVars list remains the primary source; this small fallback
+// covers shipped providers such as Claude-Ollama, whose fixed local token is
+// useful but not marked secret in the catalog.
+const CREDENTIAL_ENV_VAR_RE = /(?:^|_)(?:API_KEY|AUTH_TOKEN|ACCESS_TOKEN|BEARER_TOKEN|CLIENT_SECRET|PASSWORD|TOKEN|SECRET)(?:_|$)/i;
+
+const providerHasStoredKey = (provider) =>
+ provider?.hasApiKey === true || Boolean(provider?.apiKey);
+
+const credentialEnvVar = (provider) => {
+ const envVars = provider?.envVars && typeof provider.envVars === 'object' ? provider.envVars : {};
+ const secretEnvVars = Array.isArray(provider?.secretEnvVars) ? provider.secretEnvVars : [];
+ const explicit = secretEnvVars.find((name) => typeof name === 'string' && name !== '');
+ if (explicit) return explicit;
+ return Object.keys(envVars).find((name) => CREDENTIAL_ENV_VAR_RE.test(name)) || null;
+};
+
+/**
+ * Identify how a provider authenticates, without deciding whether that
+ * credential is present. `null` is a deliberate ref for `none`, while a
+ * credential ref names the provider id, inherited sibling, or env var to look
+ * up. An own key wins over the OrcaRouter marker because the server leaves a
+ * provider carrying `provider.apiKey` untouched at spawn time.
+ *
+ * @param {{id?:string,type?:string,endpoint?:string,apiKey?:string,hasApiKey?:boolean,orcarouterBacked?:boolean,envVars?:Record<string,string>,secretEnvVars?:string[]}|null|undefined} provider
+ * @returns {{kind:'stored'|'inherited'|'env'|'none',ref:string|null}}
+ */
+export const credentialSource = (provider) => {
+ // Local API endpoints need no credential, even if an old record happens to
+ // retain one from before the endpoint was changed.
+ if (isApiProvider(provider) && isPrivateNetworkEndpoint(provider?.endpoint)) {
+ return { kind: 'none', ref: null };
+ }
+ if (providerHasStoredKey(provider)) {
+ return { kind: 'stored', ref: provider?.id || null };
+ }
+ const envVar = credentialEnvVar(provider);
+ if (envVar) return { kind: 'env', ref: envVar };
+ if (isOrcaRouterBackedProvider(provider)) return { kind: 'inherited', ref: 'orcarouter' };
+ if (isApiProvider(provider)) return { kind: 'stored', ref: provider?.id || null };
+ return { kind: 'none', ref: null };
+};
+
+const normalizeCredentialState = (state) =>
+ state === true || state === false ? state : null;
+
+const defaultKeySetFor = (provider, id) =>
+ id && id === provider?.id ? providerHasStoredKey(provider) : null;
+
+const defaultEnvVarSet = (provider, name) => {
+ if (!name || !Object.hasOwn(provider?.envVars || {}, name)) return null;
+ const value = provider.envVars[name];
+ // `***` is the sanitized secret sentinel, not evidence that the value is
+ // present. A redacted value is unknown; an explicitly empty value is known
+ // missing and is safe to report.
+ if (value === '***' || typeof value !== 'string') return null;
+ return value !== '';
+};
+
+const credentialMissing = (provider, { keySetFor = null, envVarSet = null } = {}) => {
+ const source = credentialSource(provider);
+ if (source.kind === 'none' || !source.ref) return null;
+
+ const rawState = source.kind === 'env'
+ ? (typeof envVarSet === 'function' ? envVarSet(source.ref) : defaultEnvVarSet(provider, source.ref))
+ : (typeof keySetFor === 'function' ? keySetFor(source.ref) : defaultKeySetFor(provider, source.ref));
+ if (normalizeCredentialState(rawState) !== false) return null;
+
+ if (source.kind === 'stored') return { code: 'apiKey', label: 'API key is not set' };
+ if (source.kind === 'inherited') {
+ return { code: 'inheritedApiKey', label: 'OrcaRouter API provider has no API key' };
+ }
+ return { code: 'envVar', label: `${source.ref} environment variable is not set` };
+};
+
/**
* Check if a provider is the Grok Build CLI/TUI (the `grok` command harness).
* Mirrors the Grok detection in `knownProviderContextWindow`: matches the shipped
@@ -1028,9 +1103,10 @@ export const PROVIDER_CARD_STATE = Object.freeze({
* authenticate through a secret env var — issue #4612, which also covers
* DETECTING those env-var credentials so this stops over-reporting them.)
*
- * This function consumes the published list and adds only what the browser
- * alone can see (the local-app runtime shape below). With an older server
- * publishing nothing, it falls back to deriving the credential checks itself.
+ * This function consumes the published list and adds what the browser alone
+ * can see (the local-app runtime shape and sanitized env-credential state
+ * below). With an older server publishing nothing, it falls back to deriving
+ * the credential checks itself.
*
* Inputs are passed in rather than read from globals so this stays pure:
* runtime — the provider's entry of the `runtimes` map (CLI binary)
@@ -1042,14 +1118,12 @@ export const PROVIDER_CARD_STATE = Object.freeze({
* status — the runtime-availability entry from
* `GET /api/providers/status`; `available === false`
* means the provider is benched after a failure.
- * orcaRouterKeySet — whether the sibling `orcarouter` API provider holds the
- * key an OpenCode OrcaRouter wrapper inherits at spawn
- * time. `false` covers BOTH "sibling has no key" and
- * "sibling was deleted" — the server injects the key only
- * when that provider exists and holds one, so either way
- * the wrapper cannot authenticate. `null` is for a caller
- * that genuinely cannot tell (no provider list yet) and,
- * like `runtime`, is never reported as missing.
+ * keySetFor — tri-state lookup for a stored or inherited key. It must
+ * return `true`/`false` when known and `null` or another
+ * non-boolean when unknown.
+ * envVarSet — tri-state lookup for an environment credential. An
+ * explicitly empty configured value is `false`; a missing
+ * or redacted value is unknown and must not be reported.
*
* `blocked` outranks `disabled`: a provider whose CLI isn't installed can't be
* enabled at all, so it belongs in the "needs setup" bucket whichever way its
@@ -1058,7 +1132,12 @@ export const PROVIDER_CARD_STATE = Object.freeze({
*
* @returns {{state: string, missing: {code: string, label: string}[]}}
*/
-export const providerCardState = (provider, { runtime = null, status = null, orcaRouterKeySet = null } = {}) => {
+export const providerCardState = (provider, {
+ runtime = null,
+ status = null,
+ keySetFor = null,
+ envVarSet = null,
+} = {}) => {
// The server publishes its own verdict on `GET /api/providers`
// (`missingPrerequisites`, from server/lib/providerPrerequisites.js) and
// routes the fallback chain on exactly that computation. Where it has an
@@ -1091,19 +1170,15 @@ export const providerCardState = (provider, { runtime = null, status = null, orc
if (runtime && runtime.installed === false && !resolvesOutsidePortosPath(provider)) {
addMissing('runtime', `${runtime.label || 'Runtime'} is not installed`);
}
- if (!published) {
- // API providers auth solely via the stored key — but only an endpoint outside
- // the private network actually needs one. The server attaches `Authorization`
- // only when a key is stored, so a keyless call to loopback, a LAN box, or a
- // tailnet peer running LM Studio / Ollama works exactly as configured.
- if (isApiProvider(provider) && provider?.hasApiKey !== true && !isPrivateNetworkEndpoint(provider?.endpoint)) {
- addMissing('apiKey', 'API key is not set');
- }
- // The OpenCode OrcaRouter wrappers carry no key of their own — theirs lives
- // on the sibling API provider, so that's the prerequisite to report.
- if (isOrcaRouterBackedProvider(provider) && orcaRouterKeySet === false) {
- addMissing('inheritedApiKey', 'OrcaRouter API provider has no API key');
- }
+ // The server's published findings remain authoritative for stored/inherited
+ // credentials. Env credentials are also derived here because their values
+ // are intentionally redacted in the payload; the tri-state lookup lets an
+ // explicitly empty value be reported without treating a redacted/absent
+ // value as missing.
+ const source = credentialSource(provider);
+ if (!published || source.kind === 'env') {
+ const missingCredential = credentialMissing(provider, { keySetFor, envVarSet });
+ if (missingCredential) addMissing(missingCredential.code, missingCredential.label);
}
if (missing.length > 0) return { state: PROVIDER_CARD_STATE.BLOCKED, missing };
diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.js
index 5d3a37b780..1fb7a3107c 100644
--- a/client/src/utils/providers.test.js
+++ b/client/src/utils/providers.test.js
@@ -33,6 +33,7 @@ import {
isApiProvider,
isProcessProvider,
providerRuntimeKey,
+ credentialSource,
providerCardState,
isPrivateNetworkEndpoint,
PROVIDER_CARD_STATE,
@@ -1209,6 +1210,44 @@ describe('providerRuntimeKey', () => {
});
});
+describe('credentialSource', () => {
+ it('identifies a stored public-provider key', () => {
+ expect(credentialSource({ id: 'cloud', type: 'api', endpoint: 'https://api.example.com/v1' }))
+ .toEqual({ kind: 'stored', ref: 'cloud' });
+ });
+
+ it('does not require a credential for a local API endpoint', () => {
+ expect(credentialSource({ id: 'ollama', type: 'api', endpoint: 'http://localhost:11434/v1', hasApiKey: false }))
+ .toEqual({ kind: 'none', ref: null });
+ });
+
+ it('identifies an inherited OrcaRouter key', () => {
+ expect(credentialSource({ id: 'opencode-orcarouter', type: 'cli', orcarouterBacked: true }))
+ .toEqual({ kind: 'inherited', ref: 'orcarouter' });
+ });
+
+ it('identifies env credentials from explicit metadata and conventional names', () => {
+ expect(credentialSource({
+ id: 'bedrock', type: 'cli', secretEnvVars: ['AWS_BEARER_TOKEN_BEDROCK'], envVars: { AWS_BEARER_TOKEN_BEDROCK: '' },
+ })).toEqual({ kind: 'env', ref: 'AWS_BEARER_TOKEN_BEDROCK' });
+ expect(credentialSource({
+ id: 'claude-ollama', type: 'cli', envVars: { ANTHROPIC_AUTH_TOKEN: 'ollama' },
+ })).toEqual({ kind: 'env', ref: 'ANTHROPIC_AUTH_TOKEN' });
+ });
+
+ it('lets a wrapper carrying its own key stand down from inheritance', () => {
+ expect(credentialSource({ id: 'wrapper', type: 'cli', apiKey: 'sk-example', orcarouterBacked: true }))
+ .toEqual({ kind: 'stored', ref: 'wrapper' });
+ });
+
+ it('covers the shipped Bedrock and Claude-Ollama provider shapes', () => {
+ expect(credentialSource(SHIPPED_PROVIDERS.providers['claude-code-bedrock']))
+ .toEqual({ kind: 'env', ref: 'AWS_BEARER_TOKEN_BEDROCK' });
+ expect(credentialSource(SHIPPED_PROVIDERS.providers['claude-ollama']))
+ .toEqual({ kind: 'env', ref: 'ANTHROPIC_AUTH_TOKEN' });
+ });
+});
+
describe('providerCardState', () => {
const cli = (over = {}) => ({ id: 'p1', type: 'cli', command: 'opencode', enabled: true, ...over });
const cloudApi = (over = {}) => ({ id: 'p2', type: 'api', endpoint: 'https://api.example.com/v1', enabled: true, ...over });
@@ -1277,11 +1316,47 @@ describe('providerCardState', () => {
it('blocks an OrcaRouter wrapper when the sibling API provider holds no key', () => {
const wrapper = cli({ id: 'opencode-orcarouter', orcarouterBacked: true });
- expect(providerCardState(wrapper, { orcaRouterKeySet: false }).missing)
+ expect(providerCardState(wrapper, { keySetFor: id => id === 'orcarouter' ? false : null }).missing)
.toEqual([{ code: 'inheritedApiKey', label: 'OrcaRouter API provider has no API key' }]);
// Sibling absent from the list = unknown, which must not accuse the wrapper.
- expect(providerCardState(wrapper, { orcaRouterKeySet: null }).state).toBe(PROVIDER_CARD_STATE.READY);
- expect(providerCardState(wrapper, { orcaRouterKeySet: true }).state).toBe(PROVIDER_CARD_STATE.READY);
+ expect(providerCardState(wrapper, { keySetFor: () => null }).state).toBe(PROVIDER_CARD_STATE.READY);
+ expect(providerCardState(wrapper, { keySetFor: () => true }).state).toBe(PROVIDER_CARD_STATE.READY);
+ });
+
+ it('does not require the inherited key when a wrapper carries its own key', () => {
+ const wrapper = cli({ id: 'opencode-orcarouter', apiKey: 'sk-example', orcarouterBacked: true });
+ expect(providerCardState(wrapper, { keySetFor: id => id === wrapper.id })).toEqual({
+ state: PROVIDER_CARD_STATE.READY,
+ missing: [],
+ });
+ });
+
+ it('blocks an env-credential provider whose configured value is empty, naming the variable', () => {
+ const readiness = providerCardState(cli({
+ id: 'claude-code-bedrock',
+ envVars: { AWS_BEARER_TOKEN_BEDROCK: '' },
+ secretEnvVars: ['AWS_BEARER_TOKEN_BEDROCK'],
+ }));
+ expect(readiness.state).toBe(PROVIDER_CARD_STATE.BLOCKED);
+ expect(readiness.missing).toEqual([{
+ code: 'envVar',
+ label: 'AWS_BEARER_TOKEN_BEDROCK environment variable is not set',
+ }]);
+ });
+
+ it('accepts a configured env credential', () => {
+ expect(providerCardState(cli({
+ id: 'claude-ollama',
+ envVars: { ANTHROPIC_AUTH_TOKEN: 'ollama' },
+ })).state).toBe(PROVIDER_CARD_STATE.READY);
+ });
+
+ it('does not treat an unknown env lookup as a missing credential', () => {
+ expect(providerCardState(cli({
+ id: 'claude-code-bedrock',
+ envVars: { AWS_BEARER_TOKEN_BEDROCK: '***' },
+ secretEnvVars: ['AWS_BEARER_TOKEN_BEDROCK'],
+ }), { envVarSet: () => null }).state).toBe(PROVIDER_CARD_STATE.READY);
});
it('benches an enabled provider the server marked unavailable', () => {
diff --git a/server/lib/providerPrerequisites.js b/server/lib/providerPrerequisites.js
index fd1b8db510..69d605d99e 100644
--- a/server/lib/providerPrerequisites.js
+++ b/server/lib/providerPrerequisites.js
@@ -28,8 +28,10 @@
* Same for `orcaRouterKeySet`: `false` is "the sibling holds no key", `null` is
* "the caller cannot tell". Only a definite negative produces a finding.
*
- * Credentials carried in a secret env var (Bedrock, an Ollama auth token) are
- * deliberately NOT covered here yet — that is issue #4612.
+ * Credentials carried in a secret env var (Bedrock, an Ollama auth token) stay
+ * presentation-only here: the provider card resolves them from the sanitized
+ * env-var metadata, while routing must not assume the server can inspect the
+ * process environment that will ultimately run the provider.
*/
import { PROVIDER_TYPES } from './aiToolkit/constants.js';
@@ -183,9 +185,9 @@ export const providerPrerequisites = (provider, { runtime = null, orcaRouterKeyS
&& !isPrivateNetworkEndpoint(provider?.endpoint)) {
missing.push({ code: 'apiKey', label: 'API key is not set' });
}
- // The OpenCode OrcaRouter wrappers carry no key of their own — theirs lives on
- // the sibling API provider, so that's the prerequisite to report.
- if (provider?.orcarouterBacked === true && orcaRouterKeySet === false) {
+ // OpenCode OrcaRouter wrappers normally inherit from the sibling API
+ // provider, but an explicitly stored wrapper key takes precedence at spawn.
+ if (provider?.orcarouterBacked === true && !providerHasApiKey(provider) && orcaRouterKeySet === false) {
missing.push({ code: 'inheritedApiKey', label: 'OrcaRouter API provider has no API key' });
}
@@ -213,8 +215,8 @@ export const describeMissingPrerequisites = (missing) =>
* can legitimately authenticate another way — a secret env var (Bedrock's AWS
* credentials, an Ollama auth token), or an OrcaRouter wrapper carrying its own
* key rather than the sibling's. Routing on those would take working providers
- * out of the chain, so they stay presentation-only until #4612 teaches this
- * module about env-var credentials; then they can move into this list.
+ * out of the chain, so they stay presentation-only. The provider card may
+ * report those credentials separately without changing the routing gate.
*/
export const ROUTING_BLOCKING_CODES = Object.freeze(['runtime']);
diff --git a/server/lib/providerPrerequisites.test.js b/server/lib/providerPrerequisites.test.js
index df1b93a46a..1310821c9a 100644
--- a/server/lib/providerPrerequisites.test.js
+++ b/server/lib/providerPrerequisites.test.js
@@ -126,6 +126,16 @@ describe('providerPrerequisites', () => {
expect(providerPrerequisites(wrapper, { orcaRouterKeySet: null }).met).toBe(true);
});
+ it('does not demand the sibling key when the wrapper carries its own key', () => {
+ const wrapper = cli({
+ id: 'opencode-orcarouter',
+ command: 'opencode',
+ orcarouterBacked: true,
+ apiKey: 'sk-example',
+ });
+ expect(providerPrerequisites(wrapper, { orcaRouterKeySet: false }).met).toBe(true);
+ });
+
it('collects every finding rather than stopping at the first', () => {
const wrapper = { id: 'x', type: 'api', endpoint: 'https://api.example.com', orcarouterBacked: true };
const result = providerPrerequisites(wrapper, {
diff --git a/server/routes/providers.js b/server/routes/providers.js
index 6999ce4033..a676e8607b 100644
--- a/server/routes/providers.js
+++ b/server/routes/providers.js
@@ -52,7 +52,10 @@ let runtimeSetupInFlight = false;
/**
* Sanitize a provider object for client responses.
- * Strips apiKey (replaces with hasApiKey boolean) and redacts secretEnvVars values.
+ * Strips apiKey (replaces with hasApiKey boolean) and redacts secretEnvVars
+ * values. An explicitly empty secret value stays empty so the client can
+ * distinguish "configured but blank" from an unknown redacted value when it
+ * paints provider readiness.
*/
const sanitizeProvider = (provider) => {
if (!provider) return provider;
@@ -67,7 +70,7 @@ const sanitizeProvider = (provider) => {
if (Array.isArray(secretEnvVars)) {
for (const key of secretEnvVars) {
if (key in sanitized.envVars) {
- sanitized.envVars[key] = '***';
+ sanitized.envVars[key] = sanitized.envVars[key] === '' ? '' : '***';
}
}
}
diff --git a/server/routes/providers.prerequisites.test.js b/server/routes/providers.prerequisites.test.js
index 68aba47783..1dbb2ad7b4 100644
--- a/server/routes/providers.prerequisites.test.js
+++ b/server/routes/providers.prerequisites.test.js
@@ -18,6 +18,10 @@ const { createPortOSProviderRoutes } = await import('./providers.js');
const CODEX = { id: 'codex', name: 'Codex CLI', type: 'cli', command: 'codex', envVars: {} };
const CLAUDE = { id: 'claude-code', name: 'Claude Code', type: 'cli', command: 'claude', envVars: {} };
+const BEDROCK = {
+ id: 'claude-code-bedrock', name: 'Claude Code Bedrock', type: 'cli', command: 'claude',
+ envVars: { AWS_BEARER_TOKEN_BEDROCK: '' }, secretEnvVars: ['AWS_BEARER_TOKEN_BEDROCK'],
+};
const KEYLESS_CLOUD = { id: 'openai', name: 'OpenAI', type: 'api', endpoint: 'https://api.example.com/v1', envVars: {} };
const LOCAL_API = { id: 'lmstudio', name: 'LM Studio', type: 'api', endpoint: 'http://localhost:1234/v1', envVars: {} };
@@ -80,4 +84,21 @@ describe('#4611: GET /api/providers publishes each provider\'s prerequisites', (
expect(byId.codex).toHaveProperty('canRefreshModels');
expect(byId.codex).not.toHaveProperty('apiKey');
});
+
+ it('preserves an explicitly empty secret env value for readiness to classify', async () => {
+ const byId = providersById(await request(appWith([BEDROCK])).get('/api/providers'));
+
+ expect(byId['claude-code-bedrock'].envVars.AWS_BEARER_TOKEN_BEDROCK).toBe('');
+ expect(byId['claude-code-bedrock'].secretEnvVars).toEqual(['AWS_BEARER_TOKEN_BEDROCK']);
+ });
+
+ it('continues redacting a configured secret env value', async () => {
+ const configured = {
+ ...BEDROCK,
+ envVars: { ...BEDROCK.envVars, AWS_BEARER_TOKEN_BEDROCK: 'token-example' },
+ };
+ const byId = providersById(await request(appWith([configured])).get('/api/providers'));
+
+ expect(byId['claude-code-bedrock'].envVars.AWS_BEARER_TOKEN_BEDROCK).toBe('***');
+ });
});