@bitkyc08/opencodex 2.96.0 → 2.98.0-preview.20261107
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 +215 -20
- package/gui/dist/assets/App-6TFtZsUF.css +1 -0
- package/gui/dist/assets/App-B8_sOxoz.js +59 -0
- package/gui/dist/assets/Tray-DpWEp6ee.js +1 -0
- package/gui/dist/assets/WantedSansVariable.split.0-Dwvb1WRx.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.1-1wKD2RxI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.10-CAKA6LIP.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.11-k5H85R4b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.12-BHboLsUv.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.13-9GV377ix.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.14-DovDXnrj.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.15-DTdykCig.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.16-CKz2ccgK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.17-Z2RD_KRZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.18-BcKtfonJ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.19-DEQPOSZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.2-DryboyuA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.20-Bia5JMls.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.21-Cr4jFw-E.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.22-DjjB69TZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.23-CvUzJskt.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.24-i_eMg5ox.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.25-2aKHwPX-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.26-B6wXoCEL.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.27-D4h1WfGM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.28-kvRPCStd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.29-DHAiwleD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.3-7H--eyZi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.30-C66cfAY2.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.31-FDmtiNim.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.32-DouHt2Dd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.33-B8HVvkJX.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.34-BtkRu1FN.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.35-DBylQbtk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.36-Sg089Kgh.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.37-CYtvbriS.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.38-DKkSLf8Z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.39-CecotKZD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.4-Bv8O3ZMb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.40-DdCvkmOU.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.41-ESn674Hc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.42-DL9V7NNV.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.43-yipO0cyk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.44-6rTmLZhm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.45-BJAj8lrm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.46-BDTzMn2c.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.47-Bxd4wGgi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.48-DxnFBLnH.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.49-DnVD0aOD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.5-B1wI2pp5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.50-D9JlkZd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.51-D9Vw6Bu3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.52-ClEJk4kn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.53-BSXU0vh-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.54-EcuxkR9v.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.55-CYiFhQX8.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.56--Gk9g8BK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.57-DnkOPZcy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.58-9MB8504z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.59-ByxIsN72.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.6-Bmk0dRVw.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.60-Bxwx_aWQ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.61-DA2z5sm7.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.62-C5iJPJZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.63-DAqrmaEc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.64-BgXFsljb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.65-DKiWujvu.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.66-8po4vUZ4.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.67-Cy5qyI9O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.68-BKny7Fy3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.69-B4VU4u_b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.7-BuqwNpgA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.70-BCd4n346.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.71-CkQppaWn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.72-Db7vaoFs.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.73-DI80TYWl.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.74-tMCtDAHB.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.75-Ciw0D5WG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.76-DoLjFgp-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.77-CpT2uvMy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.78-CkcJ4iZ1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.79-DsOUJjEM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.8-DsjypPd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.80-C0VwHTte.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.81-DTelu57i.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.82-BiMndGN1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.83-CVcC6eDG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.84-DlhZVt_O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.85-S8I2D3pA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.86-DozXXpH5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.87-Dsn0Vuuo.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.88-iNwxxDCr.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.89-B63u_9CZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.9-Bi3IzpMI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.90-ByeH1Pqf.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.91-UQLlagpm.woff2 +0 -0
- package/gui/dist/assets/brand-mark-VPhzz-WE.js +1 -0
- package/gui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/gui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/gui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/gui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/gui/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/gui/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/gui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/gui/dist/assets/index-5REODpG3.css +2 -0
- package/gui/dist/assets/index-BWKBeK77.js +94 -0
- package/gui/dist/assets/segment-thumb-features-BQYzrze9.js +1 -0
- package/gui/dist/classic/assets/App-Bz65x1J6.js +58 -0
- package/gui/dist/{assets/Tray-BOPQyDbH.js → classic/assets/Tray-kk7mdO6I.js} +1 -1
- package/gui/dist/classic/assets/index-Dp2j8bSc.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CvamtHjB.js +1 -0
- package/gui/dist/classic/index.html +47 -0
- package/gui/dist/favicon.png +0 -0
- package/gui/dist/favicon.svg +14 -0
- package/gui/dist/index.html +15 -2
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +17 -8
- 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/google.ts +7 -7
- package/src/adapters/kiro/adapter.ts +18 -3
- package/src/adapters/kiro/conversation.ts +8 -8
- package/src/adapters/kiro/payload.ts +45 -12
- package/src/adapters/kiro/stream.ts +230 -14
- package/src/adapters/kiro/structured-output-json.ts +191 -0
- package/src/adapters/kiro/structured-output-schema.ts +542 -0
- package/src/adapters/kiro/structured-output.ts +367 -0
- package/src/adapters/kiro-constants.ts +24 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/kiro-tools.ts +14 -9
- package/src/adapters/kiro-wire.ts +9 -5
- package/src/adapters/ollama-native.ts +11 -1
- package/src/adapters/openai-chat/messages.ts +58 -5
- package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
- package/src/adapters/openai-chat/passthrough.ts +5 -3
- package/src/adapters/openai-chat/tool-schema.ts +83 -13
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/opengateway-input.ts +18 -6
- package/src/adapters/openai-responses/passthrough.ts +5 -4
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/qoder/live-models.ts +115 -1
- 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/failure-verdict.ts +21 -0
- package/src/claude/inbound-content-options.ts +15 -2
- package/src/claude/inbound-model-options.ts +2 -1
- package/src/claude/inbound-records.ts +2 -0
- package/src/claude/inbound.ts +17 -11
- package/src/claude/outbound.ts +98 -22
- package/src/cli/capabilities-access-remote.ts +13 -0
- package/src/cli/capabilities-base.ts +26 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capabilities-provider-models.ts +3 -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 +12 -4
- package/src/cli/config-command.ts +11 -2
- package/src/cli/connect.ts +17 -2
- package/src/cli/dispatch.ts +14 -177
- package/src/cli/doctor.ts +95 -7
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +17 -8
- package/src/cli/link-apply-restart.ts +9 -2
- package/src/cli/link.ts +1 -1
- package/src/cli/models.ts +124 -38
- package/src/cli/registry.ts +12 -4
- package/src/cli/restart-failure.ts +17 -0
- package/src/cli/root.ts +8 -0
- package/src/cli/stop-approval.ts +2 -2
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +161 -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/cli/system-restart-client.ts +5 -0
- package/src/cli/uninstall-client-state.ts +12 -1
- package/src/cli/update-restart-child.ts +13 -3
- package/src/cli/update-restart-home.ts +6 -3
- package/src/cli/update-restart.ts +36 -19
- package/src/client/connect.ts +35 -15
- package/src/client/hub-client.ts +5 -0
- package/src/client/link-home.ts +3 -2
- package/src/client/link-management-relay.ts +39 -2
- package/src/client/link-readiness.ts +3 -1
- package/src/client/machine-api.ts +2 -1
- package/src/client/machine-listener.ts +10 -0
- package/src/client/orphan-token-recovery.ts +322 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/auth-context.ts +49 -103
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +18 -12
- package/src/codex/forward-transport-headers.ts +35 -6
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/lineage.ts +13 -7
- package/src/codex/native-profile-api.ts +27 -1
- 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/shim-diagnostics.ts +7 -0
- package/src/codex/shim-legacy-record.ts +290 -0
- package/src/codex/shim-windows-refresh.ts +9 -2
- package/src/codex/shim-wrapper-write.ts +7 -0
- package/src/codex/shim.ts +80 -21
- 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/diagnostics.ts +9 -9
- package/src/config/load-degrade.ts +27 -27
- package/src/config/process-state.ts +5 -0
- package/src/config/provider-validation.ts +9 -2
- package/src/config/removed-opencode-free-backup.ts +6 -3
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/config/tracked-runtime-inspection.ts +3 -3
- package/src/generated/compatibility-version.json +595 -255
- package/src/images/loop.ts +4 -3
- package/src/lib/client-error-body.ts +215 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership-removal.ts +422 -0
- package/src/lib/config-ownership.ts +650 -81
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/crash-guard.ts +4 -2
- package/src/lib/desktop-cli-handoff.d.mts +4 -5
- package/src/lib/desktop-cli-handoff.mjs +18 -17
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/errors.ts +1 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/local-management-capability.ts +3 -1
- package/src/lib/messages-error-body.ts +162 -0
- package/src/lib/messages-sse-error-presentation.ts +93 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/passive-read.ts +9 -4
- 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/socks5-fetch.ts +21 -9
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +95 -12
- package/src/lib/windows-owner-acl.ts +22 -9
- package/src/lib/winsw.ts +5 -5
- package/src/lib/workflow-budget.ts +3 -1
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +42 -73
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +21 -11
- package/src/protocols/codecs/messages-ir.ts +15 -9
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +30 -7
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/encoders/messages.ts +72 -28
- package/src/protocols/trace.ts +18 -0
- package/src/providers/antigravity-models.ts +45 -12
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/quota/anthropic-usage-windows.ts +13 -3
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/reasoning-metadata.ts +2 -1
- package/src/providers/registry/entries-extended.ts +9 -0
- package/src/providers/request-pacing.ts +3 -2
- package/src/reasoning-effort.ts +7 -2
- package/src/remote/hub-usage.ts +3 -0
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +57 -0
- package/src/server/anthropic-rate-limit-headers.ts +75 -3
- 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 +174 -84
- package/src/server/context-history.ts +5 -1
- package/src/server/gui-static.ts +4 -1
- package/src/server/hub-usage.ts +7 -2
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/link-management.ts +8 -0
- package/src/server/index/ollama-routes.ts +91 -0
- package/src/server/index/serve-options.ts +44 -24
- package/src/server/index/startup-warnings.ts +5 -12
- package/src/server/index/websocket-handler.ts +5 -2
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +9 -3
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/logs-usage-routes.ts +89 -4
- package/src/server/management/provider-routes.ts +2 -22
- package/src/server/management/qoder-provider-probe.ts +105 -0
- package/src/server/management/route-registry.ts +4 -1
- package/src/server/management/usage-aggregate-cache.ts +15 -5
- package/src/server/management/usage-source-facets.ts +38 -0
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +12 -4
- package/src/server/messages-native.ts +123 -47
- package/src/server/messages-response-headers.ts +25 -11
- package/src/server/messages-shared.ts +99 -65
- package/src/server/messages-sse-error-filter.ts +199 -0
- 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 +91 -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 +17 -6
- package/src/server/responses/adapter-delivery.ts +17 -10
- package/src/server/responses/adapter-dispatch.ts +32 -31
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +24 -19
- 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/codex-ws-wire.ts +19 -3
- package/src/server/responses/compact.ts +57 -24
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +7 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +43 -27
- package/src/server/responses/core-errors.ts +24 -21
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +9 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/empty-completion-guard.ts +4 -1
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +20 -18
- 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 +69 -48
- package/src/server/responses/request-transport.ts +36 -31
- package/src/server/responses/response-effects.ts +3 -2
- 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/terminal-guard.ts +30 -0
- 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/restart-replacement.ts +3 -1
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/sse-payload-rewrite.ts +23 -11
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +4 -0
- package/src/service/definition.ts +36 -4
- package/src/service/launchd.ts +89 -32
- package/src/service/logging.ts +34 -7
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/service/plist-xml.ts +59 -0
- package/src/service/state.ts +8 -0
- package/src/service/systemd-env.ts +2 -0
- package/src/service/systemd.ts +31 -7
- package/src/service/windows-taskxml.ts +16 -7
- package/src/service-manager-probe.ts +4 -10
- package/src/types/config.ts +2 -0
- package/src/types/provider.ts +2 -0
- package/src/types/request.ts +13 -1
- package/src/update/config-preflight.ts +48 -0
- package/src/update/index.ts +148 -26
- 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/client.ts +43 -0
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +64 -27
- package/src/usage/source-facets.ts +51 -0
- package/src/usage/source-filter.ts +65 -0
- package/src/usage/summary.ts +50 -8
- package/src/web-search/anthropic-executor.ts +105 -24
- package/src/web-search/executor.ts +5 -3
- package/src/web-search/loop.ts +33 -6
- package/src/web-search/progress-stream.ts +64 -5
- package/gui/dist/assets/App-bwugJRKn.js +0 -58
- package/gui/dist/assets/index-ebuVUtB7.js +0 -94
- package/gui/dist/assets/quota-summary-6HsrHQAy.js +0 -1
- /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
- /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { normalizeRecordedClient, type UsageClient } from "../usage/client";
|
|
3
4
|
import { stampApiKeyAccountLabel, usesApiKeyAccount } from "../providers/label";
|
|
4
5
|
import { KEY_ACCOUNT_LOG_LABEL_RE } from "../codex/account-label";
|
|
5
6
|
import { attemptAccountChanged, sealRequestAttemptIdentity } from "./request-log-account-rotation";
|
|
@@ -30,6 +31,9 @@ import type { RequestSpendSettlement } from "./responses/request-spend";
|
|
|
30
31
|
import type { AdapterTierMetadata } from "../providers/fastwire";
|
|
31
32
|
import { UPSTREAM_RESET_REPLAY_REFUSED_CODE } from "../lib/upstream-retry";
|
|
32
33
|
import { redactSecretString, sanitizeLogMetadataString } from "../lib/redact";
|
|
34
|
+
import type { UpstreamCondition } from "../lib/upstream-condition";
|
|
35
|
+
import { boundedServiceTier, errorDetailFor, projectErrorDetail } from "../usage/error-detail";
|
|
36
|
+
import { incompleteReasonDetail, upstreamErrorIsLocal, type FailureDetail } from "./request-log-failure-detail";
|
|
33
37
|
import {
|
|
34
38
|
appendUsageEntry,
|
|
35
39
|
classifyCacheTelemetryProvenance,
|
|
@@ -66,7 +70,7 @@ import {
|
|
|
66
70
|
} from "../usage/log";
|
|
67
71
|
import type { RequestExecutionBudget } from "../lib/request-execution-budget";
|
|
68
72
|
import type { WorkflowSpendDenialDetail } from "../lib/workflow-budget";
|
|
69
|
-
import { attributeFinalRequest, attributeSealedAttempt } from "./request-log-failure-attribution";
|
|
73
|
+
import { attributeFinalRequest, attributePhysicalAttempt, attributeSealedAttempt } from "./request-log-failure-attribution";
|
|
70
74
|
import { debugAttemptDeliverySummary } from "../lib/debug";
|
|
71
75
|
import {
|
|
72
76
|
appendUsageDebug,
|
|
@@ -116,6 +120,7 @@ export function cacheDiagnosticsObserving(): boolean {
|
|
|
116
120
|
export interface RequestLogContext extends UpstreamErrorDiagnostics {
|
|
117
121
|
model: string;
|
|
118
122
|
provider: string;
|
|
123
|
+
client?: UsageClient;
|
|
119
124
|
/** Optional process-lifetime aggregate sink, injected by the server composition owner. */
|
|
120
125
|
requestMetricsRecorder?: RequestMetricsRecorder;
|
|
121
126
|
/** Bounded terminal enum observed while inspecting a buffered response body. */
|
|
@@ -243,6 +248,8 @@ export interface RequestLogContext extends UpstreamErrorDiagnostics {
|
|
|
243
248
|
* message) extracted from a `response.failed` SSE payload or non-streaming error body, so the
|
|
244
249
|
* request log / GUI shows the actual upstream failure rather than only the HTTP-mapped code. */
|
|
245
250
|
upstreamError?: string;
|
|
251
|
+
failureDetail?: FailureDetail; // closed code + bounded params (src/lib/failure-detail.ts)
|
|
252
|
+
upstreamCondition?: UpstreamCondition; // classified at capture where the evidence is not kept on the context
|
|
246
253
|
/** HTTP status derived from a terminal `response.failed` SSE payload (429/401/503/etc.). */
|
|
247
254
|
terminalHttpStatus?: number;
|
|
248
255
|
/** Recognized structured terminal code whose exact identity must survive status mapping. */
|
|
@@ -297,6 +304,7 @@ export function rebindCacheDiagnosticBody(
|
|
|
297
304
|
|
|
298
305
|
export interface RequestLogEntry extends UpstreamErrorDiagnostics {
|
|
299
306
|
requestId: string;
|
|
307
|
+
client?: UsageClient;
|
|
300
308
|
/** The logical request this row belongs to (#4546); absent on rows written without a budget. */
|
|
301
309
|
logicalRequestId?: string;
|
|
302
310
|
timestamp: number;
|
|
@@ -353,8 +361,11 @@ export interface RequestLogEntry extends UpstreamErrorDiagnostics {
|
|
|
353
361
|
errorCode?: string;
|
|
354
362
|
terminalStatus?: ResponsesTerminalStatus;
|
|
355
363
|
closeReason?: "terminal" | "client_cancel" | "non_stream" | "body_stall" | "body_overflow";
|
|
356
|
-
/**
|
|
364
|
+
/** Input only: addRequestLog derives the two fields below from it, then removes it. */
|
|
357
365
|
upstreamError?: string;
|
|
366
|
+
upstreamCondition?: UpstreamCondition; // closed enum, src/lib/upstream-condition.ts
|
|
367
|
+
failureDetail?: FailureDetail; // closed code + bounded params, see request-log-failure-detail.ts
|
|
368
|
+
rateLimitResetAt?: number; // provider quota window end, epoch ms, bounded
|
|
358
369
|
usageStatus: UsageStatus;
|
|
359
370
|
usage?: OcxUsage;
|
|
360
371
|
totalTokens?: number;
|
|
@@ -473,12 +484,16 @@ export function requestLogEntryFromPersistedUsage(entry: PersistedUsageEntry): R
|
|
|
473
484
|
const claudeCompatibility = normalizeClaudeCompatibilityUsageLog(entry.claudeCompatibility);
|
|
474
485
|
const spend = normalizeRequestSpend(entry.spend);
|
|
475
486
|
const protocolTrace = parseProtocolTraceV1(entry.protocolTrace);
|
|
476
|
-
|
|
487
|
+
// projectErrorDetail bounds the tier fields (top-level and per attempt) itself, so this stays safe
|
|
488
|
+
// for a row that did not come through the disk reader; attempts are copied before it edits them.
|
|
489
|
+
const attempts = Array.isArray(entry.attempts) ? entry.attempts.map(attempt => ({ ...attempt })) : entry.attempts;
|
|
490
|
+
return projectErrorDetail({
|
|
477
491
|
requestId: entry.requestId,
|
|
478
492
|
...(isLogicalRequestId(entry.logicalRequestId) ? { logicalRequestId: entry.logicalRequestId } : {}),
|
|
479
493
|
timestamp: entry.timestamp,
|
|
480
494
|
model: entry.model,
|
|
481
495
|
provider: entry.provider,
|
|
496
|
+
...(Object.hasOwn(entry, "client") ? { client: normalizeRecordedClient(entry.client) ?? "unknown" } : {}),
|
|
482
497
|
...(entry.firstOutputMs !== undefined ? { firstOutputMs: entry.firstOutputMs } : {}),
|
|
483
498
|
...(entry.genStartMs !== undefined ? { genStartMs: entry.genStartMs } : {}),
|
|
484
499
|
...(entry.lastOutputMs !== undefined ? { lastOutputMs: entry.lastOutputMs } : {}),
|
|
@@ -509,14 +524,14 @@ export function requestLogEntryFromPersistedUsage(entry: PersistedUsageEntry): R
|
|
|
509
524
|
...modelIdentityLogFields(entry),
|
|
510
525
|
status: entry.status,
|
|
511
526
|
durationMs: entry.durationMs,
|
|
512
|
-
|
|
527
|
+
// Closed code, condition, failure detail and quota reset; legacy upstream text is read once and dropped.
|
|
528
|
+
...errorDetailFor(entry),
|
|
513
529
|
...(terminalStatus ? { terminalStatus } : {}),
|
|
514
530
|
...(closeReason ? { closeReason } : {}),
|
|
515
|
-
...(entry.upstreamError ? { upstreamError: entry.upstreamError } : {}),
|
|
516
531
|
usageStatus: entry.usageStatus,
|
|
517
532
|
...(entry.usage ? { usage: entry.usage } : {}),
|
|
518
533
|
...(entry.totalTokens !== undefined ? { totalTokens: entry.totalTokens } : {}),
|
|
519
|
-
...(
|
|
534
|
+
...(attempts !== undefined ? { attempts } : {}),
|
|
520
535
|
...(entry.attemptNormalizationDropped === true
|
|
521
536
|
? { attemptNormalizationDropped: true } : {}),
|
|
522
537
|
...(spend ? { spend } : {}),
|
|
@@ -534,7 +549,7 @@ export function requestLogEntryFromPersistedUsage(entry: PersistedUsageEntry): R
|
|
|
534
549
|
: {}),
|
|
535
550
|
...normalizeRequestFailureAttribution(entry),
|
|
536
551
|
...(protocolTrace ? { protocolTrace } : {}),
|
|
537
|
-
};
|
|
552
|
+
});
|
|
538
553
|
}
|
|
539
554
|
|
|
540
555
|
/**
|
|
@@ -613,6 +628,15 @@ export function rehydrateRequestLogsAfterLedgerReplacement(
|
|
|
613
628
|
}
|
|
614
629
|
|
|
615
630
|
export function addRequestLog(entry: RequestLogEntry) {
|
|
631
|
+
// Rows keep proxy-owned error facts only; upstream error text and tokens stop here (both the
|
|
632
|
+
// retained ring row and the usage.jsonl projection below read the projected entry).
|
|
633
|
+
const attemptNormalizationDropped = entry.attemptNormalizationDropped === true, client = normalizeRecordedClient(entry.client) ?? "unknown";
|
|
634
|
+
const clientDescriptor = Object.getOwnPropertyDescriptor(entry, "client");
|
|
635
|
+
if (!Object.isFrozen(entry) || !clientDescriptor?.enumerable || !("value" in clientDescriptor) || clientDescriptor.value !== client || Object.values(Object.getOwnPropertyDescriptors(entry)).some(descriptor => !("value" in descriptor))) {
|
|
636
|
+
entry = { ...entry, ...errorDetailFor(entry), client, ...(attemptNormalizationDropped ? { attemptNormalizationDropped: true } : {}) };
|
|
637
|
+
}
|
|
638
|
+
entry = projectErrorDetail(entry);
|
|
639
|
+
if (attemptNormalizationDropped && entry.attemptNormalizationDropped !== true) entry = { ...entry, attemptNormalizationDropped: true };
|
|
616
640
|
// Sanitize ONCE, at the ingress, and use that one value for both destinations.
|
|
617
641
|
//
|
|
618
642
|
// `addFinalRequestLog` is not the only way in: `addRequestLog` is exported and callable
|
|
@@ -622,13 +646,13 @@ export function addRequestLog(entry: RequestLogEntry) {
|
|
|
622
646
|
// line-oriented viewer — while `usage.jsonl` looked clean, which is the worst shape for a
|
|
623
647
|
// sanitization bug because the safe surface is the one you check.
|
|
624
648
|
const shadowCallRewrittenFrom = sanitizeLogMetadataString(entry.shadowCallRewrittenFrom);
|
|
625
|
-
const
|
|
649
|
+
const identity = modelIdentityLogFields(entry), servedModel = identity.servedModel;
|
|
626
650
|
const claudeCompatibility = normalizeClaudeCompatibilityUsageLog(entry.claudeCompatibility);
|
|
627
651
|
const jevDecision = normalizePersistedJevDecision(entry.jevDecision);
|
|
628
652
|
const attempts = normalizedAttempts(entry.attempts);
|
|
629
653
|
const attemptsDropped = Array.isArray(entry.attempts) && attempts.length < entry.attempts.length;
|
|
630
654
|
const retained: RequestLogEntry = shadowCallRewrittenFrom === entry.shadowCallRewrittenFrom
|
|
631
|
-
&& servedModel === entry.servedModel
|
|
655
|
+
&& servedModel === entry.servedModel && identity.resolvedModel === entry.resolvedModel
|
|
632
656
|
&& entry.claudeCompatibility === undefined
|
|
633
657
|
&& entry.jevDecision === undefined
|
|
634
658
|
&& !attemptsDropped
|
|
@@ -636,10 +660,7 @@ export function addRequestLog(entry: RequestLogEntry) {
|
|
|
636
660
|
: { ...entry, ...(entry.attemptNormalizationDropped === true || attemptsDropped ? { attemptNormalizationDropped: true } : {}),
|
|
637
661
|
...(shadowCallRewrittenFrom ? { shadowCallRewrittenFrom } : {}) };
|
|
638
662
|
if (!shadowCallRewrittenFrom && retained !== entry) delete retained.shadowCallRewrittenFrom;
|
|
639
|
-
if (!servedModel
|
|
640
|
-
delete retained.servedModel;
|
|
641
|
-
if (retained.resolvedModel === entry.servedModel) delete retained.resolvedModel;
|
|
642
|
-
}
|
|
663
|
+
if (retained !== entry) { if (!servedModel) delete retained.servedModel; if (!identity.resolvedModel) delete retained.resolvedModel; }
|
|
643
664
|
if (claudeCompatibility) retained.claudeCompatibility = claudeCompatibility;
|
|
644
665
|
else if (retained !== entry) delete retained.claudeCompatibility;
|
|
645
666
|
if (jevDecision) retained.jevDecision = jevDecision;
|
|
@@ -658,7 +679,8 @@ export function addRequestLog(entry: RequestLogEntry) {
|
|
|
658
679
|
...(entry.errorCode ? { errorCode: entry.errorCode } : {}),
|
|
659
680
|
...(entry.terminalStatus ? { terminalStatus: entry.terminalStatus } : {}),
|
|
660
681
|
...(entry.closeReason ? { closeReason: entry.closeReason } : {}),
|
|
661
|
-
...(entry.
|
|
682
|
+
...(entry.upstreamCondition ? { upstreamCondition: entry.upstreamCondition } : {}), ...(entry.failureDetail ? { failureDetail: entry.failureDetail } : {}),
|
|
683
|
+
...(entry.rateLimitResetAt !== undefined ? { rateLimitResetAt: entry.rateLimitResetAt } : {}),
|
|
662
684
|
}
|
|
663
685
|
: {};
|
|
664
686
|
appendUsageEntry({
|
|
@@ -667,6 +689,7 @@ export function addRequestLog(entry: RequestLogEntry) {
|
|
|
667
689
|
timestamp: entry.timestamp,
|
|
668
690
|
provider: entry.provider,
|
|
669
691
|
model: entry.model,
|
|
692
|
+
client: entry.client ?? "unknown",
|
|
670
693
|
...(isKnownUsageSurface(entry.surface) ? { surface: entry.surface } : {}),
|
|
671
694
|
// This function REBUILDS the persisted row field by field rather than
|
|
672
695
|
// spreading it, so a field missing here reaches /api/logs and never
|
|
@@ -972,7 +995,7 @@ export function applyResponseLogMetadata(logCtx: RequestLogContext, payload: unk
|
|
|
972
995
|
recordObservedServedModel(logCtx, (source as { model?: unknown }).model);
|
|
973
996
|
const serviceTier = (source as { service_tier?: unknown }).service_tier;
|
|
974
997
|
if (typeof serviceTier === "string" && serviceTier.trim()) {
|
|
975
|
-
const sanitized =
|
|
998
|
+
const sanitized = boundedServiceTier(serviceTier);
|
|
976
999
|
if (sanitized) logCtx.responseServiceTier = sanitized;
|
|
977
1000
|
logCtx.activeTierMetadata?.observeResponseServiceTier(serviceTier);
|
|
978
1001
|
} else if (Object.prototype.hasOwnProperty.call(source, "service_tier")) {
|
|
@@ -1157,7 +1180,9 @@ function captureUpstreamErrorParsed(
|
|
|
1157
1180
|
// reader-facing label so a generic 502 in /api/logs explains WHY the turn ended, not just the
|
|
1158
1181
|
// mapped HTTP code.
|
|
1159
1182
|
if (typeof reason === "string" && reason.trim()) {
|
|
1160
|
-
|
|
1183
|
+
const incomplete = incompleteReasonDetail(reason.trim()); // A known reason also gets a closed row detail.
|
|
1184
|
+
logCtx.upstreamError = redactSecretString(incomplete.text).slice(0, 500);
|
|
1185
|
+
if (incomplete.detail) logCtx.failureDetail = incomplete.detail;
|
|
1161
1186
|
}
|
|
1162
1187
|
return;
|
|
1163
1188
|
}
|
|
@@ -1168,20 +1193,6 @@ function captureUpstreamErrorParsed(
|
|
|
1168
1193
|
}
|
|
1169
1194
|
}
|
|
1170
1195
|
|
|
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
1196
|
/** Map a terminal Responses error object to the HTTP status we record in /api/logs. */
|
|
1186
1197
|
export function httpStatusFromTerminalError(error: {
|
|
1187
1198
|
type?: string;
|
|
@@ -1235,13 +1246,13 @@ export function httpStatusForRequestLogTerminal(
|
|
|
1235
1246
|
* `unresolved` rather than quietly inflating `settled`.
|
|
1236
1247
|
*/
|
|
1237
1248
|
export function requestSpendRecord(
|
|
1238
|
-
logCtx: Pick<RequestLogContext, "executionBudget" | "affinityMoveReasons" | "affinityReason">,
|
|
1249
|
+
logCtx: Pick<RequestLogContext, "executionBudget" | "affinityMoveReasons" | "affinityReason" | "affinity">,
|
|
1239
1250
|
attempts: readonly PersistedUsageAttempt[] | undefined,
|
|
1240
1251
|
): PersistedRequestSpend | undefined {
|
|
1241
1252
|
const rows = attempts ?? [];
|
|
1242
1253
|
const budget = logCtx.executionBudget;
|
|
1243
1254
|
const reasons = [...new Set(
|
|
1244
|
-
(logCtx.affinityMoveReasons ?? (logCtx.affinityReason ? [logCtx.affinityReason] : []))
|
|
1255
|
+
(logCtx.affinityMoveReasons ?? (logCtx.affinity !== "unbound" && logCtx.affinityReason ? [logCtx.affinityReason] : []))
|
|
1245
1256
|
.filter(isKnownAffinityReason),
|
|
1246
1257
|
)];
|
|
1247
1258
|
if (rows.length === 0 && !budget && reasons.length === 0) return undefined;
|
|
@@ -1277,11 +1288,11 @@ export function noteAffinityMove(
|
|
|
1277
1288
|
|
|
1278
1289
|
/**
|
|
1279
1290
|
* 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
|
-
*
|
|
1291
|
+
* one: a stored Pool account and the main login rotating as `main-pool` (#4546, #7799). A keyed
|
|
1292
|
+
* caller-owned main can also carry one. A move reads as an event with its cause.
|
|
1282
1293
|
*/
|
|
1283
1294
|
export function noteCodexSelectionAffinity(logCtx: RequestLogContext, authCtx: CodexAuthContext): void {
|
|
1284
|
-
const decision = authCtx.
|
|
1295
|
+
const decision = authCtx.affinityDecision;
|
|
1285
1296
|
if (!decision) return;
|
|
1286
1297
|
logCtx.affinity = decision.move;
|
|
1287
1298
|
logCtx.affinityReason = decision.reason;
|
|
@@ -1387,6 +1398,22 @@ export function recordKeyWireAttemptUsage(logCtx: RequestLogContext, usage: OcxU
|
|
|
1387
1398
|
return true;
|
|
1388
1399
|
}
|
|
1389
1400
|
|
|
1401
|
+
type FinalRequestLogMetaArg = Pick<RequestLogEntry, "terminalStatus" | "closeReason">;
|
|
1402
|
+
const finalRequestLogInterceptors = new WeakMap<RequestLogContext, (status: number, meta?: FinalRequestLogMetaArg) => void>();
|
|
1403
|
+
|
|
1404
|
+
/** Route inner final-log requests to an outer owner (native ingress) instead of writing them. */
|
|
1405
|
+
export function interceptFinalRequestLog(logCtx: RequestLogContext, onRequest: (status: number, meta?: FinalRequestLogMetaArg) => void): void {
|
|
1406
|
+
finalRequestLogInterceptors.set(logCtx, onRequest);
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
/** The outer owner's write: request-level status from the outer outcome, the physical attempt's from the inner one. */
|
|
1410
|
+
export function commitInterceptedFinalRequestLog(
|
|
1411
|
+
requestId: string, start: number, logCtx: RequestLogContext, status: number, meta: FinalRequestLogMetaArg | undefined,
|
|
1412
|
+
attemptStatus: number, addLog: (entry: RequestLogEntry) => void = addRequestLog,
|
|
1413
|
+
): void {
|
|
1414
|
+
writeFinalRequestLog(requestId, start, logCtx, status, meta, addLog, attemptStatus);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1390
1417
|
export function addFinalRequestLog(
|
|
1391
1418
|
requestId: string,
|
|
1392
1419
|
start: number,
|
|
@@ -1394,10 +1421,25 @@ export function addFinalRequestLog(
|
|
|
1394
1421
|
status: number,
|
|
1395
1422
|
meta?: Pick<RequestLogEntry, "terminalStatus" | "closeReason">,
|
|
1396
1423
|
addLog: (entry: RequestLogEntry) => void = addRequestLog,
|
|
1424
|
+
): void {
|
|
1425
|
+
const intercept = finalRequestLogInterceptors.get(logCtx);
|
|
1426
|
+
if (intercept) { intercept(status, meta); return; }
|
|
1427
|
+
writeFinalRequestLog(requestId, start, logCtx, status, meta, addLog);
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
function writeFinalRequestLog(
|
|
1431
|
+
requestId: string,
|
|
1432
|
+
start: number,
|
|
1433
|
+
logCtx: RequestLogContext,
|
|
1434
|
+
status: number,
|
|
1435
|
+
meta?: Pick<RequestLogEntry, "terminalStatus" | "closeReason">,
|
|
1436
|
+
addLog: (entry: RequestLogEntry) => void = addRequestLog,
|
|
1437
|
+
attemptStatus?: number,
|
|
1397
1438
|
): void {
|
|
1398
1439
|
// Mid-stream web-search aborts used to emit response.failed and land as 502/upstream_server_error.
|
|
1399
1440
|
// Prefer the client-close classification whenever the captured reason says so.
|
|
1400
|
-
|
|
1441
|
+
// A coordinated (attemptStatus) write carries an authoritative outer outcome; skip the heuristic.
|
|
1442
|
+
const effectiveStatus = attemptStatus === undefined && status >= 500 && logCtx.upstreamError && isClientClosedMessage(logCtx.upstreamError)
|
|
1401
1443
|
? 499
|
|
1402
1444
|
: status;
|
|
1403
1445
|
// Locally assigned codes name proxy refusals that status and upstream text cannot reconstruct.
|
|
@@ -1415,7 +1457,7 @@ export function addFinalRequestLog(
|
|
|
1415
1457
|
if (logCtx.activeAttempt) {
|
|
1416
1458
|
finishRequestAttempt(
|
|
1417
1459
|
logCtx.activeAttempt,
|
|
1418
|
-
effectiveStatus,
|
|
1460
|
+
attemptStatus ?? effectiveStatus,
|
|
1419
1461
|
Date.now() - (logCtx.activeAttemptStartedAt ?? start),
|
|
1420
1462
|
keyUsageOwners.has(logCtx.activeAttempt)
|
|
1421
1463
|
? logCtx.activeAttempt.usage
|
|
@@ -1423,7 +1465,9 @@ export function addFinalRequestLog(
|
|
|
1423
1465
|
);
|
|
1424
1466
|
// The final row and its active physical attempt describe the same terminal. Preserve the
|
|
1425
1467
|
// semantic code on both so detailed attempt telemetry cannot regress to a generic status code.
|
|
1426
|
-
|
|
1468
|
+
const attemptErrorCode = attemptStatus === undefined ? errorCode : attemptStatus < 400 ? undefined
|
|
1469
|
+
: logCtx.errorCode ?? requestLogErrorCode(attemptStatus, logCtx.upstreamError, logCtx.terminalErrorCode, false);
|
|
1470
|
+
if (attemptErrorCode) logCtx.activeAttempt.errorCode = attemptErrorCode;
|
|
1427
1471
|
else delete logCtx.activeAttempt.errorCode;
|
|
1428
1472
|
}
|
|
1429
1473
|
// Derived and stamped in a sibling module, before the attempt snapshot below. Every input is
|
|
@@ -1437,8 +1481,10 @@ export function addFinalRequestLog(
|
|
|
1437
1481
|
outputObserved: logCtx.firstOutputMs !== undefined,
|
|
1438
1482
|
...(logCtx.causeHint ? { causeHint: logCtx.causeHint } : {}),
|
|
1439
1483
|
locallyAnswered: logCtx.localTerminalReason !== undefined,
|
|
1440
|
-
|
|
1484
|
+
// A coordinated write derives the request pair from a copy and re-derives the attempt's own.
|
|
1485
|
+
...(logCtx.activeAttempt ? { attempt: attemptStatus === undefined ? logCtx.activeAttempt : { ...logCtx.activeAttempt } } : {}),
|
|
1441
1486
|
});
|
|
1487
|
+
if (attemptStatus !== undefined && logCtx.activeAttempt) attributePhysicalAttempt(logCtx.activeAttempt);
|
|
1442
1488
|
// The one seam every request passes exactly once, whatever transport served it and however
|
|
1443
1489
|
// it ended. The terminal usage belongs to the last send that left; the ledger resolves every
|
|
1444
1490
|
// earlier send of this request as unresolved spend rather than handing its tokens back.
|
|
@@ -1516,12 +1562,14 @@ export function addFinalRequestLog(
|
|
|
1516
1562
|
const jevDecision = normalizePersistedJevDecision(logCtx.jevDecision);
|
|
1517
1563
|
// Keyed by the live attempt objects, not the detached copies above.
|
|
1518
1564
|
const protocolTrace = protocolTraceForRequest(logCtx, logCtx.attempts);
|
|
1519
|
-
|
|
1565
|
+
// Projected before any writer (an injected one too): the row keeps only proxy-owned error facts.
|
|
1566
|
+
addLog(projectErrorDetail({
|
|
1520
1567
|
requestId,
|
|
1521
1568
|
...(isLogicalRequestId(logicalRequestId) ? { logicalRequestId } : {}),
|
|
1522
1569
|
timestamp: start,
|
|
1523
1570
|
model: isCombo ? logCtx.requestedModel! : logCtx.model,
|
|
1524
1571
|
provider: isCombo ? "combo" : logCtx.provider,
|
|
1572
|
+
client: normalizeRecordedClient(logCtx.client) ?? "unknown",
|
|
1525
1573
|
...(logCtx.surface ? { surface: logCtx.surface } : {}),
|
|
1526
1574
|
...(logCtx.apiKeyId ? { apiKeyId: logCtx.apiKeyId } : {}),
|
|
1527
1575
|
...(logCtx.admissionKind ? { admissionKind: logCtx.admissionKind } : {}),
|
|
@@ -1558,7 +1606,8 @@ export function addFinalRequestLog(
|
|
|
1558
1606
|
...(errorCode ? { errorCode } : {}),
|
|
1559
1607
|
...(meta?.terminalStatus ? { terminalStatus: meta.terminalStatus } : {}),
|
|
1560
1608
|
...(closeReason ? { closeReason } : {}),
|
|
1561
|
-
...(logCtx.upstreamError ? { upstreamError: logCtx.upstreamError } : {}),
|
|
1609
|
+
...(logCtx.upstreamError && !upstreamErrorIsLocal(logCtx) ? { upstreamError: logCtx.upstreamError } : {}), ...(logCtx.failureDetail ? { failureDetail: logCtx.failureDetail } : {}),
|
|
1610
|
+
...(logCtx.upstreamCondition ? { upstreamCondition: logCtx.upstreamCondition } : {}),
|
|
1562
1611
|
...upstreamDiagnosticLogFields(logCtx),
|
|
1563
1612
|
usageStatus,
|
|
1564
1613
|
...(loggedUsage ? { usage: loggedUsage } : {}),
|
|
@@ -1581,7 +1630,7 @@ export function addFinalRequestLog(
|
|
|
1581
1630
|
...(claudeCompatibility ? { claudeCompatibility } : {}),
|
|
1582
1631
|
...(protocolTrace ? { protocolTrace } : {}),
|
|
1583
1632
|
...attribution,
|
|
1584
|
-
});
|
|
1633
|
+
}));
|
|
1585
1634
|
// Formatted from the finalized snapshot, so the ring shows exactly what the ledger holds.
|
|
1586
1635
|
for (const attempt of attempts ?? []) debugAttemptDeliverySummary(requestId, attempt);
|
|
1587
1636
|
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 { carryProxyError, proxyErrorPresentation, 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";
|
|
@@ -127,6 +128,8 @@ export function createAdapterContinuations(
|
|
|
127
128
|
| "thinkingSignatureRecovery"
|
|
128
129
|
>,
|
|
129
130
|
) {
|
|
131
|
+
// A request-local symbol survives event spreads without being serialized or forgeable by a provider.
|
|
132
|
+
const continuationBodyStall = Symbol("continuation-body-stall");
|
|
130
133
|
const { options, logCtx, config } = requestContext;
|
|
131
134
|
const {
|
|
132
135
|
oauthDispatch,
|
|
@@ -156,6 +159,8 @@ export function createAdapterContinuations(
|
|
|
156
159
|
return { type: "error", message: "client closed request during terminal continuation", status: 499 };
|
|
157
160
|
}
|
|
158
161
|
const refusal = unwrapUpstreamRetryEvidenceError(error);
|
|
162
|
+
if (refusal instanceof AdmissionModelDeniedError || refusal instanceof SendBudgetExhaustedError) rememberProxyErrorMessage(logCtx, refusal.message, { status: refusal instanceof AdmissionModelDeniedError ? 403 : 429,
|
|
163
|
+
type: refusal instanceof AdmissionModelDeniedError ? MODEL_NOT_ALLOWED_FOR_KEY : "rate_limit_error", code: refusal instanceof AdmissionModelDeniedError ? MODEL_NOT_ALLOWED_FOR_KEY : refusal.code, presentation: refusal instanceof AdmissionModelDeniedError ? "scope" : "send" });
|
|
159
164
|
if (refusal instanceof AdmissionModelDeniedError) {
|
|
160
165
|
return {
|
|
161
166
|
type: "error", message: refusal.message, status: 403,
|
|
@@ -693,16 +698,18 @@ export function createAdapterContinuations(
|
|
|
693
698
|
}
|
|
694
699
|
|
|
695
700
|
if (!response.ok) {
|
|
696
|
-
if (route.providerName === "kiro") response = await normalizeFinalKiroHttpError(response, upstream.signal);
|
|
701
|
+
if (route.providerName === "kiro") response = carryProxyError(response, await normalizeFinalKiroHttpError(response, upstream.signal));
|
|
697
702
|
const errorText = await readDisplaySafeErrorText(response, upstream.signal, "unknown error");
|
|
698
703
|
const normalized = normalizeUpstreamErrorText(errorText, "unknown error");
|
|
704
|
+
const message = normalized.cyberPolicy
|
|
705
|
+
? normalized.message ?? (isCyberPolicyCode(normalized.code) ? CYBER_POLICY_FALLBACK_MESSAGE : normalized.safeText)
|
|
706
|
+
: `Provider continuation error ${response.status}: ${normalized.safeText}`;
|
|
707
|
+
if (isProxyError(response)) rememberProxyErrorMessage(logCtx, message, { status: normalized.cyberPolicy ? 400 : response.status,
|
|
708
|
+
type: normalized.cyberPolicy ? normalized.type ?? CYBER_POLICY_ERROR_CODE : undefined, code: normalized.cyberPolicy ? CYBER_POLICY_ERROR_CODE : undefined, presentation: proxyErrorPresentation(response) });
|
|
699
709
|
yield {
|
|
700
710
|
type: "error",
|
|
701
711
|
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}`,
|
|
712
|
+
message,
|
|
706
713
|
...(normalized.cyberPolicy
|
|
707
714
|
? {
|
|
708
715
|
errorType: normalized.type ?? CYBER_POLICY_ERROR_CODE,
|
|
@@ -744,7 +751,10 @@ export function createAdapterContinuations(
|
|
|
744
751
|
// source can synchronously abort the shared signal, which would otherwise report
|
|
745
752
|
// this timeout as a client cancellation.
|
|
746
753
|
if (error instanceof ResponseBodyInactivityError) {
|
|
747
|
-
|
|
754
|
+
const event: AdapterEvent = { type: "error", message: error.message, status: 504,
|
|
755
|
+
errorType: "upstream_error", code: "upstream_stall_timeout" };
|
|
756
|
+
Object.defineProperty(event, continuationBodyStall, { value: true, enumerable: true });
|
|
757
|
+
yield event;
|
|
748
758
|
} else if (options.abortSignal?.aborted || upstream.signal.aborted) {
|
|
749
759
|
yield { type: "error", message: "client closed request during terminal continuation", status: 499 };
|
|
750
760
|
} else {
|
|
@@ -778,6 +788,7 @@ export function createAdapterContinuations(
|
|
|
778
788
|
terminalGuardEnabled,
|
|
779
789
|
fetchTerminalGuardContinuation,
|
|
780
790
|
fetchGuardedEmptyCompletionRetry,
|
|
791
|
+
isContinuationBodyStall: (event: AdapterEvent): boolean => continuationBodyStall in event,
|
|
781
792
|
};
|
|
782
793
|
}
|
|
783
794
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { proxyErrorPresentation, 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. */
|
|
@@ -56,7 +57,7 @@ export async function deliverAdapterResponse(
|
|
|
56
57
|
>,
|
|
57
58
|
completionPolicy: Pick<ResponsesCompletionPolicy, "emptyCompletionGuardEnabled">,
|
|
58
59
|
adapterExchange: Pick<AdapterExchange, "upstreamResponse" | "upstream" | "cleanupUpstreamAbort" | "localUpstream" | "thinkingSignatureRecovery" | "refetchThinkingSignature">,
|
|
59
|
-
continuationState: Pick<AdapterContinuations, "terminalGuardEnabled" | "fetchTerminalGuardContinuation" | "fetchGuardedEmptyCompletionRetry">,
|
|
60
|
+
continuationState: Pick<AdapterContinuations, "terminalGuardEnabled" | "fetchTerminalGuardContinuation" | "fetchGuardedEmptyCompletionRetry" | "isContinuationBodyStall">,
|
|
60
61
|
): Promise<Response> {
|
|
61
62
|
const { logCtx, options, config } = requestContext;
|
|
62
63
|
const {
|
|
@@ -72,6 +73,7 @@ export async function deliverAdapterResponse(
|
|
|
72
73
|
terminalGuardEnabled,
|
|
73
74
|
fetchTerminalGuardContinuation,
|
|
74
75
|
fetchGuardedEmptyCompletionRetry,
|
|
76
|
+
isContinuationBodyStall,
|
|
75
77
|
} = continuationState;
|
|
76
78
|
const { emptyCompletionGuardEnabled } = completionPolicy;
|
|
77
79
|
const {
|
|
@@ -96,6 +98,7 @@ export async function deliverAdapterResponse(
|
|
|
96
98
|
if (nonReplayable) response = await sanitizeNonReplayableUpstreamError(response, errorSignal);
|
|
97
99
|
const body = await readDisplaySafeErrorText(response, errorSignal, "Upstream recovery failed");
|
|
98
100
|
const error = normalizeUpstreamErrorText(body, "Upstream recovery failed");
|
|
101
|
+
if (isProxyError(response)) rememberProxyErrorMessage(logCtx, error.message ?? error.safeText, { status: response.status, type: error.type ?? "upstream_error", code: error.code, presentation: proxyErrorPresentation(response) });
|
|
99
102
|
yield { type: "error", status: response.status, message: error.message ?? error.safeText,
|
|
100
103
|
errorType: error.type ?? "upstream_error", ...(error.code ? { code: error.code } : {}),
|
|
101
104
|
...(nonReplayable ? { retryable: false } : {}) };
|
|
@@ -116,15 +119,14 @@ export async function deliverAdapterResponse(
|
|
|
116
119
|
}
|
|
117
120
|
} catch (error) {
|
|
118
121
|
if (!(error instanceof ResponseBodyInactivityError)) throw error;
|
|
119
|
-
yield { type: "error", message:
|
|
120
|
-
status: 504, errorType: "upstream_error" };
|
|
122
|
+
yield { type: "error", message: error.message,
|
|
123
|
+
status: 504, errorType: "upstream_error", code: "upstream_stall_timeout" };
|
|
121
124
|
}
|
|
122
125
|
}, () => transportState.activeAdapter.name, !isNonReplayableResponse(upstreamResponse), upstreamResponse);
|
|
123
126
|
|
|
124
127
|
const clientToolCatalog = requestState.clientToolCatalogRestriction && route.provider.authMode !== "forward"
|
|
125
128
|
? requestState.clientToolCatalogRestriction : undefined;
|
|
126
|
-
const deliveryToolBridgeMaps = clientToolCatalog
|
|
127
|
-
? { ...toolBridgeMaps, ...clientToolCatalog } : toolBridgeMaps;
|
|
129
|
+
const deliveryToolBridgeMaps = currentTurnToolBridgeMaps(toolBridgeMaps, clientToolCatalog);
|
|
128
130
|
|
|
129
131
|
|
|
130
132
|
if (parsed.stream) {
|
|
@@ -154,9 +156,10 @@ export async function deliverAdapterResponse(
|
|
|
154
156
|
if (error instanceof ResponseBodyInactivityError) {
|
|
155
157
|
yield {
|
|
156
158
|
type: "error",
|
|
157
|
-
message:
|
|
159
|
+
message: error.message,
|
|
158
160
|
status: 504,
|
|
159
161
|
errorType: "upstream_error",
|
|
162
|
+
code: "upstream_stall_timeout",
|
|
160
163
|
};
|
|
161
164
|
return;
|
|
162
165
|
}
|
|
@@ -194,6 +197,7 @@ export async function deliverAdapterResponse(
|
|
|
194
197
|
? guardEmptyCompletionEventStream({
|
|
195
198
|
firstEvents: advisorStream,
|
|
196
199
|
continuation: fetchGuardedEmptyCompletionRetry,
|
|
200
|
+
preserveRetryError: isContinuationBodyStall,
|
|
197
201
|
})
|
|
198
202
|
: advisorStream;
|
|
199
203
|
const catalogGuardedEventStream = guardEmptyToolCatalogStream(completionGuardedEventStream, clientToolCatalog, translatorBudget);
|
|
@@ -253,7 +257,7 @@ export async function deliverAdapterResponse(
|
|
|
253
257
|
guardedEventStream, parsed._responseModelId ?? parsed.modelId, toolNsMap, freeformToolNames, toolSearchToolNames,
|
|
254
258
|
() => { cancelResponseCompletion(); upstream.abort(); }, 2_000,
|
|
255
259
|
{
|
|
256
|
-
translatorBudget,
|
|
260
|
+
translatorBudget, proxyErrorContext: logCtx,
|
|
257
261
|
replayCacheScope: parsed._reasoningReplayScope,
|
|
258
262
|
...(outputItemIds ? { outputItemIds } : {}),
|
|
259
263
|
...(options.forceEmptyResponseId ? { responseId: "" } : {}),
|
|
@@ -344,6 +348,7 @@ export async function deliverAdapterResponse(
|
|
|
344
348
|
for await (const event of guardEmptyCompletionEventStream({
|
|
345
349
|
firstEvents: (async function* () { yield* guardedEvents; })(),
|
|
346
350
|
continuation: fetchGuardedEmptyCompletionRetry,
|
|
351
|
+
preserveRetryError: isContinuationBodyStall,
|
|
347
352
|
})) events.push(event);
|
|
348
353
|
} else {
|
|
349
354
|
events = guardedEvents;
|
|
@@ -357,7 +362,7 @@ export async function deliverAdapterResponse(
|
|
|
357
362
|
}
|
|
358
363
|
} catch (error) {
|
|
359
364
|
if (error instanceof ResponseBodyInactivityError) {
|
|
360
|
-
return formatErrorResponse(504, "upstream_error",
|
|
365
|
+
return formatErrorResponse(504, "upstream_error", error.message);
|
|
361
366
|
}
|
|
362
367
|
throw error;
|
|
363
368
|
} finally {
|
|
@@ -407,7 +412,9 @@ export async function deliverAdapterResponse(
|
|
|
407
412
|
commitReasoningReplayServingRoute();
|
|
408
413
|
}
|
|
409
414
|
notifyResponseComplete(json);
|
|
410
|
-
|
|
415
|
+
const lastError = events.findLast(event => event.type === "error");
|
|
416
|
+
const status = json.status === "failed" && lastError && isContinuationBodyStall(lastError) ? 504 : 200;
|
|
417
|
+
return new Response(JSON.stringify(json), { status, headers: { "Content-Type": "application/json" } });
|
|
411
418
|
}
|
|
412
419
|
|
|
413
420
|
return formatErrorResponse(400, "invalid_request_error", "Non-streaming not supported by this adapter");
|