Skip to content

Commit 57f0ec5

Browse files
committed
fix(config): trust the registry adapter only when the transport still matches
Automated review on #924 found the mirror of the defect the previous commit fixed. That one made validation too strict; this one made it too loose. A `preserveCustomDestination` registry row reused under a different endpoint keeps its own adapter at runtime — `routedProviderConfig()` honors `providerMatchesRegistryTransport()`, which returns false once the endpoint diverges. `volcengine-agent-plan` is such a row with an `openai-responses` registry adapter, so a config naming that id while pointing elsewhere with `adapter: "openai-chat"` passed validation on the registry's adapter while the Responses adapter never ran. The preference was accepted and then silently ignored. Validation now starts from `provider.adapter` unless the configured transport still matches the registry's documented one. Driven red first: the volcengine-agent-plan config loaded with source "file" before the fix and now returns "requires the openai-responses wire". 279 tests pass across the five affected files, typecheck clean.
1 parent bc628a9 commit 57f0ec5

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

‎src/config.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ import {
3636
type OcxProviderConfig,
3737
} from "./types";
3838
import { isCanonicalOpenAiForwardProvider, OPENAI_CODEX_PROVIDER_ID } from "./providers/openai-tiers";
39-
import { getProviderRegistryEntry, providerModelWireDefault } from "./providers/registry";
39+
import {
40+
getProviderRegistryEntry,
41+
providerMatchesRegistryTransport,
42+
providerModelWireDefault,
43+
} from "./providers/registry";
4044
import { resolveOpenAiVirtualModel } from "./providers/openai-virtual-models";
4145
import { parseDesktopProfile } from "./claude/desktop-profile";
4246
import { isCodexReasoningEffort, modelRecordValue } from "./reasoning-effort";
@@ -769,7 +773,20 @@ export function modelPreferHostedToolsConfigError(
769773
return `${field}.${key} cannot prefer ${tool}: the model does not support it`;
770774
}
771775
}
772-
let effectiveWire = resolveEffectiveWire(key, registry?.adapter ?? provider.adapter);
776+
// Start from the registry adapter only when this config still points at the registry's
777+
// documented transport. A `preserveCustomDestination` row reused under a different
778+
// endpoint keeps its own adapter at runtime (`routedProviderConfig()` honors
779+
// `providerMatchesRegistryTransport()`), so trusting `registry.adapter` there would
780+
// accept a preference the Responses adapter never sees. Raised by the automated
781+
// review on #924.
782+
const registryTransportMatches = typeof provider.baseUrl === "string"
783+
&& providerMatchesRegistryTransport(providerName, {
784+
baseUrl: provider.baseUrl,
785+
adapter: provider.adapter as OcxProviderConfig["adapter"],
786+
...(typeof provider.authMode === "string" ? { authMode: provider.authMode as OcxProviderConfig["authMode"] } : {}),
787+
});
788+
const baseWire = registryTransportMatches ? registry?.adapter ?? provider.adapter : provider.adapter;
789+
let effectiveWire = resolveEffectiveWire(key, baseWire);
773790
const virtualWireModel = resolveOpenAiVirtualModel(providerName, key)?.wireModelId;
774791
if (virtualWireModel && virtualWireModel !== key) {
775792
effectiveWire = resolveEffectiveWire(virtualWireModel, effectiveWire);

0 commit comments

Comments
 (0)