@bitkyc08/opencodex 2.94.0 → 2.96.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/gui/dist/assets/App-B4j-Txmb.css +1 -0
- package/gui/dist/assets/App-bwugJRKn.js +58 -0
- package/gui/dist/assets/{Tray-CZatQdoF.js → Tray-BOPQyDbH.js} +1 -1
- package/gui/dist/assets/index-ebuVUtB7.js +94 -0
- package/gui/dist/assets/quota-summary-6HsrHQAy.js +1 -0
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +10 -3
- package/src/adapters/command-code-project-context.ts +3 -3
- package/src/adapters/kiro/adapter.ts +4 -1
- package/src/adapters/kiro/stream.ts +1 -0
- package/src/adapters/kiro-events.ts +1 -0
- package/src/adapters/ollama-native.ts +10 -6
- package/src/adapters/openai-chat/messages.ts +20 -7
- package/src/adapters/openai-chat/passthrough.ts +4 -2
- package/src/adapters/openai-chat/single-system.ts +24 -0
- package/src/adapters/openai-responses/canonical-forward.ts +50 -13
- package/src/adapters/openai-responses/muse-tool-catalog.ts +87 -0
- package/src/adapters/openai-responses/passthrough.ts +45 -11
- package/src/adapters/openai-responses/prompt-cache.ts +3 -1
- package/src/adapters/openai-responses/request-strips.ts +23 -4
- package/src/adapters/openai-responses/tool-output-recovery.ts +21 -8
- package/src/adapters/openai-responses/tool-schema.ts +20 -8
- package/src/adapters/openai-responses/transport.ts +17 -26
- package/src/adapters/opencode-go-additional-tools.ts +39 -6
- package/src/adapters/qoder/adapter.ts +1 -1
- package/src/adapters/qoder/image-input.ts +5 -2
- package/src/adapters/routed-agent-messages.ts +3 -0
- package/src/adapters/xai-web-search.ts +6 -3
- package/src/adapters/zed-additional-tools.ts +7 -7
- package/src/adapters/zed.ts +1 -6
- package/src/advisor/consult.ts +22 -10
- package/src/advisor/runtime.ts +10 -4
- package/src/bridge/max-output-completion.ts +41 -0
- package/src/bridge/response-json.ts +9 -4
- package/src/bridge/sse.ts +13 -2
- package/src/chatgpt/app-server-shim/bundle-trust-policy.ts +5 -0
- package/src/chatgpt/app-server-shim/launcher.ts +40 -6
- package/src/claude/compatibility.ts +5 -1
- package/src/claude/desktop-3p.ts +27 -6
- package/src/claude/desktop-model-visibility.ts +141 -0
- package/src/claude/desktop-remote-store-io.ts +8 -8
- package/src/claude/inbound-content-options.ts +11 -1
- package/src/claude/intercept/proxy-auth.ts +16 -16
- package/src/cli/account-main.ts +3 -2
- package/src/cli/agent.ts +44 -15
- package/src/cli/capabilities-agents-routing.ts +9 -0
- package/src/cli/capabilities-provider-models.ts +7 -0
- package/src/cli/chatgpt-command.ts +1 -1
- package/src/cli/codex-launcher.ts +20 -8
- package/src/cli/codex-shim-autorestore.ts +19 -1
- package/src/cli/dispatch.ts +6 -6
- package/src/cli/doctor.ts +5 -5
- package/src/cli/ensure-desired-integrations.ts +4 -3
- package/src/cli/index.ts +8 -10
- package/src/cli/init.ts +2 -2
- package/src/cli/internal-command.ts +29 -2
- package/src/cli/message-command.ts +2 -1
- package/src/cli/message-mcp-command.ts +29 -0
- package/src/cli/provider-cc-switch-import.ts +185 -0
- package/src/cli/provider.ts +5 -0
- package/src/cli/registry.ts +2 -1
- package/src/cli/restart-scope.ts +2 -2
- package/src/cli/root.ts +6 -6
- package/src/cli/stop-approval.ts +15 -1
- package/src/cli/v2.ts +69 -19
- package/src/client/machine-api.ts +2 -2
- package/src/clients/config-export.ts +14 -3
- package/src/codex/account-cooldown-response.ts +18 -0
- package/src/codex/account-store.ts +1 -0
- package/src/codex/app-server-restart-service.ts +2 -2
- package/src/codex/auth-api/login-flow.ts +2 -2
- package/src/codex/auth-api/pool-quota-probe.ts +2 -2
- package/src/codex/auth-context-provider.ts +15 -0
- package/src/codex/auth-context.ts +14 -23
- package/src/codex/catalog/bundled.ts +10 -3
- package/src/codex/catalog/metadata.ts +4 -5
- package/src/codex/catalog/native-omission.ts +28 -0
- package/src/codex/catalog/native-template.ts +58 -0
- package/src/codex/catalog/parsing.ts +3 -29
- package/src/codex/catalog/provider-models.ts +2 -1
- package/src/codex/catalog/retained-sync.ts +15 -5
- package/src/codex/catalog/write-audit.ts +18 -18
- package/src/codex/cli-install-provenance.ts +46 -45
- package/src/codex/cli-update-artifacts.ts +8 -6
- package/src/codex/cli-update-job-store-windows.ts +99 -27
- package/src/codex/cli-update-job-worker.ts +3 -11
- package/src/codex/cli-update-recovery.ts +54 -8
- package/src/codex/cli-update-selection-gate.ts +74 -4
- package/src/codex/cli-windows-plan-provenance.ts +37 -19
- package/src/codex/codex-home-owner.ts +9 -8
- package/src/codex/convergence.ts +13 -3
- package/src/codex/coordinator-doctor.ts +14 -8
- package/src/codex/desktop-app/handoff.ts +1 -1
- package/src/codex/desktop-app-restart.ts +11 -1
- package/src/codex/exec-boundary.ts +26 -5
- package/src/codex/forward-transport-headers.ts +33 -33
- package/src/codex/history-provider.ts +11 -10
- package/src/codex/inject/bounded-config-reader.ts +14 -13
- package/src/codex/installation-id.ts +72 -0
- package/src/codex/main-account.ts +6 -6
- package/src/codex/native-main-lock-file.ts +13 -12
- package/src/codex/native-residue.ts +18 -14
- package/src/codex/orca-auth-source.ts +8 -7
- package/src/codex/quota-types.ts +5 -0
- package/src/codex/quota.ts +49 -7
- package/src/codex/role-auto-assign.ts +50 -26
- package/src/codex/role-capability.ts +160 -0
- package/src/codex/role-sizing.ts +24 -6
- package/src/codex/routing/cooldown-math.ts +3 -2
- package/src/codex/runtime.ts +43 -3
- package/src/codex/shim-fingerprint.ts +11 -9
- package/src/codex/shim-inspect.ts +3 -2
- package/src/codex/shim-restore-lock.ts +11 -14
- package/src/codex/shim-state-file.ts +22 -14
- package/src/codex/shim-wrapper-write.ts +7 -6
- package/src/codex/shim.ts +25 -2
- package/src/codex/transition-state.ts +5 -4
- package/src/combos/failover.ts +43 -4
- package/src/config/atomic-write.ts +38 -7
- package/src/config/diagnostics.ts +3 -0
- package/src/config/initialize.ts +6 -6
- package/src/config/load-degrade.ts +2 -0
- package/src/config/process-state.ts +23 -5
- package/src/config/salvage.ts +1 -0
- package/src/config/schema/config-schema.ts +29 -1
- package/src/config/schema/leaf-validators.ts +7 -0
- package/src/config/schema/workflow-budget.ts +43 -0
- package/src/config/tracked-runtime-inspection.ts +188 -0
- package/src/generated/compatibility-version.json +380 -244
- package/src/grok/sync.ts +10 -1
- package/src/integrations/aside-profile-context.ts +1 -1
- package/src/integrations/droid-settings.ts +4 -4
- package/src/integrations/hermes-profiles.ts +3 -3
- package/src/lib/bounded-file-read.ts +3 -9
- package/src/lib/bun-runtime-preflight.ts +9 -8
- package/src/lib/file-identity.ts +15 -0
- package/src/lib/local-chat-completion.ts +8 -6
- package/src/lib/local-destinations.ts +32 -3
- package/src/lib/redact-folding.ts +9 -0
- package/src/lib/spend-pool-alias-validation.ts +6 -6
- package/src/lib/state-store-registrations.ts +2 -0
- package/src/lib/test-home-guard.ts +37 -9
- package/src/lib/windows-secret-acl.ts +49 -31
- package/src/lib/workflow-budget-config.ts +39 -0
- package/src/local-credentials/generation.ts +6 -2
- package/src/local-credentials/inventory.ts +132 -8
- package/src/messaging/mcp-queue-rpc.ts +102 -0
- package/src/messaging/mcp-queue-server.ts +42 -0
- package/src/messaging/mcp-queue-tools.ts +39 -0
- package/src/messaging/remote-forward-failure.ts +35 -0
- package/src/messaging/remote-ports.ts +27 -5
- package/src/messaging/remote-process.ts +30 -4
- package/src/messaging/remote-tunnels.ts +80 -15
- package/src/oauth/anthropic-identity.ts +2 -6
- package/src/oauth/antigravity-discovery-diagnostics.ts +65 -0
- package/src/oauth/google-antigravity.ts +23 -10
- package/src/oauth/index.ts +7 -0
- package/src/oauth/kiro-device-login.ts +87 -30
- package/src/oauth/kiro-iam-identity-center.ts +107 -0
- package/src/oauth/store.ts +9 -7
- package/src/providers/account-quota-disk.ts +18 -4
- package/src/providers/anthropic-subscription.ts +25 -0
- package/src/providers/cc-switch-import-bytes.ts +991 -0
- package/src/providers/cc-switch-import-source.ts +1083 -0
- package/src/providers/cc-switch-import.ts +942 -0
- package/src/providers/claude-cli-usage.ts +15 -67
- package/src/providers/derive.ts +6 -0
- package/src/providers/model-discovery-diagnostic.ts +4 -0
- package/src/providers/model-discovery.ts +4 -4
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/model-rename-migration.ts +41 -6
- package/src/providers/quota/anthropic-decision-windows.ts +5 -19
- package/src/providers/quota/anthropic-usage-windows.ts +55 -0
- package/src/providers/quota/report-cache.ts +17 -4
- package/src/providers/quota.ts +2 -2
- package/src/providers/reasoning-metadata.ts +31 -15
- package/src/providers/registry/entries-core.ts +1 -1
- package/src/providers/registry/entries-extended.ts +1 -1
- package/src/providers/registry/model-ids.ts +1 -0
- package/src/providers/registry/model-seeds.ts +2 -1
- package/src/providers/registry/types.ts +3 -1
- package/src/providers/resolved-model-policy.ts +2 -2
- package/src/providers/routed-config.ts +2 -0
- package/src/providers/stale-model-roster-migration.ts +5 -1
- package/src/providers/xai-transport.ts +4 -4
- package/src/remote-control/workspace-codex-runtime.ts +2 -2
- package/src/remote-control/workspace-executor.ts +14 -13
- package/src/responses/custom-tool-compat.ts +2 -1
- package/src/responses/item-provenance.ts +79 -0
- package/src/responses/namespace-tool-compat.ts +21 -3
- package/src/responses/parser-tools.ts +1 -0
- package/src/responses/schema.ts +5 -2
- package/src/router.ts +21 -2
- package/src/routing/analytics.ts +3 -5
- package/src/routing/fallback-policy.ts +7 -3
- package/src/routing/health.ts +5 -3
- package/src/routing/history/build-file.ts +6 -0
- package/src/routing/history/indexer.ts +158 -31
- package/src/routing/history/ingest.ts +1 -1
- package/src/routing/history/integrity.ts +208 -0
- package/src/routing/history/rebuild-job.ts +20 -6
- package/src/routing/history/rebuild-protocol.ts +2 -1
- package/src/routing/history/rebuild-worker.ts +18 -0
- package/src/routing/history/sqlite-errors.ts +9 -0
- package/src/server/admission-model-scope.ts +21 -4
- package/src/server/advisor-admission-scope.ts +29 -0
- package/src/server/audio-dictation.ts +3 -0
- package/src/server/audio-live.ts +8 -2
- package/src/server/audio-upstream.ts +2 -0
- package/src/server/auth-cors.ts +5 -2
- package/src/server/capture-admission-policy.ts +91 -0
- package/src/server/chat-completions.ts +33 -7
- package/src/server/claude-messages.ts +93 -2
- package/src/server/codex-model-list.ts +2 -1
- package/src/server/configured-credentials.ts +5 -0
- package/src/server/context-history.ts +9 -6
- package/src/server/images.ts +14 -5
- package/src/server/index/live-sideband.ts +16 -2
- package/src/server/index/serve-options.ts +13 -2
- package/src/server/index/websocket-handler.ts +4 -1
- package/src/server/live.ts +30 -5
- package/src/server/management/agent-settings-routes.ts +34 -9
- package/src/server/management/codex-agent-role-routes.ts +1 -0
- package/src/server/management/codex-role-auto-assign.ts +50 -6
- package/src/server/management/config-routes.ts +15 -4
- package/src/server/management/context.ts +3 -0
- package/src/server/management/native-integration-routes.ts +22 -0
- package/src/server/management/oauth-account-routes.ts +20 -4
- package/src/server/management/provider-overwrite-carry.ts +21 -0
- package/src/server/management/provider-routes.ts +3 -1
- package/src/server/management/route-registry.ts +2 -0
- package/src/server/management/shared.ts +17 -1
- package/src/server/management/workflow-budget-routes.ts +70 -3
- package/src/server/messages-native-eligibility.ts +6 -5
- package/src/server/messages-native-scope.ts +6 -1
- package/src/server/messages-shared.ts +57 -17
- package/src/server/persistent-gui-session.ts +4 -4
- package/src/server/request-log.ts +30 -2
- package/src/server/responses/adapter-delivery.ts +4 -0
- package/src/server/responses/adapter-dispatch.ts +5 -0
- package/src/server/responses/advisor-plan-slot.ts +4 -0
- package/src/server/responses/advisor-slot.ts +73 -46
- package/src/server/responses/codex-auth-error.ts +9 -1
- package/src/server/responses/combo-required-tool-contract.ts +39 -0
- package/src/server/responses/compact.ts +41 -20
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +2 -0
- package/src/server/responses/core-combo.ts +70 -5
- package/src/server/responses/core-lifetime.ts +4 -0
- package/src/server/responses/core-normalize.ts +7 -1
- package/src/server/responses/core-options.ts +9 -0
- package/src/server/responses/core.ts +2 -0
- package/src/server/responses/jev-model-invoke.ts +4 -2
- package/src/server/responses/passthrough-build-error.ts +36 -0
- package/src/server/responses/passthrough-dispatch.ts +10 -24
- package/src/server/responses/policy-fallback.ts +2 -0
- package/src/server/responses/request-prepare.ts +4 -5
- package/src/server/responses/request-send-budget.ts +2 -1
- package/src/server/responses/request-sidecar-auth.ts +4 -1
- package/src/server/responses/request-transport.ts +2 -3
- package/src/server/responses/run-turn-execution.ts +4 -0
- package/src/server/responses/sidecar-execution.ts +21 -5
- package/src/server/responses-snapshot-repair.ts +18 -4
- package/src/server/responses-undeclared-tool-guard.ts +4 -0
- package/src/server/search.ts +13 -4
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +5 -2
- package/src/service/state-lock.ts +12 -11
- package/src/service-manager-probe.ts +53 -8
- package/src/types/admission-policy.ts +13 -0
- package/src/types/config.ts +25 -0
- package/src/types/provider.ts +10 -0
- package/src/types/request.ts +7 -0
- package/src/types.ts +1 -0
- package/src/update/job.ts +20 -0
- package/src/update/worker-launch.ts +71 -1
- package/src/usage/log.ts +25 -4
- package/src/vision/describe.ts +4 -7
- package/src/vision/index.ts +2 -0
- package/src/vision/plan.ts +4 -0
- package/src/vision/routed-describe.ts +38 -23
- package/src/web-search/executor.ts +4 -7
- package/src/web-search/loop.ts +104 -9
- package/src/web-search/parse.ts +10 -2
- package/gui/dist/assets/App-DMps4OLk.css +0 -1
- package/gui/dist/assets/App-DmvwlhQq.js +0 -58
- package/gui/dist/assets/index-3EPO_KbX.js +0 -94
- package/gui/dist/assets/quota-summary-BHvWg9mi.js +0 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { effectiveAzureOutputBudget } from "../../adapters/azure";
|
|
2
|
+
import { buildResponsesTransport } from "../../adapters/openai-responses/transport";
|
|
3
|
+
import { isMetaAiResponsesDestination } from "../../responses/muse-tool-name-alias";
|
|
4
|
+
import { chatCanPreserveMandatoryToolChoice, hasMandatoryToolChoice } from "./combo-required-tool-contract";
|
|
5
|
+
import { isCodexAccountCooldownResponse } from "../../codex/account-cooldown-response";
|
|
2
6
|
import { resolveWireProtocolOverride } from "../adapter-resolve";
|
|
3
|
-
import {
|
|
7
|
+
import { parseSyntheticRowId } from "../fast-row";
|
|
8
|
+
import { resolveOpenAiVirtualModel } from "../../providers/openai-virtual-models";
|
|
9
|
+
import { comboCooldownRetryAfterSeconds, isDefiniteContextOverflow, type CodexAccountModelRefusal } from "../../combos/failover";
|
|
4
10
|
import { fallbackTriggerForStatus, guardFallbackHop } from "../../routing/fallback-policy";
|
|
5
11
|
import {
|
|
6
12
|
isCodexReasoningEffort,
|
|
@@ -55,7 +61,7 @@ import {
|
|
|
55
61
|
previousResponseProviderState,
|
|
56
62
|
} from "../../responses/state";
|
|
57
63
|
import { hasUnreadableEncryptedAgentTask } from "./encrypted-payload";
|
|
58
|
-
import { routeConcreteModel, comboRouteDecisionTrace } from "../../router";
|
|
64
|
+
import { captureRouteStaticPolicy, routeConcreteModel, comboRouteDecisionTrace } from "../../router";
|
|
59
65
|
import { memoryModelRouteReason } from "./memory-models";
|
|
60
66
|
import { baseProviderLabel, poolAccountProviderLabel } from "../../providers/label";
|
|
61
67
|
import { getAccountSet } from "../../oauth/store";
|
|
@@ -532,10 +538,31 @@ export async function executeComboResponses(
|
|
|
532
538
|
const payloadEligible = (target: (typeof combo.targets)[number]): boolean =>
|
|
533
539
|
comboPayloadReadable || !unreadableEncryptedAgentTask || canDecryptUnreadableAgentTask(target);
|
|
534
540
|
const meteredAllowed = admissionMayUseMeteredComboTargets(config, options.admission, combo);
|
|
541
|
+
const museToolEligible = (target: (typeof combo.targets)[number]): boolean => {
|
|
542
|
+
if (!hasMandatoryToolChoice(body)) return true;
|
|
543
|
+
try {
|
|
544
|
+
const selector = `${target.provider}/${target.model}`, { fastRow, effortRow } = parseSyntheticRowId(selector, config);
|
|
545
|
+
const route = routeConcreteModel(config, fastRow?.baseId ?? effortRow?.baseId ?? selector);
|
|
546
|
+
const modelId = resolveOpenAiVirtualModel(route.providerName, route.modelId)?.wireModelId ?? route.modelId;
|
|
547
|
+
const inboundWire = options.inboundWire ?? "responses";
|
|
548
|
+
const policy = captureRouteStaticPolicy(route.providerName, modelId, route.provider,
|
|
549
|
+
route.staticPolicy.effectiveAlias, inboundWire);
|
|
550
|
+
const provider = resolveWireProtocolOverride(route.providerName, modelId, route.provider, inboundWire, policy);
|
|
551
|
+
return provider.adapter === "openai-chat" ? chatCanPreserveMandatoryToolChoice(body, provider, modelId)
|
|
552
|
+
: provider.adapter !== "openai-responses" || !isMetaAiResponsesDestination(buildResponsesTransport(provider, { headers: req.headers }).url);
|
|
553
|
+
} catch {
|
|
554
|
+
return true;
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
const onlyMuseToolIncompatible = (): boolean => {
|
|
558
|
+
const enabled = combo.targets.filter(target => config.providers[target.provider]?.disabled !== true);
|
|
559
|
+
return enabled.length > 0 && enabled.every(target => !museToolEligible(target));
|
|
560
|
+
};
|
|
535
561
|
// Recovery can replace unreadable encrypted input, but cannot relax other admission checks.
|
|
536
562
|
const recoveryEligible = (target: (typeof combo.targets)[number]): boolean =>
|
|
537
563
|
(meteredAllowed || !target.metered)
|
|
538
564
|
&& (combo.strategy !== "jev" || target.provider !== JEV_PROVIDER_ID)
|
|
565
|
+
&& museToolEligible(target)
|
|
539
566
|
&& reasoningReplayEligible(target)
|
|
540
567
|
&& (protocolLanes?.pickable(target) ?? true);
|
|
541
568
|
const targetEligible = (target: (typeof combo.targets)[number]): boolean =>
|
|
@@ -650,6 +677,9 @@ export async function executeComboResponses(
|
|
|
650
677
|
config,
|
|
651
678
|
{ parentThreadId: inboundClientThreadId },
|
|
652
679
|
);
|
|
680
|
+
if (!options.abortSignal?.aborted && onlyMuseToolIncompatible()) {
|
|
681
|
+
return comboUnavailableResponse(`No available targets for combo: ${comboId}; targets cannot preserve mandatory tool_choice`);
|
|
682
|
+
}
|
|
653
683
|
return options.abortSignal?.aborted
|
|
654
684
|
? clientCancelledResponse()
|
|
655
685
|
: comboUnavailable(comboId, undefined,
|
|
@@ -667,6 +697,9 @@ export async function executeComboResponses(
|
|
|
667
697
|
const protocolRefusal = protocolLanes?.refusal();
|
|
668
698
|
if (protocolRefusal) return protocolRefusal;
|
|
669
699
|
if (onlyReplayIncompatibleTargetsRemain()) return targetIncompatibleResponse();
|
|
700
|
+
if (!options.abortSignal?.aborted && onlyMuseToolIncompatible()) {
|
|
701
|
+
return comboUnavailableResponse(`No available targets for combo: ${comboId}; targets cannot preserve mandatory tool_choice`);
|
|
702
|
+
}
|
|
670
703
|
return options.abortSignal?.aborted
|
|
671
704
|
? clientCancelledResponse()
|
|
672
705
|
: comboUnavailable(comboId, undefined, comboExclusionReasons(config, comboId, targetEligible));
|
|
@@ -868,10 +901,15 @@ export async function executeComboResponses(
|
|
|
868
901
|
// "OpenAI account pool has no usable account credential" while every Claude account was spent.
|
|
869
902
|
let quotaFailure: Response | undefined;
|
|
870
903
|
let quotaFailedChildLog: RequestLogContext | undefined;
|
|
904
|
+
let contextFailure: { response: Response; childLog: RequestLogContext } | undefined;
|
|
871
905
|
// Snapshotted before dispatch: a 401/403 inside this ladder cools its own provider, and that
|
|
872
906
|
// fresh cooldown is not a reason the request found no target.
|
|
873
907
|
const quotaCooldownSnapshot = snapshotComboQuotaCooldowns(config, comboId);
|
|
874
908
|
const exhaustedFailure = (): Response => {
|
|
909
|
+
if (contextFailure) {
|
|
910
|
+
adoptFailedChildLog(contextFailure.childLog);
|
|
911
|
+
return contextFailure.response;
|
|
912
|
+
}
|
|
875
913
|
const returnsQuota = lastFailure && [400, 401, 403].includes(lastFailure.status) && quotaFailure;
|
|
876
914
|
const failedChildLog = returnsQuota ? quotaFailedChildLog : lastFailedChildLog;
|
|
877
915
|
if (failedChildLog) adoptFailedChildLog(failedChildLog);
|
|
@@ -1067,6 +1105,19 @@ export async function executeComboResponses(
|
|
|
1067
1105
|
finishRequestAttempt(attempt, 499, Date.now() - started, childLog.usage);
|
|
1068
1106
|
attemptRetained = true;
|
|
1069
1107
|
};
|
|
1108
|
+
// The row is written from `logCtx`, which copies `childLog` only when the child commits. A
|
|
1109
|
+
// bridge child binds its usage later, at the terminal frame, so the binding is forwarded here
|
|
1110
|
+
// after that point. Left on `childLog`, the row would re-read the bridged wire instead of the
|
|
1111
|
+
// adapter's usage, and that wire has no providerCredits and a context-derived input count.
|
|
1112
|
+
// A binding that arrives before the commit waits for it, and a child that never commits
|
|
1113
|
+
// forwards nothing: both flags belong to this target only.
|
|
1114
|
+
let childCommitted = false;
|
|
1115
|
+
let childUsageBound = false;
|
|
1116
|
+
const forwardChildUsage = (): void => {
|
|
1117
|
+
if (!childCommitted || !childUsageBound) return;
|
|
1118
|
+
logCtx.usageFromBridge = true;
|
|
1119
|
+
if (childLog.usage) logCtx.usage = childLog.usage;
|
|
1120
|
+
};
|
|
1070
1121
|
const completedTarget = { provider: pick.target.provider, model: pick.target.model };
|
|
1071
1122
|
const writerGeneration = pick.writerGeneration;
|
|
1072
1123
|
let consumedChildFailure: ConsumedComboFailure | undefined;
|
|
@@ -1147,6 +1198,10 @@ export async function executeComboResponses(
|
|
|
1147
1198
|
comboDispatchPermit: hopDecision?.allowed ? hopDecision.permit : undefined,
|
|
1148
1199
|
comboReplaySnapshot,
|
|
1149
1200
|
deferCodexResetDerivedCooldown,
|
|
1201
|
+
onBridgeUsageBound: () => {
|
|
1202
|
+
childUsageBound = true;
|
|
1203
|
+
forwardChildUsage();
|
|
1204
|
+
},
|
|
1150
1205
|
// Attempt-relative TTFT is recorded HERE (not via childLog.firstOutputMs — a later
|
|
1151
1206
|
// Object.assign(logCtx, childLog) would overwrite the request-relative value).
|
|
1152
1207
|
onFirstOutput: () => {
|
|
@@ -1246,6 +1301,8 @@ export async function executeComboResponses(
|
|
|
1246
1301
|
options.onCodexAuthContextResolved?.(resolvedAuth);
|
|
1247
1302
|
options.setTerminalOutcomeRecorder?.(terminalRecorder);
|
|
1248
1303
|
callbackGate.commit();
|
|
1304
|
+
childCommitted = true;
|
|
1305
|
+
forwardChildUsage();
|
|
1249
1306
|
return response;
|
|
1250
1307
|
}
|
|
1251
1308
|
|
|
@@ -1382,6 +1439,12 @@ export async function executeComboResponses(
|
|
|
1382
1439
|
}
|
|
1383
1440
|
return lastFailure;
|
|
1384
1441
|
}
|
|
1442
|
+
// Retain a confirmed target context refusal when later retryable failures exhaust the ladder.
|
|
1443
|
+
// Hard stops above still return their own verdict, and every attempt keeps its own usage.
|
|
1444
|
+
if (!contextFailure && failure.response.status === 400 && isDefiniteContextOverflow(400, failure.classificationText)) {
|
|
1445
|
+
contextFailure = { childLog, response: formatErrorResponse(400, "invalid_request_error",
|
|
1446
|
+
failure.upstreamMessage ?? failure.classificationText, { code: "context_length_exceeded", classified: true }) };
|
|
1447
|
+
}
|
|
1385
1448
|
// A bare status made a revoked credential read as a provider outage. Log only the parsed
|
|
1386
1449
|
// code and message, never the raw envelope, as one redacted, bounded line.
|
|
1387
1450
|
const failureReason = sanitizeLogMetadataString(
|
|
@@ -1415,9 +1478,10 @@ export async function executeComboResponses(
|
|
|
1415
1478
|
const poolLocalRefusal = isAnthropicPoolLocalRefusal(
|
|
1416
1479
|
config, pick.target.provider, failure.response.status, failedAccount, failureNow,
|
|
1417
1480
|
);
|
|
1481
|
+
const codexLocalRefusal = isCodexAccountCooldownResponse(failure.response);
|
|
1418
1482
|
const nextPick = advanceComboAfterFailure(config, pick, {
|
|
1419
|
-
retryAfter: poolLocalRefusal ? undefined : failure.retryAfter,
|
|
1420
|
-
resetAt: failure.resetAt,
|
|
1483
|
+
retryAfter: poolLocalRefusal || codexLocalRefusal ? undefined : failure.retryAfter,
|
|
1484
|
+
resetAt: codexLocalRefusal ? undefined : failure.resetAt,
|
|
1421
1485
|
cooldownMs: combo.cooldownMs,
|
|
1422
1486
|
now: failureNow,
|
|
1423
1487
|
cooldownScope: failureCooldownScope,
|
|
@@ -1479,6 +1543,7 @@ export async function executeComboResponses(
|
|
|
1479
1543
|
if (!pick) {
|
|
1480
1544
|
if (options.abortSignal?.aborted) return clientCancelledResponse();
|
|
1481
1545
|
if (onlyReplayIncompatibleTargetsRemain(attemptedTargets)) {
|
|
1546
|
+
if (contextFailure) return exhaustedFailure();
|
|
1482
1547
|
adoptFailedChildLog(childLog);
|
|
1483
1548
|
return targetIncompatibleResponse();
|
|
1484
1549
|
}
|
|
@@ -1505,7 +1570,7 @@ export async function executeComboResponses(
|
|
|
1505
1570
|
}
|
|
1506
1571
|
const failure = exhaustedFailure();
|
|
1507
1572
|
if (
|
|
1508
|
-
lastFailure?.status === 413
|
|
1573
|
+
failure === lastFailure && lastFailure?.status === 413
|
|
1509
1574
|
&& lastFailureClassifiesOverflow
|
|
1510
1575
|
) {
|
|
1511
1576
|
if (localAdmissionRefusals?.length) logCtx.errorCode = "input_admission_refused";
|
|
@@ -3,6 +3,7 @@ import { carryResponseToolOwnership } from "./response-tool-ownership";
|
|
|
3
3
|
import { finalizeTranslatorBudgetResponse } from "../../lib/translator-budget";
|
|
4
4
|
import { carryReplayRefusal, isNonReplayableResponse, markResponseNonReplayable } from "../../lib/upstream-retry";
|
|
5
5
|
import { isVerifiedModelNotInPlanResponse, markVerifiedModelNotInPlanResponse } from "../../lib/errors";
|
|
6
|
+
import { carryCodexAccountCooldownResponse } from "../../codex/account-cooldown-response";
|
|
6
7
|
import {
|
|
7
8
|
isNativePassthroughSseResponse,
|
|
8
9
|
markNativePassthroughSseResponse,
|
|
@@ -53,6 +54,7 @@ export function finalizeOwnedTranslatorBudget(response: Response, budget: Transl
|
|
|
53
54
|
if (isNonReplayableResponse(response)) markResponseNonReplayable(finalizedResponse);
|
|
54
55
|
if (isVerifiedModelNotInPlanResponse(response)) markVerifiedModelNotInPlanResponse(finalizedResponse);
|
|
55
56
|
if (runTurnAdapterSseResponses.has(response)) runTurnAdapterSseResponses.add(finalizedResponse);
|
|
57
|
+
carryCodexAccountCooldownResponse(response, finalizedResponse);
|
|
56
58
|
return carryResponseToolOwnership(response, finalizedResponse);
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -79,6 +81,8 @@ export function finalizeAccountLease(response: Response, release: () => void, on
|
|
|
79
81
|
if (isEagerRelaySseResponse(response)) markEagerRelaySseResponse(wrapped);
|
|
80
82
|
if (isPreinspectedJsonResponse(response)) markPreinspectedJsonResponse(wrapped);
|
|
81
83
|
if (runTurnAdapterSseResponses.has(response)) runTurnAdapterSseResponses.add(wrapped);
|
|
84
|
+
// Retained compaction delivers through this lease wrapper; keep a local cooldown refusal local (#7850).
|
|
85
|
+
carryCodexAccountCooldownResponse(response, wrapped);
|
|
82
86
|
return carryResponseToolOwnership(response, carryReplayRefusal(response, wrapped));
|
|
83
87
|
}
|
|
84
88
|
|
|
@@ -346,11 +346,17 @@ export async function applyFinalRouteRequestNormalization(args: {
|
|
|
346
346
|
// Native passthrough keeps its snapshot-owned effort contract, including saved exclusions.
|
|
347
347
|
if (!shouldApplyNativeEffortClamp(route.providerName, route.provider, finalSelectedModelId)) {
|
|
348
348
|
const previousEffort = parsed.options.reasoning;
|
|
349
|
+
const previousThinkingEnabled = parsed.options.thinkingEnabled;
|
|
349
350
|
normalizeThinkingOptions(route.provider, route.modelId, parsed.options);
|
|
351
|
+
const raw = parsed._rawBody as { reasoning?: unknown } | undefined;
|
|
350
352
|
if (previousEffort !== undefined && parsed.options.reasoning === undefined) {
|
|
351
|
-
const raw = parsed._rawBody as { reasoning?: unknown } | undefined;
|
|
352
353
|
if (raw) raw.reasoning = stripEmptyLadderEffort(raw.reasoning, []);
|
|
353
354
|
}
|
|
355
|
+
if (previousThinkingEnabled !== undefined && parsed.options.thinkingEnabled === undefined
|
|
356
|
+
&& raw?.reasoning && typeof raw.reasoning === "object" && !Array.isArray(raw.reasoning)) {
|
|
357
|
+
delete (raw.reasoning as { enabled?: boolean }).enabled;
|
|
358
|
+
if (Object.keys(raw.reasoning).length === 0) delete raw.reasoning;
|
|
359
|
+
}
|
|
354
360
|
}
|
|
355
361
|
const { applyEffortCap, effortCapAppliesTo, supportedLadderFor } = await import("../effort-policy");
|
|
356
362
|
const surface = collabSurface(parsed);
|
|
@@ -98,6 +98,8 @@ export interface DirectRequestOption {
|
|
|
98
98
|
export interface HandleResponsesOptions {
|
|
99
99
|
/** Immutable caller scope inherited by a capability-authenticated internal sidecar request. */
|
|
100
100
|
admissionScope?: AdmissionModelScope;
|
|
101
|
+
/** Captured synchronously at ingress, before parsing or child replay can suspend. */
|
|
102
|
+
advisorAdmissionPolicy?: import("../../types/admission-policy").CapturedAdmissionPolicy;
|
|
101
103
|
/** Internal request-owned policy authorization; never read from client headers or body. */
|
|
102
104
|
policyRequestScope?: PolicyRequestScope;
|
|
103
105
|
/** Internal concrete selector chosen from the original policy evaluation. */
|
|
@@ -215,6 +217,13 @@ export interface HandleResponsesOptions {
|
|
|
215
217
|
callerDirectAuth?: CallerDirectAuth | null;
|
|
216
218
|
/** Internal recursion guard; callers outside this module must not set it. */
|
|
217
219
|
comboAttempt?: boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Set by the combo loop for each child. A child logs into its own context, which the combo
|
|
222
|
+
* copies once when the child commits, and the bridge reports usage after that, at the terminal
|
|
223
|
+
* frame. The transport calls this when it binds that usage on the child's context, so the combo
|
|
224
|
+
* can carry the binding to the context that writes the row.
|
|
225
|
+
*/
|
|
226
|
+
onBridgeUsageBound?: () => void;
|
|
218
227
|
/** Child-owned prepaid initial send; capacity remains charged until dispatch or unsent release. */
|
|
219
228
|
comboInitialSend?: { permit: SingleUseDispatchPermit; producerOwned?: boolean };
|
|
220
229
|
/** Exact externally booked combo hop, used for its child's spend preflight and send reports. */
|
|
@@ -14,6 +14,7 @@ import type { TranslatorBudget } from "../../lib/translator-budget";
|
|
|
14
14
|
import { executeComboResponses } from "./core-combo";
|
|
15
15
|
import { registerTurn, unregisterTurn } from "../lifecycle";
|
|
16
16
|
import { runWithCompactionRecovery } from "./compaction-recovery";
|
|
17
|
+
import { captureAdmissionPolicy } from "../capture-admission-policy";
|
|
17
18
|
/**
|
|
18
19
|
* Route one `/v1/responses` request through the adapter pipeline: recovery loop, passthrough
|
|
19
20
|
* wire, image/web-search bridges, and the terminal-guard continuation.
|
|
@@ -35,6 +36,7 @@ export async function handleResponses(
|
|
|
35
36
|
try {
|
|
36
37
|
const response = await runWithCompactionRecovery(req, config, logCtx, {
|
|
37
38
|
...options, abortSignal,
|
|
39
|
+
advisorAdmissionPolicy: options.advisorAdmissionPolicy ?? captureAdmissionPolicy(config, options.admission, options.admissionScope),
|
|
38
40
|
openAiSidecarAuth: options.openAiSidecarAuth === undefined
|
|
39
41
|
? captureExplicitOpenAiCallerAuth(req.headers, config) : options.openAiSidecarAuth,
|
|
40
42
|
nativeCallerAuth: options.nativeCallerAuth === undefined
|
|
@@ -24,8 +24,8 @@ export interface JevModelInvokerContext {
|
|
|
24
24
|
/** The request that owns the combo; only its spend root is reused, never its headers. */
|
|
25
25
|
req: Pick<Request, "headers">;
|
|
26
26
|
config: OcxConfig;
|
|
27
|
-
/** Parent options: only the resolved admission scope and Codex auth policy cross over. */
|
|
28
|
-
options: Pick<HandleResponsesOptions, "admission" | "admissionScope" | "codexAuthPolicy">;
|
|
27
|
+
/** Parent options: only the resolved admission scope, Advisor caller policy and Codex auth policy cross over. */
|
|
28
|
+
options: Pick<HandleResponsesOptions, "admission" | "admissionScope" | "advisorAdmissionPolicy" | "codexAuthPolicy">;
|
|
29
29
|
handleResponses: HandleResponses;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -154,6 +154,8 @@ export function createJevModelInvoker(context: JevModelInvokerContext): JevModel
|
|
|
154
154
|
// capability-authenticated internal call carries the caller's scope while its own
|
|
155
155
|
// admission is the host's broad key.
|
|
156
156
|
...(context.options.admissionScope ? { admissionScope: context.options.admissionScope } : {}),
|
|
157
|
+
// The parent's ingress snapshot; without it the detached turn would re-read mutable config (#7859).
|
|
158
|
+
...(context.options.advisorAdmissionPolicy ? { advisorAdmissionPolicy: context.options.advisorAdmissionPolicy } : {}),
|
|
157
159
|
...(context.options.codexAuthPolicy ? { codexAuthPolicy: context.options.codexAuthPolicy } : {}),
|
|
158
160
|
// Explicit nulls: handleResponses captures caller credentials only when these are undefined.
|
|
159
161
|
callerDirectAuth: null,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { releaseCodexAuthContextProbeLease, type CodexAuthContext } from "../../codex/auth-context";
|
|
2
|
+
import { formatErrorResponse } from "../../bridge";
|
|
3
|
+
import { redactSecretString } from "../../lib/redact";
|
|
4
|
+
import { NamespaceToolCollisionError } from "../../responses/namespace-tool-compat";
|
|
5
|
+
import { RoutedCustomToolCompatError } from "../../responses/custom-tool-compat";
|
|
6
|
+
import { XaiToolSchemaCompatibilityError } from "../../adapters/xai-tool-schema";
|
|
7
|
+
import { MuseToolChoiceCompatibilityError } from "../../adapters/openai-responses/muse-tool-choice";
|
|
8
|
+
import { MuseToolCatalogCompatibilityError } from "../../adapters/openai-responses/muse-tool-catalog";
|
|
9
|
+
import { OpenGatewayInputCompatibilityError } from "../../adapters/openai-responses/opengateway-input";
|
|
10
|
+
import { mapCodexAuthContextErrorToResponse } from "./codex-auth-error";
|
|
11
|
+
|
|
12
|
+
/** Input-lowering errors are 400; late credential/identity failures retain their own contract. */
|
|
13
|
+
export function passthroughBuildErrorResponse(error: unknown, accountSelector?: string): Response | undefined {
|
|
14
|
+
const refusal = mapCodexAuthContextErrorToResponse(error, { now: Date.now(), accountSelector });
|
|
15
|
+
if (refusal) return refusal;
|
|
16
|
+
if (error instanceof NamespaceToolCollisionError
|
|
17
|
+
|| error instanceof XaiToolSchemaCompatibilityError
|
|
18
|
+
|| error instanceof RoutedCustomToolCompatError
|
|
19
|
+
|| error instanceof MuseToolChoiceCompatibilityError
|
|
20
|
+
|| error instanceof MuseToolCatalogCompatibilityError
|
|
21
|
+
|| error instanceof OpenGatewayInputCompatibilityError) {
|
|
22
|
+
return formatErrorResponse(400, "invalid_request_error", redactSecretString(error.message));
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Auth failures precede generic adapter-build 400s and preservation of an older rejection. */
|
|
28
|
+
export function codexAdapterBuildRefusal(error: unknown, context: CodexAuthContext | undefined,
|
|
29
|
+
accountSelector?: string, cleanup?: () => void): Response | undefined {
|
|
30
|
+
const refusal = mapCodexAuthContextErrorToResponse(error, { now: Date.now(), accountSelector });
|
|
31
|
+
if (refusal) {
|
|
32
|
+
cleanup?.();
|
|
33
|
+
releaseCodexAuthContextProbeLease(context);
|
|
34
|
+
}
|
|
35
|
+
return refusal;
|
|
36
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
|
|
2
|
+
import { passthroughBuildErrorResponse } from "./passthrough-build-error";
|
|
1
3
|
import { recoverAutoPausedAccount, rotatePassthroughKeyOn429 } from "./passthrough-key-rotation";
|
|
2
4
|
import { adoptCodexWsStage, capturePassthroughAffinity } from "./passthrough-observations";
|
|
3
5
|
import { spendLedgerStorageErrorResponse } from "./spend-storage-error";
|
|
@@ -48,13 +50,9 @@ import {
|
|
|
48
50
|
createCodexAuthDispatchGuard,
|
|
49
51
|
} from "../../codex/auth-context";
|
|
50
52
|
import {
|
|
51
|
-
NamespaceToolCollisionError,
|
|
52
53
|
restoreRoutedNamespaceCalls,
|
|
53
54
|
} from "../../responses/namespace-tool-compat";
|
|
54
|
-
import { restoreRoutedCustomCalls
|
|
55
|
-
import { XaiToolSchemaCompatibilityError } from "../../adapters/xai-tool-schema";
|
|
56
|
-
import { MuseToolChoiceCompatibilityError } from "../../adapters/openai-responses/muse-tool-choice";
|
|
57
|
-
import { OpenGatewayInputCompatibilityError } from "../../adapters/openai-responses/opengateway-input";
|
|
55
|
+
import { restoreRoutedCustomCalls } from "../../responses/custom-tool-compat";
|
|
58
56
|
import { formatErrorResponse } from "../../bridge";
|
|
59
57
|
import { redactSecretString } from "../../lib/redact";
|
|
60
58
|
import {
|
|
@@ -378,21 +376,8 @@ export async function preparePassthroughExchange(
|
|
|
378
376
|
});
|
|
379
377
|
} catch (error) {
|
|
380
378
|
releaseCodexAuthContextProbeLease(admissionState.authCtx);
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
// it here escaped every catch up to the Bun handler, so the same request produced an
|
|
384
|
-
// unstructured 500 — and no request log — depending only on whether a rotation ran first.
|
|
385
|
-
// Same shape for a tool_choice this proxy cannot honor: the destination rejects a schema the
|
|
386
|
-
// catalog had to drop, so the selector naming it is a client input error, not a 500.
|
|
387
|
-
if (
|
|
388
|
-
error instanceof NamespaceToolCollisionError
|
|
389
|
-
|| error instanceof XaiToolSchemaCompatibilityError
|
|
390
|
-
|| error instanceof RoutedCustomToolCompatError
|
|
391
|
-
|| error instanceof MuseToolChoiceCompatibilityError
|
|
392
|
-
|| error instanceof OpenGatewayInputCompatibilityError
|
|
393
|
-
) {
|
|
394
|
-
return formatErrorResponse(400, "invalid_request_error", redactSecretString(error.message));
|
|
395
|
-
}
|
|
379
|
+
const refusal = passthroughBuildErrorResponse(error, route.codexAccountNamespace);
|
|
380
|
+
if (refusal) return refusal;
|
|
396
381
|
throw error;
|
|
397
382
|
}
|
|
398
383
|
const functionRepairSchemas = isCanonicalOpenAiForwardProvider(route.provider)
|
|
@@ -480,10 +465,9 @@ export async function preparePassthroughExchange(
|
|
|
480
465
|
for (const callType of collectProviderExecutedCallTypes(clientToolAuthorizationBody)) {
|
|
481
466
|
providerExecutedCallTypes.add(callType);
|
|
482
467
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
);
|
|
468
|
+
// Serialization drops provenance, so never slice transformed input by the raw prefix.
|
|
469
|
+
// Current wrappers were captured above; adapter-injected hosted tools are top-level.
|
|
470
|
+
const currentOutboundCatalog = { tools: outboundRequestBody?.tools };
|
|
487
471
|
for (const callType of collectProviderExecutedCallTypes(currentOutboundCatalog)) {
|
|
488
472
|
providerExecutedCallTypes.add(callType);
|
|
489
473
|
}
|
|
@@ -1123,6 +1107,7 @@ export async function preparePassthroughExchange(
|
|
|
1123
1107
|
recordAdapterReasoning(logCtx, request);
|
|
1124
1108
|
recordAdapterTier(logCtx, request);
|
|
1125
1109
|
} catch (err) {
|
|
1110
|
+
if (err instanceof CodexInstallationIdUnavailableError) return { failed: transportFailureResponse(err) };
|
|
1126
1111
|
upstream.abort();
|
|
1127
1112
|
if (options.abortSignal?.aborted) return { failed: clientCancelledResponse() };
|
|
1128
1113
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -1417,6 +1402,7 @@ export async function preparePassthroughExchange(
|
|
|
1417
1402
|
recordAdapterReasoning(logCtx, request);
|
|
1418
1403
|
recordAdapterTier(logCtx, request);
|
|
1419
1404
|
} catch (err) {
|
|
1405
|
+
if (err instanceof CodexInstallationIdUnavailableError) return transportFailureResponse(err);
|
|
1420
1406
|
upstream.abort();
|
|
1421
1407
|
if (options.abortSignal?.aborted) return clientCancelledResponse();
|
|
1422
1408
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -15,6 +15,7 @@ import { parseSyntheticRowId } from "../fast-row";
|
|
|
15
15
|
import { routeConcreteModel } from "../../router";
|
|
16
16
|
import { isPolicyCandidateRefusal, policyWireDestination, type PolicyRequestScope } from "./policy-request-scope";
|
|
17
17
|
import { fallbackTriggerForStatus, guardFallbackHop } from "../../routing/fallback-policy";
|
|
18
|
+
import { captureAdmissionPolicy } from "../capture-admission-policy";
|
|
18
19
|
|
|
19
20
|
type CoreHandler = typeof handleResponsesCore;
|
|
20
21
|
type CoreOptions = Parameters<CoreHandler>[3];
|
|
@@ -182,6 +183,7 @@ export async function handleResponsesWithPolicyFallback(
|
|
|
182
183
|
let rawBody: Record<string, unknown> | null = null;
|
|
183
184
|
const coreOptions: CoreOptions = {
|
|
184
185
|
...options,
|
|
186
|
+
advisorAdmissionPolicy: options.advisorAdmissionPolicy ?? captureAdmissionPolicy(config, options.admission, options.admissionScope),
|
|
185
187
|
policyRequestScope: policyScope,
|
|
186
188
|
openAiSidecarAuth: options.openAiSidecarAuth === undefined
|
|
187
189
|
? captureExplicitOpenAiCallerAuth(req.headers, config) : options.openAiSidecarAuth,
|
|
@@ -76,7 +76,7 @@ import { anthropicSessionKeyFromParts } from "../../oauth/anthropic-routing";
|
|
|
76
76
|
import { configuredAnthropicInstance } from "../../providers/anthropic-instance";
|
|
77
77
|
import { isTranslatorBudgetExceededError } from "../../lib/translator-budget";
|
|
78
78
|
import { bindTurnTerminationScope, rememberDeliveredFinalAnswer } from "../../responses/turn-termination";
|
|
79
|
-
import { observeCacheDiagnosticInbound, rebindCacheDiagnosticBody, requestLogSpeedLabel, readConfiguredCodexServiceTier } from "../request-log";
|
|
79
|
+
import { noteCodexSelectionAffinity, observeCacheDiagnosticInbound, rebindCacheDiagnosticBody, requestLogSpeedLabel, readConfiguredCodexServiceTier } from "../request-log";
|
|
80
80
|
import type { RouteResult } from "../../router";
|
|
81
81
|
import {
|
|
82
82
|
captureRouteStaticPolicy,
|
|
@@ -665,6 +665,7 @@ export async function prepareResponsesRequest(
|
|
|
665
665
|
return formatErrorResponse(401, "authentication_error", "Anthropic Pool 2 requires an enabled configured provider");
|
|
666
666
|
}
|
|
667
667
|
const admissionScope = options.admissionScope ?? resolveAdmissionModelScope(config, options.admission);
|
|
668
|
+
const advisorAdmissionPolicy = options.advisorAdmissionPolicy;
|
|
668
669
|
const captureInboundRoutePolicy = (candidate: RouteResult, captureRequestPolicy = true): RouteResult => {
|
|
669
670
|
// Router-collapsed aliases bypass the combo loop. Re-pick before capturing destination
|
|
670
671
|
// policy so random/RR cannot refuse while an unmetered target is still usable.
|
|
@@ -1585,10 +1586,7 @@ export async function prepareResponsesRequest(
|
|
|
1585
1586
|
// A move is the expensive event: it discards the prefix warmed on the previous account. Record
|
|
1586
1587
|
// it as an event with its cause, so the operator reads it off one line instead of inferring it
|
|
1587
1588
|
// from account labels across many (#4546).
|
|
1588
|
-
|
|
1589
|
-
logCtx.affinity = admissionState.authCtx.affinityDecision.move;
|
|
1590
|
-
logCtx.affinityReason = admissionState.authCtx.affinityDecision.reason;
|
|
1591
|
-
}
|
|
1589
|
+
noteCodexSelectionAffinity(logCtx, admissionState.authCtx);
|
|
1592
1590
|
{
|
|
1593
1591
|
const binding = conversationStateBindingFromAuth(admissionState.authCtx, poolAffinityKey);
|
|
1594
1592
|
if (binding) {
|
|
@@ -1632,6 +1630,7 @@ export async function prepareResponsesRequest(
|
|
|
1632
1630
|
// the key scope as it stood when this request was admitted.
|
|
1633
1631
|
inboundSelector,
|
|
1634
1632
|
admissionScope,
|
|
1633
|
+
advisorAdmissionPolicy,
|
|
1635
1634
|
translatorBudget,
|
|
1636
1635
|
parsed,
|
|
1637
1636
|
toolBridgeMaps,
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
workflowSendCeilingReached,
|
|
7
7
|
workflowSpendCeilingReached,
|
|
8
8
|
} from "../../lib/workflow-budget";
|
|
9
|
+
import { currentWorkflowBudgetPolicy } from "../../lib/workflow-budget-config";
|
|
9
10
|
import { poolContinuityRefusalReason, workflowRefusalResponse } from "../workflow-refusal";
|
|
10
11
|
import type { AttemptRecoveryKind, AttemptRecoveryWithheld } from "../../usage/log";
|
|
11
12
|
import { noteAttemptRecoveryWithheld, noteAttemptSend } from "../request-log";
|
|
@@ -93,7 +94,7 @@ export function createResponsesSendBudget(
|
|
|
93
94
|
// dropping the record to make room would hand the fan-out a fresh allowance, which is the
|
|
94
95
|
// laundering this ceiling exists to stop. The client is told the task needs a new grant
|
|
95
96
|
// rather than being given a synthetic upstream error.
|
|
96
|
-
if (workflowSendCeilingReached(workflowRootId)) {
|
|
97
|
+
if (workflowSendCeilingReached(workflowRootId, currentWorkflowBudgetPolicy())) {
|
|
97
98
|
// A log context exists here, unlike at HTTP admission, so the row this request writes is
|
|
98
99
|
// marked synthetic rather than reading as a request that vanished with zero sends.
|
|
99
100
|
return workflowRefusalResponse("workflow-sends-exhausted", logCtx, undefined, workflowRootId);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
|
|
1
2
|
import type { ResponsesRequestContext } from "./core-options";
|
|
2
3
|
import type { PreparedResponsesRequest } from "./request-prepare";
|
|
3
4
|
import type { ResponsesTransport } from "./request-transport";
|
|
@@ -111,7 +112,8 @@ export async function prepareResponsesSidecarAuth(
|
|
|
111
112
|
// An unavailable/cooling/expired Multi credential disables the helper; it
|
|
112
113
|
// must not turn a valid routed-provider request into a Codex-auth failure.
|
|
113
114
|
if (
|
|
114
|
-
!(err instanceof
|
|
115
|
+
!(err instanceof CodexInstallationIdUnavailableError)
|
|
116
|
+
&& !(err instanceof CodexPoolAuthenticationError)
|
|
115
117
|
&& !(err instanceof CodexAuthContextError)
|
|
116
118
|
&& !(err instanceof CodexAccountCooldownError)
|
|
117
119
|
&& !(err instanceof CodexThreadAffinityExpiredError)
|
|
@@ -131,6 +133,7 @@ export async function prepareResponsesSidecarAuth(
|
|
|
131
133
|
? undefined
|
|
132
134
|
: planVisionSidecar(config, route.provider, route.modelId, parsed, openAiSidecar, {
|
|
133
135
|
admission: options.admission, codexAuthPolicy: options.codexAuthPolicy, providerName: route.providerName,
|
|
136
|
+
advisorAdmissionPolicy: options.advisorAdmissionPolicy,
|
|
134
137
|
});
|
|
135
138
|
const recordSidecarOutcome = openAiSidecar?.recordOutcome;
|
|
136
139
|
if (visionPlan) {
|
|
@@ -541,12 +541,11 @@ export async function prepareResponsesTransport(
|
|
|
541
541
|
logCtx.usageFromBridge = true;
|
|
542
542
|
if (usesApiKeyAccount(route.provider)) {
|
|
543
543
|
logCtx.usage = logCtx.activeAttempt?.usage;
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
if (usage) {
|
|
544
|
+
} else if (usage) {
|
|
547
545
|
logCtx.usage = usage;
|
|
548
546
|
if (logCtx.activeAttempt) logCtx.activeAttempt.usage = usage;
|
|
549
547
|
}
|
|
548
|
+
options.onBridgeUsageBound?.();
|
|
550
549
|
};
|
|
551
550
|
const selectionIsCurrent = (binding: DispatchBinding | undefined): boolean => {
|
|
552
551
|
if (!anthropicAdmissionIsCurrent()) return false;
|
|
@@ -911,6 +911,8 @@ export async function executeResponsesRunTurn(
|
|
|
911
911
|
toolParameterSchemas,
|
|
912
912
|
...(options.onFirstOutput ? { onFirstOutput: options.onFirstOutput } : {}),
|
|
913
913
|
...(routedCompaction ? { compaction: true, compactionRetention: parsed._compactionRetention } : {}),
|
|
914
|
+
completeOnMaxOutputTokens: config.completeOnMaxOutputTokens === true && enforceDeclaredToolNames,
|
|
915
|
+
textFormat: parsed.options.textFormat,
|
|
914
916
|
// grok-build's strict decoder dies on the typed response.heartbeat frame; its
|
|
915
917
|
// eventsource layer tolerates comment keep-alives. Codex needs the opposite.
|
|
916
918
|
...(logCtx.surface === "grok" ? { heartbeatStyle: "comment" as const } : {}),
|
|
@@ -1072,6 +1074,8 @@ export async function executeResponsesRunTurn(
|
|
|
1072
1074
|
bareCustomToolNames,
|
|
1073
1075
|
toolSearchToolNames,
|
|
1074
1076
|
...(routedCompaction ? { compaction: true, compactionRetention: parsed._compactionRetention } : {}),
|
|
1077
|
+
completeOnMaxOutputTokens: config.completeOnMaxOutputTokens === true && enforceDeclaredToolNames,
|
|
1078
|
+
textFormat: parsed.options.textFormat,
|
|
1075
1079
|
onProviderState: state => { providerState = state; },
|
|
1076
1080
|
onUsage: usage => {
|
|
1077
1081
|
transportState.bindKeyUsageFromBridge(usage);
|
|
@@ -9,7 +9,7 @@ import type { ResponsesSendBudget } from "./request-send-budget";
|
|
|
9
9
|
import { formatErrorResponse } from "../../bridge";
|
|
10
10
|
import { planWebSearch, buildWebSearchTool, runWithWebSearch } from "../../web-search";
|
|
11
11
|
import { createRegisteredAdvisorPlan } from "./advisor-plan-slot";
|
|
12
|
-
import { ADVISOR_TOOL_NAME } from "./advisor-slot";
|
|
12
|
+
import { ADVISOR_TOOL_NAME, createAdvisorSidecarStep } from "./advisor-slot";
|
|
13
13
|
import { buildToolBridgeMaps } from "./collaboration";
|
|
14
14
|
import {
|
|
15
15
|
planImageBridge,
|
|
@@ -75,6 +75,7 @@ export async function executeResponsesSidecars(
|
|
|
75
75
|
| "rememberKiroDeliveredFinalAnswer"
|
|
76
76
|
| "responseStateOptions"
|
|
77
77
|
| "admissionScope"
|
|
78
|
+
| "advisorAdmissionPolicy"
|
|
78
79
|
>,
|
|
79
80
|
transportState: Pick<
|
|
80
81
|
ResponsesTransport,
|
|
@@ -195,6 +196,7 @@ export async function executeResponsesSidecars(
|
|
|
195
196
|
workerIdentity: `${route.modelId} (provider ${route.providerName})`,
|
|
196
197
|
workerModelId: route.modelId,
|
|
197
198
|
admissionScope,
|
|
199
|
+
admissionPolicy: requestState.advisorAdmissionPolicy,
|
|
198
200
|
abortSignal: options.abortSignal,
|
|
199
201
|
});
|
|
200
202
|
// Preflight only on real worker turns: a routed-compaction turn is a summarization request,
|
|
@@ -655,7 +657,21 @@ export async function executeResponsesSidecars(
|
|
|
655
657
|
// Placed BEFORE the runTurn early-return for non-runTurn adapters so dual-tool turns dispatch
|
|
656
658
|
// through web-search instead of being swallowed. runTurn adapters never enter this branch.
|
|
657
659
|
if (canRunWebSearch && wsPlan) {
|
|
658
|
-
|
|
660
|
+
const webSearchAdvisor = advisorPlan && !routedCompaction
|
|
661
|
+
&& typeof advisorPlan.consult === "function" && typeof advisorPlan.formatUnavailable === "function"
|
|
662
|
+
? advisorPlan
|
|
663
|
+
: undefined;
|
|
664
|
+
parsed.context.tools = [
|
|
665
|
+
...(parsed.context.tools ?? []).filter(tool => !webSearchAdvisor || (!tool.advisor && tool.name !== ADVISOR_TOOL_NAME)),
|
|
666
|
+
buildWebSearchTool(),
|
|
667
|
+
...(webSearchAdvisor ? [webSearchAdvisor.tool] : []),
|
|
668
|
+
];
|
|
669
|
+
if (webSearchAdvisor) {
|
|
670
|
+
requestState.toolBridgeMaps = buildToolBridgeMaps(parsed);
|
|
671
|
+
translatorBudget.chargeRetained(new TextEncoder().encode(ADVISOR_TOOL_NAME).byteLength * 2, {
|
|
672
|
+
kind: "retained_collectors",
|
|
673
|
+
});
|
|
674
|
+
}
|
|
659
675
|
// Resolve the mutable route at send time: a 429 rotation replaces route.provider, so retaining
|
|
660
676
|
// one pre-rotation providerFetch would keep the old credential and transport pin.
|
|
661
677
|
const routedProviderFetch = ((input: Parameters<typeof globalThis.fetch>[0], init?: RequestInit) =>
|
|
@@ -666,6 +682,7 @@ export async function executeResponsesSidecars(
|
|
|
666
682
|
})(input, init)) as typeof globalThis.fetch;
|
|
667
683
|
const loopResponse = await runWithWebSearch({
|
|
668
684
|
parsed, adapter: transportState.adapter,
|
|
685
|
+
...(webSearchAdvisor ? { advisor: createAdvisorSidecarStep(webSearchAdvisor as Parameters<typeof createAdvisorSidecarStep>[0]) } : {}),
|
|
669
686
|
chatRawReasoningVisible: options.chatRawReasoningVisible,
|
|
670
687
|
...(transportState.adapter.name === "anthropic" ? { thinkingRecovery } : {}),
|
|
671
688
|
clientToolCatalogRestriction: route.provider.authMode === "forward" ? undefined : requestState.clientToolCatalogRestriction,
|
|
@@ -773,9 +790,8 @@ export async function executeResponsesSidecars(
|
|
|
773
790
|
|
|
774
791
|
// Advisor synthetic tool + stream guard: attach ONLY when this function is about to hand the
|
|
775
792
|
// request back to the normal translated exchange (no sidecar loop claimed the turn, not a
|
|
776
|
-
// run-turn adapter, not compaction).
|
|
777
|
-
// run-turn
|
|
778
|
-
// cannot intercept. Preflight (above) still applies to those paths — only the tool does not.
|
|
793
|
+
// run-turn adapter, not compaction). Web-search handles advisor in its own loop above; the
|
|
794
|
+
// image/video and run-turn loops cannot intercept it. Preflight still applies to those paths.
|
|
779
795
|
if (advisorPlan && !routedCompaction && !transportState.adapter.runTurn && !wsPlan && !imgPlan && !vidPlan) {
|
|
780
796
|
// A client-declared tool named "advisor" would collide with the synthetic injection (one
|
|
781
797
|
// wire name, two schemas); the synthetic runtime owns the name for this turn.
|