From aacd24c537f00a522be2f782445b1ff241810b65 Mon Sep 17 00:00:00 2001 From: bitkyc08-arch Date: Wed, 26 Aug 2026 01:51:03 +0900 Subject: [PATCH] fix(fastwire): do not read a non-authoritative tier echo as a downgrade The ChatGPT-internal Codex backend returns service_tier: default even on turns it scheduled as priority, so treating that echo as a verdict marked every Fast request response-declined. That is a false negative, and it also skews cost attribution because fastOutcome drives priority pricing. TierObservationContext gains responseTierAuthoritative. Absent means assume authoritative, so the public API path is unchanged; core.ts sets it false only for the canonical ChatGPT-forward destination, where the echo can neither confirm nor deny Fast. The raw echo is still recorded - this suppresses a verdict, not the evidence. Driven red first: removing the guard fails exactly the new case. --- src/providers/fastwire.ts | 8 ++++- src/server/responses/core.ts | 10 +++++- src/types/provider.ts | 9 ++++++ tests/fastwire-observability.test.ts | 48 ++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/providers/fastwire.ts b/src/providers/fastwire.ts index 9098bd9df9..34116e7133 100644 --- a/src/providers/fastwire.ts +++ b/src/providers/fastwire.ts @@ -246,6 +246,7 @@ export function tierObservationContext( policy: ResolvedFastPolicy, fastMode: boolean | undefined, callerTier: string | undefined, + responseTierAuthoritative?: boolean, ): TierObservationContext { return { capability: policy.capability, @@ -253,6 +254,7 @@ export function tierObservationContext( fastWire: policy.fastWire, demandDecision: fastMode === true ? "force-fast" : fastMode === false ? "force-default" : "inherit", ...(callerTier !== undefined ? { callerTier } : {}), + ...(responseTierAuthoritative !== undefined ? { responseTierAuthoritative } : {}), }; } @@ -344,7 +346,11 @@ export function createAdapterTierMetadata( const responseCanConfirmFast = effectiveFastRequested && context.eligibility === "eligible" - && wireValue !== null; + && wireValue !== null + // A destination whose echo is not authoritative can neither confirm nor deny Fast. The + // ChatGPT-internal Codex backend echoes "default" on priority-scheduled turns, so believing + // it reported every Fast request as `response-declined` (#2558). + && context.responseTierAuthoritative !== false; return { outcome, observeResponseServiceTier(value: unknown) { diff --git a/src/server/responses/core.ts b/src/server/responses/core.ts index e66e85bd6f..cc97021462 100644 --- a/src/server/responses/core.ts +++ b/src/server/responses/core.ts @@ -1701,7 +1701,15 @@ async function applyFinalRouteRequestNormalization(args: { ); const modelServiceTierSupport = serviceTierSupportFromPolicy(fastPolicy); const callerTier = parsed.options.serviceTier; - parsed.options.tierObservation = tierObservationContext(fastPolicy, config.fastMode, callerTier); + // The ChatGPT-internal Codex backend echoes `service_tier: "default"` even on turns it + // scheduled as priority, so its echo cannot confirm OR deny Fast. Believing it reported every + // Fast request as `response-declined` (#2558). The public API's echo stays authoritative. + parsed.options.tierObservation = tierObservationContext( + fastPolicy, + config.fastMode, + callerTier, + isCanonicalOpenAiForwardProvider(route.provider) ? false : undefined, + ); parsed.options.tierDecision = decideTier(fastPolicy, config.fastMode, callerTier); parsed.options.serviceTier = tierValueAfterDecision(parsed.options.tierDecision, callerTier); if (fastPolicy.capability === true && fastPolicy.fastWire === null) { diff --git a/src/types/provider.ts b/src/types/provider.ts index e6a66d577f..de490414ca 100644 --- a/src/types/provider.ts +++ b/src/types/provider.ts @@ -115,6 +115,15 @@ export interface TierObservationContext { fastWire: FastWire | null; demandDecision: "force-fast" | "force-default" | "inherit"; callerTier?: string; + /** + * Whether the destination's echoed `service_tier` is authoritative about Fast scheduling. + * + * The ChatGPT-internal Codex backend returns `service_tier: "default"` on turns that were in + * fact scheduled as priority, so treating its echo as a downgrade produced a false + * `response-declined` on every Fast request (#2558). Absent means "assume authoritative", + * preserving the behaviour for the public API where the echo does mean what it says. + */ + responseTierAuthoritative?: boolean; } export type TierDecision = diff --git a/tests/fastwire-observability.test.ts b/tests/fastwire-observability.test.ts index d712a038ad..3a21681cae 100644 --- a/tests/fastwire-observability.test.ts +++ b/tests/fastwire-observability.test.ts @@ -827,3 +827,51 @@ describe("FastWire gate and compatibility fingerprint", () => { expect(buildBehaviorFingerprintV1(base)).not.toBe(buildBehaviorFingerprintV1(performance)); }); }); + +describe("#2558 a non-authoritative destination cannot confirm or deny Fast", () => { + /** + * The ChatGPT-internal Codex backend echoes service_tier: "default" even on turns it + * scheduled as priority. Believing that echo classified every Fast request as + * response-declined, which is a false negative that also drives priority cost attribution. + */ + const nonAuthoritative = () => observation({ responseTierAuthoritative: false }); + + test("an echoed default is not a downgrade when the destination is not authoritative", () => { + const tracker = createAdapterTierMetadata( + nonAuthoritative(), + { kind: "set", value: "priority" }, + "service-tier", + "priority", + )!; + tracker.observeResponseServiceTier("default"); + expect(tracker.outcome.fastDowngradeReason).toBeUndefined(); + expect(tracker.outcome.fastOutcome).not.toBe("downgraded"); + // The raw echo is still recorded — this suppresses a verdict, not the evidence. + expect(tracker.outcome.responseServiceTier).toBe("default"); + }); + + test("the same echo IS a downgrade on an authoritative destination", () => { + const tracker = createAdapterTierMetadata( + observation(), + { kind: "set", value: "priority" }, + "service-tier", + "priority", + )!; + tracker.observeResponseServiceTier("default"); + expect(tracker.outcome.fastOutcome).toBe("downgraded"); + expect(tracker.outcome.fastDowngradeReason).toBe("response-declined"); + }); + + test("an omitted flag keeps the authoritative default", () => { + // Absent must mean "assume authoritative" so the public API path is unchanged. + const tracker = createAdapterTierMetadata( + observation({}), + { kind: "set", value: "priority" }, + "service-tier", + "priority", + )!; + tracker.observeResponseServiceTier("default"); + expect(tracker.outcome.fastOutcome).toBe("downgraded"); + }); +}); +