Skip to content

Commit 806c9ff

Browse files
committed
fix(xai): block service tier on OAuth gateway
1 parent 3c5a34f commit 806c9ff

6 files changed

Lines changed: 60 additions & 18 deletions

File tree

‎src/providers/fastwire.ts‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function registryDefaultForModel(
116116
modelId: string,
117117
inbound: InboundWire,
118118
authMode: ProviderAuthKind | undefined,
119-
): string | undefined {
119+
): { adapter: string; forwardCallerServiceTier?: boolean } | undefined {
120120
const normalizedModelId = modelId.trim().toLowerCase();
121121
if (!Object.hasOwn(defaults, normalizedModelId)) return undefined;
122122
const declared = defaults[normalizedModelId];
@@ -128,14 +128,20 @@ function registryDefaultForModel(
128128
}
129129
}
130130
const wire = typeof declared === "string" ? declared : declared.wire;
131-
return MODEL_ADAPTER_OVERRIDE_ALLOWED.has(wire) ? wire : undefined;
131+
if (!MODEL_ADAPTER_OVERRIDE_ALLOWED.has(wire)) return undefined;
132+
return {
133+
adapter: wire,
134+
...(typeof declared !== "string" && declared.forwardCallerServiceTier !== undefined
135+
? { forwardCallerServiceTier: declared.forwardCallerServiceTier }
136+
: {}),
137+
};
132138
}
133139

134140
function resolvePolicyAdapter(
135141
authority: FastPolicyAuthority,
136142
modelId: string,
137143
inbound: InboundWire,
138-
): { adapter: string; hardPinned: boolean } {
144+
): { adapter: string; hardPinned: boolean; forwardCallerServiceTier?: boolean } {
139145
// Hard pins and configured overrides deliberately use the same exact-key semantics as
140146
// resolveWireProtocolOverride(). Registry defaults alone normalize ids at their boundary.
141147
const hardPin = Object.hasOwn(authority.hardPins, modelId)
@@ -156,7 +162,15 @@ function resolvePolicyAdapter(
156162
inbound,
157163
authority.providerAuthMode,
158164
);
159-
if (registryDefault !== undefined) return { adapter: registryDefault, hardPinned: false };
165+
if (registryDefault !== undefined) {
166+
return {
167+
adapter: registryDefault.adapter,
168+
hardPinned: false,
169+
...(registryDefault.forwardCallerServiceTier !== undefined
170+
? { forwardCallerServiceTier: registryDefault.forwardCallerServiceTier }
171+
: {}),
172+
};
173+
}
160174
}
161175
}
162176
return { adapter: authority.providerAdapter, hardPinned: false };
@@ -167,7 +181,11 @@ export function resolveFastPolicy(
167181
modelId: string,
168182
inbound: InboundWire = "responses",
169183
): ResolvedFastPolicy {
170-
const { adapter, hardPinned } = resolvePolicyAdapter(authority, modelId, inbound);
184+
const { adapter, hardPinned, forwardCallerServiceTier } = resolvePolicyAdapter(
185+
authority,
186+
modelId,
187+
inbound,
188+
);
171189
const exactCapability = exactModelValue(authority.capability.models, modelId);
172190
const capability = authority.capability.provider === false
173191
? false
@@ -185,6 +203,7 @@ export function resolveFastPolicy(
185203
// tier still needs the final wire's forwarding permission.
186204
const forwardCallerTier = capability !== false
187205
&& callerWireAvailable
206+
&& forwardCallerServiceTier !== false
188207
&& (adapter !== "openai-chat" || authority.capability.chatServiceTier === true);
189208

190209
let eligibility: ResolvedFastPolicy["eligibility"];

‎src/providers/registry.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export type ModelWireDefault = string | {
3636
wire: string;
3737
inbound: readonly InboundWire[];
3838
authModes?: readonly ProviderAuthKind[];
39+
/** Whether this registry-selected route may relay a caller-owned service_tier. */
40+
forwardCallerServiceTier?: boolean;
3941
};
4042

4143
export interface ResponsesTerminalRepairPolicy {
@@ -1020,8 +1022,18 @@ export const PROVIDER_REGISTRY: readonly ProviderRegistryEntry[] = [
10201022
// Codex Responses traffic can relay xAI's SSE as it arrives instead of waiting for the
10211023
// Chat Completions compatibility stream to flush at the end of a reasoning turn.
10221024
modelWireDefaults: {
1023-
"grok-4.6": { wire: "openai-responses", inbound: ["responses"], authModes: ["oauth"] },
1024-
"grok-4.5": { wire: "openai-responses", inbound: ["responses"], authModes: ["oauth"] },
1025+
"grok-4.6": {
1026+
wire: "openai-responses",
1027+
inbound: ["responses"],
1028+
authModes: ["oauth"],
1029+
forwardCallerServiceTier: false,
1030+
},
1031+
"grok-4.5": {
1032+
wire: "openai-responses",
1033+
inbound: ["responses"],
1034+
authModes: ["oauth"],
1035+
forwardCallerServiceTier: false,
1036+
},
10251037
},
10261038
// Vision lineup per docs.x.ai model-capabilities/images/understanding: the grok-4.x chat
10271039
// models accept image input (JPEG/PNG, URL or base64). Without this the catalog leaves

‎src/providers/service-tier.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ function cloneRegistryWireDefaults(
5050
...(declaration.authModes
5151
? { authModes: Object.freeze([...declaration.authModes]) }
5252
: {}),
53+
...(declaration.forwardCallerServiceTier !== undefined
54+
? { forwardCallerServiceTier: declaration.forwardCallerServiceTier }
55+
: {}),
5356
});
5457
}
5558
return Object.freeze(clone);
@@ -221,13 +224,11 @@ export function serviceTierSupportFromPolicy(
221224
): boolean | undefined {
222225
if (policy.eligibility === "eligible") return true;
223226
if (policy.eligibility === "unclassified") {
224-
// B1 regression guard: an unclassified chat-wire route whose final adapter will not
225-
// forward any tier cannot serialize service_tier, so projecting "unknown" would let
226-
// require.serviceTier: "unsupported" routing stop matching groq/ollama-class providers
227-
// that main projected as false. Chat + no forwarding stays a definitive false; a
228-
// chat route with chatServiceTier: true (forwarding allowed) keeps the historical
229-
// unknown, as does every unclassified Responses-wire route.
230-
if (policy.adapter === "openai-chat" && !policy.forwardCallerTier) return false;
227+
// An unclassified route that cannot forward a caller tier has definitive negative
228+
// evidence even when its adapter can normally serialize service_tier. This covers both
229+
// Chat routes without chatServiceTier and a registry default that explicitly closes a
230+
// subscription gateway. Generic unclassified Responses routes still project unknown.
231+
if (!policy.forwardCallerTier) return false;
231232
return undefined;
232233
}
233234
return false;

‎structure/04_transports-and-sidecars.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ requires a compatible FastWire mapping on the final adapter and an eligible poli
5151
`fastMode: false` drops it. On classified Chat routes, `chatServiceTier` separately authorizes
5252
foreign caller values; an exact-model `true` does not grant that forwarding permission. On
5353
unclassified Chat routes it gates every caller tier because no canonical Fast capability has been
54-
validated. Exact `false`
54+
validated. An object-form registry wire default may also set `forwardCallerServiceTier: false` to
55+
close a known subscription gateway while leaving generic unclassified Responses passthrough
56+
unchanged. Exact `false`
5557
narrows provider defaults, and provider-level `supportsServiceTier: false` cannot be reopened.
5658
Capability is namespaced by the selected provider and model; model-name similarity and adapter type
5759
alone never opt a gateway in.
@@ -75,7 +77,9 @@ declares the Grok 4.5 and 4.6 subscription models as Responses backends, so only
7577
Responses traffic for those exact models selects `openai-responses`. API-key requests, translated
7678
Chat/Anthropic callers, other Grok models, and explicit model adapter overrides retain their
7779
existing wire. This lets Codex receive native xAI SSE deltas as they arrive without widening the
78-
credential or compatibility boundary.
80+
credential or compatibility boundary. These OAuth subscription defaults drop caller-owned
81+
`service_tier`; they neither advertise nor inject Fast. The API-key transport remains governed by
82+
its separate capability declaration.
7983

8084
OpenCode Go documents `gpt-5.6-luna` on `/zen/go/v1/responses` while sibling models use its Chat or
8185
Anthropic endpoints. The built-in preset therefore selects `openai-responses` only for Luna and

‎tests/fastwire-policy.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,11 @@ describe("resolveFastPolicy matrix", () => {
268268
authMode: "key" as const,
269269
});
270270

271-
expect(fastPolicyForModel(oauthProvider, "grok-4.6", "xai").adapter)
272-
.toBe("openai-responses");
271+
expect(fastPolicyForModel(oauthProvider, "grok-4.6", "xai")).toMatchObject({
272+
adapter: "openai-responses",
273+
eligibility: "unclassified",
274+
forwardCallerTier: false,
275+
});
273276
expect(fastPolicyForModel(keyProvider, "grok-4.6", "xai").adapter)
274277
.toBe("openai-chat");
275278
});

‎tests/server-xai-responses-streaming.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function config(): OcxConfig {
4949
port: 0,
5050
hostname: "127.0.0.1",
5151
defaultProvider: "xai",
52+
fastMode: true,
5253
providers: {
5354
xai: {
5455
adapter: "openai-chat",
@@ -169,6 +170,7 @@ describe("xAI OAuth Responses streaming", () => {
169170
input: "hello",
170171
stream: true,
171172
store: false,
173+
service_tier: "priority",
172174
reasoning: { effort: "xhigh", summary: "auto" },
173175
}),
174176
});
@@ -196,6 +198,7 @@ describe("xAI OAuth Responses streaming", () => {
196198
expect(outboundBody?.model).toBe("grok-4.6");
197199
expect(outboundBody?.input).toBe("hello");
198200
expect(outboundBody?.stream).toBe(true);
201+
expect(outboundBody?.service_tier).toBeUndefined();
199202
expect(outboundBody?.reasoning).toMatchObject({ effort: "xhigh" });
200203
expect(outboundBody?.messages).toBeUndefined();
201204
expect(outboundBody?.reasoning_effort).toBeUndefined();

0 commit comments

Comments
 (0)