@bitkyc08/opencodex 2.95.0 → 2.97.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ocx.mjs +214 -19
- package/gui/dist/assets/{App-8yedBkhm.js → App-DuNhggE1.js} +18 -18
- package/gui/dist/assets/{Tray-erSMzxPG.js → Tray-CEw0y0jR.js} +1 -1
- package/gui/dist/assets/index-CynE_Rue.js +94 -0
- package/gui/dist/assets/{quota-summary-BK4VuQNc.js → quota-summary-VHFSlUuM.js} +1 -1
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/kiro/stream.ts +63 -4
- package/src/adapters/kiro-constants.ts +15 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/ollama-native.ts +21 -7
- package/src/adapters/openai-responses/canonical-forward.ts +50 -13
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/passthrough.ts +8 -8
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/openai-responses/transport.ts +17 -26
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/qoder/adapter.ts +1 -1
- package/src/adapters/qoder/image-input.ts +5 -2
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/outbound.ts +49 -2
- package/src/cli/agent.ts +44 -15
- package/src/cli/capabilities-agents-routing.ts +9 -0
- package/src/cli/capabilities-base.ts +25 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +5 -4
- package/src/cli/dispatch.ts +11 -176
- package/src/cli/ensure-desired-integrations.ts +4 -3
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +9 -2
- package/src/cli/link.ts +1 -1
- package/src/cli/message-command.ts +2 -1
- package/src/cli/message-mcp-command.ts +29 -0
- package/src/cli/registry.ts +12 -4
- package/src/cli/root.ts +8 -0
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +150 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/client/connect.ts +31 -14
- package/src/client/link-home.ts +3 -2
- package/src/client/machine-listener.ts +3 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/account-store.ts +1 -0
- package/src/codex/auth-context-provider.ts +15 -0
- package/src/codex/auth-context.ts +59 -122
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +6 -8
- package/src/codex/forward-transport-headers.ts +65 -36
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/installation-id.ts +72 -0
- package/src/codex/lineage.ts +13 -7
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/process-state.ts +5 -0
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/generated/compatibility-version.json +496 -192
- package/src/grok/sync.ts +10 -1
- package/src/images/loop.ts +2 -1
- package/src/lib/client-error-body.ts +184 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership.ts +4 -0
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/desktop-cli-handoff.d.mts +1 -1
- package/src/lib/desktop-cli-handoff.mjs +11 -1
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +14 -11
- package/src/lib/windows-owner-acl.ts +13 -6
- package/src/lib/windows-secret-acl.ts +2 -2
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/messaging/mcp-queue-rpc.ts +102 -0
- package/src/messaging/mcp-queue-server.ts +42 -0
- package/src/messaging/mcp-queue-tools.ts +39 -0
- package/src/oauth/anthropic-identity.ts +2 -6
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +41 -74
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +1 -1
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +4 -0
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/trace.ts +18 -0
- package/src/providers/anthropic-subscription.ts +25 -0
- package/src/providers/claude-cli-usage.ts +15 -67
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/quota/anthropic-decision-windows.ts +5 -19
- package/src/providers/quota/anthropic-usage-windows.ts +65 -0
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/request-pacing.ts +3 -2
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/parser-tools.ts +1 -0
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/responses/schema.ts +5 -2
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +56 -0
- package/src/server/audio-dictation.ts +3 -0
- package/src/server/audio-live.ts +8 -2
- package/src/server/audio-upstream.ts +2 -0
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +57 -27
- package/src/server/context-history.ts +14 -7
- package/src/server/images.ts +14 -5
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/live-sideband.ts +16 -2
- package/src/server/index/ollama-routes.ts +89 -0
- package/src/server/index/serve-options.ts +22 -4
- package/src/server/index/websocket-handler.ts +5 -3
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +4 -2
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/live.ts +30 -5
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/route-registry.ts +1 -1
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +1 -1
- package/src/server/messages-native.ts +12 -7
- package/src/server/messages-shared.ts +6 -2
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +79 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +9 -4
- package/src/server/responses/adapter-delivery.ts +5 -4
- package/src/server/responses/adapter-dispatch.ts +36 -30
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +22 -17
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/combo-required-tool-contract.ts +24 -12
- package/src/server/responses/compact.ts +89 -41
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +34 -12
- package/src/server/responses/core-combo-failure.ts +5 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +51 -33
- package/src/server/responses/core-errors.ts +22 -20
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +8 -1
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-build-error.ts +36 -0
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +26 -39
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +67 -48
- package/src/server/responses/request-sidecar-auth.ts +3 -1
- package/src/server/responses/request-transport.ts +35 -31
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/search.ts +13 -4
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +5 -2
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/types/config.ts +2 -0
- package/src/update/index.ts +133 -25
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +60 -27
- package/src/vision/describe.ts +4 -7
- package/src/web-search/executor.ts +4 -7
- package/src/web-search/loop.ts +31 -5
- package/gui/dist/assets/index-D7DCm5eQ.js +0 -94
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { conversationStateAccountId, releaseRequestOwnedMainOnOutcome, isKeyedRequestOwnedMain } from "../../codex/request-owned-affinity";
|
|
2
|
+
import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
|
|
1
3
|
import { captureAccountAutoPauseAttempt, wasPermanentAccountRefusal } from "../../oauth/account-auto-pause";
|
|
2
4
|
import type { OcxConfig, OcxProviderConfig, OcxParsedRequest } from "../../types";
|
|
3
5
|
import type { CodexAuthContext, CodexAuthPolicyConfig } from "../../codex/auth-context";
|
|
@@ -25,6 +27,7 @@ import { formatErrorResponse } from "../../bridge";
|
|
|
25
27
|
import { readBoundedResponseBody } from "../../lib/bounded-body";
|
|
26
28
|
import { upstreamErrorMessageFromPayload, isRateLimitOrQuotaFailureMessage } from "../../lib/errors";
|
|
27
29
|
import { isNonReplayableResponse, isTransientUpstreamStatus, SendBudgetExhaustedError } from "../../lib/upstream-retry";
|
|
30
|
+
import { applyClaudeBridgePoolSession } from "../claude-bridge-pool-session";
|
|
28
31
|
import {
|
|
29
32
|
codexWsPreOutputRefusalHold,
|
|
30
33
|
codexWsPreOutputRefusalOutcomeRecorded,
|
|
@@ -488,6 +491,8 @@ export interface CodexPoolAccountRetryArgs {
|
|
|
488
491
|
abortSignal?: AbortSignal;
|
|
489
492
|
onCodexAuthContextResolved?: (ctx: CodexAuthContext) => void;
|
|
490
493
|
deferCodexResetDerivedCooldown?: boolean;
|
|
494
|
+
/** Private Claude bridge pool identity; alternate selection completes it like the first pick. */
|
|
495
|
+
claudeBridgePoolSession?: string;
|
|
491
496
|
// Narrowed subset of HandleResponsesOptions: the retry rebuilds the adapter, so it
|
|
492
497
|
// needs the inbound scope or the retry could land on a different wire than the
|
|
493
498
|
// first attempt.
|
|
@@ -765,7 +770,9 @@ export async function retryCodexPoolOnAlternateAccount(
|
|
|
765
770
|
}
|
|
766
771
|
try {
|
|
767
772
|
retryAuthCtx ??= await resolveCodexAuthContext(
|
|
768
|
-
|
|
773
|
+
// Alternate selection keeps the initial Claude bridge pool identity; the retry's upstream
|
|
774
|
+
// headers are still built from uncompleted callerAuthHeaders below.
|
|
775
|
+
applyClaudeBridgePoolSession(callerAuthHeaders, { codexAccountMode: "pool" }, options),
|
|
769
776
|
config,
|
|
770
777
|
"pool",
|
|
771
778
|
{
|
|
@@ -886,7 +893,7 @@ export async function retryCodexPoolOnAlternateAccount(
|
|
|
886
893
|
retryHeaders = headersForCodexAuthContext(callerAuthHeaders, retryAuthCtx, options.codexAuthPolicy ?? config, route.modelId, options.admission);
|
|
887
894
|
retryProvider = applyCodexAuthContextToProvider(stripCodexRuntimeProviderFields(route.provider), retryAuthCtx, "pool");
|
|
888
895
|
} catch (error) {
|
|
889
|
-
if (!(error instanceof CodexPoolAccountCreditsOffError)) throw error;
|
|
896
|
+
if (!(error instanceof CodexPoolAccountCreditsOffError) && !(error instanceof CodexInstallationIdUnavailableError)) throw error;
|
|
890
897
|
// Body/entitlement reads above can outlive credit consent. No alternate will send:
|
|
891
898
|
// release its reservation and probes, then let the owner map the policy refusal.
|
|
892
899
|
accountMovePermit?.release();
|
|
@@ -911,9 +918,7 @@ export async function retryCodexPoolOnAlternateAccount(
|
|
|
911
918
|
{
|
|
912
919
|
const binding = conversationStateBindingFromAuth(
|
|
913
920
|
retryAuthCtx,
|
|
914
|
-
firstAuthCtx.
|
|
915
|
-
? firstAuthCtx.affinityKey
|
|
916
|
-
: undefined,
|
|
921
|
+
firstAuthCtx.affinityKey ?? firstAuthCtx.conversationStateKey,
|
|
917
922
|
);
|
|
918
923
|
if (binding) {
|
|
919
924
|
applyAccountChangeConversationStateScrub({
|
|
@@ -924,16 +929,26 @@ export async function retryCodexPoolOnAlternateAccount(
|
|
|
924
929
|
&& parsed._nativeReasoningRetention?.accountSwitch === true,
|
|
925
930
|
bindingKey: binding.bindingKey,
|
|
926
931
|
servingAccountId: binding.accountId,
|
|
927
|
-
priorAccountId: firstAuthCtx
|
|
932
|
+
priorAccountId: conversationStateAccountId(firstAuthCtx),
|
|
928
933
|
logCtx,
|
|
929
934
|
});
|
|
930
935
|
}
|
|
931
936
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
+
let request;
|
|
938
|
+
try {
|
|
939
|
+
request = await retryAdapter.buildRequest(parsed, {
|
|
940
|
+
headers: retryHeaders,
|
|
941
|
+
providerName: route.providerName,
|
|
942
|
+
translatorBudget: options.translatorBudget,
|
|
943
|
+
});
|
|
944
|
+
} catch (error) {
|
|
945
|
+
if (!(error instanceof CodexInstallationIdUnavailableError)) throw error;
|
|
946
|
+
accountMovePermit?.release();
|
|
947
|
+
releaseCodexAuthContextProbeLease(firstAuthCtx);
|
|
948
|
+
releaseCodexAuthContextProbeLease(retryAuthCtx);
|
|
949
|
+
await firstResponse.body?.cancel().catch(() => undefined);
|
|
950
|
+
return { kind: "transport", error, authCtx: retryAuthCtx };
|
|
951
|
+
}
|
|
937
952
|
recordAdapterReasoning(logCtx, request);
|
|
938
953
|
recordAdapterTier(logCtx, request);
|
|
939
954
|
|
|
@@ -1153,7 +1168,14 @@ export function codexForwardTerminalOutcomeRecorder(
|
|
|
1153
1168
|
modelId?: string,
|
|
1154
1169
|
logCtx?: RequestLogContext,
|
|
1155
1170
|
): ((status: ResponsesTerminalStatus, httpStatusOverride?: number) => void) | undefined {
|
|
1156
|
-
if (!usesCodexForwardPoolAuth(authCtx, provider))
|
|
1171
|
+
if (!usesCodexForwardPoolAuth(authCtx, provider)) {
|
|
1172
|
+
if (!isKeyedRequestOwnedMain(authCtx) || !isCanonicalOpenAiForwardProvider(provider)) return undefined;
|
|
1173
|
+
return (status, httpStatusOverride) => {
|
|
1174
|
+
const quota = [httpStatusOverride, logCtx?.terminalHttpStatus].find(value => value === 429 || value === 402);
|
|
1175
|
+
const outcome = status === "completed" || (status === "incomplete" && quota === undefined) ? 200 : (quota ?? httpStatusOverride ?? logCtx?.terminalHttpStatus ?? 502);
|
|
1176
|
+
releaseRequestOwnedMainOnOutcome(authCtx, outcome, modelId);
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1157
1179
|
const windowMeta = codexFailureWindowOutcomeMeta(authCtx);
|
|
1158
1180
|
return (status, httpStatusOverride) => {
|
|
1159
1181
|
const quotaStatus = [httpStatusOverride, logCtx?.terminalHttpStatus]
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { comboFailureEvidence, carryProxyError } from "../../lib/client-error-body";
|
|
1
2
|
import { codexAccountModelRefusal, codexAccountModelRefusalHardStopCode, type CodexAccountModelRefusal } from "../../combos/failover";
|
|
2
3
|
import { parseRetryAfterMs } from "../../combos";
|
|
3
4
|
import type { ConsumedComboFailure, HandleResponsesOptions } from "./core-options";
|
|
@@ -62,7 +63,9 @@ export async function consumeComboFailure(
|
|
|
62
63
|
let scopeRefusalBody: string | undefined;
|
|
63
64
|
let verifiedPlanRefusal = false;
|
|
64
65
|
try {
|
|
65
|
-
const
|
|
66
|
+
const legacy = comboFailureEvidence(response);
|
|
67
|
+
if (legacy !== undefined) void response.body?.cancel().catch(() => undefined);
|
|
68
|
+
const body = await readBoundedResponseBody(legacy === undefined ? response : new Response(legacy), { signal, reportUtf8Validity: serverError });
|
|
66
69
|
// A 5xx body counts as quota or classification evidence only when it decoded as valid
|
|
67
70
|
// UTF-8, matching shouldRetryCodexPoolAccountQuota. A malformed byte keeps the status-only
|
|
68
71
|
// fallback, with one exception: a cyber-policy refusal must still stop the combo, so the
|
|
@@ -139,6 +142,7 @@ export async function consumeComboFailure(
|
|
|
139
142
|
},
|
|
140
143
|
);
|
|
141
144
|
if (nonReplayable) markResponseNonReplayable(failureResponse);
|
|
145
|
+
carryProxyError(response, failureResponse);
|
|
142
146
|
carryReplayRefusal(response, failureResponse);
|
|
143
147
|
if (verifiedPlanRefusal) markVerifiedModelNotInPlanResponse(failureResponse);
|
|
144
148
|
carryAnthropicRefusalCredential(response, failureResponse);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clientFacingModelLabel } from "../../lib/error-destination";
|
|
1
2
|
/**
|
|
2
3
|
* Native Chat candidates inside the combo loop (PF-07).
|
|
3
4
|
*
|
|
@@ -126,7 +127,7 @@ export function createComboProtocolLanes(input: {
|
|
|
126
127
|
const settle = (target: ComboTarget, targetRoute: RouteResult): RouteResult | undefined => {
|
|
127
128
|
try {
|
|
128
129
|
const route: RouteResult = { ...targetRoute };
|
|
129
|
-
assertRouteAllowedByScope(admissionScope,
|
|
130
|
+
assertRouteAllowedByScope(admissionScope, clientFacingModelLabel(undefined), route);
|
|
130
131
|
const routedProvider = route.provider;
|
|
131
132
|
route.staticPolicy = captureRouteStaticPolicy(
|
|
132
133
|
route.providerName, route.modelId, routedProvider, route.staticPolicy.effectiveAlias, "chat",
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { comboLogLabel, comboTargetLogLabel } from "../../combos/resolve";
|
|
2
|
+
import { clientFacingModelLabel, clientFacingModelText } from "../../lib/error-destination";
|
|
3
|
+
import { projectLocalModelRefusalLog } from "../request-log-failure-detail";
|
|
4
|
+
import { carryProxyErrorContext, hasProxyErrorMessage, markProxyError } from "../../lib/client-error-body";
|
|
5
|
+
import { classifyUpstreamCondition } from "../../lib/upstream-condition";
|
|
1
6
|
import { effectiveAzureOutputBudget } from "../../adapters/azure";
|
|
2
7
|
import { buildResponsesTransport } from "../../adapters/openai-responses/transport";
|
|
3
8
|
import { isMetaAiResponsesDestination } from "../../responses/muse-tool-name-alias";
|
|
4
|
-
import { hasMandatoryToolChoice } from "./combo-required-tool-contract";
|
|
9
|
+
import { chatCanPreserveMandatoryToolChoice, hasMandatoryToolChoice } from "./combo-required-tool-contract";
|
|
5
10
|
import { isCodexAccountCooldownResponse } from "../../codex/account-cooldown-response";
|
|
6
11
|
import { resolveWireProtocolOverride } from "../adapter-resolve";
|
|
12
|
+
import { parseSyntheticRowId } from "../fast-row";
|
|
13
|
+
import { resolveOpenAiVirtualModel } from "../../providers/openai-virtual-models";
|
|
7
14
|
import { comboCooldownRetryAfterSeconds, isDefiniteContextOverflow, type CodexAccountModelRefusal } from "../../combos/failover";
|
|
8
15
|
import { fallbackTriggerForStatus, guardFallbackHop } from "../../routing/fallback-policy";
|
|
9
16
|
import {
|
|
@@ -52,7 +59,6 @@ import {
|
|
|
52
59
|
} from "../../combos";
|
|
53
60
|
import { formatErrorResponse } from "../../bridge";
|
|
54
61
|
import { SEND_BUDGET_EXHAUSTED_CODE } from "../../lib/errors";
|
|
55
|
-
import { redactSecretString, sanitizeLogMetadataString } from "../../lib/redact";
|
|
56
62
|
import {
|
|
57
63
|
expandPreviousResponseInput,
|
|
58
64
|
previousResponseReplayFailure,
|
|
@@ -381,19 +387,22 @@ export async function executeComboResponses(
|
|
|
381
387
|
options: HandleResponsesOptions & { translatorBudget: TranslatorBudget },
|
|
382
388
|
requestDispatchers: ResponsesDispatchers,
|
|
383
389
|
): Promise<Response> {
|
|
390
|
+
const clientModelLabel = options.clientModelLabel ?? clientFacingModelLabel(undefined);
|
|
391
|
+
const responseModel = clientFacingModelText(clientModelLabel);
|
|
384
392
|
const requestedModel = options.mainHardLockFallbackOverride?.sourceModel
|
|
385
393
|
?? (typeof (rawBody as { model?: unknown } | null)?.model === "string"
|
|
386
394
|
? (rawBody as { model: string }).model
|
|
387
395
|
: `combo/${comboId}`);
|
|
396
|
+
if (requestedModel !== responseModel) options = { ...options, clientResponseModelLabel: clientModelLabel };
|
|
388
397
|
Object.assign(logCtx, {
|
|
389
|
-
requestedModel,
|
|
390
|
-
model:
|
|
398
|
+
requestedModel: responseModel,
|
|
399
|
+
model: responseModel,
|
|
391
400
|
provider: "combo",
|
|
392
401
|
comboId,
|
|
393
402
|
});
|
|
394
403
|
const combo = getCombo(config, comboId);
|
|
395
404
|
if (!combo) {
|
|
396
|
-
return formatErrorResponse(404, "invalid_request_error",
|
|
405
|
+
return formatErrorResponse(404, "invalid_request_error", "Unknown combo");
|
|
397
406
|
}
|
|
398
407
|
// Resolve against the original request once; every bridge candidate receives the same trusted
|
|
399
408
|
// result after its provisional Authorization is removed, including an explicitly keyless result.
|
|
@@ -457,7 +466,7 @@ export async function executeComboResponses(
|
|
|
457
466
|
);
|
|
458
467
|
}
|
|
459
468
|
if (combo.imageInput === "disabled" && comboRequestHasImageInput(body)) {
|
|
460
|
-
return formatErrorResponse(400, "invalid_request_error",
|
|
469
|
+
return formatErrorResponse(400, "invalid_request_error", "This combo does not accept image input");
|
|
461
470
|
}
|
|
462
471
|
const comboReplaySnapshot = {
|
|
463
472
|
sourceBody: body,
|
|
@@ -507,9 +516,10 @@ export async function executeComboResponses(
|
|
|
507
516
|
attempt: childLog.activeAttempt,
|
|
508
517
|
});
|
|
509
518
|
}
|
|
519
|
+
carryProxyErrorContext(childLog, logCtx);
|
|
510
520
|
Object.assign(logCtx, childLog, {
|
|
511
|
-
requestedModel,
|
|
512
|
-
model:
|
|
521
|
+
requestedModel: responseModel,
|
|
522
|
+
model: responseModel,
|
|
513
523
|
provider: "combo",
|
|
514
524
|
comboId,
|
|
515
525
|
routeDecision: logCtx.routeDecision,
|
|
@@ -517,6 +527,11 @@ export async function executeComboResponses(
|
|
|
517
527
|
activeAttempt: undefined,
|
|
518
528
|
activeAttemptStartedAt: undefined,
|
|
519
529
|
});
|
|
530
|
+
if (requestedModel !== responseModel) {
|
|
531
|
+
projectLocalModelRefusalLog(logCtx, clientModelLabel);
|
|
532
|
+
logCtx.model = responseModel; logCtx.requestedModel = responseModel;
|
|
533
|
+
if (options.clientModelLabel) logCtx.jevDecision = undefined;
|
|
534
|
+
}
|
|
520
535
|
};
|
|
521
536
|
|
|
522
537
|
const unreadableEncryptedAgentTask = hasUnreadableEncryptedAgentTask(
|
|
@@ -539,13 +554,15 @@ export async function executeComboResponses(
|
|
|
539
554
|
const museToolEligible = (target: (typeof combo.targets)[number]): boolean => {
|
|
540
555
|
if (!hasMandatoryToolChoice(body)) return true;
|
|
541
556
|
try {
|
|
542
|
-
const
|
|
557
|
+
const selector = `${target.provider}/${target.model}`, { fastRow, effortRow } = parseSyntheticRowId(selector, config);
|
|
558
|
+
const route = routeConcreteModel(config, fastRow?.baseId ?? effortRow?.baseId ?? selector);
|
|
559
|
+
const modelId = resolveOpenAiVirtualModel(route.providerName, route.modelId)?.wireModelId ?? route.modelId;
|
|
543
560
|
const inboundWire = options.inboundWire ?? "responses";
|
|
544
|
-
const policy = captureRouteStaticPolicy(route.providerName,
|
|
561
|
+
const policy = captureRouteStaticPolicy(route.providerName, modelId, route.provider,
|
|
545
562
|
route.staticPolicy.effectiveAlias, inboundWire);
|
|
546
|
-
const provider = resolveWireProtocolOverride(route.providerName,
|
|
547
|
-
return provider.adapter
|
|
548
|
-
|| !isMetaAiResponsesDestination(buildResponsesTransport(provider, { headers: req.headers }).url);
|
|
563
|
+
const provider = resolveWireProtocolOverride(route.providerName, modelId, route.provider, inboundWire, policy);
|
|
564
|
+
return provider.adapter === "openai-chat" ? chatCanPreserveMandatoryToolChoice(body, provider, modelId)
|
|
565
|
+
: provider.adapter !== "openai-responses" || !isMetaAiResponsesDestination(buildResponsesTransport(provider, { headers: req.headers }).url);
|
|
549
566
|
} catch {
|
|
550
567
|
return true;
|
|
551
568
|
}
|
|
@@ -674,7 +691,7 @@ export async function executeComboResponses(
|
|
|
674
691
|
{ parentThreadId: inboundClientThreadId },
|
|
675
692
|
);
|
|
676
693
|
if (!options.abortSignal?.aborted && onlyMuseToolIncompatible()) {
|
|
677
|
-
return comboUnavailableResponse(
|
|
694
|
+
return comboUnavailableResponse("No available targets for combo; targets cannot preserve mandatory tool_choice");
|
|
678
695
|
}
|
|
679
696
|
return options.abortSignal?.aborted
|
|
680
697
|
? clientCancelledResponse()
|
|
@@ -694,7 +711,7 @@ export async function executeComboResponses(
|
|
|
694
711
|
if (protocolRefusal) return protocolRefusal;
|
|
695
712
|
if (onlyReplayIncompatibleTargetsRemain()) return targetIncompatibleResponse();
|
|
696
713
|
if (!options.abortSignal?.aborted && onlyMuseToolIncompatible()) {
|
|
697
|
-
return comboUnavailableResponse(
|
|
714
|
+
return comboUnavailableResponse("No available targets for combo; targets cannot preserve mandatory tool_choice");
|
|
698
715
|
}
|
|
699
716
|
return options.abortSignal?.aborted
|
|
700
717
|
? clientCancelledResponse()
|
|
@@ -808,7 +825,7 @@ export async function executeComboResponses(
|
|
|
808
825
|
if (pinReuse?.released) decision = { ...decision, pinReason: pinReuse.released };
|
|
809
826
|
jevDecision = decision;
|
|
810
827
|
pick = { ...selected.pick, attempted: [targetKey(selected.pick.target)] };
|
|
811
|
-
logCtx.jevDecision = normalizePersistedJevDecision({
|
|
828
|
+
logCtx.jevDecision = !options.clientModelLabel || requestedModel === responseModel ? normalizePersistedJevDecision({
|
|
812
829
|
version: 1,
|
|
813
830
|
comboId,
|
|
814
831
|
selected: {
|
|
@@ -827,10 +844,10 @@ export async function executeComboResponses(
|
|
|
827
844
|
...(decision.quota ? { quota: decision.quota } : {}),
|
|
828
845
|
...(decision.pinned ? { pinned: true } : {}),
|
|
829
846
|
...(decision.pinReason ? { pinReason: decision.pinReason } : {}),
|
|
830
|
-
});
|
|
847
|
+
}) : undefined;
|
|
831
848
|
console.debug("[combo] JEV decision", {
|
|
832
849
|
backend: decision.backend,
|
|
833
|
-
|
|
850
|
+
target: comboTargetLogLabel(config, comboId, pick.target),
|
|
834
851
|
effort: decision.effort,
|
|
835
852
|
gate: decision.gate,
|
|
836
853
|
latencyMs: decision.latencyMs,
|
|
@@ -849,7 +866,7 @@ export async function executeComboResponses(
|
|
|
849
866
|
}
|
|
850
867
|
// One immutable combo selection trace, before any child dispatch; child
|
|
851
868
|
// adoption below must never replace it with a concrete child route trace.
|
|
852
|
-
const decision = comboRouteDecisionTrace(config, comboId, pick,
|
|
869
|
+
const decision = comboRouteDecisionTrace(config, comboId, pick, responseModel);
|
|
853
870
|
const selectedReason = options.memoryModelPhase
|
|
854
871
|
? memoryModelRouteReason(options.memoryModelPhase)
|
|
855
872
|
: toolLoopPin ? COMBO_TOOL_LOOP_PIN_REASON : jevDecision?.pinned ? JEV_SESSION_PIN_ROUTE_REASON : undefined;
|
|
@@ -927,7 +944,7 @@ export async function executeComboResponses(
|
|
|
927
944
|
}
|
|
928
945
|
const remainingQuotaCooldownMs = quotaCooldownUntil === undefined ? 0 : quotaCooldownUntil - Date.now();
|
|
929
946
|
return remainingQuotaCooldownMs > 0
|
|
930
|
-
? comboUnavailableResponse(
|
|
947
|
+
? comboUnavailableResponse("No available targets for combo", {
|
|
931
948
|
retryAfter: String(Math.max(1, Math.ceil(remainingQuotaCooldownMs / 1000))),
|
|
932
949
|
}) : lastFailure;
|
|
933
950
|
};
|
|
@@ -1283,9 +1300,10 @@ export async function executeComboResponses(
|
|
|
1283
1300
|
attemptRetained = true;
|
|
1284
1301
|
noteComboSuccess(comboId, combo, pick.target, pick.writerGeneration);
|
|
1285
1302
|
settleComboReprobeSuccess(pick);
|
|
1303
|
+
carryProxyErrorContext(childLog, logCtx);
|
|
1286
1304
|
Object.assign(logCtx, childLog, {
|
|
1287
|
-
requestedModel,
|
|
1288
|
-
model:
|
|
1305
|
+
requestedModel: responseModel,
|
|
1306
|
+
model: responseModel,
|
|
1289
1307
|
provider: "combo",
|
|
1290
1308
|
comboId,
|
|
1291
1309
|
routeDecision: logCtx.routeDecision,
|
|
@@ -1311,6 +1329,7 @@ export async function executeComboResponses(
|
|
|
1311
1329
|
try {
|
|
1312
1330
|
failure = consumedChildFailure
|
|
1313
1331
|
?? await consumeComboFailure(response, options.abortSignal);
|
|
1332
|
+
if (hasProxyErrorMessage(childLog, failure.upstreamMessage ?? "", { type: failure.upstreamType, code: failure.upstreamCode })) markProxyError(failure.response);
|
|
1314
1333
|
if (preflightModelRefusal !== undefined) failure = { ...failure, codexModelRefusal: preflightModelRefusal };
|
|
1315
1334
|
} catch (error) {
|
|
1316
1335
|
if (options.abortSignal?.aborted) {
|
|
@@ -1421,7 +1440,7 @@ export async function executeComboResponses(
|
|
|
1421
1440
|
adoptFailedChildLog(childLog);
|
|
1422
1441
|
if (classifyOverflow && failureDecision === "stop") {
|
|
1423
1442
|
return wantsStream
|
|
1424
|
-
? streamingContextOverflowResponse(
|
|
1443
|
+
? streamingContextOverflowResponse(responseModel, options.translatorBudget)
|
|
1425
1444
|
: jsonContextOverflowResponse();
|
|
1426
1445
|
}
|
|
1427
1446
|
return lastFailure;
|
|
@@ -1430,7 +1449,7 @@ export async function executeComboResponses(
|
|
|
1430
1449
|
adoptFailedChildLog(childLog);
|
|
1431
1450
|
if (classifyOverflow) {
|
|
1432
1451
|
return wantsStream
|
|
1433
|
-
? streamingContextOverflowResponse(
|
|
1452
|
+
? streamingContextOverflowResponse(responseModel, options.translatorBudget)
|
|
1434
1453
|
: jsonContextOverflowResponse();
|
|
1435
1454
|
}
|
|
1436
1455
|
return lastFailure;
|
|
@@ -1441,14 +1460,13 @@ export async function executeComboResponses(
|
|
|
1441
1460
|
contextFailure = { childLog, response: formatErrorResponse(400, "invalid_request_error",
|
|
1442
1461
|
failure.upstreamMessage ?? failure.classificationText, { code: "context_length_exceeded", classified: true }) };
|
|
1443
1462
|
}
|
|
1444
|
-
// A bare status made a revoked credential read as a provider outage. Log
|
|
1445
|
-
//
|
|
1446
|
-
const failureReason =
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
);
|
|
1463
|
+
// A bare status made a revoked credential read as a provider outage. Log the classified
|
|
1464
|
+
// condition (a closed member), never upstream-authored code or message text.
|
|
1465
|
+
const failureReason = classifyUpstreamCondition({
|
|
1466
|
+
status: failure.response.status, code: failure.upstreamCode, type: failure.upstreamType, message: failure.upstreamMessage,
|
|
1467
|
+
});
|
|
1450
1468
|
console.warn(
|
|
1451
|
-
`[combo] ${comboId}: ${
|
|
1469
|
+
`[combo] ${comboLogLabel(config, comboId)}: ${comboTargetLogLabel(config, comboId, pick.target)} failed with ${failure.response.status}`
|
|
1452
1470
|
+ ` after ${Date.now() - started}ms${failureReason ? `: ${failureReason}` : ""}`,
|
|
1453
1471
|
);
|
|
1454
1472
|
const failureNow = Date.now();
|
|
@@ -1571,11 +1589,11 @@ export async function executeComboResponses(
|
|
|
1571
1589
|
) {
|
|
1572
1590
|
if (localAdmissionRefusals?.length) logCtx.errorCode = "input_admission_refused";
|
|
1573
1591
|
const localMessage = localAdmissionRefusals?.length
|
|
1574
|
-
? `opencodex refused this turn locally; nothing was sent upstream. No target of combo
|
|
1592
|
+
? `opencodex refused this turn locally; nothing was sent upstream. No target of this combo `
|
|
1575
1593
|
+ `that was tried can fit its input: ${localAdmissionRefusals.join(" ")} Compact the conversation before retrying.`
|
|
1576
1594
|
: undefined;
|
|
1577
1595
|
return (rawBody as { stream?: unknown } | null)?.stream === true
|
|
1578
|
-
? streamingContextOverflowResponse(
|
|
1596
|
+
? streamingContextOverflowResponse(responseModel, options.translatorBudget, localMessage)
|
|
1579
1597
|
: jsonContextOverflowResponse(localMessage);
|
|
1580
1598
|
}
|
|
1581
1599
|
return failure;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { ComboExclusionReasons } from "../../combos/resolve";
|
|
2
|
+
import { markProxyError } from "../../lib/client-error-body";
|
|
3
|
+
import { formatClientRetryAfter } from "../../lib/client-retry-after";
|
|
1
4
|
import { readBoundedResponseBody } from "../../lib/bounded-body";
|
|
2
5
|
import { redactSecretString } from "../../lib/redact";
|
|
3
6
|
import { isCyberPolicyMessage, isCyberPolicyCode } from "../../lib/errors";
|
|
@@ -80,18 +83,18 @@ export function normalizeUpstreamErrorText(text: string, fallback: string): Norm
|
|
|
80
83
|
|
|
81
84
|
export function decodeRequestErrorResponse(err: unknown, label: string): Response {
|
|
82
85
|
if (isTranslatorBudgetExceededError(err)) {
|
|
83
|
-
return formatErrorResponse(413, "request_too_large", "request translation buffer exceeded the safe limit", {
|
|
86
|
+
return markProxyError(formatErrorResponse(413, "request_too_large", "request translation buffer exceeded the safe limit", {
|
|
84
87
|
code: "translation_buffer_limit",
|
|
85
|
-
});
|
|
88
|
+
}));
|
|
86
89
|
}
|
|
87
90
|
if (err instanceof UnsupportedContentEncodingError) {
|
|
88
|
-
return formatErrorResponse(415, "invalid_request_error", err.message);
|
|
91
|
+
return markProxyError(formatErrorResponse(415, "invalid_request_error", err.message));
|
|
89
92
|
}
|
|
90
93
|
if (err instanceof DecompressedBodyTooLargeError) {
|
|
91
|
-
return formatErrorResponse(413, "inbound_body_too_large", describeInboundBodyRefusal(err));
|
|
94
|
+
return markProxyError(formatErrorResponse(413, "inbound_body_too_large", describeInboundBodyRefusal(err)));
|
|
92
95
|
}
|
|
93
96
|
console.warn(`[${label}] request body decode/parse failed: ${err instanceof Error ? `${err.name}: ${err.message}` : String(err)}`);
|
|
94
|
-
return formatErrorResponse(400, "invalid_request_error", "Invalid JSON body");
|
|
97
|
+
return markProxyError(formatErrorResponse(400, "invalid_request_error", "Invalid JSON body"));
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
|
|
@@ -102,20 +105,19 @@ export function comboUnavailableResponse(
|
|
|
102
105
|
options?: { retryAfter?: string | null },
|
|
103
106
|
): Response {
|
|
104
107
|
const headers = new Headers({ "Content-Type": "application/json" });
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return new Response(
|
|
108
|
+
// Advice leaves in this proxy's format, whatever form the earliest cooldown was recorded in.
|
|
109
|
+
const advice = formatClientRetryAfter(options?.retryAfter);
|
|
110
|
+
if (advice !== undefined) headers.set("Retry-After", advice);
|
|
111
|
+
return markProxyError(new Response(
|
|
110
112
|
JSON.stringify({
|
|
111
113
|
error: { message, type: "server_error", code: "combo_unavailable" },
|
|
112
114
|
}),
|
|
113
115
|
{ status: 503, headers },
|
|
114
|
-
);
|
|
116
|
+
));
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
|
|
118
|
-
export function comboUnavailable(comboId: string, now = Date.now(), reasons
|
|
120
|
+
export function comboUnavailable(comboId: string, now = Date.now(), reasons?: ComboExclusionReasons): Response {
|
|
119
121
|
return comboUnavailableResponse(new NoAvailableComboTargetsError(comboId, reasons).message, {
|
|
120
122
|
retryAfter: comboCooldownRetryAfterSeconds(comboId, now),
|
|
121
123
|
});
|
|
@@ -129,7 +131,7 @@ export function comboUnavailable(comboId: string, now = Date.now(), reasons = ""
|
|
|
129
131
|
* response completes (`client_cancelled`).
|
|
130
132
|
*/
|
|
131
133
|
export function clientCancelledResponse(): Response {
|
|
132
|
-
return formatErrorResponse(499, "client_cancelled", "Client cancelled request");
|
|
134
|
+
return markProxyError(formatErrorResponse(499, "client_cancelled", "Client cancelled request"));
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
/**
|
|
@@ -154,10 +156,10 @@ export function anthropicPoolCooldownResponse(
|
|
|
154
156
|
): Response {
|
|
155
157
|
if (refusal.usageLimit !== null && !options.comboAttempt) {
|
|
156
158
|
if (options.logCtx) options.logCtx.errorCode = "usage_limit_reached";
|
|
157
|
-
return formatUsageLimitReachedResponse(refusal.message, refusal.usageLimit.resetsAt, refusal.retryAfterSeconds);
|
|
159
|
+
return markProxyError(formatUsageLimitReachedResponse(refusal.message, refusal.usageLimit.resetsAt, refusal.retryAfterSeconds));
|
|
158
160
|
}
|
|
159
|
-
return formatErrorResponse(429, "rate_limit_error", refusal.retryableMessage,
|
|
160
|
-
refusal.retryAfterSeconds === null ? undefined : { retryAfter: String(refusal.retryAfterSeconds) });
|
|
161
|
+
return markProxyError(formatErrorResponse(429, "rate_limit_error", refusal.retryableMessage,
|
|
162
|
+
refusal.retryAfterSeconds === null ? undefined : { retryAfter: String(refusal.retryAfterSeconds) }));
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
|
|
@@ -166,7 +168,7 @@ export const UNREADABLE_ENCRYPTED_AGENT_TASK_MESSAGE =
|
|
|
166
168
|
|
|
167
169
|
|
|
168
170
|
export function unreadableEncryptedAgentTaskResponse(reason?: AgentTaskRecoveryFailureReason): Response {
|
|
169
|
-
return new Response(
|
|
171
|
+
return markProxyError(new Response(
|
|
170
172
|
JSON.stringify({
|
|
171
173
|
error: {
|
|
172
174
|
message: UNREADABLE_ENCRYPTED_AGENT_TASK_MESSAGE,
|
|
@@ -176,7 +178,7 @@ export function unreadableEncryptedAgentTaskResponse(reason?: AgentTaskRecoveryF
|
|
|
176
178
|
},
|
|
177
179
|
}),
|
|
178
180
|
{ status: 400, headers: { "Content-Type": "application/json" } },
|
|
179
|
-
);
|
|
181
|
+
));
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
|
|
@@ -185,7 +187,7 @@ export const TARGET_INCOMPATIBLE_MESSAGE =
|
|
|
185
187
|
|
|
186
188
|
|
|
187
189
|
export function targetIncompatibleResponse(): Response {
|
|
188
|
-
return new Response(
|
|
190
|
+
return markProxyError(new Response(
|
|
189
191
|
JSON.stringify({
|
|
190
192
|
error: {
|
|
191
193
|
message: TARGET_INCOMPATIBLE_MESSAGE,
|
|
@@ -194,5 +196,5 @@ export function targetIncompatibleResponse(): Response {
|
|
|
194
196
|
},
|
|
195
197
|
}),
|
|
196
198
|
{ status: 400, headers: { "Content-Type": "application/json" } },
|
|
197
|
-
);
|
|
199
|
+
));
|
|
198
200
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { carryProxyError } from "../../lib/client-error-body";
|
|
1
2
|
import type { TranslatorBudget } from "../../lib/translator-budget";
|
|
2
3
|
import { carryResponseToolOwnership } from "./response-tool-ownership";
|
|
3
4
|
import { finalizeTranslatorBudgetResponse } from "../../lib/translator-budget";
|
|
4
5
|
import { carryReplayRefusal, isNonReplayableResponse, markResponseNonReplayable } from "../../lib/upstream-retry";
|
|
5
6
|
import { isVerifiedModelNotInPlanResponse, markVerifiedModelNotInPlanResponse } from "../../lib/errors";
|
|
6
7
|
import { carryCodexAccountCooldownResponse } from "../../codex/account-cooldown-response";
|
|
8
|
+
import { carryFormattedQuotaSource } from "../../bridge/errors";
|
|
7
9
|
import {
|
|
8
10
|
isNativePassthroughSseResponse,
|
|
9
11
|
markNativePassthroughSseResponse,
|
|
@@ -43,7 +45,7 @@ export const UPSTREAM_JSON_BODY_READ_OPTIONS = {
|
|
|
43
45
|
|
|
44
46
|
|
|
45
47
|
export function finalizeOwnedTranslatorBudget(response: Response, budget: TranslatorBudget, signal?: AbortSignal): Response {
|
|
46
|
-
const finalizedResponse = finalizeTranslatorBudgetResponse(response, budget, signal);
|
|
48
|
+
const finalizedResponse = carryProxyError(response, finalizeTranslatorBudgetResponse(response, budget, signal));
|
|
47
49
|
if (isNativePassthroughSseResponse(response)) {
|
|
48
50
|
markNativePassthroughSseResponse(finalizedResponse);
|
|
49
51
|
}
|
|
@@ -55,7 +57,7 @@ export function finalizeOwnedTranslatorBudget(response: Response, budget: Transl
|
|
|
55
57
|
if (isVerifiedModelNotInPlanResponse(response)) markVerifiedModelNotInPlanResponse(finalizedResponse);
|
|
56
58
|
if (runTurnAdapterSseResponses.has(response)) runTurnAdapterSseResponses.add(finalizedResponse);
|
|
57
59
|
carryCodexAccountCooldownResponse(response, finalizedResponse);
|
|
58
|
-
return carryResponseToolOwnership(response, finalizedResponse);
|
|
60
|
+
return carryResponseToolOwnership(response, carryFormattedQuotaSource(response, finalizedResponse));
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
/** Release a serving-account slot when the client body ends, errors or is cancelled. */
|
|
@@ -75,6 +77,7 @@ export function finalizeAccountLease(response: Response, release: () => void, on
|
|
|
75
77
|
async cancel(reason) { onCancel?.(); try { await reader.cancel(reason); } finally { finish(); } },
|
|
76
78
|
});
|
|
77
79
|
const wrapped = new Response(body, { status: response.status, statusText: response.statusText, headers: response.headers });
|
|
80
|
+
carryProxyError(response, wrapped);
|
|
78
81
|
if (isNonReplayableResponse(response)) markResponseNonReplayable(wrapped);
|
|
79
82
|
if (isVerifiedModelNotInPlanResponse(response)) markVerifiedModelNotInPlanResponse(wrapped);
|
|
80
83
|
if (isNativePassthroughSseResponse(response)) markNativePassthroughSseResponse(wrapped);
|
|
@@ -83,7 +86,7 @@ export function finalizeAccountLease(response: Response, release: () => void, on
|
|
|
83
86
|
if (runTurnAdapterSseResponses.has(response)) runTurnAdapterSseResponses.add(wrapped);
|
|
84
87
|
// Retained compaction delivers through this lease wrapper; keep a local cooldown refusal local (#7850).
|
|
85
88
|
carryCodexAccountCooldownResponse(response, wrapped);
|
|
86
|
-
return carryResponseToolOwnership(response, carryReplayRefusal(response, wrapped));
|
|
89
|
+
return carryResponseToolOwnership(response, carryReplayRefusal(response, carryFormattedQuotaSource(response, wrapped)));
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
|
|
@@ -156,6 +156,7 @@ export async function applyFinalRouteRequestNormalization(args: {
|
|
|
156
156
|
|
|
157
157
|
// Only Anthropic message routes retain the Codex-facing selector. Other providers must keep
|
|
158
158
|
// their existing response.model contract even when their public and wire model ids differ.
|
|
159
|
+
// Request preparation assigns the original client label separately for synthetic turns.
|
|
159
160
|
const responseModelId = parsed.modelId;
|
|
160
161
|
const preserveAnthropicResponseModel = route.providerName === "anthropic"
|
|
161
162
|
|| route.provider.adapter === "anthropic";
|
|
@@ -346,11 +347,17 @@ export async function applyFinalRouteRequestNormalization(args: {
|
|
|
346
347
|
// Native passthrough keeps its snapshot-owned effort contract, including saved exclusions.
|
|
347
348
|
if (!shouldApplyNativeEffortClamp(route.providerName, route.provider, finalSelectedModelId)) {
|
|
348
349
|
const previousEffort = parsed.options.reasoning;
|
|
350
|
+
const previousThinkingEnabled = parsed.options.thinkingEnabled;
|
|
349
351
|
normalizeThinkingOptions(route.provider, route.modelId, parsed.options);
|
|
352
|
+
const raw = parsed._rawBody as { reasoning?: unknown } | undefined;
|
|
350
353
|
if (previousEffort !== undefined && parsed.options.reasoning === undefined) {
|
|
351
|
-
const raw = parsed._rawBody as { reasoning?: unknown } | undefined;
|
|
352
354
|
if (raw) raw.reasoning = stripEmptyLadderEffort(raw.reasoning, []);
|
|
353
355
|
}
|
|
356
|
+
if (previousThinkingEnabled !== undefined && parsed.options.thinkingEnabled === undefined
|
|
357
|
+
&& raw?.reasoning && typeof raw.reasoning === "object" && !Array.isArray(raw.reasoning)) {
|
|
358
|
+
delete (raw.reasoning as { enabled?: boolean }).enabled;
|
|
359
|
+
if (Object.keys(raw.reasoning).length === 0) delete raw.reasoning;
|
|
360
|
+
}
|
|
354
361
|
}
|
|
355
362
|
const { applyEffortCap, effortCapAppliesTo, supportedLadderFor } = await import("../effort-policy");
|
|
356
363
|
const surface = collabSurface(parsed);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ClientFacingModelLabel } from "../../lib/error-destination";
|
|
1
2
|
import type { CodexAccountModelRefusal } from "../../combos/failover";
|
|
2
3
|
import type { NativeResponseControl } from "./native-response-control";
|
|
3
4
|
import type { AdapterEvent, OcxUsage, OcxProviderContinuationState, OcxConfig } from "../../types";
|
|
@@ -96,6 +97,10 @@ export interface DirectRequestOption {
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
export interface HandleResponsesOptions {
|
|
100
|
+
/** Original caller label, carried through synthetic children without route substitution. */
|
|
101
|
+
clientModelLabel?: ClientFacingModelLabel;
|
|
102
|
+
/** Original client envelope label when a combo was selected by a synthetic rewrite. */
|
|
103
|
+
clientResponseModelLabel?: ClientFacingModelLabel;
|
|
99
104
|
/** Immutable caller scope inherited by a capability-authenticated internal sidecar request. */
|
|
100
105
|
admissionScope?: AdmissionModelScope;
|
|
101
106
|
/** Captured synchronously at ingress, before parsing or child replay can suspend. */
|
|
@@ -118,6 +123,8 @@ export interface HandleResponsesOptions {
|
|
|
118
123
|
claudeGoAffinity?: { sessionLane?: string };
|
|
119
124
|
/** Validated Claude metadata identity; projected only into final canonical attempt headers. */
|
|
120
125
|
claudeNativeSessionId?: string;
|
|
126
|
+
/** Private Claude bridge pool identity (validated, principal-scoped when derived); completes session-id/thread-id only on Codex account-selection headers. */
|
|
127
|
+
claudeBridgePoolSession?: string;
|
|
121
128
|
/** Original live policy owner; separate from caller-specific routing/sidecar snapshots. */
|
|
122
129
|
codexAuthPolicy?: CodexAuthPolicyConfig;
|
|
123
130
|
turnAdmissionLease?: AdmissionLease;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markProxyError } from "../../lib/client-error-body";
|
|
1
2
|
import { supportsNativeResponsesCompactionTrigger } from "../../providers/openai-tiers";
|
|
2
3
|
import type { OcxConfig } from "../../types";
|
|
3
4
|
import type { RequestLogContext } from "../request-log";
|
|
@@ -44,7 +45,7 @@ export async function handleResponsesInner(
|
|
|
44
45
|
const requestState = await prepareResponsesRequest(requestContext, admissionState, requestDispatchers);
|
|
45
46
|
if (requestState instanceof Response) return requestState;
|
|
46
47
|
const transportState = await prepareResponsesTransport(requestContext, admissionState, requestState);
|
|
47
|
-
if (transportState instanceof Response) return transportState;
|
|
48
|
+
if (transportState instanceof Response) return markProxyError(transportState);
|
|
48
49
|
options.onCompactionRecoveryRoute?.(requestState.route);
|
|
49
50
|
if (requestState.parsed._compactionRequest && options.compactionRecoveryKind !== "compaction-v1"
|
|
50
51
|
&& (requestState.parsed._portableCompaction || !supportsNativeResponsesCompactionTrigger(requestState.route.provider))) {
|
|
@@ -54,7 +55,7 @@ export async function handleResponsesInner(
|
|
|
54
55
|
}
|
|
55
56
|
const execute = async (): Promise<Response> => {
|
|
56
57
|
const sidecarState = await prepareResponsesSidecarAuth(requestContext, requestState, transportState);
|
|
57
|
-
if (sidecarState instanceof Response) return sidecarState;
|
|
58
|
+
if (sidecarState instanceof Response) return markProxyError(sidecarState);
|
|
58
59
|
const responseEffects = createResponsesEffects(
|
|
59
60
|
requestContext,
|
|
60
61
|
admissionState,
|
|
@@ -62,7 +63,7 @@ export async function handleResponsesInner(
|
|
|
62
63
|
sidecarState,
|
|
63
64
|
);
|
|
64
65
|
const sendBudgetState = createResponsesSendBudget(requestContext);
|
|
65
|
-
if (sendBudgetState instanceof Response) return sendBudgetState;
|
|
66
|
+
if (sendBudgetState instanceof Response) return markProxyError(sendBudgetState);
|
|
66
67
|
if ("passthrough" in transportState.adapter && transportState.adapter.passthrough && !sidecarState.routedCompaction) {
|
|
67
68
|
const passthroughResult = await executePassthroughResponse(
|
|
68
69
|
requestContext,
|