@bitkyc08/opencodex 2.95.0 → 2.97.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ocx.mjs +214 -19
- package/gui/dist/assets/{App-8yedBkhm.js → App-DuNhggE1.js} +18 -18
- package/gui/dist/assets/{Tray-erSMzxPG.js → Tray-CEw0y0jR.js} +1 -1
- package/gui/dist/assets/index-CynE_Rue.js +94 -0
- package/gui/dist/assets/{quota-summary-BK4VuQNc.js → quota-summary-VHFSlUuM.js} +1 -1
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/kiro/stream.ts +63 -4
- package/src/adapters/kiro-constants.ts +15 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/ollama-native.ts +21 -7
- package/src/adapters/openai-responses/canonical-forward.ts +50 -13
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/passthrough.ts +8 -8
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/openai-responses/transport.ts +17 -26
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/qoder/adapter.ts +1 -1
- package/src/adapters/qoder/image-input.ts +5 -2
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/outbound.ts +49 -2
- package/src/cli/agent.ts +44 -15
- package/src/cli/capabilities-agents-routing.ts +9 -0
- package/src/cli/capabilities-base.ts +25 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +5 -4
- package/src/cli/dispatch.ts +11 -176
- package/src/cli/ensure-desired-integrations.ts +4 -3
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +9 -2
- package/src/cli/link.ts +1 -1
- package/src/cli/message-command.ts +2 -1
- package/src/cli/message-mcp-command.ts +29 -0
- package/src/cli/registry.ts +12 -4
- package/src/cli/root.ts +8 -0
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +150 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/client/connect.ts +31 -14
- package/src/client/link-home.ts +3 -2
- package/src/client/machine-listener.ts +3 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/account-store.ts +1 -0
- package/src/codex/auth-context-provider.ts +15 -0
- package/src/codex/auth-context.ts +59 -122
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +6 -8
- package/src/codex/forward-transport-headers.ts +65 -36
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/installation-id.ts +72 -0
- package/src/codex/lineage.ts +13 -7
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/process-state.ts +5 -0
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/generated/compatibility-version.json +496 -192
- package/src/grok/sync.ts +10 -1
- package/src/images/loop.ts +2 -1
- package/src/lib/client-error-body.ts +184 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership.ts +4 -0
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/desktop-cli-handoff.d.mts +1 -1
- package/src/lib/desktop-cli-handoff.mjs +11 -1
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +14 -11
- package/src/lib/windows-owner-acl.ts +13 -6
- package/src/lib/windows-secret-acl.ts +2 -2
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/messaging/mcp-queue-rpc.ts +102 -0
- package/src/messaging/mcp-queue-server.ts +42 -0
- package/src/messaging/mcp-queue-tools.ts +39 -0
- package/src/oauth/anthropic-identity.ts +2 -6
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +41 -74
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +1 -1
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +4 -0
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/trace.ts +18 -0
- package/src/providers/anthropic-subscription.ts +25 -0
- package/src/providers/claude-cli-usage.ts +15 -67
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/quota/anthropic-decision-windows.ts +5 -19
- package/src/providers/quota/anthropic-usage-windows.ts +65 -0
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/request-pacing.ts +3 -2
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/parser-tools.ts +1 -0
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/responses/schema.ts +5 -2
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +56 -0
- package/src/server/audio-dictation.ts +3 -0
- package/src/server/audio-live.ts +8 -2
- package/src/server/audio-upstream.ts +2 -0
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +57 -27
- package/src/server/context-history.ts +14 -7
- package/src/server/images.ts +14 -5
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/live-sideband.ts +16 -2
- package/src/server/index/ollama-routes.ts +89 -0
- package/src/server/index/serve-options.ts +22 -4
- package/src/server/index/websocket-handler.ts +5 -3
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +4 -2
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/live.ts +30 -5
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/route-registry.ts +1 -1
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +1 -1
- package/src/server/messages-native.ts +12 -7
- package/src/server/messages-shared.ts +6 -2
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +79 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +9 -4
- package/src/server/responses/adapter-delivery.ts +5 -4
- package/src/server/responses/adapter-dispatch.ts +36 -30
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +22 -17
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/combo-required-tool-contract.ts +24 -12
- package/src/server/responses/compact.ts +89 -41
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +34 -12
- package/src/server/responses/core-combo-failure.ts +5 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +51 -33
- package/src/server/responses/core-errors.ts +22 -20
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +8 -1
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-build-error.ts +36 -0
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +26 -39
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +67 -48
- package/src/server/responses/request-sidecar-auth.ts +3 -1
- package/src/server/responses/request-transport.ts +35 -31
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/search.ts +13 -4
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +5 -2
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/types/config.ts +2 -0
- package/src/update/index.ts +133 -25
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +60 -27
- package/src/vision/describe.ts +4 -7
- package/src/web-search/executor.ts +4 -7
- package/src/web-search/loop.ts +31 -5
- package/gui/dist/assets/index-D7DCm5eQ.js +0 -94
|
@@ -30,6 +30,9 @@ import type { RequestSpendSettlement } from "./responses/request-spend";
|
|
|
30
30
|
import type { AdapterTierMetadata } from "../providers/fastwire";
|
|
31
31
|
import { UPSTREAM_RESET_REPLAY_REFUSED_CODE } from "../lib/upstream-retry";
|
|
32
32
|
import { redactSecretString, sanitizeLogMetadataString } from "../lib/redact";
|
|
33
|
+
import type { UpstreamCondition } from "../lib/upstream-condition";
|
|
34
|
+
import { boundedServiceTier, errorDetailFor, projectErrorDetail } from "../usage/error-detail";
|
|
35
|
+
import { incompleteReasonDetail, upstreamErrorIsLocal, type FailureDetail } from "./request-log-failure-detail";
|
|
33
36
|
import {
|
|
34
37
|
appendUsageEntry,
|
|
35
38
|
classifyCacheTelemetryProvenance,
|
|
@@ -66,7 +69,7 @@ import {
|
|
|
66
69
|
} from "../usage/log";
|
|
67
70
|
import type { RequestExecutionBudget } from "../lib/request-execution-budget";
|
|
68
71
|
import type { WorkflowSpendDenialDetail } from "../lib/workflow-budget";
|
|
69
|
-
import { attributeFinalRequest, attributeSealedAttempt } from "./request-log-failure-attribution";
|
|
72
|
+
import { attributeFinalRequest, attributePhysicalAttempt, attributeSealedAttempt } from "./request-log-failure-attribution";
|
|
70
73
|
import { debugAttemptDeliverySummary } from "../lib/debug";
|
|
71
74
|
import {
|
|
72
75
|
appendUsageDebug,
|
|
@@ -243,6 +246,8 @@ export interface RequestLogContext extends UpstreamErrorDiagnostics {
|
|
|
243
246
|
* message) extracted from a `response.failed` SSE payload or non-streaming error body, so the
|
|
244
247
|
* request log / GUI shows the actual upstream failure rather than only the HTTP-mapped code. */
|
|
245
248
|
upstreamError?: string;
|
|
249
|
+
failureDetail?: FailureDetail; // closed code + bounded params (src/lib/failure-detail.ts)
|
|
250
|
+
upstreamCondition?: UpstreamCondition; // classified at capture where the evidence is not kept on the context
|
|
246
251
|
/** HTTP status derived from a terminal `response.failed` SSE payload (429/401/503/etc.). */
|
|
247
252
|
terminalHttpStatus?: number;
|
|
248
253
|
/** Recognized structured terminal code whose exact identity must survive status mapping. */
|
|
@@ -353,8 +358,11 @@ export interface RequestLogEntry extends UpstreamErrorDiagnostics {
|
|
|
353
358
|
errorCode?: string;
|
|
354
359
|
terminalStatus?: ResponsesTerminalStatus;
|
|
355
360
|
closeReason?: "terminal" | "client_cancel" | "non_stream" | "body_stall" | "body_overflow";
|
|
356
|
-
/**
|
|
361
|
+
/** Input only: addRequestLog derives the two fields below from it, then removes it. */
|
|
357
362
|
upstreamError?: string;
|
|
363
|
+
upstreamCondition?: UpstreamCondition; // closed enum, src/lib/upstream-condition.ts
|
|
364
|
+
failureDetail?: FailureDetail; // closed code + bounded params, see request-log-failure-detail.ts
|
|
365
|
+
rateLimitResetAt?: number; // provider quota window end, epoch ms, bounded
|
|
358
366
|
usageStatus: UsageStatus;
|
|
359
367
|
usage?: OcxUsage;
|
|
360
368
|
totalTokens?: number;
|
|
@@ -473,7 +481,10 @@ export function requestLogEntryFromPersistedUsage(entry: PersistedUsageEntry): R
|
|
|
473
481
|
const claudeCompatibility = normalizeClaudeCompatibilityUsageLog(entry.claudeCompatibility);
|
|
474
482
|
const spend = normalizeRequestSpend(entry.spend);
|
|
475
483
|
const protocolTrace = parseProtocolTraceV1(entry.protocolTrace);
|
|
476
|
-
|
|
484
|
+
// projectErrorDetail bounds the tier fields (top-level and per attempt) itself, so this stays safe
|
|
485
|
+
// for a row that did not come through the disk reader; attempts are copied before it edits them.
|
|
486
|
+
const attempts = Array.isArray(entry.attempts) ? entry.attempts.map(attempt => ({ ...attempt })) : entry.attempts;
|
|
487
|
+
return projectErrorDetail({
|
|
477
488
|
requestId: entry.requestId,
|
|
478
489
|
...(isLogicalRequestId(entry.logicalRequestId) ? { logicalRequestId: entry.logicalRequestId } : {}),
|
|
479
490
|
timestamp: entry.timestamp,
|
|
@@ -509,14 +520,14 @@ export function requestLogEntryFromPersistedUsage(entry: PersistedUsageEntry): R
|
|
|
509
520
|
...modelIdentityLogFields(entry),
|
|
510
521
|
status: entry.status,
|
|
511
522
|
durationMs: entry.durationMs,
|
|
512
|
-
|
|
523
|
+
// Closed code, condition, failure detail and quota reset; legacy upstream text is read once and dropped.
|
|
524
|
+
...errorDetailFor(entry),
|
|
513
525
|
...(terminalStatus ? { terminalStatus } : {}),
|
|
514
526
|
...(closeReason ? { closeReason } : {}),
|
|
515
|
-
...(entry.upstreamError ? { upstreamError: entry.upstreamError } : {}),
|
|
516
527
|
usageStatus: entry.usageStatus,
|
|
517
528
|
...(entry.usage ? { usage: entry.usage } : {}),
|
|
518
529
|
...(entry.totalTokens !== undefined ? { totalTokens: entry.totalTokens } : {}),
|
|
519
|
-
...(
|
|
530
|
+
...(attempts !== undefined ? { attempts } : {}),
|
|
520
531
|
...(entry.attemptNormalizationDropped === true
|
|
521
532
|
? { attemptNormalizationDropped: true } : {}),
|
|
522
533
|
...(spend ? { spend } : {}),
|
|
@@ -534,7 +545,7 @@ export function requestLogEntryFromPersistedUsage(entry: PersistedUsageEntry): R
|
|
|
534
545
|
: {}),
|
|
535
546
|
...normalizeRequestFailureAttribution(entry),
|
|
536
547
|
...(protocolTrace ? { protocolTrace } : {}),
|
|
537
|
-
};
|
|
548
|
+
});
|
|
538
549
|
}
|
|
539
550
|
|
|
540
551
|
/**
|
|
@@ -613,6 +624,9 @@ export function rehydrateRequestLogsAfterLedgerReplacement(
|
|
|
613
624
|
}
|
|
614
625
|
|
|
615
626
|
export function addRequestLog(entry: RequestLogEntry) {
|
|
627
|
+
// Rows keep proxy-owned error facts only; upstream error text and tokens stop here (both the
|
|
628
|
+
// retained ring row and the usage.jsonl projection below read the projected entry).
|
|
629
|
+
entry = projectErrorDetail(entry);
|
|
616
630
|
// Sanitize ONCE, at the ingress, and use that one value for both destinations.
|
|
617
631
|
//
|
|
618
632
|
// `addFinalRequestLog` is not the only way in: `addRequestLog` is exported and callable
|
|
@@ -622,13 +636,13 @@ export function addRequestLog(entry: RequestLogEntry) {
|
|
|
622
636
|
// line-oriented viewer — while `usage.jsonl` looked clean, which is the worst shape for a
|
|
623
637
|
// sanitization bug because the safe surface is the one you check.
|
|
624
638
|
const shadowCallRewrittenFrom = sanitizeLogMetadataString(entry.shadowCallRewrittenFrom);
|
|
625
|
-
const
|
|
639
|
+
const identity = modelIdentityLogFields(entry), servedModel = identity.servedModel;
|
|
626
640
|
const claudeCompatibility = normalizeClaudeCompatibilityUsageLog(entry.claudeCompatibility);
|
|
627
641
|
const jevDecision = normalizePersistedJevDecision(entry.jevDecision);
|
|
628
642
|
const attempts = normalizedAttempts(entry.attempts);
|
|
629
643
|
const attemptsDropped = Array.isArray(entry.attempts) && attempts.length < entry.attempts.length;
|
|
630
644
|
const retained: RequestLogEntry = shadowCallRewrittenFrom === entry.shadowCallRewrittenFrom
|
|
631
|
-
&& servedModel === entry.servedModel
|
|
645
|
+
&& servedModel === entry.servedModel && identity.resolvedModel === entry.resolvedModel
|
|
632
646
|
&& entry.claudeCompatibility === undefined
|
|
633
647
|
&& entry.jevDecision === undefined
|
|
634
648
|
&& !attemptsDropped
|
|
@@ -636,10 +650,7 @@ export function addRequestLog(entry: RequestLogEntry) {
|
|
|
636
650
|
: { ...entry, ...(entry.attemptNormalizationDropped === true || attemptsDropped ? { attemptNormalizationDropped: true } : {}),
|
|
637
651
|
...(shadowCallRewrittenFrom ? { shadowCallRewrittenFrom } : {}) };
|
|
638
652
|
if (!shadowCallRewrittenFrom && retained !== entry) delete retained.shadowCallRewrittenFrom;
|
|
639
|
-
if (!servedModel
|
|
640
|
-
delete retained.servedModel;
|
|
641
|
-
if (retained.resolvedModel === entry.servedModel) delete retained.resolvedModel;
|
|
642
|
-
}
|
|
653
|
+
if (retained !== entry) { if (!servedModel) delete retained.servedModel; if (!identity.resolvedModel) delete retained.resolvedModel; }
|
|
643
654
|
if (claudeCompatibility) retained.claudeCompatibility = claudeCompatibility;
|
|
644
655
|
else if (retained !== entry) delete retained.claudeCompatibility;
|
|
645
656
|
if (jevDecision) retained.jevDecision = jevDecision;
|
|
@@ -658,7 +669,8 @@ export function addRequestLog(entry: RequestLogEntry) {
|
|
|
658
669
|
...(entry.errorCode ? { errorCode: entry.errorCode } : {}),
|
|
659
670
|
...(entry.terminalStatus ? { terminalStatus: entry.terminalStatus } : {}),
|
|
660
671
|
...(entry.closeReason ? { closeReason: entry.closeReason } : {}),
|
|
661
|
-
...(entry.
|
|
672
|
+
...(entry.upstreamCondition ? { upstreamCondition: entry.upstreamCondition } : {}), ...(entry.failureDetail ? { failureDetail: entry.failureDetail } : {}),
|
|
673
|
+
...(entry.rateLimitResetAt !== undefined ? { rateLimitResetAt: entry.rateLimitResetAt } : {}),
|
|
662
674
|
}
|
|
663
675
|
: {};
|
|
664
676
|
appendUsageEntry({
|
|
@@ -972,7 +984,7 @@ export function applyResponseLogMetadata(logCtx: RequestLogContext, payload: unk
|
|
|
972
984
|
recordObservedServedModel(logCtx, (source as { model?: unknown }).model);
|
|
973
985
|
const serviceTier = (source as { service_tier?: unknown }).service_tier;
|
|
974
986
|
if (typeof serviceTier === "string" && serviceTier.trim()) {
|
|
975
|
-
const sanitized =
|
|
987
|
+
const sanitized = boundedServiceTier(serviceTier);
|
|
976
988
|
if (sanitized) logCtx.responseServiceTier = sanitized;
|
|
977
989
|
logCtx.activeTierMetadata?.observeResponseServiceTier(serviceTier);
|
|
978
990
|
} else if (Object.prototype.hasOwnProperty.call(source, "service_tier")) {
|
|
@@ -1157,7 +1169,9 @@ function captureUpstreamErrorParsed(
|
|
|
1157
1169
|
// reader-facing label so a generic 502 in /api/logs explains WHY the turn ended, not just the
|
|
1158
1170
|
// mapped HTTP code.
|
|
1159
1171
|
if (typeof reason === "string" && reason.trim()) {
|
|
1160
|
-
|
|
1172
|
+
const incomplete = incompleteReasonDetail(reason.trim()); // A known reason also gets a closed row detail.
|
|
1173
|
+
logCtx.upstreamError = redactSecretString(incomplete.text).slice(0, 500);
|
|
1174
|
+
if (incomplete.detail) logCtx.failureDetail = incomplete.detail;
|
|
1161
1175
|
}
|
|
1162
1176
|
return;
|
|
1163
1177
|
}
|
|
@@ -1168,20 +1182,6 @@ function captureUpstreamErrorParsed(
|
|
|
1168
1182
|
}
|
|
1169
1183
|
}
|
|
1170
1184
|
|
|
1171
|
-
/** Map a raw `incomplete_details.reason` (emitted by the bridge) to a reader-facing label. */
|
|
1172
|
-
function incompleteReasonLabel(reason: string): string {
|
|
1173
|
-
switch (reason) {
|
|
1174
|
-
case "max_output_tokens":
|
|
1175
|
-
return `Output reached the requested token limit (${reason})`;
|
|
1176
|
-
case "upstream_stall_timeout":
|
|
1177
|
-
return `Upstream stalled: no data for the stall-timeout window (${reason})`;
|
|
1178
|
-
case "adapter_eof":
|
|
1179
|
-
return `Upstream stream ended unexpectedly without a terminal event (${reason})`;
|
|
1180
|
-
default:
|
|
1181
|
-
return `Upstream incomplete: ${reason}`;
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
1185
|
/** Map a terminal Responses error object to the HTTP status we record in /api/logs. */
|
|
1186
1186
|
export function httpStatusFromTerminalError(error: {
|
|
1187
1187
|
type?: string;
|
|
@@ -1235,13 +1235,13 @@ export function httpStatusForRequestLogTerminal(
|
|
|
1235
1235
|
* `unresolved` rather than quietly inflating `settled`.
|
|
1236
1236
|
*/
|
|
1237
1237
|
export function requestSpendRecord(
|
|
1238
|
-
logCtx: Pick<RequestLogContext, "executionBudget" | "affinityMoveReasons" | "affinityReason">,
|
|
1238
|
+
logCtx: Pick<RequestLogContext, "executionBudget" | "affinityMoveReasons" | "affinityReason" | "affinity">,
|
|
1239
1239
|
attempts: readonly PersistedUsageAttempt[] | undefined,
|
|
1240
1240
|
): PersistedRequestSpend | undefined {
|
|
1241
1241
|
const rows = attempts ?? [];
|
|
1242
1242
|
const budget = logCtx.executionBudget;
|
|
1243
1243
|
const reasons = [...new Set(
|
|
1244
|
-
(logCtx.affinityMoveReasons ?? (logCtx.affinityReason ? [logCtx.affinityReason] : []))
|
|
1244
|
+
(logCtx.affinityMoveReasons ?? (logCtx.affinity !== "unbound" && logCtx.affinityReason ? [logCtx.affinityReason] : []))
|
|
1245
1245
|
.filter(isKnownAffinityReason),
|
|
1246
1246
|
)];
|
|
1247
1247
|
if (rows.length === 0 && !budget && reasons.length === 0) return undefined;
|
|
@@ -1277,11 +1277,11 @@ export function noteAffinityMove(
|
|
|
1277
1277
|
|
|
1278
1278
|
/**
|
|
1279
1279
|
* Copy the selection's own affinity decision onto the request log. Both Pool-served kinds carry
|
|
1280
|
-
* one: a stored Pool account and the main login rotating as `main-pool` (#4546, #7799). A
|
|
1281
|
-
*
|
|
1280
|
+
* one: a stored Pool account and the main login rotating as `main-pool` (#4546, #7799). A keyed
|
|
1281
|
+
* caller-owned main can also carry one. A move reads as an event with its cause.
|
|
1282
1282
|
*/
|
|
1283
1283
|
export function noteCodexSelectionAffinity(logCtx: RequestLogContext, authCtx: CodexAuthContext): void {
|
|
1284
|
-
const decision = authCtx.
|
|
1284
|
+
const decision = authCtx.affinityDecision;
|
|
1285
1285
|
if (!decision) return;
|
|
1286
1286
|
logCtx.affinity = decision.move;
|
|
1287
1287
|
logCtx.affinityReason = decision.reason;
|
|
@@ -1387,6 +1387,22 @@ export function recordKeyWireAttemptUsage(logCtx: RequestLogContext, usage: OcxU
|
|
|
1387
1387
|
return true;
|
|
1388
1388
|
}
|
|
1389
1389
|
|
|
1390
|
+
type FinalRequestLogMetaArg = Pick<RequestLogEntry, "terminalStatus" | "closeReason">;
|
|
1391
|
+
const finalRequestLogInterceptors = new WeakMap<RequestLogContext, (status: number, meta?: FinalRequestLogMetaArg) => void>();
|
|
1392
|
+
|
|
1393
|
+
/** Route inner final-log requests to an outer owner (native ingress) instead of writing them. */
|
|
1394
|
+
export function interceptFinalRequestLog(logCtx: RequestLogContext, onRequest: (status: number, meta?: FinalRequestLogMetaArg) => void): void {
|
|
1395
|
+
finalRequestLogInterceptors.set(logCtx, onRequest);
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
/** The outer owner's write: request-level status from the outer outcome, the physical attempt's from the inner one. */
|
|
1399
|
+
export function commitInterceptedFinalRequestLog(
|
|
1400
|
+
requestId: string, start: number, logCtx: RequestLogContext, status: number, meta: FinalRequestLogMetaArg | undefined,
|
|
1401
|
+
attemptStatus: number, addLog: (entry: RequestLogEntry) => void = addRequestLog,
|
|
1402
|
+
): void {
|
|
1403
|
+
writeFinalRequestLog(requestId, start, logCtx, status, meta, addLog, attemptStatus);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1390
1406
|
export function addFinalRequestLog(
|
|
1391
1407
|
requestId: string,
|
|
1392
1408
|
start: number,
|
|
@@ -1394,10 +1410,25 @@ export function addFinalRequestLog(
|
|
|
1394
1410
|
status: number,
|
|
1395
1411
|
meta?: Pick<RequestLogEntry, "terminalStatus" | "closeReason">,
|
|
1396
1412
|
addLog: (entry: RequestLogEntry) => void = addRequestLog,
|
|
1413
|
+
): void {
|
|
1414
|
+
const intercept = finalRequestLogInterceptors.get(logCtx);
|
|
1415
|
+
if (intercept) { intercept(status, meta); return; }
|
|
1416
|
+
writeFinalRequestLog(requestId, start, logCtx, status, meta, addLog);
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
function writeFinalRequestLog(
|
|
1420
|
+
requestId: string,
|
|
1421
|
+
start: number,
|
|
1422
|
+
logCtx: RequestLogContext,
|
|
1423
|
+
status: number,
|
|
1424
|
+
meta?: Pick<RequestLogEntry, "terminalStatus" | "closeReason">,
|
|
1425
|
+
addLog: (entry: RequestLogEntry) => void = addRequestLog,
|
|
1426
|
+
attemptStatus?: number,
|
|
1397
1427
|
): void {
|
|
1398
1428
|
// Mid-stream web-search aborts used to emit response.failed and land as 502/upstream_server_error.
|
|
1399
1429
|
// Prefer the client-close classification whenever the captured reason says so.
|
|
1400
|
-
|
|
1430
|
+
// A coordinated (attemptStatus) write carries an authoritative outer outcome; skip the heuristic.
|
|
1431
|
+
const effectiveStatus = attemptStatus === undefined && status >= 500 && logCtx.upstreamError && isClientClosedMessage(logCtx.upstreamError)
|
|
1401
1432
|
? 499
|
|
1402
1433
|
: status;
|
|
1403
1434
|
// Locally assigned codes name proxy refusals that status and upstream text cannot reconstruct.
|
|
@@ -1415,7 +1446,7 @@ export function addFinalRequestLog(
|
|
|
1415
1446
|
if (logCtx.activeAttempt) {
|
|
1416
1447
|
finishRequestAttempt(
|
|
1417
1448
|
logCtx.activeAttempt,
|
|
1418
|
-
effectiveStatus,
|
|
1449
|
+
attemptStatus ?? effectiveStatus,
|
|
1419
1450
|
Date.now() - (logCtx.activeAttemptStartedAt ?? start),
|
|
1420
1451
|
keyUsageOwners.has(logCtx.activeAttempt)
|
|
1421
1452
|
? logCtx.activeAttempt.usage
|
|
@@ -1423,7 +1454,9 @@ export function addFinalRequestLog(
|
|
|
1423
1454
|
);
|
|
1424
1455
|
// The final row and its active physical attempt describe the same terminal. Preserve the
|
|
1425
1456
|
// semantic code on both so detailed attempt telemetry cannot regress to a generic status code.
|
|
1426
|
-
|
|
1457
|
+
const attemptErrorCode = attemptStatus === undefined ? errorCode : attemptStatus < 400 ? undefined
|
|
1458
|
+
: logCtx.errorCode ?? requestLogErrorCode(attemptStatus, logCtx.upstreamError, logCtx.terminalErrorCode, false);
|
|
1459
|
+
if (attemptErrorCode) logCtx.activeAttempt.errorCode = attemptErrorCode;
|
|
1427
1460
|
else delete logCtx.activeAttempt.errorCode;
|
|
1428
1461
|
}
|
|
1429
1462
|
// Derived and stamped in a sibling module, before the attempt snapshot below. Every input is
|
|
@@ -1437,8 +1470,10 @@ export function addFinalRequestLog(
|
|
|
1437
1470
|
outputObserved: logCtx.firstOutputMs !== undefined,
|
|
1438
1471
|
...(logCtx.causeHint ? { causeHint: logCtx.causeHint } : {}),
|
|
1439
1472
|
locallyAnswered: logCtx.localTerminalReason !== undefined,
|
|
1440
|
-
|
|
1473
|
+
// A coordinated write derives the request pair from a copy and re-derives the attempt's own.
|
|
1474
|
+
...(logCtx.activeAttempt ? { attempt: attemptStatus === undefined ? logCtx.activeAttempt : { ...logCtx.activeAttempt } } : {}),
|
|
1441
1475
|
});
|
|
1476
|
+
if (attemptStatus !== undefined && logCtx.activeAttempt) attributePhysicalAttempt(logCtx.activeAttempt);
|
|
1442
1477
|
// The one seam every request passes exactly once, whatever transport served it and however
|
|
1443
1478
|
// it ended. The terminal usage belongs to the last send that left; the ledger resolves every
|
|
1444
1479
|
// earlier send of this request as unresolved spend rather than handing its tokens back.
|
|
@@ -1516,7 +1551,8 @@ export function addFinalRequestLog(
|
|
|
1516
1551
|
const jevDecision = normalizePersistedJevDecision(logCtx.jevDecision);
|
|
1517
1552
|
// Keyed by the live attempt objects, not the detached copies above.
|
|
1518
1553
|
const protocolTrace = protocolTraceForRequest(logCtx, logCtx.attempts);
|
|
1519
|
-
|
|
1554
|
+
// Projected before any writer (an injected one too): the row keeps only proxy-owned error facts.
|
|
1555
|
+
addLog(projectErrorDetail({
|
|
1520
1556
|
requestId,
|
|
1521
1557
|
...(isLogicalRequestId(logicalRequestId) ? { logicalRequestId } : {}),
|
|
1522
1558
|
timestamp: start,
|
|
@@ -1558,7 +1594,8 @@ export function addFinalRequestLog(
|
|
|
1558
1594
|
...(errorCode ? { errorCode } : {}),
|
|
1559
1595
|
...(meta?.terminalStatus ? { terminalStatus: meta.terminalStatus } : {}),
|
|
1560
1596
|
...(closeReason ? { closeReason } : {}),
|
|
1561
|
-
...(logCtx.upstreamError ? { upstreamError: logCtx.upstreamError } : {}),
|
|
1597
|
+
...(logCtx.upstreamError && !upstreamErrorIsLocal(logCtx) ? { upstreamError: logCtx.upstreamError } : {}), ...(logCtx.failureDetail ? { failureDetail: logCtx.failureDetail } : {}),
|
|
1598
|
+
...(logCtx.upstreamCondition ? { upstreamCondition: logCtx.upstreamCondition } : {}),
|
|
1562
1599
|
...upstreamDiagnosticLogFields(logCtx),
|
|
1563
1600
|
usageStatus,
|
|
1564
1601
|
...(loggedUsage ? { usage: loggedUsage } : {}),
|
|
@@ -1581,7 +1618,7 @@ export function addFinalRequestLog(
|
|
|
1581
1618
|
...(claudeCompatibility ? { claudeCompatibility } : {}),
|
|
1582
1619
|
...(protocolTrace ? { protocolTrace } : {}),
|
|
1583
1620
|
...attribution,
|
|
1584
|
-
});
|
|
1621
|
+
}));
|
|
1585
1622
|
// Formatted from the finalized snapshot, so the ring shows exactly what the ledger holds.
|
|
1586
1623
|
for (const attempt of attempts ?? []) debugAttemptDeliverySummary(requestId, attempt);
|
|
1587
1624
|
if (isUsageDebugEnabled()) {
|
|
@@ -7,6 +7,7 @@ export type ResponseLogBodyEnd = "eof" | "read_error" | "cancel";
|
|
|
7
7
|
|
|
8
8
|
export interface ResponseLogBodyOptions {
|
|
9
9
|
json: boolean;
|
|
10
|
+
inspectionSource?: string;
|
|
10
11
|
inspect: (text: string) => void;
|
|
11
12
|
finalize: (reason: ResponseLogBodyEnd) => void;
|
|
12
13
|
/** Internal test seam; this is not a provider-controlled limit. */
|
|
@@ -95,6 +96,10 @@ export function createBoundedResponseLogBody(
|
|
|
95
96
|
const reader = body.getReader();
|
|
96
97
|
let ended = false;
|
|
97
98
|
let inspectionFailed = false;
|
|
99
|
+
if (options.inspectionSource !== undefined) {
|
|
100
|
+
try { inspection.append(new TextEncoder().encode(options.inspectionSource)); }
|
|
101
|
+
catch { inspectionFailed = true; inspection.dispose(); }
|
|
102
|
+
}
|
|
98
103
|
|
|
99
104
|
const release = () => bestEffort(() => reader.releaseLock());
|
|
100
105
|
const finish = (reason: ResponseLogBodyEnd) => {
|
|
@@ -135,7 +140,7 @@ export function createBoundedResponseLogBody(
|
|
|
135
140
|
}
|
|
136
141
|
if (!inspectionFailed) {
|
|
137
142
|
try {
|
|
138
|
-
inspection.append(result.value);
|
|
143
|
+
if (options.inspectionSource === undefined) inspection.append(result.value);
|
|
139
144
|
} catch {
|
|
140
145
|
inspectionFailed = true;
|
|
141
146
|
inspection.dispose();
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
* The issuer association lives next to thread affinity in `src/codex/routing.ts`.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { conversationStateAccountId } from "../../codex/request-owned-affinity";
|
|
13
14
|
import type { CodexAuthContext } from "../../codex/auth-context";
|
|
15
|
+
import { CODEX_UNKNOWN_CONVERSATION_STATE_ISSUER, peekConversationStateStoredIssuerAccount } from "../../codex/routing/thread-affinity";
|
|
14
16
|
import {
|
|
15
17
|
peekConversationStateIssuer,
|
|
16
18
|
rememberConversationStateIssuer,
|
|
@@ -216,14 +218,20 @@ export function scrubUnportableConversationStateInPlace(body: unknown): boolean
|
|
|
216
218
|
return changed;
|
|
217
219
|
}
|
|
218
220
|
|
|
221
|
+
/** Preserve a Pool context's absent key instead of borrowing the raw request key. */
|
|
222
|
+
export function compactAlternateAffinityKey(authCtx: CodexAuthContext, rawKey: () => string | undefined): string | undefined {
|
|
223
|
+
return authCtx.kind === "main" ? (authCtx.affinityKey ?? authCtx.conversationStateKey ?? rawKey()) : authCtx.affinityKey ?? authCtx.conversationStateKey;
|
|
224
|
+
}
|
|
225
|
+
|
|
219
226
|
export function conversationStateBindingFromAuth(
|
|
220
227
|
authCtx: CodexAuthContext,
|
|
221
228
|
fallbackAffinityKey?: string | null,
|
|
222
229
|
): { accountId: string; bindingKey: string } | null {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
230
|
+
const accountId = conversationStateAccountId(authCtx);
|
|
231
|
+
if (!accountId) return null;
|
|
232
|
+
const bindingKey = authCtx.affinityKey ?? authCtx.conversationStateKey ?? fallbackAffinityKey ?? undefined;
|
|
233
|
+
if (!bindingKey) return null;
|
|
234
|
+
return { accountId, bindingKey };
|
|
227
235
|
}
|
|
228
236
|
|
|
229
237
|
export function rememberServingConversationStateIssuer(
|
|
@@ -232,7 +240,8 @@ export function rememberServingConversationStateIssuer(
|
|
|
232
240
|
): void {
|
|
233
241
|
const binding = conversationStateBindingFromAuth(authCtx, fallbackAffinityKey);
|
|
234
242
|
if (!binding) return;
|
|
235
|
-
rememberConversationStateIssuer(binding.bindingKey, binding.accountId
|
|
243
|
+
rememberConversationStateIssuer(binding.bindingKey, binding.accountId, undefined,
|
|
244
|
+
authCtx.kind === "pool" ? { generation: authCtx.generation, chatgptAccountId: authCtx.chatgptAccountId } : undefined);
|
|
236
245
|
}
|
|
237
246
|
|
|
238
247
|
export interface ApplyAccountChangeConversationStateScrubArgs {
|
|
@@ -314,7 +323,9 @@ export function accountChangeFileReferenceRefusal(
|
|
|
314
323
|
const { body, bindingKey, servingAccountId, priorAccountId } = args;
|
|
315
324
|
if (!servingAccountId || !bindingKey) return undefined;
|
|
316
325
|
const issuer = peekConversationStateIssuer(bindingKey);
|
|
317
|
-
const accountChanged = (issuer
|
|
326
|
+
const accountChanged = (issuer === CODEX_UNKNOWN_CONVERSATION_STATE_ISSUER
|
|
327
|
+
? peekConversationStateStoredIssuerAccount(bindingKey) !== servingAccountId
|
|
328
|
+
: issuer != null && issuer !== servingAccountId)
|
|
318
329
|
|| (priorAccountId != null && priorAccountId !== servingAccountId);
|
|
319
330
|
if (!accountChanged) return undefined;
|
|
320
331
|
// Checked against the carriers directly rather than through the portability verdict: that
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isProxyError, rememberProxyErrorMessage } from "../../lib/client-error-body";
|
|
1
2
|
import { bindAnthropicRejectionResponse } from "../../adapters/anthropic-rejection-memo";
|
|
2
3
|
import { rotateAnthropicAccountOnResponseForInstance } from "../../oauth/anthropic-account-refusal";
|
|
3
4
|
import type { ResponsesRequestContext } from "./core-options";
|
|
@@ -156,6 +157,8 @@ export function createAdapterContinuations(
|
|
|
156
157
|
return { type: "error", message: "client closed request during terminal continuation", status: 499 };
|
|
157
158
|
}
|
|
158
159
|
const refusal = unwrapUpstreamRetryEvidenceError(error);
|
|
160
|
+
if (refusal instanceof AdmissionModelDeniedError || refusal instanceof SendBudgetExhaustedError) rememberProxyErrorMessage(logCtx, refusal.message, { status: refusal instanceof AdmissionModelDeniedError ? 403 : 429,
|
|
161
|
+
type: refusal instanceof AdmissionModelDeniedError ? MODEL_NOT_ALLOWED_FOR_KEY : "rate_limit_error", code: refusal instanceof AdmissionModelDeniedError ? MODEL_NOT_ALLOWED_FOR_KEY : refusal.code });
|
|
159
162
|
if (refusal instanceof AdmissionModelDeniedError) {
|
|
160
163
|
return {
|
|
161
164
|
type: "error", message: refusal.message, status: 403,
|
|
@@ -696,13 +699,15 @@ export function createAdapterContinuations(
|
|
|
696
699
|
if (route.providerName === "kiro") response = await normalizeFinalKiroHttpError(response, upstream.signal);
|
|
697
700
|
const errorText = await readDisplaySafeErrorText(response, upstream.signal, "unknown error");
|
|
698
701
|
const normalized = normalizeUpstreamErrorText(errorText, "unknown error");
|
|
702
|
+
const message = normalized.cyberPolicy
|
|
703
|
+
? normalized.message ?? (isCyberPolicyCode(normalized.code) ? CYBER_POLICY_FALLBACK_MESSAGE : normalized.safeText)
|
|
704
|
+
: `Provider continuation error ${response.status}: ${normalized.safeText}`;
|
|
705
|
+
if (isProxyError(response)) rememberProxyErrorMessage(logCtx, message, { status: normalized.cyberPolicy ? 400 : response.status,
|
|
706
|
+
type: normalized.cyberPolicy ? normalized.type ?? CYBER_POLICY_ERROR_CODE : undefined, code: normalized.cyberPolicy ? CYBER_POLICY_ERROR_CODE : undefined });
|
|
699
707
|
yield {
|
|
700
708
|
type: "error",
|
|
701
709
|
status: normalized.cyberPolicy ? 400 : response.status,
|
|
702
|
-
message
|
|
703
|
-
? normalized.message
|
|
704
|
-
?? (isCyberPolicyCode(normalized.code) ? CYBER_POLICY_FALLBACK_MESSAGE : normalized.safeText)
|
|
705
|
-
: `Provider continuation error ${response.status}: ${normalized.safeText}`,
|
|
710
|
+
message,
|
|
706
711
|
...(normalized.cyberPolicy
|
|
707
712
|
? {
|
|
708
713
|
errorType: normalized.type ?? CYBER_POLICY_ERROR_CODE,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isProxyError, rememberProxyErrorMessage } from "../../lib/client-error-body";
|
|
1
2
|
import type { ResponsesRequestContext } from "./core-options";
|
|
2
3
|
import type { PreparedResponsesRequest } from "./request-prepare";
|
|
3
4
|
import type { ResponsesTransport } from "./request-transport";
|
|
@@ -27,7 +28,7 @@ import { readDisplaySafeErrorText, normalizeUpstreamErrorText } from "./core-err
|
|
|
27
28
|
import { sanitizeNonReplayableUpstreamError } from "./non-replayable-error";
|
|
28
29
|
import { isNonReplayableResponse } from "../../lib/upstream-retry";
|
|
29
30
|
import { isCanonicalOpenAiForwardProvider } from "../../providers/openai-tiers";
|
|
30
|
-
import { guardEmptyToolCatalogEvents, guardEmptyToolCatalogStream } from "../../lib/empty-tool-catalog";
|
|
31
|
+
import { currentTurnToolBridgeMaps, guardEmptyToolCatalogEvents, guardEmptyToolCatalogStream } from "../../lib/empty-tool-catalog";
|
|
31
32
|
import { guardCompactionSummary } from "../../responses/compaction-summary";
|
|
32
33
|
|
|
33
34
|
/** One responsibility of the Responses request pipeline; state owners are explicit. */
|
|
@@ -96,6 +97,7 @@ export async function deliverAdapterResponse(
|
|
|
96
97
|
if (nonReplayable) response = await sanitizeNonReplayableUpstreamError(response, errorSignal);
|
|
97
98
|
const body = await readDisplaySafeErrorText(response, errorSignal, "Upstream recovery failed");
|
|
98
99
|
const error = normalizeUpstreamErrorText(body, "Upstream recovery failed");
|
|
100
|
+
if (isProxyError(response)) rememberProxyErrorMessage(logCtx, error.message ?? error.safeText, { status: response.status, type: error.type ?? "upstream_error", code: error.code });
|
|
99
101
|
yield { type: "error", status: response.status, message: error.message ?? error.safeText,
|
|
100
102
|
errorType: error.type ?? "upstream_error", ...(error.code ? { code: error.code } : {}),
|
|
101
103
|
...(nonReplayable ? { retryable: false } : {}) };
|
|
@@ -123,8 +125,7 @@ export async function deliverAdapterResponse(
|
|
|
123
125
|
|
|
124
126
|
const clientToolCatalog = requestState.clientToolCatalogRestriction && route.provider.authMode !== "forward"
|
|
125
127
|
? requestState.clientToolCatalogRestriction : undefined;
|
|
126
|
-
const deliveryToolBridgeMaps = clientToolCatalog
|
|
127
|
-
? { ...toolBridgeMaps, ...clientToolCatalog } : toolBridgeMaps;
|
|
128
|
+
const deliveryToolBridgeMaps = currentTurnToolBridgeMaps(toolBridgeMaps, clientToolCatalog);
|
|
128
129
|
|
|
129
130
|
|
|
130
131
|
if (parsed.stream) {
|
|
@@ -253,7 +254,7 @@ export async function deliverAdapterResponse(
|
|
|
253
254
|
guardedEventStream, parsed._responseModelId ?? parsed.modelId, toolNsMap, freeformToolNames, toolSearchToolNames,
|
|
254
255
|
() => { cancelResponseCompletion(); upstream.abort(); }, 2_000,
|
|
255
256
|
{
|
|
256
|
-
translatorBudget,
|
|
257
|
+
translatorBudget, proxyErrorContext: logCtx,
|
|
257
258
|
replayCacheScope: parsed._reasoningReplayScope,
|
|
258
259
|
...(outputItemIds ? { outputItemIds } : {}),
|
|
259
260
|
...(options.forceEmptyResponseId ? { responseId: "" } : {}),
|