@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
|
@@ -269,6 +269,8 @@ export async function deliverAdapterResponse(
|
|
|
269
269
|
toolParameterSchemas,
|
|
270
270
|
...(options.onFirstOutput ? { onFirstOutput: options.onFirstOutput } : {}),
|
|
271
271
|
...(routedCompaction ? { compaction: true, compactionRetention: parsed._compactionRetention } : {}),
|
|
272
|
+
completeOnMaxOutputTokens: config.completeOnMaxOutputTokens === true && options.inboundWire !== "chat" && options.inboundWire !== "anthropic",
|
|
273
|
+
textFormat: parsed.options.textFormat,
|
|
272
274
|
// Same grok-surface split as the runTurn branch above.
|
|
273
275
|
...(logCtx.surface === "grok" ? { heartbeatStyle: "comment" as const } : {}),
|
|
274
276
|
onUsage: usage => {
|
|
@@ -378,6 +380,8 @@ export async function deliverAdapterResponse(
|
|
|
378
380
|
freeformToolNames,
|
|
379
381
|
toolSearchToolNames,
|
|
380
382
|
...(routedCompaction ? { compaction: true, compactionRetention: parsed._compactionRetention } : {}),
|
|
383
|
+
completeOnMaxOutputTokens: config.completeOnMaxOutputTokens === true && options.inboundWire !== "chat" && options.inboundWire !== "anthropic",
|
|
384
|
+
textFormat: parsed.options.textFormat,
|
|
381
385
|
onProviderState: state => { providerState = state; },
|
|
382
386
|
onUsage: usage => {
|
|
383
387
|
transportState.bindKeyUsageFromBridge(usage);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { codexAdapterBuildRefusal } from "./passthrough-build-error";
|
|
1
2
|
import { recoverAutoPausedAccount } from "./account-auto-pause-recovery";
|
|
2
3
|
import { wasAccountAutoPaused, wasPermanentAccountRefusal } from "../../oauth/account-auto-pause";
|
|
3
4
|
import { bindAnthropicRejectionResponse } from "../../adapters/anthropic-rejection-memo";
|
|
@@ -364,6 +365,8 @@ export async function prepareAdapterExchange(
|
|
|
364
365
|
code: "translation_buffer_limit",
|
|
365
366
|
});
|
|
366
367
|
}
|
|
368
|
+
const authRefusal = codexAdapterBuildRefusal(err, admissionState.authCtx, route.codexAccountNamespace);
|
|
369
|
+
if (authRefusal) return authRefusal;
|
|
367
370
|
const msg = err instanceof Error ? err.message : String(err);
|
|
368
371
|
return formatErrorResponse(400, "invalid_request_error", redactSecretString(msg));
|
|
369
372
|
}
|
|
@@ -662,6 +665,8 @@ export async function prepareAdapterExchange(
|
|
|
662
665
|
recordAdapterReasoning(logCtx, retryRequest);
|
|
663
666
|
recordAdapterTier(logCtx, retryRequest);
|
|
664
667
|
} catch (err) {
|
|
668
|
+
const authRefusal = options.abortSignal?.aborted ? undefined : codexAdapterBuildRefusal(err, admissionState.authCtx, route.codexAccountNamespace, () => { cleanupUpstreamAbort(); upstream.abort(); });
|
|
669
|
+
if (authRefusal) return { failed: authRefusal };
|
|
665
670
|
// A rotated credential that cannot be shaped keeps the refusal it was meant to
|
|
666
671
|
// replace. The image-tier rebuild is different: the request itself failed to shape,
|
|
667
672
|
// and its established 413/400 build-error contract stays authoritative.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Core-owned, config-scoped registration. An inactive install has no Advisor factory. */
|
|
2
2
|
import type { OcxConfig, OcxParsedRequest, OcxTool } from "../../types";
|
|
3
3
|
import type { AdmissionModelScope } from "../admission-model-scope";
|
|
4
|
+
import type { AdvisorPlan } from "./advisor-slot";
|
|
4
5
|
|
|
5
6
|
export interface AdvisorPlanInput {
|
|
6
7
|
config: OcxConfig;
|
|
@@ -8,11 +9,14 @@ export interface AdvisorPlanInput {
|
|
|
8
9
|
workerModelId: string;
|
|
9
10
|
/** Immutable scope captured from the request that is paying for this sidecar. */
|
|
10
11
|
admissionScope?: AdmissionModelScope;
|
|
12
|
+
admissionPolicy?: import("../../types/admission-policy").CapturedAdmissionPolicy;
|
|
11
13
|
abortSignal?: AbortSignal;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export interface RegisteredAdvisorPlan {
|
|
15
17
|
tool: OcxTool;
|
|
18
|
+
consult?: AdvisorPlan["consult"];
|
|
19
|
+
formatUnavailable?: AdvisorPlan["formatUnavailable"];
|
|
16
20
|
preflightInject(parsed: OcxParsedRequest): Promise<boolean>;
|
|
17
21
|
attachGuard(parsed: OcxParsedRequest): void;
|
|
18
22
|
}
|
|
@@ -69,6 +69,7 @@ export interface AdvisorPlan {
|
|
|
69
69
|
parsed: OcxParsedRequest,
|
|
70
70
|
reason: "manual",
|
|
71
71
|
question: string | undefined,
|
|
72
|
+
abortSignal?: AbortSignal,
|
|
72
73
|
): Promise<AdvisorConsultOutcome>;
|
|
73
74
|
/**
|
|
74
75
|
* Runtime-owned text for a failed or limited consultation. The guard never composes failure
|
|
@@ -78,6 +79,68 @@ export interface AdvisorPlan {
|
|
|
78
79
|
formatUnavailable(kind: "manual" | "limit", error: string): string;
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
export interface AdvisorSidecarCall {
|
|
83
|
+
id: string;
|
|
84
|
+
name: string;
|
|
85
|
+
question?: string;
|
|
86
|
+
providerMetadata?: import("../../types").OcxProviderOpaqueToolCallMetadata;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Shares continuation/consultation bounds between the normal guard and fetch sidecar loops.
|
|
91
|
+
* Each leg is reserved before any expert await, while repeated calls receive one bounded limit
|
|
92
|
+
* result instead of starting another consultation. The tool result preserves the worker call id.
|
|
93
|
+
*/
|
|
94
|
+
export function createAdvisorSidecarStep(plan: AdvisorPlan) {
|
|
95
|
+
let consultations = 0;
|
|
96
|
+
let continuations = 0;
|
|
97
|
+
let finalContinuationUsed = false;
|
|
98
|
+
return {
|
|
99
|
+
beginLeg(): Extract<AdapterEvent, { type: "error" }> | undefined {
|
|
100
|
+
const final = consultations >= MAX_ADVISOR_CONSULTATIONS_PER_REQUEST;
|
|
101
|
+
if (continuations >= MAX_ADVISOR_CONTINUATIONS_PER_REQUEST || finalContinuationUsed) {
|
|
102
|
+
return {
|
|
103
|
+
type: "error",
|
|
104
|
+
status: 502,
|
|
105
|
+
errorType: "advisor_continuation_limit",
|
|
106
|
+
message: "Advisor worker continuation limit reached; no further worker calls were sent.",
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
continuations += 1;
|
|
110
|
+
finalContinuationUsed ||= final;
|
|
111
|
+
return undefined;
|
|
112
|
+
},
|
|
113
|
+
async consultCall(parsed: OcxParsedRequest, call: AdvisorSidecarCall, abortSignal?: AbortSignal) {
|
|
114
|
+
let outcome: AdvisorConsultOutcome;
|
|
115
|
+
if (consultations >= MAX_ADVISOR_CONSULTATIONS_PER_REQUEST) {
|
|
116
|
+
outcome = {
|
|
117
|
+
ok: false,
|
|
118
|
+
isError: true,
|
|
119
|
+
content: plan.formatUnavailable("limit", "consultation limit reached for this request"),
|
|
120
|
+
};
|
|
121
|
+
} else {
|
|
122
|
+
consultations += 1;
|
|
123
|
+
try {
|
|
124
|
+
outcome = await plan.consult(parsed, "manual", call.question, abortSignal);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (isTranslatorBudgetExceededError(error)) throw error;
|
|
127
|
+
outcome = {
|
|
128
|
+
ok: false,
|
|
129
|
+
isError: true,
|
|
130
|
+
content: plan.formatUnavailable("manual", error instanceof Error ? error.message : String(error)),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { outcome, message: advisorToolResult(call, outcome, Date.now()) };
|
|
135
|
+
},
|
|
136
|
+
exhausted(): boolean {
|
|
137
|
+
return consultations >= MAX_ADVISOR_CONSULTATIONS_PER_REQUEST;
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type AdvisorSidecarStep = ReturnType<typeof createAdvisorSidecarStep>;
|
|
143
|
+
|
|
81
144
|
interface HeldAdvisorCall {
|
|
82
145
|
id: string;
|
|
83
146
|
name: string;
|
|
@@ -90,10 +153,10 @@ interface HeldAdvisorCall {
|
|
|
90
153
|
|
|
91
154
|
function parseAdvisorArgs(call: HeldAdvisorCall, retention: AdvisorRetention): { question?: string } {
|
|
92
155
|
// Reserve both the joined input and parsed JSON before either is materialized.
|
|
93
|
-
return retention.copy(call.argumentBytes * 2 + 4, () =>
|
|
156
|
+
return retention.copy(call.argumentBytes * 2 + 4, () => parseAdvisorQuestionArgs(call.args.join("")));
|
|
94
157
|
}
|
|
95
158
|
|
|
96
|
-
function
|
|
159
|
+
export function parseAdvisorQuestionArgs(argsBuf: string): { question?: string } {
|
|
97
160
|
if (argsBuf.trim() === "") return {};
|
|
98
161
|
try {
|
|
99
162
|
const parsed: unknown = JSON.parse(argsBuf);
|
|
@@ -129,7 +192,7 @@ function assistantMessageFromLeg(
|
|
|
129
192
|
}
|
|
130
193
|
|
|
131
194
|
function advisorToolResult(
|
|
132
|
-
call:
|
|
195
|
+
call: AdvisorSidecarCall,
|
|
133
196
|
outcome: AdvisorConsultOutcome,
|
|
134
197
|
timestamp: number,
|
|
135
198
|
): OcxToolResultMessage {
|
|
@@ -163,11 +226,8 @@ export function createAdvisorStreamGuard(options: AdvisorGuardOptions): AsyncGen
|
|
|
163
226
|
}
|
|
164
227
|
export function createAdvisorGuard(plan: AdvisorPlan): NonNullable<OcxParsedRequest["_advisorGuard"]> {
|
|
165
228
|
// Shared across invocations of this request's guard, including an empty-completion retry.
|
|
166
|
-
|
|
167
|
-
let continuations = 0;
|
|
168
|
-
let finalContinuationUsed = false;
|
|
229
|
+
const sidecar = createAdvisorSidecarStep(plan);
|
|
169
230
|
return async function* guardAdvisorStream(options: Omit<AdvisorGuardOptions, "plan">): AsyncGenerator<AdapterEvent> {
|
|
170
|
-
const maxConsultations = MAX_ADVISOR_CONSULTATIONS_PER_REQUEST;
|
|
171
231
|
let parsed = options.parsed;
|
|
172
232
|
let accumulatedUsage: OcxUsage | undefined;
|
|
173
233
|
let source: AsyncIterable<AdapterEvent> = options.firstEvents;
|
|
@@ -275,61 +335,28 @@ export function createAdvisorGuard(plan: AdvisorPlan): NonNullable<OcxParsedRequ
|
|
|
275
335
|
|
|
276
336
|
// Consume this leg's done — the continuation replaces it.
|
|
277
337
|
accumulatedUsage = retention.usage(accumulatedUsage, terminalEvent?.usage);
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
status: 502,
|
|
282
|
-
errorType: "advisor_continuation_limit",
|
|
283
|
-
message: "Advisor worker continuation limit reached; no further worker calls were sent.",
|
|
284
|
-
...(accumulatedUsage ? { usage: accumulatedUsage } : {}),
|
|
285
|
-
};
|
|
338
|
+
const continuationError = sidecar.beginLeg();
|
|
339
|
+
if (continuationError) {
|
|
340
|
+
yield accumulatedUsage ? { ...continuationError, usage: accumulatedUsage } : continuationError;
|
|
286
341
|
return;
|
|
287
342
|
}
|
|
288
|
-
// A repeated call after tool removal gets one last paired limit result, never a loop.
|
|
289
|
-
const isFinalContinuation = consultations >= maxConsultations;
|
|
290
|
-
// Reserve before any consultation await, so simultaneous guard entries share the bound.
|
|
291
|
-
continuations += 1;
|
|
292
|
-
finalContinuationUsed ||= isFinalContinuation;
|
|
293
343
|
const timestamp = Date.now();
|
|
294
344
|
const assistant = retention.history(retention.replayReservation(), () => assistantMessageFromLeg(legEvents, advisorCalls, timestamp, retention));
|
|
295
345
|
const messages: OcxMessage[] = [...parsed.context.messages];
|
|
296
346
|
if (assistant) messages.push(assistant);
|
|
297
347
|
|
|
298
348
|
for (const call of advisorCalls) {
|
|
299
|
-
if (consultations >= maxConsultations) {
|
|
300
|
-
// Runtime-owned limit text: not advice, and never a genuine advice wrapper.
|
|
301
|
-
const outcome = {
|
|
302
|
-
ok: false,
|
|
303
|
-
isError: true,
|
|
304
|
-
content: plan.formatUnavailable("limit", "consultation limit reached for this request"),
|
|
305
|
-
};
|
|
306
|
-
messages.push(retention.history(jsonUtf8Bytes(outcome) + jsonUtf8Bytes(call.id) + 256, () => advisorToolResult(call, outcome, timestamp))!);
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
consultations += 1;
|
|
310
349
|
// Later calls in the same leg must see what came before them: the rebuilt worker turn
|
|
311
350
|
// and every earlier advisor result in this leg's accumulated messages.
|
|
312
351
|
const consultParsed: OcxParsedRequest = {
|
|
313
352
|
...parsed,
|
|
314
353
|
context: { ...parsed.context, messages },
|
|
315
354
|
};
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
outcome = await plan.consult(consultParsed, "manual", call.question);
|
|
319
|
-
} catch (error) {
|
|
320
|
-
if (isTranslatorBudgetExceededError(error)) throw error;
|
|
321
|
-
// Runtime-owned failure text only: the implementation neutralizes untrusted exception
|
|
322
|
-
// text so it can never forge a genuine advice wrapper.
|
|
323
|
-
outcome = {
|
|
324
|
-
ok: false,
|
|
325
|
-
isError: true,
|
|
326
|
-
content: plan.formatUnavailable("manual", error instanceof Error ? error.message : String(error)),
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
messages.push(retention.history(jsonUtf8Bytes(outcome) + jsonUtf8Bytes(call.id) + 256, () => advisorToolResult(call, outcome, timestamp))!);
|
|
355
|
+
const consulted = await sidecar.consultCall(consultParsed, call);
|
|
356
|
+
messages.push(retention.history(jsonUtf8Bytes(consulted.outcome) + jsonUtf8Bytes(call.id) + 256, () => consulted.message)!);
|
|
330
357
|
}
|
|
331
358
|
|
|
332
|
-
const exhausted =
|
|
359
|
+
const exhausted = sidecar.exhausted();
|
|
333
360
|
const tools = exhausted
|
|
334
361
|
? parsed.context.tools?.filter(tool => !tool.advisor && tool.name !== ADVISOR_TOOL_NAME)
|
|
335
362
|
: parsed.context.tools;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
|
|
1
2
|
import { formatErrorResponse } from "../../bridge";
|
|
2
3
|
import {
|
|
3
4
|
CodexAccountCooldownError,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
MainAuthJsonChangedDuringRefreshError,
|
|
18
19
|
} from "../../codex/main-account";
|
|
19
20
|
import { NativeProfileError } from "../../codex/native-profile-types";
|
|
21
|
+
import { markCodexAccountCooldownResponse } from "../../codex/account-cooldown-response";
|
|
20
22
|
|
|
21
23
|
export interface CodexAuthContextErrorResponseOptions {
|
|
22
24
|
accountSelector?: string;
|
|
@@ -77,8 +79,14 @@ export function mapCodexAuthContextErrorToResponse(
|
|
|
77
79
|
error: unknown,
|
|
78
80
|
options: CodexAuthContextErrorResponseOptions,
|
|
79
81
|
): Response | undefined {
|
|
82
|
+
if (error instanceof CodexInstallationIdUnavailableError) {
|
|
83
|
+
return formatErrorResponse(503, "server_busy", error.message);
|
|
84
|
+
}
|
|
80
85
|
if (error instanceof CodexAccountCooldownError) {
|
|
81
|
-
|
|
86
|
+
const response = cooldownErrorResponse(error, options.now, options.accountSelector);
|
|
87
|
+
// Exact class only (#7850): main hard-lock, credit, Reserve, recovery-withheld and future
|
|
88
|
+
// policy subclasses keep their own retry semantics, including in combo target cooldowns.
|
|
89
|
+
return error.constructor === CodexAccountCooldownError ? markCodexAccountCooldownResponse(response) : response;
|
|
82
90
|
}
|
|
83
91
|
if (error instanceof CodexMainProfileDrainingError) {
|
|
84
92
|
return codexMainProfileDrainingResponse();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { REQUIRED_TOOL_CONTRACT_CODE } from "../../lib/errors";
|
|
2
|
+
import { mapToolChoice } from "../../responses/parser-tools";
|
|
3
|
+
import { modelInList, type OcxProviderConfig } from "../../types";
|
|
2
4
|
import { hasResponseMediaType } from "../../lib/http-response-semantics";
|
|
3
5
|
import { applyReplayRefusalClientHeaders, isNonReplayableResponse, markResponseNonReplayable } from "../../lib/upstream-retry";
|
|
4
6
|
import { clientWireOf } from "../inference/client-wire";
|
|
@@ -10,6 +12,43 @@ export type RequiredToolContract =
|
|
|
10
12
|
| { kind: "any"; hostedCallTypes: ReadonlySet<string> }
|
|
11
13
|
| { kind: "named"; name: string };
|
|
12
14
|
|
|
15
|
+
const allowedHostedSelectors = new Set([
|
|
16
|
+
"web_search", "web_search_preview", "file_search", "computer_use_preview", "computer_use",
|
|
17
|
+
"code_interpreter", "image_generation", "image_gen", "tool_search",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
function knownToolSelector(value: unknown): boolean {
|
|
21
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
22
|
+
const entry = value as Record<string, unknown>;
|
|
23
|
+
if (entry.type === "mcp") return typeof entry.server_label === "string" && !!entry.server_label.trim()
|
|
24
|
+
&& (entry.name === undefined || entry.name === null || (typeof entry.name === "string" && !!entry.name.trim()));
|
|
25
|
+
if (entry.name !== undefined && (typeof entry.name !== "string" || !entry.name.trim())) return false;
|
|
26
|
+
if (entry.type === "function" || entry.type === "custom") return typeof entry.name === "string";
|
|
27
|
+
return typeof entry.type === "string" && allowedHostedSelectors.has(entry.type);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Only definite, well-formed mandatory selectors justify excluding a destination. */
|
|
31
|
+
export function hasMandatoryToolChoice(rawBody: unknown): boolean {
|
|
32
|
+
if (!rawBody || typeof rawBody !== "object" || Array.isArray(rawBody)) return false;
|
|
33
|
+
const choice = (rawBody as Record<string, unknown>).tool_choice;
|
|
34
|
+
if (choice === "required") return true;
|
|
35
|
+
if (!choice || typeof choice !== "object" || Array.isArray(choice)) return false;
|
|
36
|
+
const selector = choice as Record<string, unknown>;
|
|
37
|
+
// Eligibility is broader than terminal inspection: hosted selectors retain their own terminal owner.
|
|
38
|
+
if (selector.type !== "allowed_tools") return knownToolSelector(selector);
|
|
39
|
+
return selector.mode === "required"
|
|
40
|
+
&& Array.isArray(selector.tools) && selector.tools.length > 0
|
|
41
|
+
&& selector.tools.every(knownToolSelector);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A translated Chat target must not turn a mandatory selector into auto or none. */
|
|
45
|
+
export function chatCanPreserveMandatoryToolChoice(rawBody: unknown, provider: OcxProviderConfig, modelId: string): boolean {
|
|
46
|
+
if (!hasMandatoryToolChoice(rawBody)) return true;
|
|
47
|
+
if (modelInList(provider.autoToolChoiceOnlyModels, modelId)) return false;
|
|
48
|
+
const mapped = mapToolChoice((rawBody as Record<string, unknown>).tool_choice);
|
|
49
|
+
return mapped === "required" || (!!mapped && typeof mapped === "object");
|
|
50
|
+
}
|
|
51
|
+
|
|
13
52
|
const hostedCalls = new Map([
|
|
14
53
|
["web_search", "web_search_call"], ["web_search_preview", "web_search_call"],
|
|
15
54
|
["file_search", "file_search_call"], ["code_interpreter", "code_interpreter_call"],
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
|
|
2
|
+
import { isolateCodexPoolClientMetadata } from "../../codex/forward-transport-headers";
|
|
1
3
|
import { captureAccountAutoPauseAttempt, wasAccountAutoPaused, wasPermanentAccountRefusal } from "../../oauth/account-auto-pause";
|
|
2
4
|
import { spendLedgerStorageErrorResponse } from "./spend-storage-error";
|
|
5
|
+
import { captureAdmissionPolicy } from "../capture-admission-policy";
|
|
3
6
|
import { createPhysicalSendReporter, rebindPhysicalSend } from "../../lib/request-execution-budget";
|
|
4
7
|
import { hasResponseMediaType } from "../../lib/http-response-semantics";
|
|
5
8
|
import { createInferenceSendBudget } from "../inference/context";
|
|
@@ -319,6 +322,7 @@ function compactHandoffRoute(
|
|
|
319
322
|
}
|
|
320
323
|
|
|
321
324
|
export interface HandleResponsesCompactOptions {
|
|
325
|
+
advisorAdmissionPolicy?: import("../../types/admission-policy").CapturedAdmissionPolicy;
|
|
322
326
|
compactionRoutingOverride?: CompactionRoutingOverride | null;
|
|
323
327
|
nativeMainRefreshDependencies?: NativeMainRefreshDependencies;
|
|
324
328
|
/** Release the listener's idle guard only after the complete request body is accepted. */
|
|
@@ -391,7 +395,7 @@ async function refreshNativeMainCompactContext(args: {
|
|
|
391
395
|
});
|
|
392
396
|
for (const name of FORWARD_HEADERS) {
|
|
393
397
|
const value = selected.get(name);
|
|
394
|
-
if (value) headers.set(name, value);
|
|
398
|
+
if (value !== null) headers.set(name, value);
|
|
395
399
|
}
|
|
396
400
|
const override = (refreshedProvider as { _codexAccountOverride?: { accessToken: string; chatgptAccountId: string } })._codexAccountOverride;
|
|
397
401
|
if (override) {
|
|
@@ -486,7 +490,7 @@ async function refreshPoolCompactContext(args: {
|
|
|
486
490
|
});
|
|
487
491
|
for (const name of FORWARD_HEADERS) {
|
|
488
492
|
const value = selected.get(name);
|
|
489
|
-
if (value) headers.set(name, value);
|
|
493
|
+
if (value !== null) headers.set(name, value);
|
|
490
494
|
}
|
|
491
495
|
const override = (refreshedProvider as { _codexAccountOverride?: { accessToken: string; chatgptAccountId: string } })._codexAccountOverride;
|
|
492
496
|
if (override) {
|
|
@@ -539,11 +543,12 @@ async function resolveAlternateCompactContext(args: {
|
|
|
539
543
|
excludeAccountId: string | null;
|
|
540
544
|
turnAdmissionLease?: AdmissionLease;
|
|
541
545
|
admission?: DataPlaneAdmission;
|
|
542
|
-
}): Promise<{ authCtx: CodexAuthContext; provider: OcxProviderConfig; headers: Headers } | null> {
|
|
546
|
+
}): Promise<{ authCtx: CodexAuthContext; provider: OcxProviderConfig; headers: Headers } | { failure: Response } | null> {
|
|
543
547
|
const { req, config, route, selectedModelId, excludeAccountId, turnAdmissionLease } = args;
|
|
544
548
|
if (!route.codexAccountMode || !excludeAccountId) return null;
|
|
549
|
+
let authCtx: CodexAuthContext | undefined;
|
|
545
550
|
try {
|
|
546
|
-
|
|
551
|
+
authCtx = await resolveCodexAuthContext(req.headers, config, route.codexAccountMode, {
|
|
547
552
|
admission: args.admission,
|
|
548
553
|
...(selectedModelId ? { modelId: selectedModelId } : {}),
|
|
549
554
|
excludeAccountId,
|
|
@@ -559,7 +564,7 @@ async function resolveAlternateCompactContext(args: {
|
|
|
559
564
|
const selected = headersForCodexAuthContext(req.headers, authCtx, config, selectedModelId, args.admission);
|
|
560
565
|
for (const name of FORWARD_HEADERS) {
|
|
561
566
|
const value = selected.get(name);
|
|
562
|
-
if (value) headers.set(name, value);
|
|
567
|
+
if (value !== null) headers.set(name, value);
|
|
563
568
|
}
|
|
564
569
|
const override = (provider as { _codexAccountOverride?: { accessToken: string; chatgptAccountId: string } })._codexAccountOverride;
|
|
565
570
|
if (override) {
|
|
@@ -569,6 +574,8 @@ async function resolveAlternateCompactContext(args: {
|
|
|
569
574
|
if (provider.apiKey) headers.set("authorization", `Bearer ${resolveProviderApiKey(provider.apiKey)}`);
|
|
570
575
|
return { authCtx, provider, headers };
|
|
571
576
|
} catch (err) {
|
|
577
|
+
releaseCodexAuthContextProbeLease(authCtx);
|
|
578
|
+
if (err instanceof CodexInstallationIdUnavailableError) return { failure: formatErrorResponse(503, "server_busy", err.message) };
|
|
572
579
|
if (err instanceof CodexMainProfileDrainingError) {
|
|
573
580
|
// The native-main fence can start after account A has already rejected the
|
|
574
581
|
// request. Treat the now-fenced main profile as no alternate and preserve A's
|
|
@@ -601,7 +608,7 @@ function compactResponseHeaders(upstream: Response): Headers {
|
|
|
601
608
|
const headers = new Headers({ "Content-Type": upstream.headers.get("content-type") ?? "application/json" });
|
|
602
609
|
for (const name of COMPACT_PASSTHROUGH_HEADERS) {
|
|
603
610
|
const value = upstream.headers.get(name);
|
|
604
|
-
if (value) headers.set(name, value);
|
|
611
|
+
if (value !== null) headers.set(name, value);
|
|
605
612
|
}
|
|
606
613
|
return headers;
|
|
607
614
|
}
|
|
@@ -660,6 +667,7 @@ export async function handleResponsesCompact(
|
|
|
660
667
|
admission?: DataPlaneAdmission,
|
|
661
668
|
options: HandleResponsesCompactOptions = {},
|
|
662
669
|
): Promise<Response> {
|
|
670
|
+
options = { ...options, advisorAdmissionPolicy: options.advisorAdmissionPolicy ?? captureAdmissionPolicy(config, admission) };
|
|
663
671
|
let body: unknown;
|
|
664
672
|
try {
|
|
665
673
|
body = await readJsonRequestBody(req, undefined, resolveInboundBodyLimitBytes(config.maxInboundBodyBytes));
|
|
@@ -904,7 +912,7 @@ export async function handleResponsesCompact(
|
|
|
904
912
|
compactProvider = applyCodexAuthContextToProvider(route.provider, authCtx, route.codexAccountMode);
|
|
905
913
|
for (const name of FORWARD_HEADERS) {
|
|
906
914
|
const value = selected.get(name);
|
|
907
|
-
if (value) headers.set(name, value);
|
|
915
|
+
if (value !== null) headers.set(name, value);
|
|
908
916
|
}
|
|
909
917
|
const override = (compactProvider as { _codexAccountOverride?: { accessToken: string; chatgptAccountId: string } })._codexAccountOverride;
|
|
910
918
|
if (override) {
|
|
@@ -1055,6 +1063,14 @@ export async function handleResponsesCompact(
|
|
|
1055
1063
|
compactHostAdmissionLease = null;
|
|
1056
1064
|
};
|
|
1057
1065
|
const connectMs = () => resolveConnectTimeoutMs(config.connectTimeoutMs, { localUpstream: isLocalUpstream(compactUrl) });
|
|
1066
|
+
const applyCompactPoolQuotaHeaders = async (ctx: CodexAuthContext, response: Response) => {
|
|
1067
|
+
if (ctx.kind !== "pool" && ctx.kind !== "main-pool") return;
|
|
1068
|
+
const { applyAccountQuotaFromUpstreamHeaders } = await import("../../codex/quota");
|
|
1069
|
+
applyAccountQuotaFromUpstreamHeaders(ctx.accountId, response.headers, ctx.writerGeneration,
|
|
1070
|
+
ctx.kind === "main-pool" ? ctx.mainQuotaWriter : undefined,
|
|
1071
|
+
{ modelId: route.modelId, poolWriter: ctx.kind === "pool" ? ctx.poolQuotaWriter : undefined,
|
|
1072
|
+
poolResponse: ctx.kind === "pool" });
|
|
1073
|
+
};
|
|
1058
1074
|
// Takes its context explicitly: the alternate-account flow below records a rejection
|
|
1059
1075
|
// against A while promoting B, then records B's own outcome. A closure over a single
|
|
1060
1076
|
// `authCtx` cannot express either.
|
|
@@ -1163,6 +1179,9 @@ export async function handleResponsesCompact(
|
|
|
1163
1179
|
if (!isOpenAiOperatedResponsesDestination(sendProvider) && sendProvider.preserveResponsesMessageMetadata !== true) {
|
|
1164
1180
|
replayBody = stripInternalChatMessageMetadataPassthrough(replayBody) as typeof replayBody;
|
|
1165
1181
|
}
|
|
1182
|
+
if (sendAuthCtx.kind === "pool" && isCanonicalOpenAiForwardProvider(sendProvider)) {
|
|
1183
|
+
replayBody = isolateCodexPoolClientMetadata(replayBody, sendAuthCtx.chatgptAccountId) as typeof replayBody;
|
|
1184
|
+
}
|
|
1166
1185
|
// A queued key selection can refresh the destination; project only for this send.
|
|
1167
1186
|
return isOpenAiOperatedResponsesDestination(sendProvider)
|
|
1168
1187
|
? repairUrlCitationAnnotations(replayBody) : stripCanonicalOnlyInputItems(stripCanonicalOnlyTopLevelFields(replayBody));
|
|
@@ -1466,6 +1485,12 @@ export async function handleResponsesCompact(
|
|
|
1466
1485
|
excludeAccountId: authCtx.accountId,
|
|
1467
1486
|
turnAdmissionLease,
|
|
1468
1487
|
});
|
|
1488
|
+
if (alternate && "failure" in alternate) {
|
|
1489
|
+
await applyCompactPoolQuotaHeaders(authCtx, upstream);
|
|
1490
|
+
recordCompactPoolOutcome(authCtx, upstream.status, { retryAfter: firstRetryAfter, resetAt: firstResetAt });
|
|
1491
|
+
await upstream.body?.cancel().catch(() => undefined);
|
|
1492
|
+
return alternate.failure;
|
|
1493
|
+
}
|
|
1469
1494
|
// Resolution can await a credential refresh, so the client may have gone away
|
|
1470
1495
|
// while we were choosing B. Re-check before spending anything: recording A,
|
|
1471
1496
|
// cancelling its body, and sending B are all observable side effects, and B's
|
|
@@ -1507,17 +1532,7 @@ export async function handleResponsesCompact(
|
|
|
1507
1532
|
// quota snapshot that produced it, so refresh A's cache before recording its
|
|
1508
1533
|
// rejection. Skipping this leaves quota-strategy routing and the dashboard
|
|
1509
1534
|
// reading numbers from before the account ran out.
|
|
1510
|
-
|
|
1511
|
-
const { applyAccountQuotaFromUpstreamHeaders } = await import("../../codex/auth-api");
|
|
1512
|
-
applyAccountQuotaFromUpstreamHeaders(
|
|
1513
|
-
authCtx.accountId,
|
|
1514
|
-
upstream.headers,
|
|
1515
|
-
authCtx.writerGeneration,
|
|
1516
|
-
authCtx.kind === "main-pool" ? authCtx.mainQuotaWriter : undefined,
|
|
1517
|
-
{ modelId: route.modelId, poolWriter: authCtx.kind === "pool" ? authCtx.poolQuotaWriter : undefined,
|
|
1518
|
-
poolResponse: authCtx.kind === "pool" },
|
|
1519
|
-
);
|
|
1520
|
-
}
|
|
1535
|
+
await applyCompactPoolQuotaHeaders(authCtx, upstream);
|
|
1521
1536
|
recordCompactPoolOutcome(authCtx, upstream.status, {
|
|
1522
1537
|
retryAfter: firstRetryAfter,
|
|
1523
1538
|
resetAt: firstResetAt,
|
|
@@ -1566,6 +1581,12 @@ export async function handleResponsesCompact(
|
|
|
1566
1581
|
excludeAccountId: authCtx.accountId,
|
|
1567
1582
|
turnAdmissionLease,
|
|
1568
1583
|
});
|
|
1584
|
+
if (alternate && "failure" in alternate) {
|
|
1585
|
+
await applyCompactPoolQuotaHeaders(authCtx, upstream);
|
|
1586
|
+
recordCompactPoolOutcome(authCtx, firstStatus, { retryAfter: firstRetryAfter, resetAt: firstResetAt });
|
|
1587
|
+
await upstream.body?.cancel().catch(() => undefined);
|
|
1588
|
+
return alternate.failure;
|
|
1589
|
+
}
|
|
1569
1590
|
if (alternate && req.signal.aborted) {
|
|
1570
1591
|
releaseCodexAuthContextProbeLease(alternate.authCtx);
|
|
1571
1592
|
recordCompactPoolOutcome(outcomeCtx, 499);
|
|
@@ -1725,7 +1746,7 @@ export async function handleResponsesCompact(
|
|
|
1725
1746
|
const internalHeaders = new Headers({ "content-type": "application/json" });
|
|
1726
1747
|
for (const name of FORWARD_HEADERS) {
|
|
1727
1748
|
const value = req.headers.get(name);
|
|
1728
|
-
if (value) internalHeaders.set(name, value);
|
|
1749
|
+
if (value || (value !== null && (name === "x-codex-installation-id" || name === "x-codex-turn-metadata"))) internalHeaders.set(name, value);
|
|
1729
1750
|
}
|
|
1730
1751
|
copyResponsesClientMetadata(internalHeaders, req.headers, route.provider);
|
|
1731
1752
|
const internalReq = new Request("http://localhost/v1/responses", {
|
|
@@ -1739,7 +1760,7 @@ export async function handleResponsesCompact(
|
|
|
1739
1760
|
// fallback spend four more.
|
|
1740
1761
|
// internalReq keeps only FORWARD_HEADERS, so the caller principal is resolved from req.
|
|
1741
1762
|
const replayPrincipal = { clientPrincipalId: resolveContextPrincipal(req, config, admission) };
|
|
1742
|
-
const response = await handleResponses(internalReq, config, logCtx, { abortSignal: req.signal, turnAdmissionLease, sendBudget, compactionRecoveryKind: "compaction-v1", compactionRoutingOverride: options.compactionRoutingOverride, replayPrincipal, ...(admission ? { admission } : {}) });
|
|
1763
|
+
const response = await handleResponses(internalReq, config, logCtx, { abortSignal: req.signal, turnAdmissionLease, sendBudget, compactionRecoveryKind: "compaction-v1", compactionRoutingOverride: options.compactionRoutingOverride, advisorAdmissionPolicy: options.advisorAdmissionPolicy, replayPrincipal, ...(admission ? { admission } : {}) });
|
|
1743
1764
|
if (req.signal.aborted) {
|
|
1744
1765
|
void response.body?.cancel(req.signal.reason).catch(() => undefined);
|
|
1745
1766
|
return formatErrorResponse(499, "client_cancelled", "Client cancelled compact request");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
|
|
1
2
|
import { captureAccountAutoPauseAttempt, wasPermanentAccountRefusal } from "../../oauth/account-auto-pause";
|
|
2
3
|
import type { OcxConfig, OcxProviderConfig, OcxParsedRequest } from "../../types";
|
|
3
4
|
import type { CodexAuthContext, CodexAuthPolicyConfig } from "../../codex/auth-context";
|
|
@@ -886,7 +887,7 @@ export async function retryCodexPoolOnAlternateAccount(
|
|
|
886
887
|
retryHeaders = headersForCodexAuthContext(callerAuthHeaders, retryAuthCtx, options.codexAuthPolicy ?? config, route.modelId, options.admission);
|
|
887
888
|
retryProvider = applyCodexAuthContextToProvider(stripCodexRuntimeProviderFields(route.provider), retryAuthCtx, "pool");
|
|
888
889
|
} catch (error) {
|
|
889
|
-
if (!(error instanceof CodexPoolAccountCreditsOffError)) throw error;
|
|
890
|
+
if (!(error instanceof CodexPoolAccountCreditsOffError) && !(error instanceof CodexInstallationIdUnavailableError)) throw error;
|
|
890
891
|
// Body/entitlement reads above can outlive credit consent. No alternate will send:
|
|
891
892
|
// release its reservation and probes, then let the owner map the policy refusal.
|
|
892
893
|
accountMovePermit?.release();
|
|
@@ -929,11 +930,21 @@ export async function retryCodexPoolOnAlternateAccount(
|
|
|
929
930
|
});
|
|
930
931
|
}
|
|
931
932
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
933
|
+
let request;
|
|
934
|
+
try {
|
|
935
|
+
request = await retryAdapter.buildRequest(parsed, {
|
|
936
|
+
headers: retryHeaders,
|
|
937
|
+
providerName: route.providerName,
|
|
938
|
+
translatorBudget: options.translatorBudget,
|
|
939
|
+
});
|
|
940
|
+
} catch (error) {
|
|
941
|
+
if (!(error instanceof CodexInstallationIdUnavailableError)) throw error;
|
|
942
|
+
accountMovePermit?.release();
|
|
943
|
+
releaseCodexAuthContextProbeLease(firstAuthCtx);
|
|
944
|
+
releaseCodexAuthContextProbeLease(retryAuthCtx);
|
|
945
|
+
await firstResponse.body?.cancel().catch(() => undefined);
|
|
946
|
+
return { kind: "transport", error, authCtx: retryAuthCtx };
|
|
947
|
+
}
|
|
937
948
|
recordAdapterReasoning(logCtx, request);
|
|
938
949
|
recordAdapterTier(logCtx, request);
|
|
939
950
|
|
|
@@ -4,6 +4,7 @@ import type { ConsumedComboFailure, HandleResponsesOptions } from "./core-option
|
|
|
4
4
|
import type { OcxUsage } from "../../types";
|
|
5
5
|
import { readBoundedResponseBody } from "../../lib/bounded-body";
|
|
6
6
|
import { carryAnthropicRefusalCredential } from "../../oauth/anthropic-account-refusal";
|
|
7
|
+
import { carryCodexAccountCooldownResponse } from "../../codex/account-cooldown-response";
|
|
7
8
|
import { codexQuotaFailureMessage, codexQuotaOutcomeMeta } from "./core-codex-account";
|
|
8
9
|
import {
|
|
9
10
|
isRateLimitOrQuotaFailureMessage,
|
|
@@ -141,6 +142,7 @@ export async function consumeComboFailure(
|
|
|
141
142
|
carryReplayRefusal(response, failureResponse);
|
|
142
143
|
if (verifiedPlanRefusal) markVerifiedModelNotInPlanResponse(failureResponse);
|
|
143
144
|
carryAnthropicRefusalCredential(response, failureResponse);
|
|
145
|
+
carryCodexAccountCooldownResponse(response, failureResponse);
|
|
144
146
|
return {
|
|
145
147
|
response: failureResponse,
|
|
146
148
|
...(nonReplayable ? { nonReplayable: true } : {}),
|