@bitkyc08/opencodex 2.96.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-bwugJRKn.js → App-DuNhggE1.js} +15 -15
- package/gui/dist/assets/{Tray-BOPQyDbH.js → Tray-CEw0y0jR.js} +1 -1
- package/gui/dist/assets/index-CynE_Rue.js +94 -0
- package/gui/dist/assets/{quota-summary-6HsrHQAy.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 +11 -1
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/passthrough.ts +5 -4
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/physical-send.ts +3 -3
- 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/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/help.ts +2 -2
- package/src/cli/index.ts +5 -1
- package/src/cli/link.ts +1 -1
- package/src/cli/registry.ts +11 -3
- 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/auth-context.ts +49 -103
- 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 +35 -6
- 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/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 +433 -165
- 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/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +36 -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/fastwire.ts +3 -2
- package/src/providers/quota/anthropic-usage-windows.ts +13 -3
- 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/progressive-freeform-input.ts +354 -45
- 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/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 +51 -24
- package/src/server/context-history.ts +5 -1
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/ollama-routes.ts +89 -0
- package/src/server/index/serve-options.ts +21 -4
- package/src/server/index/websocket-handler.ts +4 -2
- 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/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 +31 -30
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +19 -18
- 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/compact.ts +53 -23
- 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 +17 -6
- 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 +41 -27
- 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 +1 -0
- 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-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +19 -17
- 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-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/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- 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/web-search/loop.ts +31 -5
- package/gui/dist/assets/index-ebuVUtB7.js +0 -94
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { clientFacingModelLabel, type ClientFacingModelLabel } from "../../lib/error-destination";
|
|
2
|
+
import { formatClientRetryAfter } from "../../lib/client-retry-after";
|
|
3
|
+
import { conversationStateAccountId, releaseRequestOwnedMainOnOutcome, isKeyedRequestOwnedMain } from "../../codex/request-owned-affinity";
|
|
1
4
|
import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
|
|
5
|
+
import { MAIN_CODEX_ACCOUNT_ID } from "../../codex/account-id";
|
|
2
6
|
import { isolateCodexPoolClientMetadata } from "../../codex/forward-transport-headers";
|
|
3
7
|
import { captureAccountAutoPauseAttempt, wasAccountAutoPaused, wasPermanentAccountRefusal } from "../../oauth/account-auto-pause";
|
|
4
8
|
import { spendLedgerStorageErrorResponse } from "./spend-storage-error";
|
|
@@ -12,7 +16,7 @@ import { join } from "node:path";
|
|
|
12
16
|
import { rmSync } from "node:fs";
|
|
13
17
|
import { previewXaiOauthWireModel } from "./core-normalize";
|
|
14
18
|
import {
|
|
15
|
-
admissionModelDeniedResponse,
|
|
19
|
+
admissionModelDeniedResponse, projectAdmissionModelDeniedLog,
|
|
16
20
|
AdmissionModelDeniedError,
|
|
17
21
|
assertRouteAllowedByScope,
|
|
18
22
|
resolveAdmissionModelScope,
|
|
@@ -97,6 +101,7 @@ import { codexFailureWindowOutcomeMeta } from "../../codex/routing/failure-windo
|
|
|
97
101
|
import {
|
|
98
102
|
applyAccountChangeConversationStateScrub,
|
|
99
103
|
conversationStateBindingFromAuth,
|
|
104
|
+
compactAlternateAffinityKey,
|
|
100
105
|
accountChangeFileReferenceRefusal,
|
|
101
106
|
rememberServingConversationStateIssuer,
|
|
102
107
|
conversationCarriesUploadedFiles,
|
|
@@ -111,7 +116,7 @@ import {
|
|
|
111
116
|
fetchWithTransientRetry,
|
|
112
117
|
applyUpstreamRecoveryInit,
|
|
113
118
|
isNonReplayableResponse,
|
|
114
|
-
SendBudgetExhaustedError,
|
|
119
|
+
SendBudgetExhaustedError, errorDestinationLabel,
|
|
115
120
|
TRANSIENT_RETRY_MAX_ATTEMPTS,
|
|
116
121
|
type UpstreamSendRecovery,
|
|
117
122
|
} from "../../lib/upstream-retry";
|
|
@@ -322,6 +327,7 @@ function compactHandoffRoute(
|
|
|
322
327
|
}
|
|
323
328
|
|
|
324
329
|
export interface HandleResponsesCompactOptions {
|
|
330
|
+
clientModelLabel?: ClientFacingModelLabel;
|
|
325
331
|
advisorAdmissionPolicy?: import("../../types/admission-policy").CapturedAdmissionPolicy;
|
|
326
332
|
compactionRoutingOverride?: CompactionRoutingOverride | null;
|
|
327
333
|
nativeMainRefreshDependencies?: NativeMainRefreshDependencies;
|
|
@@ -608,7 +614,12 @@ function compactResponseHeaders(upstream: Response): Headers {
|
|
|
608
614
|
const headers = new Headers({ "Content-Type": upstream.headers.get("content-type") ?? "application/json" });
|
|
609
615
|
for (const name of COMPACT_PASSTHROUGH_HEADERS) {
|
|
610
616
|
const value = upstream.headers.get(name);
|
|
611
|
-
if (value
|
|
617
|
+
if (value === null) continue;
|
|
618
|
+
if (name === "retry-after") {
|
|
619
|
+
// Retry advice leaves as an integer this proxy formats, never the upstream bytes.
|
|
620
|
+
const advice = formatClientRetryAfter(value);
|
|
621
|
+
if (advice !== undefined) headers.set(name, advice);
|
|
622
|
+
} else headers.set(name, value);
|
|
612
623
|
}
|
|
613
624
|
return headers;
|
|
614
625
|
}
|
|
@@ -677,6 +688,8 @@ export async function handleResponsesCompact(
|
|
|
677
688
|
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
678
689
|
return formatErrorResponse(400, "invalid_request_error", "Invalid compaction request body");
|
|
679
690
|
}
|
|
691
|
+
const clientModelLabel = options.clientModelLabel ?? clientFacingModelLabel(options.compactionRoutingOverride?.sourceModel ?? (body as { model?: unknown }).model);
|
|
692
|
+
options = { ...options, clientModelLabel };
|
|
680
693
|
// Compaction forwards client history upstream too; keep local artifact paths out of it.
|
|
681
694
|
redactHostedImageDisplayPaths(body);
|
|
682
695
|
if (!options.compactionRoutingOverride) {
|
|
@@ -730,14 +743,14 @@ export async function handleResponsesCompact(
|
|
|
730
743
|
// Routed xAI OAuth compaction must preview its Fast wire model here;
|
|
731
744
|
// native compact keeps checking the destination it dispatches directly.
|
|
732
745
|
const callerTier = (raw as Record<string, unknown>).service_tier;
|
|
733
|
-
assertRouteAllowedByScope(resolveAdmissionModelScope(config, admission),
|
|
746
|
+
assertRouteAllowedByScope(resolveAdmissionModelScope(config, admission), clientModelLabel, {
|
|
734
747
|
providerName: route.providerName,
|
|
735
748
|
modelId: previewXaiOauthWireModel({ options: {
|
|
736
749
|
serviceTier: compactFastRow ? "priority" : typeof callerTier === "string" ? callerTier : undefined,
|
|
737
750
|
} }, route, config, "responses"),
|
|
738
751
|
});
|
|
739
752
|
} catch (err) {
|
|
740
|
-
if (err instanceof AdmissionModelDeniedError) return admissionModelDeniedResponse(err);
|
|
753
|
+
if (err instanceof AdmissionModelDeniedError) return admissionModelDeniedResponse(projectAdmissionModelDeniedLog(err, logCtx));
|
|
741
754
|
if (err instanceof NoEligiblePolicyCandidateError) {
|
|
742
755
|
// Persist the evaluation trace (per-candidate exclusions + the
|
|
743
756
|
// no-eligible reason) so a failed compact policy request stays
|
|
@@ -983,6 +996,7 @@ export async function handleResponsesCompact(
|
|
|
983
996
|
if (refusal) return refusal;
|
|
984
997
|
applyAccountChangeConversationStateScrub({
|
|
985
998
|
body: raw,
|
|
999
|
+
headers,
|
|
986
1000
|
bindingKey: binding.bindingKey,
|
|
987
1001
|
servingAccountId: binding.accountId,
|
|
988
1002
|
logCtx,
|
|
@@ -1001,7 +1015,11 @@ export async function handleResponsesCompact(
|
|
|
1001
1015
|
&& compactProvider.supportsNativeCompactEndpoint === true
|
|
1002
1016
|
? buildResponsesTransport({ ...compactProvider, apiKey: compactProvider.apiKey ? resolveProviderApiKey(compactProvider.apiKey) : undefined }, { headers: req.headers })
|
|
1003
1017
|
: undefined;
|
|
1004
|
-
if (gatewayTransport)
|
|
1018
|
+
if (gatewayTransport) {
|
|
1019
|
+
headers = new Headers(gatewayTransport.headers);
|
|
1020
|
+
const binding = conversationStateBindingFromAuth(authCtx, codexPoolAffinityKey(req.headers));
|
|
1021
|
+
if (binding) applyAccountChangeConversationStateScrub({ body: compactBody, headers, bindingKey: binding.bindingKey, servingAccountId: binding.accountId, logCtx });
|
|
1022
|
+
}
|
|
1005
1023
|
// Native v1 bypasses the adapter serializer. Bind the same replay provenance as ordinary
|
|
1006
1024
|
// turns, but leave canonical compact's established account-state handling unchanged.
|
|
1007
1025
|
const gatewayReplayParsed = gatewayTransport ? parseRequest(raw) : undefined;
|
|
@@ -1084,8 +1102,12 @@ export async function handleResponsesCompact(
|
|
|
1084
1102
|
} = {},
|
|
1085
1103
|
) => {
|
|
1086
1104
|
// A gateway response is not evidence about any Codex account.
|
|
1087
|
-
if (gatewayTransport
|
|
1105
|
+
if (gatewayTransport) return;
|
|
1088
1106
|
if ((outcome === 401 || outcome === 403) && upstream && wasPermanentAccountRefusal(upstream)) return;
|
|
1107
|
+
if (!usesCodexForwardPoolAuth(ctx, route.provider)) {
|
|
1108
|
+
if (isKeyedRequestOwnedMain(ctx) && typeof outcome === "number" && (!upstream || !isNonReplayableResponse(upstream)) && isCanonicalOpenAiForwardProvider(route.provider)) releaseRequestOwnedMainOnOutcome(ctx, outcome, selectedModelId);
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1089
1111
|
recordCodexUpstreamOutcome(config, ctx.accountId, outcome, {
|
|
1090
1112
|
...meta,
|
|
1091
1113
|
...codexFailureWindowOutcomeMeta(ctx),
|
|
@@ -1123,7 +1145,7 @@ export async function handleResponsesCompact(
|
|
|
1123
1145
|
identityId: logCtx.accountLogLabel }));
|
|
1124
1146
|
let started = false;
|
|
1125
1147
|
try {
|
|
1126
|
-
if (report.beforeSend?.() === false) throw new SendBudgetExhaustedError(
|
|
1148
|
+
if (report.beforeSend?.() === false) throw new SendBudgetExhaustedError(errorDestinationLabel(compactUrl));
|
|
1127
1149
|
started = true;
|
|
1128
1150
|
return await (report.execute ? report.execute(doFetch) : doFetch());
|
|
1129
1151
|
} finally {
|
|
@@ -1135,11 +1157,11 @@ export async function handleResponsesCompact(
|
|
|
1135
1157
|
sendClass: "auth-recovery",
|
|
1136
1158
|
targetKey: compactTargetKey,
|
|
1137
1159
|
});
|
|
1138
|
-
if (!decision.allowed) return Promise.reject(new SendBudgetExhaustedError(
|
|
1160
|
+
if (!decision.allowed) return Promise.reject(new SendBudgetExhaustedError(errorDestinationLabel(compactUrl)));
|
|
1139
1161
|
const dispatch = () => {
|
|
1140
1162
|
if (!decision.permit.use()) {
|
|
1141
1163
|
decision.permit.release();
|
|
1142
|
-
throw new SendBudgetExhaustedError(
|
|
1164
|
+
throw new SendBudgetExhaustedError(errorDestinationLabel(compactUrl));
|
|
1143
1165
|
}
|
|
1144
1166
|
return doFetch();
|
|
1145
1167
|
};
|
|
@@ -1153,7 +1175,9 @@ export async function handleResponsesCompact(
|
|
|
1153
1175
|
onPhysicalDispatch?: () => void,
|
|
1154
1176
|
): Promise<Response> => {
|
|
1155
1177
|
// A gateway send carries only its own transport headers, whatever recovery handed in.
|
|
1178
|
+
// An account-change scrub that removed the turn state from the send headers still applies.
|
|
1156
1179
|
let wireHeaders = gatewayTransport ? new Headers(gatewayTransport.headers) : sendHeaders;
|
|
1180
|
+
if (gatewayTransport && !sendHeaders.has("x-codex-turn-state")) wireHeaders.delete("x-codex-turn-state");
|
|
1157
1181
|
sendHeaders = wireHeaders;
|
|
1158
1182
|
const buildCompactSendBody = () => {
|
|
1159
1183
|
if (gatewayReplayParsed) bindRouteReasoningReplayScope({
|
|
@@ -1238,7 +1262,7 @@ export async function handleResponsesCompact(
|
|
|
1238
1262
|
if (req.signal.aborted) throw req.signal.reason;
|
|
1239
1263
|
stampApiKeyAccountLabel(logCtx, route.providerName, sendProvider);
|
|
1240
1264
|
if (!rebindPhysicalSend(sendBudget, { poolId: logCtx.spendPoolId ?? route.providerName,
|
|
1241
|
-
identityId: logCtx.accountLogLabel })) throw new SendBudgetExhaustedError(
|
|
1265
|
+
identityId: logCtx.accountLogLabel })) throw new SendBudgetExhaustedError(errorDestinationLabel(compactUrl));
|
|
1242
1266
|
noteProviderAttemptSend(logCtx, route.providerName, sendProvider, logCtx.usageLogInputTokens, upstreamRecovery);
|
|
1243
1267
|
const physicalFetch = ((input, physicalInit) => sendWithConnectionPolicy(
|
|
1244
1268
|
distributedKeyPhysicalFetch((sendProvider as { fetch?: typeof fetch }).fetch ?? execute, route.providerName, sendProvider, compactUrl), String(input),
|
|
@@ -1262,7 +1286,7 @@ export async function handleResponsesCompact(
|
|
|
1262
1286
|
? sendSingleCompactAttempt(doFetch)
|
|
1263
1287
|
: fetchWithTransientRetry(doFetch, {
|
|
1264
1288
|
abortSignal: req.signal,
|
|
1265
|
-
label: safeHostLabel(compactUrl),
|
|
1289
|
+
label: safeHostLabel(compactUrl), destination: errorDestinationLabel(compactUrl),
|
|
1266
1290
|
// Key-auth policy is a logical-request total; canonical forward keeps its default
|
|
1267
1291
|
// ladder. Both intersect the same shared base remainder as ordinary Responses.
|
|
1268
1292
|
attempts: sendBudget.remainingBaseSends(transientSendCapFor(
|
|
@@ -1382,6 +1406,8 @@ export async function handleResponsesCompact(
|
|
|
1382
1406
|
outcomeCtx = replay.authCtx;
|
|
1383
1407
|
compactProvider = replay.provider;
|
|
1384
1408
|
headers = replay.headers;
|
|
1409
|
+
const replayBinding = conversationStateBindingFromAuth(replay.authCtx, codexPoolAffinityKey(req.headers));
|
|
1410
|
+
if (replayBinding) applyAccountChangeConversationStateScrub({ body: compactBody, headers, bindingKey: replayBinding.bindingKey, servingAccountId: replayBinding.accountId, logCtx });
|
|
1385
1411
|
logCtx.accountLogLabel = codexAuthContextLogLabel(replay.authCtx, config);
|
|
1386
1412
|
try {
|
|
1387
1413
|
upstream = await sendCompactAttempt(compactProvider, headers, "single", authCtx);
|
|
@@ -1425,20 +1451,24 @@ export async function handleResponsesCompact(
|
|
|
1425
1451
|
recordCompactPoolOutcome(outcomeCtx, outcome);
|
|
1426
1452
|
return formatErrorResponse(502, "upstream_error", "Failed to connect to compact upstream");
|
|
1427
1453
|
};
|
|
1428
|
-
const scrubCompactStateForAlternate = (alternateAuthCtx: CodexAuthContext): void => {
|
|
1429
|
-
const
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
)
|
|
1454
|
+
const scrubCompactStateForAlternate = (alternateAuthCtx: CodexAuthContext, alternateHeaders: Headers): void => {
|
|
1455
|
+
const affinityKey = compactAlternateAffinityKey(authCtx, () => codexPoolAffinityKey(req.headers))
|
|
1456
|
+
?? codexPoolAffinityKey(req.headers);
|
|
1457
|
+
const priorAccountId = conversationStateAccountId(authCtx);
|
|
1458
|
+
// An unkeyed caller-owned main alternate has no binding of its own, but moving off the issuing
|
|
1459
|
+
// account still makes the carried state foreign. Scrub for this request only; nothing persists.
|
|
1460
|
+
const binding = conversationStateBindingFromAuth(alternateAuthCtx, affinityKey)
|
|
1461
|
+
?? (alternateAuthCtx.kind === "main" && priorAccountId && affinityKey
|
|
1462
|
+
? { bindingKey: affinityKey, accountId: priorAccountId === MAIN_CODEX_ACCOUNT_ID ? "__caller_main__" : MAIN_CODEX_ACCOUNT_ID }
|
|
1463
|
+
: null);
|
|
1435
1464
|
if (!binding) return;
|
|
1436
1465
|
for (const body of [raw, compactBody]) {
|
|
1437
1466
|
applyAccountChangeConversationStateScrub({
|
|
1438
1467
|
body,
|
|
1468
|
+
headers: alternateHeaders,
|
|
1439
1469
|
bindingKey: binding.bindingKey,
|
|
1440
1470
|
servingAccountId: binding.accountId,
|
|
1441
|
-
priorAccountId: authCtx
|
|
1471
|
+
priorAccountId: conversationStateAccountId(authCtx),
|
|
1442
1472
|
logCtx,
|
|
1443
1473
|
});
|
|
1444
1474
|
}
|
|
@@ -1541,7 +1571,7 @@ export async function handleResponsesCompact(
|
|
|
1541
1571
|
await upstream.body?.cancel().catch(() => undefined);
|
|
1542
1572
|
outcomeCtx = alternate.authCtx;
|
|
1543
1573
|
logCtx.accountLogLabel = codexAuthContextLogLabel(alternate.authCtx, config);
|
|
1544
|
-
scrubCompactStateForAlternate(alternate.authCtx);
|
|
1574
|
+
scrubCompactStateForAlternate(alternate.authCtx, alternate.headers);
|
|
1545
1575
|
try {
|
|
1546
1576
|
upstream = await sendCompactAttempt(alternate.provider, alternate.headers, "single", alternate.authCtx);
|
|
1547
1577
|
} catch (err) {
|
|
@@ -1598,7 +1628,7 @@ export async function handleResponsesCompact(
|
|
|
1598
1628
|
// B's identity before B's admission, so every budget and spend check runs against B. A's
|
|
1599
1629
|
// response stays intact until B is actually sent.
|
|
1600
1630
|
logCtx.accountLogLabel = codexAuthContextLogLabel(alternate.authCtx, config);
|
|
1601
|
-
scrubCompactStateForAlternate(alternate.authCtx);
|
|
1631
|
+
scrubCompactStateForAlternate(alternate.authCtx, alternate.headers);
|
|
1602
1632
|
const recordFirstMove = () => {
|
|
1603
1633
|
recordCompactPoolOutcome(authCtx, firstStatus, { retryAfter: firstRetryAfter, resetAt: firstResetAt });
|
|
1604
1634
|
void upstream.body?.cancel().catch(() => undefined);
|
|
@@ -1760,7 +1790,7 @@ export async function handleResponsesCompact(
|
|
|
1760
1790
|
// fallback spend four more.
|
|
1761
1791
|
// internalReq keeps only FORWARD_HEADERS, so the caller principal is resolved from req.
|
|
1762
1792
|
const replayPrincipal = { clientPrincipalId: resolveContextPrincipal(req, config, admission) };
|
|
1763
|
-
const response = await handleResponses(internalReq, config, logCtx, { abortSignal: req.signal, turnAdmissionLease, sendBudget, compactionRecoveryKind: "compaction-v1", compactionRoutingOverride: options.compactionRoutingOverride, advisorAdmissionPolicy: options.advisorAdmissionPolicy, replayPrincipal, ...(admission ? { admission } : {}) });
|
|
1793
|
+
const response = await handleResponses(internalReq, config, logCtx, { clientModelLabel: options.clientModelLabel, abortSignal: req.signal, turnAdmissionLease, sendBudget, compactionRecoveryKind: "compaction-v1", compactionRoutingOverride: options.compactionRoutingOverride, advisorAdmissionPolicy: options.advisorAdmissionPolicy, replayPrincipal, ...(admission ? { admission } : {}) });
|
|
1764
1794
|
if (req.signal.aborted) {
|
|
1765
1795
|
void response.body?.cancel(req.signal.reason).catch(() => undefined);
|
|
1766
1796
|
return formatErrorResponse(499, "client_cancelled", "Client cancelled compact request");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clientFacingModelText } from "../../lib/error-destination";
|
|
1
2
|
import type { AdapterEvent, OcxConfig } from "../../types";
|
|
2
3
|
import { carryResponseToolOwnership } from "./response-tool-ownership";
|
|
3
4
|
import { routeConcreteModel, type RouteResult } from "../../router";
|
|
@@ -160,7 +161,8 @@ export async function runWithCompactionRecovery(
|
|
|
160
161
|
let target: RouteResult;
|
|
161
162
|
try { target = routeConcreteModel(config, recovery.model); } catch { return keep(response); }
|
|
162
163
|
if (!routed(target, kind) || identity(sourceRoute) === identity(target)) return keep(response);
|
|
163
|
-
const originalModel = firstOptions.
|
|
164
|
+
const originalModel = firstOptions.clientModelLabel ? clientFacingModelText(firstOptions.clientModelLabel)
|
|
165
|
+
: firstOptions.compactionRoutingOverride?.sourceModel ?? String(snapshot.model);
|
|
164
166
|
// Use the established protocol commit boundary. For runTurn streams the direct event
|
|
165
167
|
// observer additionally preserves side-effect heartbeats that the bridge does not publish.
|
|
166
168
|
if (response.ok && hasResponseMediaType(response.headers, "text/event-stream")) {
|
|
@@ -268,7 +270,7 @@ export async function runWithCompactionRecovery(
|
|
|
268
270
|
options.accountLoad.lease = null;
|
|
269
271
|
}
|
|
270
272
|
fallback = await dispatch(child, config, logCtx, {
|
|
271
|
-
...options, compactionRecoveryAttempted: true, compactionRecoveryPermit: recoveryPermit,
|
|
273
|
+
...options, clientModelLabel: firstOptions.clientModelLabel, compactionRecoveryAttempted: true, compactionRecoveryPermit: recoveryPermit,
|
|
272
274
|
compactionRoutingOverride: { sourceModel: originalModel },
|
|
273
275
|
onRequestBodyRead: undefined, onRequestBodyParsed: undefined,
|
|
274
276
|
onCompactionRecoveryRoute: undefined, onCompactionRecoveryAdapterEvent: undefined,
|
|
@@ -7,6 +7,7 @@ import { resolvePolicyProfileId } from "../../routing/profile";
|
|
|
7
7
|
import { parseSyntheticRowId } from "../fast-row";
|
|
8
8
|
import { recallComboForLane } from "./combo-session-recall";
|
|
9
9
|
import { sessionLaneIdFromRequest } from "../request-log-conversation";
|
|
10
|
+
import { isLocalCompactionCheckpoint } from "../../responses/compaction-history-framing";
|
|
10
11
|
|
|
11
12
|
/** `sourceModel` is the conversation's own selector before the rewrite. */
|
|
12
13
|
export interface CompactionRoutingOverride {
|
|
@@ -38,7 +39,7 @@ function configuredTriggers(value: unknown): readonly string[] | null {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export interface CompactionRoutingOverrideOptions {
|
|
41
|
-
/**
|
|
42
|
+
/** Responses accepts remote triggers or opted-in local checkpoints; compact carries neither. */
|
|
42
43
|
endpoint?: "responses" | "compact";
|
|
43
44
|
transport?: "websocket";
|
|
44
45
|
}
|
|
@@ -66,8 +67,10 @@ export function applyCompactionRoutingOverride(
|
|
|
66
67
|
? source.startsWith(selector.slice(0, -1)) && source.length > selector.length - 1
|
|
67
68
|
: source === selector)) return null;
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const remoteTrigger = Array.isArray(raw.input) && raw.input.some(item => record(item)?.type === "compaction_trigger");
|
|
71
|
+
const localCheckpoint = options.endpoint !== "compact" && !remoteTrigger
|
|
72
|
+
&& config.codexClientCompaction === true && isLocalCompactionCheckpoint(raw.input);
|
|
73
|
+
if (options.endpoint !== "compact" && !remoteTrigger && !localCheckpoint) return null;
|
|
71
74
|
|
|
72
75
|
const metadata: unknown[] = [];
|
|
73
76
|
const header = headers.get("x-codex-turn-metadata");
|
|
@@ -81,7 +84,9 @@ export function applyCompactionRoutingOverride(
|
|
|
81
84
|
try {
|
|
82
85
|
const parsed = record(JSON.parse(value));
|
|
83
86
|
if (parsed?.request_kind !== "compaction") return null;
|
|
84
|
-
const
|
|
87
|
+
const compaction = record(parsed.compaction);
|
|
88
|
+
if (localCheckpoint && compaction?.implementation !== "responses") return null;
|
|
89
|
+
const carried = compaction?.trigger;
|
|
85
90
|
if (typeof carried !== "string" || !triggers.includes(carried)) return null;
|
|
86
91
|
// Copies that name different triggers are not agreement, and picking either one would
|
|
87
92
|
// let a caller widen an override by disagreeing with itself.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { markProxyError } from "../../lib/client-error-body";
|
|
2
|
+
import { applyClaudeBridgePoolSession } from "../claude-bridge-pool-session";
|
|
1
3
|
import type { OcxProviderConfig, OcxConfig } from "../../types";
|
|
2
4
|
import { isCanonicalOpenAiForwardProvider } from "../../providers/openai-tiers";
|
|
3
5
|
import type { CodexAuthContext } from "../../codex/auth-context";
|
|
@@ -111,7 +113,7 @@ function validatedCallerDirectHeaders(
|
|
|
111
113
|
return captureCallerDirectAuth(headers, config) ? headers : undefined;
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
|
|
116
|
+
function codexRouteCredentialDomainHeadersFor(
|
|
115
117
|
req: Request,
|
|
116
118
|
route: RouteResult,
|
|
117
119
|
options: HandleResponsesOptions,
|
|
@@ -156,6 +158,20 @@ export function codexRouteCredentialDomainHeaders(
|
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Credential-domain headers for Codex account SELECTION (previews, recovery, final resolution).
|
|
163
|
+
* A Claude bridge pool identity is completed here only; upstream headers are always materialized
|
|
164
|
+
* from the uncompleted form, so the synthesized pair never reaches the wire.
|
|
165
|
+
*/
|
|
166
|
+
export function codexRouteCredentialDomainHeaders(
|
|
167
|
+
req: Request, route: RouteResult, options: HandleResponsesOptions,
|
|
168
|
+
credentialDomainWasRewritten: boolean, config: OcxConfig,
|
|
169
|
+
): Headers {
|
|
170
|
+
return applyClaudeBridgePoolSession(
|
|
171
|
+
codexRouteCredentialDomainHeadersFor(req, route, options, credentialDomainWasRewritten, config), route, options,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
159
175
|
/**
|
|
160
176
|
* Does this route substitute OUR stored main credential, and does the caller own the credential
|
|
161
177
|
* this request will authenticate with?
|
|
@@ -208,9 +224,9 @@ export async function resolveResponsesCodexAuth(
|
|
|
208
224
|
let authCtx: CodexAuthContext | undefined;
|
|
209
225
|
// Ingress already refuses assertion_only; a later internal hop must not reach a pool or
|
|
210
226
|
// routed credential with it either, because that would be a silent credential swap.
|
|
211
|
-
if (hasAgentAssertionAuthorization(req.headers)) return { ok: false, response: agentAssertionUnsupportedResponse() };
|
|
227
|
+
if (hasAgentAssertionAuthorization(req.headers)) return { ok: false, response: markProxyError(agentAssertionUnsupportedResponse()) };
|
|
212
228
|
try {
|
|
213
|
-
let authInputHeaders =
|
|
229
|
+
let authInputHeaders = codexRouteCredentialDomainHeadersFor(
|
|
214
230
|
req,
|
|
215
231
|
route,
|
|
216
232
|
options,
|
|
@@ -270,7 +286,9 @@ export async function resolveResponsesCodexAuth(
|
|
|
270
286
|
validateForwardAdmissionCredential(authInputHeaders, config);
|
|
271
287
|
}
|
|
272
288
|
if (route.codexAccountMode) {
|
|
273
|
-
|
|
289
|
+
// Only selection sees the Claude bridge pool identity; materialization below keeps the
|
|
290
|
+
// uncompleted headers, so the wire matches the original request.
|
|
291
|
+
authCtx = await resolveCodexAuthContext(applyClaudeBridgePoolSession(authInputHeaders, route, options), config, route.codexAccountMode, {
|
|
274
292
|
admission: options.admission,
|
|
275
293
|
codexAuthPolicy: options.codexAuthPolicy,
|
|
276
294
|
accountId: route.codexAccountId,
|
|
@@ -323,7 +341,7 @@ export async function resolveResponsesCodexAuth(
|
|
|
323
341
|
releaseCodexAuthContextProbeLease(authCtx);
|
|
324
342
|
return {
|
|
325
343
|
ok: false,
|
|
326
|
-
response: formatErrorResponse(401, "authentication_error", "Selected Codex account needs reauthentication"),
|
|
344
|
+
response: markProxyError(formatErrorResponse(401, "authentication_error", "Selected Codex account needs reauthentication")),
|
|
327
345
|
};
|
|
328
346
|
}
|
|
329
347
|
if (stripAuthorization) {
|
|
@@ -371,9 +389,9 @@ export async function resolveResponsesCodexAuth(
|
|
|
371
389
|
console.error(`[codex-auth] Pool account ${safeAccountLabel} token failed; reauthentication required`);
|
|
372
390
|
}
|
|
373
391
|
if (err instanceof ForwardAdmissionCredentialError) {
|
|
374
|
-
return { ok: false, response: formatErrorResponse(401, "authentication_error", err.message) };
|
|
392
|
+
return { ok: false, response: markProxyError(formatErrorResponse(401, "authentication_error", err.message)) };
|
|
375
393
|
}
|
|
376
|
-
if (err instanceof AgentAssertionUnsupportedError) return { ok: false, response: agentAssertionUnsupportedResponse() };
|
|
394
|
+
if (err instanceof AgentAssertionUnsupportedError) return { ok: false, response: markProxyError(agentAssertionUnsupportedResponse()) };
|
|
377
395
|
const response = mapCodexAuthContextErrorToResponse(err, {
|
|
378
396
|
accountSelector: route.codexAccountNamespace,
|
|
379
397
|
now: Date.now(),
|
|
@@ -438,15 +456,15 @@ export function poolCredentialRefreshIncompleteResponse(args: {
|
|
|
438
456
|
if (args.logCtx) markLocalRequestLogRefusal(args.logCtx, CODEX_POOL_REFRESH_INCOMPLETE_LOG_REASON);
|
|
439
457
|
const label = args.accountSelector ?? codexAuthContextLogLabel(args.authCtx, args.config);
|
|
440
458
|
const account = label ? `Codex pool account ${label}` : "the selected Codex pool account";
|
|
441
|
-
const response = formatErrorResponse(
|
|
459
|
+
const response = markProxyError(formatErrorResponse(
|
|
442
460
|
503,
|
|
443
461
|
"server_busy",
|
|
444
462
|
`Codex credential refresh did not complete for ${account}; retry this request. `
|
|
445
463
|
+ "If it keeps failing, sign in to that account again.",
|
|
446
|
-
);
|
|
464
|
+
));
|
|
447
465
|
const headers = new Headers(response.headers);
|
|
448
466
|
headers.set("Retry-After", "1");
|
|
449
|
-
return new Response(response.body, { status: response.status, headers });
|
|
467
|
+
return markProxyError(new Response(response.body, { status: response.status, headers }));
|
|
450
468
|
}
|
|
451
469
|
|
|
452
470
|
|
|
@@ -484,7 +502,7 @@ export async function refreshPoolForwardAuth(args: {
|
|
|
484
502
|
ok: false,
|
|
485
503
|
quarantine: true,
|
|
486
504
|
quarantineGeneration: refreshed.generation,
|
|
487
|
-
response: formatErrorResponse(401, "authentication_error", "Selected Codex account needs reauthentication"),
|
|
505
|
+
response: markProxyError(formatErrorResponse(401, "authentication_error", "Selected Codex account needs reauthentication")),
|
|
488
506
|
};
|
|
489
507
|
}
|
|
490
508
|
// Only a CAS this request performed itself proves the new credential descends from
|
|
@@ -522,7 +540,7 @@ export async function refreshPoolForwardAuth(args: {
|
|
|
522
540
|
return {
|
|
523
541
|
ok: false,
|
|
524
542
|
quarantine: true,
|
|
525
|
-
response: formatErrorResponse(401, "authentication_error", "Selected Codex account needs reauthentication"),
|
|
543
|
+
response: markProxyError(formatErrorResponse(401, "authentication_error", "Selected Codex account needs reauthentication")),
|
|
526
544
|
};
|
|
527
545
|
}
|
|
528
546
|
if (options.abortSignal?.aborted || req.signal.aborted) {
|
|
@@ -564,7 +582,7 @@ export async function refreshNativeMainForwardAuth(args: {
|
|
|
564
582
|
> {
|
|
565
583
|
const { req, config, route, authCtx, substituteMainCredential, options } = args;
|
|
566
584
|
if (authCtx.kind !== "main-pool") {
|
|
567
|
-
return { ok: false, response: formatErrorResponse(401, "authentication_error", "No native main credential to refresh") };
|
|
585
|
+
return { ok: false, response: markProxyError(formatErrorResponse(401, "authentication_error", "No native main credential to refresh")) };
|
|
568
586
|
}
|
|
569
587
|
try {
|
|
570
588
|
const refreshed = await forceRefreshMainAccountToken(authCtx.accessToken, {
|
|
@@ -572,7 +590,7 @@ export async function refreshNativeMainForwardAuth(args: {
|
|
|
572
590
|
...(options.nativeMainRefreshDependencies ?? {}),
|
|
573
591
|
});
|
|
574
592
|
if (!refreshed) {
|
|
575
|
-
return { ok: false, response: formatErrorResponse(401, "authentication_error", "Codex main account needs reauthentication") };
|
|
593
|
+
return { ok: false, response: markProxyError(formatErrorResponse(401, "authentication_error", "Codex main account needs reauthentication")) };
|
|
576
594
|
}
|
|
577
595
|
const refreshedAuthCtx: CodexAuthContext = {
|
|
578
596
|
...authCtx,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { conversationStateAccountId, releaseRequestOwnedMainOnOutcome, isKeyedRequestOwnedMain } from "../../codex/request-owned-affinity";
|
|
1
2
|
import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
|
|
2
3
|
import { captureAccountAutoPauseAttempt, wasPermanentAccountRefusal } from "../../oauth/account-auto-pause";
|
|
3
4
|
import type { OcxConfig, OcxProviderConfig, OcxParsedRequest } from "../../types";
|
|
@@ -26,6 +27,7 @@ import { formatErrorResponse } from "../../bridge";
|
|
|
26
27
|
import { readBoundedResponseBody } from "../../lib/bounded-body";
|
|
27
28
|
import { upstreamErrorMessageFromPayload, isRateLimitOrQuotaFailureMessage } from "../../lib/errors";
|
|
28
29
|
import { isNonReplayableResponse, isTransientUpstreamStatus, SendBudgetExhaustedError } from "../../lib/upstream-retry";
|
|
30
|
+
import { applyClaudeBridgePoolSession } from "../claude-bridge-pool-session";
|
|
29
31
|
import {
|
|
30
32
|
codexWsPreOutputRefusalHold,
|
|
31
33
|
codexWsPreOutputRefusalOutcomeRecorded,
|
|
@@ -489,6 +491,8 @@ export interface CodexPoolAccountRetryArgs {
|
|
|
489
491
|
abortSignal?: AbortSignal;
|
|
490
492
|
onCodexAuthContextResolved?: (ctx: CodexAuthContext) => void;
|
|
491
493
|
deferCodexResetDerivedCooldown?: boolean;
|
|
494
|
+
/** Private Claude bridge pool identity; alternate selection completes it like the first pick. */
|
|
495
|
+
claudeBridgePoolSession?: string;
|
|
492
496
|
// Narrowed subset of HandleResponsesOptions: the retry rebuilds the adapter, so it
|
|
493
497
|
// needs the inbound scope or the retry could land on a different wire than the
|
|
494
498
|
// first attempt.
|
|
@@ -766,7 +770,9 @@ export async function retryCodexPoolOnAlternateAccount(
|
|
|
766
770
|
}
|
|
767
771
|
try {
|
|
768
772
|
retryAuthCtx ??= await resolveCodexAuthContext(
|
|
769
|
-
|
|
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),
|
|
770
776
|
config,
|
|
771
777
|
"pool",
|
|
772
778
|
{
|
|
@@ -912,9 +918,7 @@ export async function retryCodexPoolOnAlternateAccount(
|
|
|
912
918
|
{
|
|
913
919
|
const binding = conversationStateBindingFromAuth(
|
|
914
920
|
retryAuthCtx,
|
|
915
|
-
firstAuthCtx.
|
|
916
|
-
? firstAuthCtx.affinityKey
|
|
917
|
-
: undefined,
|
|
921
|
+
firstAuthCtx.affinityKey ?? firstAuthCtx.conversationStateKey,
|
|
918
922
|
);
|
|
919
923
|
if (binding) {
|
|
920
924
|
applyAccountChangeConversationStateScrub({
|
|
@@ -925,7 +929,7 @@ export async function retryCodexPoolOnAlternateAccount(
|
|
|
925
929
|
&& parsed._nativeReasoningRetention?.accountSwitch === true,
|
|
926
930
|
bindingKey: binding.bindingKey,
|
|
927
931
|
servingAccountId: binding.accountId,
|
|
928
|
-
priorAccountId: firstAuthCtx
|
|
932
|
+
priorAccountId: conversationStateAccountId(firstAuthCtx),
|
|
929
933
|
logCtx,
|
|
930
934
|
});
|
|
931
935
|
}
|
|
@@ -1164,7 +1168,14 @@ export function codexForwardTerminalOutcomeRecorder(
|
|
|
1164
1168
|
modelId?: string,
|
|
1165
1169
|
logCtx?: RequestLogContext,
|
|
1166
1170
|
): ((status: ResponsesTerminalStatus, httpStatusOverride?: number) => void) | undefined {
|
|
1167
|
-
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
|
+
}
|
|
1168
1179
|
const windowMeta = codexFailureWindowOutcomeMeta(authCtx);
|
|
1169
1180
|
return (status, httpStatusOverride) => {
|
|
1170
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",
|