@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,3 +1,8 @@
|
|
|
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";
|
|
@@ -54,7 +59,6 @@ import {
|
|
|
54
59
|
} from "../../combos";
|
|
55
60
|
import { formatErrorResponse } from "../../bridge";
|
|
56
61
|
import { SEND_BUDGET_EXHAUSTED_CODE } from "../../lib/errors";
|
|
57
|
-
import { redactSecretString, sanitizeLogMetadataString } from "../../lib/redact";
|
|
58
62
|
import {
|
|
59
63
|
expandPreviousResponseInput,
|
|
60
64
|
previousResponseReplayFailure,
|
|
@@ -383,19 +387,22 @@ export async function executeComboResponses(
|
|
|
383
387
|
options: HandleResponsesOptions & { translatorBudget: TranslatorBudget },
|
|
384
388
|
requestDispatchers: ResponsesDispatchers,
|
|
385
389
|
): Promise<Response> {
|
|
390
|
+
const clientModelLabel = options.clientModelLabel ?? clientFacingModelLabel(undefined);
|
|
391
|
+
const responseModel = clientFacingModelText(clientModelLabel);
|
|
386
392
|
const requestedModel = options.mainHardLockFallbackOverride?.sourceModel
|
|
387
393
|
?? (typeof (rawBody as { model?: unknown } | null)?.model === "string"
|
|
388
394
|
? (rawBody as { model: string }).model
|
|
389
395
|
: `combo/${comboId}`);
|
|
396
|
+
if (requestedModel !== responseModel) options = { ...options, clientResponseModelLabel: clientModelLabel };
|
|
390
397
|
Object.assign(logCtx, {
|
|
391
|
-
requestedModel,
|
|
392
|
-
model:
|
|
398
|
+
requestedModel: responseModel,
|
|
399
|
+
model: responseModel,
|
|
393
400
|
provider: "combo",
|
|
394
401
|
comboId,
|
|
395
402
|
});
|
|
396
403
|
const combo = getCombo(config, comboId);
|
|
397
404
|
if (!combo) {
|
|
398
|
-
return formatErrorResponse(404, "invalid_request_error",
|
|
405
|
+
return formatErrorResponse(404, "invalid_request_error", "Unknown combo");
|
|
399
406
|
}
|
|
400
407
|
// Resolve against the original request once; every bridge candidate receives the same trusted
|
|
401
408
|
// result after its provisional Authorization is removed, including an explicitly keyless result.
|
|
@@ -459,7 +466,7 @@ export async function executeComboResponses(
|
|
|
459
466
|
);
|
|
460
467
|
}
|
|
461
468
|
if (combo.imageInput === "disabled" && comboRequestHasImageInput(body)) {
|
|
462
|
-
return formatErrorResponse(400, "invalid_request_error",
|
|
469
|
+
return formatErrorResponse(400, "invalid_request_error", "This combo does not accept image input");
|
|
463
470
|
}
|
|
464
471
|
const comboReplaySnapshot = {
|
|
465
472
|
sourceBody: body,
|
|
@@ -509,9 +516,10 @@ export async function executeComboResponses(
|
|
|
509
516
|
attempt: childLog.activeAttempt,
|
|
510
517
|
});
|
|
511
518
|
}
|
|
519
|
+
carryProxyErrorContext(childLog, logCtx);
|
|
512
520
|
Object.assign(logCtx, childLog, {
|
|
513
|
-
requestedModel,
|
|
514
|
-
model:
|
|
521
|
+
requestedModel: responseModel,
|
|
522
|
+
model: responseModel,
|
|
515
523
|
provider: "combo",
|
|
516
524
|
comboId,
|
|
517
525
|
routeDecision: logCtx.routeDecision,
|
|
@@ -519,6 +527,11 @@ export async function executeComboResponses(
|
|
|
519
527
|
activeAttempt: undefined,
|
|
520
528
|
activeAttemptStartedAt: undefined,
|
|
521
529
|
});
|
|
530
|
+
if (requestedModel !== responseModel) {
|
|
531
|
+
projectLocalModelRefusalLog(logCtx, clientModelLabel);
|
|
532
|
+
logCtx.model = responseModel; logCtx.requestedModel = responseModel;
|
|
533
|
+
if (options.clientModelLabel) logCtx.jevDecision = undefined;
|
|
534
|
+
}
|
|
522
535
|
};
|
|
523
536
|
|
|
524
537
|
const unreadableEncryptedAgentTask = hasUnreadableEncryptedAgentTask(
|
|
@@ -678,7 +691,7 @@ export async function executeComboResponses(
|
|
|
678
691
|
{ parentThreadId: inboundClientThreadId },
|
|
679
692
|
);
|
|
680
693
|
if (!options.abortSignal?.aborted && onlyMuseToolIncompatible()) {
|
|
681
|
-
return comboUnavailableResponse(
|
|
694
|
+
return comboUnavailableResponse("No available targets for combo; targets cannot preserve mandatory tool_choice");
|
|
682
695
|
}
|
|
683
696
|
return options.abortSignal?.aborted
|
|
684
697
|
? clientCancelledResponse()
|
|
@@ -698,7 +711,7 @@ export async function executeComboResponses(
|
|
|
698
711
|
if (protocolRefusal) return protocolRefusal;
|
|
699
712
|
if (onlyReplayIncompatibleTargetsRemain()) return targetIncompatibleResponse();
|
|
700
713
|
if (!options.abortSignal?.aborted && onlyMuseToolIncompatible()) {
|
|
701
|
-
return comboUnavailableResponse(
|
|
714
|
+
return comboUnavailableResponse("No available targets for combo; targets cannot preserve mandatory tool_choice");
|
|
702
715
|
}
|
|
703
716
|
return options.abortSignal?.aborted
|
|
704
717
|
? clientCancelledResponse()
|
|
@@ -812,7 +825,7 @@ export async function executeComboResponses(
|
|
|
812
825
|
if (pinReuse?.released) decision = { ...decision, pinReason: pinReuse.released };
|
|
813
826
|
jevDecision = decision;
|
|
814
827
|
pick = { ...selected.pick, attempted: [targetKey(selected.pick.target)] };
|
|
815
|
-
logCtx.jevDecision = normalizePersistedJevDecision({
|
|
828
|
+
logCtx.jevDecision = !options.clientModelLabel || requestedModel === responseModel ? normalizePersistedJevDecision({
|
|
816
829
|
version: 1,
|
|
817
830
|
comboId,
|
|
818
831
|
selected: {
|
|
@@ -831,10 +844,10 @@ export async function executeComboResponses(
|
|
|
831
844
|
...(decision.quota ? { quota: decision.quota } : {}),
|
|
832
845
|
...(decision.pinned ? { pinned: true } : {}),
|
|
833
846
|
...(decision.pinReason ? { pinReason: decision.pinReason } : {}),
|
|
834
|
-
});
|
|
847
|
+
}) : undefined;
|
|
835
848
|
console.debug("[combo] JEV decision", {
|
|
836
849
|
backend: decision.backend,
|
|
837
|
-
|
|
850
|
+
target: comboTargetLogLabel(config, comboId, pick.target),
|
|
838
851
|
effort: decision.effort,
|
|
839
852
|
gate: decision.gate,
|
|
840
853
|
latencyMs: decision.latencyMs,
|
|
@@ -853,7 +866,7 @@ export async function executeComboResponses(
|
|
|
853
866
|
}
|
|
854
867
|
// One immutable combo selection trace, before any child dispatch; child
|
|
855
868
|
// adoption below must never replace it with a concrete child route trace.
|
|
856
|
-
const decision = comboRouteDecisionTrace(config, comboId, pick,
|
|
869
|
+
const decision = comboRouteDecisionTrace(config, comboId, pick, responseModel);
|
|
857
870
|
const selectedReason = options.memoryModelPhase
|
|
858
871
|
? memoryModelRouteReason(options.memoryModelPhase)
|
|
859
872
|
: toolLoopPin ? COMBO_TOOL_LOOP_PIN_REASON : jevDecision?.pinned ? JEV_SESSION_PIN_ROUTE_REASON : undefined;
|
|
@@ -931,7 +944,7 @@ export async function executeComboResponses(
|
|
|
931
944
|
}
|
|
932
945
|
const remainingQuotaCooldownMs = quotaCooldownUntil === undefined ? 0 : quotaCooldownUntil - Date.now();
|
|
933
946
|
return remainingQuotaCooldownMs > 0
|
|
934
|
-
? comboUnavailableResponse(
|
|
947
|
+
? comboUnavailableResponse("No available targets for combo", {
|
|
935
948
|
retryAfter: String(Math.max(1, Math.ceil(remainingQuotaCooldownMs / 1000))),
|
|
936
949
|
}) : lastFailure;
|
|
937
950
|
};
|
|
@@ -1287,9 +1300,10 @@ export async function executeComboResponses(
|
|
|
1287
1300
|
attemptRetained = true;
|
|
1288
1301
|
noteComboSuccess(comboId, combo, pick.target, pick.writerGeneration);
|
|
1289
1302
|
settleComboReprobeSuccess(pick);
|
|
1303
|
+
carryProxyErrorContext(childLog, logCtx);
|
|
1290
1304
|
Object.assign(logCtx, childLog, {
|
|
1291
|
-
requestedModel,
|
|
1292
|
-
model:
|
|
1305
|
+
requestedModel: responseModel,
|
|
1306
|
+
model: responseModel,
|
|
1293
1307
|
provider: "combo",
|
|
1294
1308
|
comboId,
|
|
1295
1309
|
routeDecision: logCtx.routeDecision,
|
|
@@ -1315,6 +1329,7 @@ export async function executeComboResponses(
|
|
|
1315
1329
|
try {
|
|
1316
1330
|
failure = consumedChildFailure
|
|
1317
1331
|
?? await consumeComboFailure(response, options.abortSignal);
|
|
1332
|
+
if (hasProxyErrorMessage(childLog, failure.upstreamMessage ?? "", { type: failure.upstreamType, code: failure.upstreamCode })) markProxyError(failure.response);
|
|
1318
1333
|
if (preflightModelRefusal !== undefined) failure = { ...failure, codexModelRefusal: preflightModelRefusal };
|
|
1319
1334
|
} catch (error) {
|
|
1320
1335
|
if (options.abortSignal?.aborted) {
|
|
@@ -1425,7 +1440,7 @@ export async function executeComboResponses(
|
|
|
1425
1440
|
adoptFailedChildLog(childLog);
|
|
1426
1441
|
if (classifyOverflow && failureDecision === "stop") {
|
|
1427
1442
|
return wantsStream
|
|
1428
|
-
? streamingContextOverflowResponse(
|
|
1443
|
+
? streamingContextOverflowResponse(responseModel, options.translatorBudget)
|
|
1429
1444
|
: jsonContextOverflowResponse();
|
|
1430
1445
|
}
|
|
1431
1446
|
return lastFailure;
|
|
@@ -1434,7 +1449,7 @@ export async function executeComboResponses(
|
|
|
1434
1449
|
adoptFailedChildLog(childLog);
|
|
1435
1450
|
if (classifyOverflow) {
|
|
1436
1451
|
return wantsStream
|
|
1437
|
-
? streamingContextOverflowResponse(
|
|
1452
|
+
? streamingContextOverflowResponse(responseModel, options.translatorBudget)
|
|
1438
1453
|
: jsonContextOverflowResponse();
|
|
1439
1454
|
}
|
|
1440
1455
|
return lastFailure;
|
|
@@ -1445,14 +1460,13 @@ export async function executeComboResponses(
|
|
|
1445
1460
|
contextFailure = { childLog, response: formatErrorResponse(400, "invalid_request_error",
|
|
1446
1461
|
failure.upstreamMessage ?? failure.classificationText, { code: "context_length_exceeded", classified: true }) };
|
|
1447
1462
|
}
|
|
1448
|
-
// A bare status made a revoked credential read as a provider outage. Log
|
|
1449
|
-
//
|
|
1450
|
-
const failureReason =
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
);
|
|
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
|
+
});
|
|
1454
1468
|
console.warn(
|
|
1455
|
-
`[combo] ${comboId}: ${
|
|
1469
|
+
`[combo] ${comboLogLabel(config, comboId)}: ${comboTargetLogLabel(config, comboId, pick.target)} failed with ${failure.response.status}`
|
|
1456
1470
|
+ ` after ${Date.now() - started}ms${failureReason ? `: ${failureReason}` : ""}`,
|
|
1457
1471
|
);
|
|
1458
1472
|
const failureNow = Date.now();
|
|
@@ -1575,11 +1589,11 @@ export async function executeComboResponses(
|
|
|
1575
1589
|
) {
|
|
1576
1590
|
if (localAdmissionRefusals?.length) logCtx.errorCode = "input_admission_refused";
|
|
1577
1591
|
const localMessage = localAdmissionRefusals?.length
|
|
1578
|
-
? `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 `
|
|
1579
1593
|
+ `that was tried can fit its input: ${localAdmissionRefusals.join(" ")} Compact the conversation before retrying.`
|
|
1580
1594
|
: undefined;
|
|
1581
1595
|
return (rawBody as { stream?: unknown } | null)?.stream === true
|
|
1582
|
-
? streamingContextOverflowResponse(
|
|
1596
|
+
? streamingContextOverflowResponse(responseModel, options.translatorBudget, localMessage)
|
|
1583
1597
|
: jsonContextOverflowResponse(localMessage);
|
|
1584
1598
|
}
|
|
1585
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";
|
|
@@ -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,
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
import { redactSecretString } from "../../lib/redact";
|
|
34
34
|
import { outboundCredentials } from "../../lib/outbound-credential-registry";
|
|
35
35
|
import { compressUpstreamRequestBody, isCanonicalCodexResponsesUrl } from "./request-compression";
|
|
36
|
+
import { redeemOutboundTurnState, TURN_STATE_BINDING_INIT, turnStateBinding } from "../turn-state-handles";
|
|
36
37
|
|
|
37
38
|
export { withUpstreamHttpVersion };
|
|
38
39
|
|
|
@@ -382,6 +383,10 @@ export function providerFetch(
|
|
|
382
383
|
// else keeps the provider's HTTP fetch. See ws-upstream.ts for the details.
|
|
383
384
|
const unobserved = async (input: Parameters<typeof globalThis.fetch>[0], init?: RequestInit,
|
|
384
385
|
reacquirePacing?: (provider: OcxProviderConfig, modelId?: string) => Promise<void>) => {
|
|
386
|
+
// Turn-state handles are redeemed here, at the send, where the admitted caller, the provider and
|
|
387
|
+
// the outbound account are all settled; a handle bound to anything else is not forwarded.
|
|
388
|
+
const sendHeaders = (sent?: RequestInit) => new Headers(sent?.headers ?? (input instanceof Request ? input.headers : undefined));
|
|
389
|
+
init = redeemOutboundTurnState(init, turnStateBinding(providerName, sendHeaders(init)));
|
|
385
390
|
const upstreamWebsocket = provider.upstreamWebsocket;
|
|
386
391
|
if (!options.httpOnly && typeof input === "string" && init
|
|
387
392
|
&& shouldUseCodexWsUpstream(input, init, runtime, upstreamWebsocket)) {
|
|
@@ -412,7 +417,8 @@ export function providerFetch(
|
|
|
412
417
|
};
|
|
413
418
|
const fallback = ((url: Parameters<typeof globalThis.fetch>[0], fallbackInit?: RequestInit) =>
|
|
414
419
|
httpFetch(url, { ...fallbackInit, [WS_FALLBACK_RECEIPT]: notifyOnce } as RequestInit, reacquirePacing, null)) as typeof globalThis.fetch;
|
|
415
|
-
const wsSend = codexWsExecutor((url: Parameters<typeof globalThis.fetch>[0], wsInit?: RequestInit) => codexWsUpstreamFetch(String(url),
|
|
420
|
+
const wsSend = codexWsExecutor((url: Parameters<typeof globalThis.fetch>[0], wsInit?: RequestInit) => codexWsUpstreamFetch(String(url),
|
|
421
|
+
{ ...(wsInit ?? init), [TURN_STATE_BINDING_INIT]: turnStateBinding(providerName, sendHeaders(wsInit ?? init)) } as RequestInit,
|
|
416
422
|
fallback, runtime, options.onCodexWsQuota, options.beforeDispatch, options.nativeControl,
|
|
417
423
|
async () => { (await waitForPacing(init.signal ?? undefined))?.release(); }, notifyOnce, options.preOutputRefusalHold),
|
|
418
424
|
{ provider, http: markEgressTransparentExecutor(fallback) });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clientFacingModelText, type ClientFacingModelLabel } from "../../lib/error-destination";
|
|
1
2
|
/**
|
|
2
3
|
* Pre-dispatch input admission (#1412).
|
|
3
4
|
*
|
|
@@ -63,6 +64,8 @@ export interface InputAdmissionResult {
|
|
|
63
64
|
estimatedTokens: number;
|
|
64
65
|
/** Resolved ceiling, or null when nothing could be resolved (=> always admitted). */
|
|
65
66
|
ceiling: number | null;
|
|
67
|
+
/** Actual shared context window when an input-only ceiling differs. */
|
|
68
|
+
contextWindow?: number | null;
|
|
66
69
|
/** Output space reserved by the combo preflight; absent on the loose direct gate. */
|
|
67
70
|
requiredOutputHeadroom?: number;
|
|
68
71
|
}
|
|
@@ -310,6 +313,7 @@ export function checkComboTargetInputAdmission(
|
|
|
310
313
|
estimatedTokens,
|
|
311
314
|
ceiling,
|
|
312
315
|
requiredOutputHeadroom,
|
|
316
|
+
...(window !== ceiling ? { contextWindow: window } : {}),
|
|
313
317
|
};
|
|
314
318
|
}
|
|
315
319
|
|
|
@@ -325,8 +329,30 @@ export function checkInputAdmission(
|
|
|
325
329
|
modelId: string,
|
|
326
330
|
nativeContextCap?: NativeContextLimitsInput,
|
|
327
331
|
): InputAdmissionResult {
|
|
328
|
-
const ceiling =
|
|
332
|
+
const { window, ceiling } = resolveContextLimits(provider, providerName, modelId, nativeContextCap);
|
|
329
333
|
if (ceiling === null) return { admitted: true, estimatedTokens: 0, ceiling: null };
|
|
330
334
|
const estimatedTokens = estimateInputTokens(parsed, modelId, provider);
|
|
331
|
-
return { admitted: estimatedTokens <= ceiling * ADMISSION_TOLERANCE, estimatedTokens, ceiling
|
|
335
|
+
return { admitted: estimatedTokens <= ceiling * ADMISSION_TOLERANCE, estimatedTokens, ceiling,
|
|
336
|
+
...(window !== ceiling ? { contextWindow: window } : {}) };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function inputAdmissionRefusalMessage(input: InputAdmissionResult, model: ClientFacingModelLabel): string {
|
|
340
|
+
const count = (value: number | null) => value !== null && Number.isFinite(value) && value >= 0 ? Math.trunc(value) : 0;
|
|
341
|
+
const label = clientFacingModelText(model);
|
|
342
|
+
const estimate = count(input.estimatedTokens);
|
|
343
|
+
const ceiling = count(input.ceiling);
|
|
344
|
+
if (input.contextWindow !== undefined && input.estimatedTokens > ceiling) {
|
|
345
|
+
const window = input.contextWindow === null ? "" : `; context window: ${count(input.contextWindow)} tokens`;
|
|
346
|
+
return `Estimated input (~${estimate} tokens) exceeds the input limit of ${label} (${ceiling} tokens${window}). `
|
|
347
|
+
+ "Start a new session or choose a model with a larger input limit.";
|
|
348
|
+
}
|
|
349
|
+
const window = count(input.contextWindow ?? input.ceiling);
|
|
350
|
+
const inputLimit = input.contextWindow !== undefined ? `; input limit: ${ceiling} tokens` : "";
|
|
351
|
+
return input.requiredOutputHeadroom !== undefined
|
|
352
|
+
? `Estimated input (~${estimate} tokens) plus ${count(input.requiredOutputHeadroom)} `
|
|
353
|
+
+ `tokens of requested output headroom cannot fit the context window of ${label} `
|
|
354
|
+
+ `(${window} tokens${inputLimit}).`
|
|
355
|
+
: `Estimated input (~${estimate} tokens) is far past the context window `
|
|
356
|
+
+ `of ${label} (${window} tokens${inputLimit}). Start a new session or choose a `
|
|
357
|
+
+ `model with a larger context window.`;
|
|
332
358
|
}
|
|
@@ -120,7 +120,7 @@ export class NativeInjectionChannel implements NativeResponseControl {
|
|
|
120
120
|
this.providerExecutedCallTypes, this.declaredBareToolNames,
|
|
121
121
|
);
|
|
122
122
|
if (undeclared !== undefined) {
|
|
123
|
-
injectionError(UNDECLARED_TOOL_CALL_ERROR_CODE, undeclaredToolCallMessage(
|
|
123
|
+
injectionError(UNDECLARED_TOOL_CALL_ERROR_CODE, undeclaredToolCallMessage());
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
/** Advertise client-owned function/custom calls and approvals, never hosted execution. */
|
|
@@ -5,10 +5,19 @@ export function nativeResponseRecord(value: unknown): value is Record<string, un
|
|
|
5
5
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
const canonical = (item: unknown): string => Array.isArray(item) ? `[${item.map(canonical).join(",")}]`
|
|
9
|
+
: nativeResponseRecord(item) ? `{${Object.keys(item).sort().map(key => `${JSON.stringify(key)}:${canonical(item[key])}`).join(",")}}`
|
|
10
|
+
: JSON.stringify(item) ?? "null";
|
|
11
|
+
const fingerprint = (json: string): string => createHash("sha256").update(json).digest("hex");
|
|
12
|
+
|
|
8
13
|
/** Compare JSON content by value: object-key order is irrelevant, array order is not. */
|
|
9
14
|
export function nativeResponseFingerprint(value: unknown): string {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
return fingerprint(canonical(value));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Keep transient body keys within the existing 64-byte digest payload bound. */
|
|
19
|
+
export function nativeResponseOutputIdentity(item: Record<string, unknown>): string {
|
|
20
|
+
if (typeof item.id === "string") return `id:${item.id}`;
|
|
21
|
+
const json = canonical(item);
|
|
22
|
+
return Buffer.byteLength(json, "utf8") <= 64 ? `json:${json}` : `body:${fingerprint(json)}`;
|
|
14
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { nativeResponseFingerprint as injectionFingerprint, nativeResponseRecord as record } from "./native-response-json";
|
|
1
|
+
import { nativeResponseFingerprint as injectionFingerprint, nativeResponseOutputIdentity as identity, nativeResponseRecord as record } from "./native-response-json";
|
|
2
2
|
type Frame = Record<string, unknown>;
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -10,7 +10,6 @@ export function nativeResponseOutput(done: ReadonlyMap<number, Frame>, terminal:
|
|
|
10
10
|
const observed = [...done.entries()].sort((a, b) => a[0] - b[0]).map(([, item]) => item);
|
|
11
11
|
if (terminal == null || (Array.isArray(terminal) && !terminal.length)) return observed;
|
|
12
12
|
if (!Array.isArray(terminal) || terminal.some(item => !record(item))) throw new Error("Invalid native response output.");
|
|
13
|
-
const identity = (item: Frame) => typeof item.id === "string" ? `id:${item.id}` : `body:${injectionFingerprint(item)}`;
|
|
14
13
|
const positions = new Map<string, number>();
|
|
15
14
|
observed.forEach((item, index) => {
|
|
16
15
|
const key = identity(item);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { carryProxyError } from "../../lib/client-error-body";
|
|
1
2
|
import { isNonReplayableResponse, isReplayRefusalResponse, markResponseNonReplayable } from "../../lib/upstream-retry";
|
|
2
3
|
import { clientCancelledResponse, readDisplaySafeErrorText } from "./core-errors";
|
|
3
4
|
|
|
@@ -44,5 +45,5 @@ export async function sanitizeNonReplayableUpstreamError(
|
|
|
44
45
|
status: response.status, headers,
|
|
45
46
|
});
|
|
46
47
|
markResponseNonReplayable(safe);
|
|
47
|
-
return safe;
|
|
48
|
+
return carryProxyError(response, safe);
|
|
48
49
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { markProxyError } from "../../lib/client-error-body";
|
|
1
2
|
import { formatErrorResponse } from "../../bridge";
|
|
2
3
|
import { RequestPacingQueueOverloadError } from "../../providers/request-pacing";
|
|
3
4
|
|
|
4
5
|
/** Convert local request-pacing admission failures into a retryable HTTP response. */
|
|
5
6
|
export function requestPacingOverloadResponse(error: unknown): Response | undefined {
|
|
6
7
|
if (!(error instanceof RequestPacingQueueOverloadError)) return undefined;
|
|
7
|
-
return formatErrorResponse(
|
|
8
|
+
return markProxyError(formatErrorResponse(
|
|
8
9
|
429,
|
|
9
10
|
"rate_limit_error",
|
|
10
11
|
error.message,
|
|
11
12
|
{ retryAfter: String(error.retryAfterSeconds) },
|
|
12
|
-
);
|
|
13
|
+
));
|
|
13
14
|
}
|