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

address review (claude+codex): map Bedrock id against settings.json env; tighten Claude-id guard

Adam Eivy3b7adb77b268
diff --git a/server/lib/providerModels.js b/server/lib/providerModels.js
index ce5bd9cd03..b8b39790d5 100644
--- a/server/lib/providerModels.js
+++ b/server/lib/providerModels.js
@@ -70,9 +70,10 @@ const detectClaudeFamily = (id) => {
*
* - No-op when Bedrock mode is off, the id is empty/non-string, or it already
* carries a region/`anthropic.` prefix.
- * - No-op for non-Claude ids (codex `gpt-5`, gemini, etc.) — only ids with a
- * recognized Claude family or a `claude…` prefix are rewritten, so applying
- * this at a shared argv chokepoint can't corrupt another vendor's model.
+ * - No-op for any id that doesn't contain `claude` (codex `gpt-5`, gemini, a
+ * custom local alias like `my-sonnet-lora`, etc.) — only Claude ids are
+ * Bedrock-mappable, so applying this at a shared argv chokepoint can't
+ * corrupt another vendor's model.
* - Prefers the matching `ANTHROPIC_DEFAULT_<FAMILY>_MODEL` env value when it
* is itself a region-prefixed Bedrock id (the wrapper's exact choice); else
* falls back to a `global.anthropic.<id>` prefix-rewrite.
@@ -85,8 +86,8 @@ export function toBedrockModelId(id, env = process.env) {
if (!isBedrockEnabled(env)) return id;
if (typeof id !== 'string' || !id) return id;
if (hasBedrockRegionPrefix(id)) return id;
+ if (!/claude/i.test(id)) return id; // not a Claude id — leave alone
const family = detectClaudeFamily(id);
- if (!family && !/^claude[-.]/i.test(id)) return id; // not a Claude id — leave alone
if (family) {
const override = env?.[BEDROCK_FAMILY_ENV[family]];
if (hasBedrockRegionPrefix(override)) return override;
diff --git a/server/lib/providerModels.test.js b/server/lib/providerModels.test.js
index f51226f5db..e47c92c8e2 100644
--- a/server/lib/providerModels.test.js
+++ b/server/lib/providerModels.test.js
@@ -253,8 +253,13 @@ describe('providerModels', () => {
}
});
- it('leaves non-Claude vendor ids untouched even with Bedrock on', () => {
- for (const id of ['gpt-5', 'gemini-2.5-pro', 'o1-preview']) {
+ it('leaves non-Claude ids untouched even with Bedrock on (must contain "claude")', () => {
+ for (const id of [
+ 'gpt-5', 'gemini-2.5-pro', 'o1-preview',
+ // A custom alias that merely contains a family word but isn't a Claude
+ // id must NOT be rewritten (would otherwise become global.anthropic.*).
+ 'sonnet', 'my-sonnet-lora', 'opus-tune-v2',
+ ]) {
expect(toBedrockModelId(id, ON), id).toBe(id);
}
});
diff --git a/server/services/agentCliSpawning.js b/server/services/agentCliSpawning.js
index 4906def29c..7549a7e21e 100644
--- a/server/services/agentCliSpawning.js
+++ b/server/services/agentCliSpawning.js
@@ -233,8 +233,15 @@ export function createStreamJsonParser() {
/**
* Build spawn command and arguments for a CLI provider.
* Returns { command, args, stdinMode } based on provider type.
+ *
+ * `settingsEnv` is the `~/.claude/settings.json` env block (from
+ * `getClaudeSettingsEnv()`). It MUST be folded into the Bedrock-mapping env
+ * because that is how a Bedrock host commonly supplies `CLAUDE_CODE_USE_BEDROCK`
+ * to the spawned child (see the spawn env below at the `claudeSettingsEnv`
+ * merge) — without it, a settings-only Bedrock box would map against an env
+ * missing the flag and still emit a bare, Bedrock-invalid `--model`.
*/
-export function buildCliSpawnConfig(provider, model) {
+export function buildCliSpawnConfig(provider, model, settingsEnv = {}) {
const providerId = provider?.id || 'claude-code';
const effectiveModel = providerId === 'codex' && model === 'codex-configured-default' ? null : model;
@@ -284,8 +291,10 @@ export function buildCliSpawnConfig(provider, model) {
if (effectiveModel) {
// Bedrock box: map a bare Claude id to its region-prefixed Bedrock form
// just-in-time (no-op off Bedrock / for already-prefixed or non-Claude ids).
+ // Env precedence mirrors the actual spawn env below: process.env <
+ // settingsEnv (~/.claude/settings.json) < provider.envVars.
const injectedModel = resolveBedrockCliModel(effectiveModel, {
- env: { ...process.env, ...provider?.envVars },
+ env: { ...process.env, ...settingsEnv, ...provider?.envVars },
providerId,
});
args.push('--model', injectedModel);
diff --git a/server/services/agentCliSpawning.test.js b/server/services/agentCliSpawning.test.js
index 4a28a96a88..094208df55 100644
--- a/server/services/agentCliSpawning.test.js
+++ b/server/services/agentCliSpawning.test.js
@@ -186,6 +186,50 @@ describe('buildCliSpawnConfig', () => {
expect(config.command).toBe('agy');
expect(config.args).toEqual(['--print', '--dangerously-skip-permissions']);
});
+
+ describe('Bedrock model-id mapping', () => {
+ // buildCliSpawnConfig reads process.env for the Bedrock signal; isolate the
+ // tests from whatever the host/CI environment happens to set.
+ let savedBedrock;
+ beforeEach(() => {
+ savedBedrock = process.env.CLAUDE_CODE_USE_BEDROCK;
+ delete process.env.CLAUDE_CODE_USE_BEDROCK;
+ });
+ afterEach(() => {
+ if (savedBedrock === undefined) delete process.env.CLAUDE_CODE_USE_BEDROCK;
+ else process.env.CLAUDE_CODE_USE_BEDROCK = savedBedrock;
+ });
+
+ const modelOf = (args) => args[args.indexOf('--model') + 1];
+
+ it('passes a bare Claude model through unchanged when Bedrock mode is off', () => {
+ const config = buildCliSpawnConfig({ id: 'claude-code', command: 'claude' }, 'claude-opus-4-8');
+ expect(modelOf(config.args)).toBe('claude-opus-4-8');
+ });
+
+ it('maps a bare Claude model when Bedrock comes ONLY from settings.json env (regression: #1521 blocking)', () => {
+ const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ // provider.envVars empty (plain claude-code), Bedrock supplied via the
+ // ~/.claude/settings.json env block — the case the original fix missed.
+ const config = buildCliSpawnConfig(
+ { id: 'claude-code', command: 'claude', envVars: {} },
+ 'claude-opus-4-8',
+ { CLAUDE_CODE_USE_BEDROCK: '1' },
+ );
+ expect(modelOf(config.args)).toBe('global.anthropic.claude-opus-4-8');
+ spy.mockRestore();
+ });
+
+ it('maps a bare Claude model when Bedrock comes from provider.envVars', () => {
+ const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ const config = buildCliSpawnConfig(
+ { id: 'claude-code', command: 'claude', envVars: { CLAUDE_CODE_USE_BEDROCK: '1' } },
+ 'claude-opus-4-8',
+ );
+ expect(modelOf(config.args)).toBe('global.anthropic.claude-opus-4-8');
+ spy.mockRestore();
+ });
+ });
});
describe('stream error containment', () => {
diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.js
index 2d79808c9a..034edf2b01 100644
--- a/server/services/agentLifecycle.js
+++ b/server/services/agentLifecycle.js
@@ -323,9 +323,16 @@ export async function spawnAgentForTask(task) {
cosEvents.emit('job:spawned', { jobId: task.metadata.jobId });
}
+ // Read ~/.claude/settings.json env BEFORE building the argv so the Bedrock
+ // model-id mapping in buildCliSpawnConfig sees the same CLAUDE_CODE_USE_BEDROCK
+ // the child is actually spawned with (the spawn helpers merge this env too).
+ // Without it, a host that supplies Bedrock mode only via settings.json would
+ // bake a bare, Bedrock-invalid --model into the argv. Cached (5-min TTL), so
+ // the spawn helper's own getClaudeSettingsEnv() call is effectively free.
+ const cliSettingsEnv = isClaudeCliProvider(provider) ? await getClaudeSettingsEnv() : {};
const cliConfig = isTui
? buildTuiSpawnConfig(provider, selectedModel)
- : buildCliSpawnConfig(provider, selectedModel);
+ : buildCliSpawnConfig(provider, selectedModel, cliSettingsEnv);
emitLog('success', `Spawning agent for task ${task.id}`, {
agentId,