@bitkyc08/opencodex 2.92.0 → 2.93.0-preview.20261027

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.
Files changed (259) hide show
  1. package/bin/ocx.mjs +10 -5
  2. package/gui/dist/assets/App-CJZoq-uF.js +58 -0
  3. package/gui/dist/assets/{Tray-BSsxznDm.js → Tray-BWQPcgZn.js} +1 -1
  4. package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
  5. package/gui/dist/assets/{index-BlFE_VB_.js → index-Xfct8owH.js} +12 -12
  6. package/gui/dist/assets/{quota-summary-BRlbXgw0.js → quota-summary-DxToX1rV.js} +1 -1
  7. package/gui/dist/index.html +2 -2
  8. package/package.json +5 -5
  9. package/src/adapters/anthropic.ts +28 -5
  10. package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
  11. package/src/adapters/coding-agent/profile.ts +54 -16
  12. package/src/adapters/coding-agent/turn.ts +30 -2
  13. package/src/adapters/command-code.ts +114 -7
  14. package/src/adapters/cursor/native-exec-fs.ts +11 -9
  15. package/src/adapters/devin/live-models.ts +4 -0
  16. package/src/adapters/google-wire-compiler.ts +1 -2
  17. package/src/adapters/kiro/reasoning.ts +2 -0
  18. package/src/adapters/kiro-refusal.ts +6 -1
  19. package/src/adapters/kiro-wire.ts +1 -1
  20. package/src/adapters/openai-chat/messages.ts +8 -2
  21. package/src/adapters/openai-chat/passthrough.ts +35 -14
  22. package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
  23. package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
  24. package/src/adapters/openai-chat/required-tool-result.ts +64 -0
  25. package/src/adapters/openai-chat.ts +7 -8
  26. package/src/adapters/openai-responses/passthrough.ts +7 -4
  27. package/src/adapters/openai-responses/reasoning.ts +13 -0
  28. package/src/adapters/openai-responses/request-strips.ts +1 -1
  29. package/src/adapters/qoder/adapter.ts +129 -8
  30. package/src/adapters/qoder/scaffold-guard.ts +5 -0
  31. package/src/adapters/reasoning-controls.ts +16 -0
  32. package/src/adapters/tool-call-id.ts +1 -3
  33. package/src/bridge/errors.ts +27 -0
  34. package/src/bridge.ts +1 -1
  35. package/src/chat/inbound.ts +4 -1
  36. package/src/chat/outbound.ts +9 -2
  37. package/src/chat/reasoning-details.ts +28 -5
  38. package/src/claude/desktop-first-party.ts +54 -4
  39. package/src/claude/desktop-picker.ts +11 -8
  40. package/src/claude/first-party-settings.ts +3 -1
  41. package/src/claude/inbound.ts +2 -1
  42. package/src/claude/intercept/local-ca.ts +2 -1
  43. package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
  44. package/src/claude/intercept/picker-ca-startup.ts +3 -1
  45. package/src/claude/intercept/picker-models.ts +6 -3
  46. package/src/claude/intercept/picker-runtime.ts +3 -2
  47. package/src/claude/intercept/runtime.ts +6 -3
  48. package/src/claude/model-info.ts +31 -8
  49. package/src/cli/account-api.ts +11 -0
  50. package/src/cli/capabilities-agents-routing.ts +2 -2
  51. package/src/cli/capabilities-base.ts +7 -1
  52. package/src/cli/capabilities-observe-system.ts +10 -0
  53. package/src/cli/claude-desktop.ts +9 -8
  54. package/src/cli/claude.ts +3 -2
  55. package/src/cli/codex-shim-autorestore.ts +9 -0
  56. package/src/cli/combo-result.ts +7 -0
  57. package/src/cli/combo.ts +18 -0
  58. package/src/cli/cross-home-owner.ts +13 -1
  59. package/src/cli/dispatch.ts +25 -6
  60. package/src/cli/ensure-desired-integrations.ts +8 -6
  61. package/src/cli/export-command.ts +4 -1
  62. package/src/cli/help.ts +2 -1
  63. package/src/cli/index.ts +45 -45
  64. package/src/cli/integration-plan-dto.ts +4 -0
  65. package/src/cli/opencode.ts +20 -9
  66. package/src/cli/registry.ts +6 -4
  67. package/src/cli/root.ts +9 -0
  68. package/src/cli/status.ts +59 -1
  69. package/src/cli/stop-restore.ts +113 -0
  70. package/src/cli/sync-expectation.ts +60 -0
  71. package/src/cli/uninstall-integrations.ts +41 -7
  72. package/src/client/connect.ts +40 -3
  73. package/src/client/link-home.ts +10 -1
  74. package/src/client/machine-api.ts +3 -1
  75. package/src/client/sync-expectation.ts +118 -0
  76. package/src/clients/config-export/agent-clients.ts +96 -0
  77. package/src/clients/config-export/contracts.ts +25 -7
  78. package/src/clients/config-export/qoder.ts +38 -23
  79. package/src/clients/config-export/reasoning-metadata.ts +55 -8
  80. package/src/clients/config-export.ts +12 -0
  81. package/src/clients/lazycodex.ts +7 -2
  82. package/src/clients/reasoning-controls.ts +49 -0
  83. package/src/codex/auth-api/account-identity.ts +14 -0
  84. package/src/codex/auth-api/account-list.ts +29 -2
  85. package/src/codex/auth-api/http.ts +13 -0
  86. package/src/codex/auth-api/main-account-probe.ts +2 -2
  87. package/src/codex/auth-api/pool-mode-gate.ts +16 -3
  88. package/src/codex/auth-api/pool-quota-probe.ts +15 -0
  89. package/src/codex/auth-context.ts +15 -12
  90. package/src/codex/catalog/build-entries.ts +22 -0
  91. package/src/codex/catalog/configured-tiers.ts +70 -0
  92. package/src/codex/catalog/effort.ts +44 -10
  93. package/src/codex/catalog/gather-capture.ts +1 -0
  94. package/src/codex/catalog/heal-observation.ts +155 -13
  95. package/src/codex/catalog/metadata.ts +6 -0
  96. package/src/codex/catalog/model-hints.ts +60 -11
  97. package/src/codex/catalog/model-visibility.ts +3 -2
  98. package/src/codex/catalog/native-models.ts +18 -3
  99. package/src/codex/catalog/parsing.ts +10 -8
  100. package/src/codex/catalog/pinned-models.ts +2 -1
  101. package/src/codex/catalog/provider-models.ts +4 -5
  102. package/src/codex/catalog/retained-sync.ts +2 -1
  103. package/src/codex/catalog/routed-gather.ts +19 -20
  104. package/src/codex/catalog/write-audit.ts +3 -2
  105. package/src/codex/catalog-self-heal.ts +43 -23
  106. package/src/codex/collision-identity.ts +30 -5
  107. package/src/codex/convergence.ts +4 -3
  108. package/src/codex/data/roster-pinned-models.json +177 -1
  109. package/src/codex/desired-state.ts +6 -1
  110. package/src/codex/desktop-compatibility/installed-build.ts +88 -12
  111. package/src/codex/desktop-compatibility/runtime.ts +29 -5
  112. package/src/codex/desktop-compatibility/usage-controller.ts +2 -0
  113. package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
  114. package/src/codex/inject/config-toml.ts +0 -18
  115. package/src/codex/inject/plan.ts +18 -3
  116. package/src/codex/inject/remove.ts +6 -2
  117. package/src/codex/inject.ts +1 -1
  118. package/src/codex/journal.ts +61 -1
  119. package/src/codex/model-entitlements.ts +1 -1
  120. package/src/codex/native-main-owner.ts +27 -1
  121. package/src/codex/native-profile-store.ts +2 -1
  122. package/src/codex/pool-credit-policy.ts +35 -1
  123. package/src/codex/quota-types.ts +3 -0
  124. package/src/codex/quota.ts +24 -4
  125. package/src/codex/role-auto-assign.ts +6 -2
  126. package/src/codex/subagent-defaults.ts +49 -4
  127. package/src/combos/failover.ts +17 -2
  128. package/src/combos/jev-decision-contract.ts +22 -1
  129. package/src/combos/jev-service-exchange.ts +3 -1
  130. package/src/combos/jev.ts +95 -9
  131. package/src/combos/resolve.ts +45 -1
  132. package/src/combos/types.ts +24 -0
  133. package/src/config/load-degrade.ts +5 -0
  134. package/src/config/paths.ts +19 -3
  135. package/src/config/pending-teardown.ts +22 -1
  136. package/src/config/provider-validation.ts +15 -4
  137. package/src/config/removed-opencode-free.ts +11 -0
  138. package/src/config/schema/leaf-validators.ts +5 -0
  139. package/src/generated/compatibility-version.json +314 -230
  140. package/src/generated/model-metadata.ts +5 -5
  141. package/src/images/loop.ts +16 -2
  142. package/src/integrations/catalog-refresh.ts +1 -1
  143. package/src/integrations/hermes-profiles.ts +251 -0
  144. package/src/integrations/merge.ts +8 -0
  145. package/src/integrations/mutation-plan.ts +19 -4
  146. package/src/integrations/registry.ts +5 -0
  147. package/src/integrations/state.ts +36 -1
  148. package/src/integrations/writer.ts +18 -4
  149. package/src/lib/bun-path-runtime.mjs +2 -1
  150. package/src/lib/errors.ts +62 -0
  151. package/src/lib/eventstream-decoder.ts +81 -37
  152. package/src/lib/opaque-proxy-tunnel.ts +32 -8
  153. package/src/lib/pinned-http.ts +35 -2
  154. package/src/lib/process-control.ts +13 -1
  155. package/src/lib/socks5-fetch.ts +59 -64
  156. package/src/lib/socks5-upload-waiter.ts +50 -0
  157. package/src/lib/sse-decoder.ts +7 -2
  158. package/src/lib/state-store-sweeper.ts +40 -14
  159. package/src/lib/windows-native-principal-worker.ts +14 -0
  160. package/src/lib/windows-native-principal.ts +188 -0
  161. package/src/lib/windows-secret-acl.ts +39 -3
  162. package/src/lib/windows-user-principal.ts +62 -18
  163. package/src/link/ssh-config.ts +35 -3
  164. package/src/providers/account-quota-disk.ts +12 -4
  165. package/src/providers/codebuddy-models.ts +6 -0
  166. package/src/providers/codex-capacity.ts +3 -1
  167. package/src/providers/derive.ts +28 -0
  168. package/src/providers/kiro-models.ts +3 -0
  169. package/src/providers/mimo-thinking.ts +12 -0
  170. package/src/providers/model-rename-fields.ts +1 -0
  171. package/src/providers/model-rename-migration.ts +10 -0
  172. package/src/providers/openai-sidecar-credit.ts +2 -2
  173. package/src/providers/reasoning-capabilities.ts +76 -0
  174. package/src/providers/registry/entries-core.ts +14 -12
  175. package/src/providers/registry/entries-extended.ts +63 -20
  176. package/src/providers/registry/model-ids.ts +2 -0
  177. package/src/providers/registry/model-seeds.ts +93 -28
  178. package/src/providers/registry/types.ts +10 -1
  179. package/src/providers/resolved-model-policy.ts +26 -6
  180. package/src/providers/routed-config.ts +9 -1
  181. package/src/providers/stale-model-roster-migration.ts +44 -7
  182. package/src/remote-control/workspace-pi-runtime.ts +11 -6
  183. package/src/responses/compaction-summary.ts +45 -0
  184. package/src/responses/muse-tool-name-alias.ts +1 -2
  185. package/src/responses/parser.ts +3 -2
  186. package/src/responses/schema.ts +1 -0
  187. package/src/responses/thought-signature-replay.ts +10 -2
  188. package/src/routing/capability.ts +8 -2
  189. package/src/routing/history/ingest.ts +28 -3
  190. package/src/server/auth-cors.ts +3 -2
  191. package/src/server/chat-completions.ts +7 -0
  192. package/src/server/chat-native-eligibility.ts +7 -0
  193. package/src/server/chat-native-reasoning.ts +14 -4
  194. package/src/server/direct-local-http.ts +5 -2
  195. package/src/server/effort-policy.ts +5 -1
  196. package/src/server/index/live-sideband.ts +18 -15
  197. package/src/server/index/serve-options.ts +5 -4
  198. package/src/server/management/agent-settings-routes.ts +27 -15
  199. package/src/server/management/combo-routes.ts +4 -0
  200. package/src/server/management/config-routes.ts +2 -2
  201. package/src/server/management/decision-discovery.ts +12 -2
  202. package/src/server/management/hermes-profile-routes.ts +156 -0
  203. package/src/server/management/integration-routes.ts +85 -24
  204. package/src/server/management/model-routes.ts +2 -2
  205. package/src/server/management/model-row-export-metadata.ts +25 -6
  206. package/src/server/management/model-rows.ts +15 -20
  207. package/src/server/management/native-integration-routes.ts +11 -8
  208. package/src/server/management/route-registry.ts +4 -0
  209. package/src/server/management-api.ts +5 -0
  210. package/src/server/models-capabilities.ts +21 -3
  211. package/src/server/responses/adapter-delivery.ts +11 -1
  212. package/src/server/responses/adapter-dispatch.ts +2 -2
  213. package/src/server/responses/codex-ws-exchange.ts +39 -9
  214. package/src/server/responses/codex-ws-session.ts +38 -4
  215. package/src/server/responses/codex-ws-wire.ts +6 -1
  216. package/src/server/responses/combo-required-tool-contract.ts +103 -0
  217. package/src/server/responses/combo-stream-preflight.ts +8 -1
  218. package/src/server/responses/compact.ts +4 -3
  219. package/src/server/responses/context-overflow.ts +8 -1
  220. package/src/server/responses/core-combo-failure.ts +10 -0
  221. package/src/server/responses/core-combo.ts +23 -15
  222. package/src/server/responses/core-lifetime.ts +3 -0
  223. package/src/server/responses/core-normalize.ts +11 -1
  224. package/src/server/responses/core-options.ts +2 -0
  225. package/src/server/responses/main-hard-lock-routing.ts +60 -44
  226. package/src/server/responses/passthrough-delivery.ts +40 -2
  227. package/src/server/responses/policy-fallback.ts +6 -1
  228. package/src/server/responses/request-compression.ts +12 -7
  229. package/src/server/responses/request-prepare.ts +22 -2
  230. package/src/server/responses/request-sidecar-auth.ts +2 -0
  231. package/src/server/responses/response-effects.ts +22 -10
  232. package/src/server/responses/sidecar-execution.ts +11 -3
  233. package/src/server/stop-teardown.ts +36 -1
  234. package/src/server/ws-bridge.ts +1 -1
  235. package/src/service/desktop-supervision.d.mts +7 -4
  236. package/src/service/desktop-supervision.mjs +90 -13
  237. package/src/service/ownership-mutation-lease.mjs +21 -7
  238. package/src/types/config.ts +8 -2
  239. package/src/types/provider.ts +20 -6
  240. package/src/types/request.ts +10 -0
  241. package/src/types.ts +1 -0
  242. package/src/update/bind-probe.ts +29 -0
  243. package/src/update/job.ts +10 -29
  244. package/src/update/npm-install-job.ps1 +173 -0
  245. package/src/update/npm-install.mjs +70 -0
  246. package/src/update/stop-contract.d.mts +1 -0
  247. package/src/update/stop-contract.mjs +14 -0
  248. package/src/update/stop-decision.d.mts +1 -1
  249. package/src/update/stop-decision.mjs +13 -3
  250. package/src/update/teardown-handover.ts +166 -0
  251. package/src/update/transactional-install.d.mts +14 -3
  252. package/src/update/transactional-install.mjs +33 -7
  253. package/src/usage/expected-prices.ts +64 -31
  254. package/src/usage/timeline.ts +19 -9
  255. package/src/vision/eligibility.ts +15 -5
  256. package/src/vision/plan.ts +2 -2
  257. package/src/web-search/loop.ts +16 -2
  258. package/gui/dist/assets/App-sUf_8afJ.js +0 -58
  259. package/gui/dist/assets/index-DPeB9HpV.css +0 -1
@@ -15,20 +15,30 @@
15
15
  * those records all-or-nothing, so creating one here would hide the rest of the registry seed.
16
16
  * Same shape and restraint as `stale-context-window-migration`.
17
17
  */
18
- import { ALIBABA_INTL_TOKEN_PLAN_BASE_URL } from "./base-url-choices";
18
+ import { ALIBABA_INTL_TOKEN_PLAN_BASE_URL, MOONSHOT_CN_BASE_URL, MOONSHOT_INTL_BASE_URL } from "./base-url-choices";
19
19
  import { PROVIDER_REGISTRY, normalizedProviderEndpoint } from "./registry";
20
20
  import {
21
21
  ALIBABA_TOKEN_PLAN_MODELS,
22
22
  ALIBABA_INTL_TOKEN_PLAN_MODELS,
23
23
  ALIBABA_TOKEN_PLAN_CONTEXT_WINDOWS,
24
24
  ALIBABA_TOKEN_PLAN_MAX_OUTPUT_TOKENS,
25
+ KIMI_API_DEFAULT_REASONING_EFFORTS,
26
+ KIMI_API_MODEL_CONTEXT_WINDOWS,
27
+ KIMI_API_MODELS,
28
+ KIMI_API_MODELS_BEFORE_K31,
29
+ META_MODEL_API_MODELS,
30
+ META_MUSE_CONTEXT_WINDOW,
31
+ META_MUSE_MODELS,
32
+ META_MUSE_WONDER_MODEL,
25
33
  MINIMAX_M31_DEFAULT_REASONING_EFFORT,
26
- MINIMAX_M31_FLASH_PREVIEW,
34
+ MINIMAX_M31_FLASH,
35
+ MINIMAX_M31_FLASH_MAX_OUTPUT_TOKENS,
27
36
  MINIMAX_MODELS,
28
37
  MINIMAX_MODELS_BEFORE_M31,
29
38
  MINIMAX_MODEL_CONTEXT_WINDOWS,
30
39
  } from "./registry/model-seeds";
31
40
  import type { OcxConfig } from "../types";
41
+ import { modelRecordValue } from "../reasoning-effort";
32
42
 
33
43
  export interface StaleModelRoster {
34
44
  /** Registry provider id whose saved rows may carry the old roster. */
@@ -71,16 +81,33 @@ const ALIBABA_INTL_TOKEN_PLAN_MODELS_BEFORE_1017 = [
71
81
  ];
72
82
 
73
83
  /**
74
- * MiniMax-M3.1-Flash-Preview (2026-09-30). MiniMax's /v1/models roster does not list the
75
- * preview, so live discovery cannot add it; the catalog keeps it only when it is configured.
84
+ * MiniMax-M3.1-Flash (2026-10-21). MiniMax's /v1/models roster does not list the
85
+ * Flash, so live discovery cannot add it; the catalog keeps it only when it is configured.
76
86
  */
77
87
  export const STALE_MODEL_ROSTERS: readonly StaleModelRoster[] = [
88
+ {
89
+ provider: "meta-model",
90
+ from: META_MUSE_MODELS,
91
+ to: META_MODEL_API_MODELS,
92
+ contextWindows: { [META_MUSE_WONDER_MODEL]: META_MUSE_CONTEXT_WINDOW },
93
+ // A Custom row may keep this id pointed at another gateway
94
+ // (preserveCustomDestination); only api.meta.ai publishes the roster `to` describes.
95
+ destinationBaseUrls: ["https://api.meta.ai/v1"],
96
+ },
97
+ {
98
+ provider: "deepseek",
99
+ from: ["deepseek-chat", "deepseek-reasoner", "deepseek-flash", "deepseek-v4-flash", "deepseek-v4-flash-vision-exp"],
100
+ to: ["deepseek-chat", "deepseek-reasoner", "deepseek-flash", "deepseek-v4-flash", "deepseek-v4-pro", "deepseek-v4-flash-vision-exp"],
101
+ contextWindows: { "deepseek-v4-pro": 1_048_576 },
102
+ destinationBaseUrls: ["https://api.deepseek.com", "https://api.deepseek.com/v1"],
103
+ },
78
104
  ...["minimax", "minimax-cn"].map(provider => ({
79
105
  provider,
80
106
  from: MINIMAX_MODELS_BEFORE_M31,
81
107
  to: MINIMAX_MODELS,
82
- contextWindows: { [MINIMAX_M31_FLASH_PREVIEW]: MINIMAX_MODEL_CONTEXT_WINDOWS[MINIMAX_M31_FLASH_PREVIEW]! },
83
- defaultReasoningEfforts: { [MINIMAX_M31_FLASH_PREVIEW]: MINIMAX_M31_DEFAULT_REASONING_EFFORT },
108
+ contextWindows: { [MINIMAX_M31_FLASH]: MINIMAX_MODEL_CONTEXT_WINDOWS[MINIMAX_M31_FLASH]! },
109
+ maxOutputTokens: { [MINIMAX_M31_FLASH]: MINIMAX_M31_FLASH_MAX_OUTPUT_TOKENS },
110
+ defaultReasoningEfforts: { [MINIMAX_M31_FLASH]: MINIMAX_M31_DEFAULT_REASONING_EFFORT },
84
111
  })),
85
112
  ...[
86
113
  { provider: "alibaba-token-plan", from: ALIBABA_TOKEN_PLAN_MODELS_BEFORE_1017, to: ALIBABA_TOKEN_PLAN_MODELS },
@@ -96,6 +123,16 @@ export const STALE_MODEL_ROSTERS: readonly StaleModelRoster[] = [
96
123
  maxOutputTokens: ALIBABA_TOKEN_PLAN_MAX_OUTPUT_TOKENS,
97
124
  defaultReasoningEfforts: { "deepseek-v4.1-flash-1017": "high" },
98
125
  })),
126
+ // Kimi K3.1 Pro (#7653). Both the International and China platforms list kimi-k3.1-pro and
127
+ // -highspeed; a Custom URL may be another gateway, so it keeps its saved list.
128
+ {
129
+ provider: "moonshot",
130
+ from: KIMI_API_MODELS_BEFORE_K31,
131
+ to: KIMI_API_MODELS,
132
+ contextWindows: KIMI_API_MODEL_CONTEXT_WINDOWS,
133
+ defaultReasoningEfforts: KIMI_API_DEFAULT_REASONING_EFFORTS,
134
+ destinationBaseUrls: [MOONSHOT_INTL_BASE_URL, MOONSHOT_CN_BASE_URL],
135
+ },
99
136
  ];
100
137
 
101
138
  function sameList(value: unknown, expected: readonly string[]): boolean {
@@ -121,7 +158,7 @@ function fillExisting<T>(container: Record<string, T> | undefined, values: Reado
121
158
  let filled = false;
122
159
  for (const id of ids) {
123
160
  const value = values[id];
124
- if (value !== undefined && !Object.prototype.hasOwnProperty.call(container, id)) {
161
+ if (value !== undefined && modelRecordValue(container, id) === undefined) {
125
162
  container[id] = value;
126
163
  filled = true;
127
164
  }
@@ -137,13 +137,18 @@ class PiRpcProcess {
137
137
  async prompt(message: string): Promise<void> {
138
138
  if (this.activeSettle) throw new Error("Pi Remote Workspace turn is already active");
139
139
  const settled = new Promise<void>((resolve, reject) => { this.activeSettle = { resolve, reject }; });
140
+ const active = this.activeSettle;
140
141
  try {
141
- const accepted = await this.command("prompt", { message });
142
- if (accepted.success !== true) throw new Error(safeError(accepted.error, "Pi rejected the prompt"));
143
- await settled;
144
- } catch (error) {
145
- this.activeSettle = null;
146
- throw error;
142
+ // Either operation can fail first. Observe both immediately, including an
143
+ // extension error or child exit that arrives before the prompt response.
144
+ await Promise.all([
145
+ this.command("prompt", { message }).then(accepted => {
146
+ if (accepted.success !== true) throw new Error(safeError(accepted.error, "Pi rejected the prompt"));
147
+ }),
148
+ settled,
149
+ ]);
150
+ } finally {
151
+ if (this.activeSettle === active) this.activeSettle = null;
147
152
  }
148
153
  }
149
154
 
@@ -0,0 +1,45 @@
1
+ import type { AdapterEvent } from "../types";
2
+ import { releaseTranslatedEvent, type TranslatorBudget } from "../lib/translator-budget";
3
+ import { isTruncatedStopReason } from "./truncated-stop-reason";
4
+
5
+ /** Keep client/hosted tool events out of a routed Anthropic summary's compaction item. */
6
+ export async function* guardCompactionSummary(
7
+ events: AsyncIterable<AdapterEvent>,
8
+ budget: TranslatorBudget,
9
+ ): AsyncGenerator<AdapterEvent> {
10
+ let hasText = false;
11
+ let attemptedTool = false;
12
+ for await (const event of events) {
13
+ if (event.type === "text_delta" && !event.anthropicThinkingSignature) {
14
+ hasText ||= event.text.trim().length > 0;
15
+ yield event;
16
+ continue;
17
+ }
18
+ if (event.type === "error" || event.type === "incomplete") {
19
+ yield event;
20
+ return;
21
+ }
22
+ if (event.type === "done") {
23
+ if (!isTruncatedStopReason(event.stopReason)
24
+ // An absent stop reason is accepted, as on every other completion path: some
25
+ // Anthropic-compatible endpoints omit it. An explicit non-terminal reason is not.
26
+ && (attemptedTool || !hasText
27
+ || (event.stopReason !== undefined && event.stopReason !== "end_turn" && event.stopReason !== "stop_sequence"))) {
28
+ releaseTranslatedEvent(event, budget);
29
+ yield {
30
+ type: "error", status: 502, errorType: "upstream_error",
31
+ code: "compaction_invalid_summary", retryable: false,
32
+ message: "Compaction requires a non-empty text summary without tool calls and a normal completion.",
33
+ usage: event.usage,
34
+ };
35
+ } else {
36
+ yield event;
37
+ }
38
+ return;
39
+ }
40
+ if (event.type === "tool_call_start" || event.type === "tool_call_delta" || event.type === "tool_call_end"
41
+ || event.type === "web_search_call_begin" || event.type === "web_search_call_end") attemptedTool = true;
42
+ releaseTranslatedEvent(event, budget);
43
+ yield { type: "heartbeat" };
44
+ }
45
+ }
@@ -1,4 +1,3 @@
1
- import { createHash } from "node:crypto";
2
1
  import { wireToolInnerName } from "./tool-name-aliases";
3
2
 
4
3
  const MUSE_TOOL_NAME_MAX = 64;
@@ -53,7 +52,7 @@ function isPassThroughMuseToolName(name: string): boolean {
53
52
 
54
53
  function hashSuffix(originalName: string, salt: number): string {
55
54
  const hashInput = salt === 0 ? originalName : originalName + "#" + salt;
56
- return createHash("sha256").update(hashInput).digest("hex").slice(0, MUSE_TOOL_NAME_HASH_LEN);
55
+ return Bun.SHA256.hash(hashInput, "hex").slice(0, MUSE_TOOL_NAME_HASH_LEN);
57
56
  }
58
57
 
59
58
  /**
@@ -185,8 +185,8 @@ function attachPendingReasoningToCallOwner(
185
185
 
186
186
  const REASONING_EFFORTS = new Set(["none", "minimal", "low", "medium", "high", "xhigh", "max"]);
187
187
 
188
- export function hasValidatedActiveReasoningEffort(options: Pick<OcxRequestOptions, "reasoning">): boolean {
189
- return options.reasoning !== undefined && options.reasoning !== "none";
188
+ export function hasValidatedActiveReasoningEffort(options: Pick<OcxRequestOptions, "reasoning" | "thinkingEnabled">): boolean {
189
+ return options.thinkingEnabled ?? (options.reasoning !== undefined && options.reasoning !== "none");
190
190
  }
191
191
 
192
192
 
@@ -695,6 +695,7 @@ export function parseRequest(
695
695
  // `reasoning_effort_for_request`), so current clients never send it — but a catalog that
696
696
  // advertises ultra plus an older/direct caller can. Degrade it to max like upstream instead of
697
697
  // silently dropping reasoning altogether.
698
+ if (data.reasoning?.enabled !== undefined) options.thinkingEnabled = data.reasoning.enabled;
698
699
  const requestedEffort = data.reasoning?.effort === "ultra" ? "max" : data.reasoning?.effort;
699
700
  if (requestedEffort && REASONING_EFFORTS.has(requestedEffort)) {
700
701
  options.reasoning = requestedEffort;
@@ -180,6 +180,7 @@ export const toolChoiceSchema = z.union([
180
180
  ]);
181
181
 
182
182
  export const reasoningConfigSchema = z.object({
183
+ enabled: z.boolean().optional(),
183
184
  effort: z.string().optional(),
184
185
  summary: z.enum(["auto", "concise", "detailed", "none"]).optional(),
185
186
  });
@@ -64,6 +64,7 @@ let entries = new Map<string, StoredEntry>();
64
64
  let totalBytes = 0;
65
65
  let loaded = false;
66
66
  let persistChain: Promise<void> = Promise.resolve();
67
+ let pendingPersist: Promise<void> | undefined;
67
68
 
68
69
  function storePath(): string {
69
70
  return join(getConfigDir(), STORE_FILE_NAME);
@@ -203,8 +204,12 @@ function prune(nowMs: number): void {
203
204
  }
204
205
 
205
206
  function persist(): Promise<void> {
206
- persistChain = persistChain
207
+ // Mutations share a queued snapshot only until serialization starts. Arrivals during
208
+ // its write get a subsequent batch, without extending earlier callers' barriers.
209
+ if (pendingPersist) return pendingPersist;
210
+ const batch = persistChain
207
211
  .then(async () => {
212
+ if (pendingPersist === batch) pendingPersist = undefined;
208
213
  const snapshot = JSON.stringify({
209
214
  version: STORE_VERSION,
210
215
  entries: [...entries].map(([key, entry]) => ({ key, sig: entry.sig, savedAt: entry.savedAt })),
@@ -214,7 +219,9 @@ function persist(): Promise<void> {
214
219
  .catch(() => {
215
220
  // Best-effort persistence: the in-memory store still serves the running process.
216
221
  });
217
- return persistChain;
222
+ pendingPersist = batch;
223
+ persistChain = batch;
224
+ return batch;
218
225
  }
219
226
 
220
227
  /**
@@ -331,6 +338,7 @@ export function resetThoughtSignatureReplayForTests(): void {
331
338
  totalBytes = 0;
332
339
  loaded = false;
333
340
  persistChain = Promise.resolve();
341
+ pendingPersist = undefined;
334
342
  cachedSalt = undefined;
335
343
  saltLoaded = false;
336
344
  }
@@ -182,7 +182,8 @@ export function candidateCapabilityEvidence(
182
182
  ? (nativeOpenAiContextWindow(modelId, nativeContextLimits(config)) ?? rawContextWindow)
183
183
  : rawContextWindow;
184
184
 
185
- // `noVisionModels` is checked before the modality chain because that is the order
185
+ // Exact capability declarations precede legacy vision hints, matching runtime eligibility.
186
+ // `noVisionModels` is checked before the remaining modality chain because that is the order
186
187
  // `isModelTextOnly` uses: it matches the no-vision list and returns true before it
187
188
  // ever reads `modelInputModalities` (`src/vision/index.ts:32`). So a `gpt-oss`
188
189
  // no-vision entry beats an exact `gpt-oss:120b` entry that lists "image", and
@@ -191,10 +192,15 @@ export function candidateCapabilityEvidence(
191
192
  // #2086: routing *acts* on this evidence, so it would select the candidate for image
192
193
  // work that execution then rejects.
193
194
  const noVision = modelInList(provider?.noVisionModels, modelId);
194
- const modalities = noVision
195
+ const explicitModalities = Object.hasOwn(provider?.modelCapabilities ?? {}, modelId)
196
+ ? provider?.modelCapabilities?.[modelId]?.inputModalities : undefined;
197
+ const modalities = explicitModalities?.length ? explicitModalities : noVision
195
198
  ? ["text"]
196
199
  : (modelRecordValue(provider?.modelInputModalities, modelId)
197
200
  ?? modelRecordValue(registryEntry?.modelInputModalities, modelId)
201
+ // Provider-wide declaration, for ids the per-model maps do not list. Read from the
202
+ // provider only: a name-only registry lookup would apply it to a custom destination.
203
+ ?? provider?.inputModalities
198
204
  ?? catalogRow?.inputModalities
199
205
  ?? (isNative ? nativeInputModalities(modelId) : undefined));
200
206
  const image = Array.isArray(modalities)
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import type { Database } from "bun:sqlite";
10
- import { closeSync, fstatSync, openSync, readSync } from "node:fs";
10
+ import { closeSync, fstatSync, openSync, readSync, type BigIntStats } from "node:fs";
11
11
  import {
12
12
  encodePersistedRequestedModel,
13
13
  exactFileIdentity,
@@ -23,6 +23,20 @@ export const REQUEST_HISTORY_READ_CHUNK_BYTES = 64 * 1024;
23
23
  // never truncated or rewritten by the indexer.
24
24
  export const REQUEST_HISTORY_MAX_RECORD_BYTES = 1024 * 1024;
25
25
 
26
+ // One small observation per live database handle, never retained ledger bytes. An
27
+ // unterminated tail cannot advance indexedOffset, but need not be reread until its
28
+ // exact file revision changes. The indexer's schema/identity/quick_check gates still run.
29
+ const tailObservations = new WeakMap<Database, {
30
+ path: string;
31
+ revision: string;
32
+ nextOffset: number;
33
+ endOffset: number | undefined;
34
+ }>();
35
+
36
+ function tailRevision(stat: BigIntStats): string {
37
+ return [stat.dev, stat.ino, stat.birthtimeNs, stat.size, stat.mtimeNs, stat.ctimeNs].join(":");
38
+ }
39
+
26
40
  /** The ledger at the recorded path is no longer the file the rebuild started from. */
27
41
  export class RequestHistoryIndexStaleError extends Error {
28
42
  constructor(message: string) {
@@ -51,6 +65,7 @@ function metaNumber(dbHandle: Database, key: string): number {
51
65
  }
52
66
 
53
67
  export function resetAndCreateSchema(dbHandle: Database): void {
68
+ tailObservations.delete(dbHandle);
54
69
  dbHandle.exec("DROP TABLE IF EXISTS requests");
55
70
  dbHandle.exec("DROP TABLE IF EXISTS schema_meta");
56
71
  dbHandle.exec(HISTORY_DDL);
@@ -62,6 +77,7 @@ export function resetAndCreateSchema(dbHandle: Database): void {
62
77
  }
63
78
 
64
79
  export function recordSourceMeta(dbHandle: Database, revision: UsageLogRevision | null): void {
80
+ tailObservations.delete(dbHandle);
65
81
  setMeta(dbHandle, HISTORY_META_KEYS.sourcePath, revision?.path ?? "");
66
82
  setMeta(dbHandle, HISTORY_META_KEYS.sourceDev, revision?.dev ?? 0);
67
83
  setMeta(dbHandle, HISTORY_META_KEYS.sourceIno, revision?.ino ?? 0);
@@ -176,7 +192,7 @@ export function ingestSourceTail(
176
192
  };
177
193
 
178
194
  fd = openSync(path, "r");
179
- const stat = fstatSync(fd);
195
+ const stat = fstatSync(fd, { bigint: true });
180
196
  const expected = options.expected;
181
197
  if (expected) {
182
198
  const opened = exactFileIdentity(fd);
@@ -184,6 +200,12 @@ export function ingestSourceTail(
184
200
  throw new RequestHistoryIndexStaleError("usage log changed before indexing");
185
201
  }
186
202
  }
203
+ const revision = tailRevision(stat);
204
+ const observed = tailObservations.get(dbHandle);
205
+ if (observed?.path === path && observed.revision === revision
206
+ && observed.nextOffset === fromOffset && observed.endOffset === options.endOffset) return 0;
207
+ // A failed or interrupted attempt must never publish a reusable observation.
208
+ tailObservations.delete(dbHandle);
187
209
  const size = options.endOffset === undefined
188
210
  ? Number(stat.size)
189
211
  : Math.min(Number(stat.size), options.endOffset);
@@ -230,8 +252,11 @@ export function ingestSourceTail(
230
252
  setMeta(dbHandle, HISTORY_META_KEYS.indexedOffset, nextOffset);
231
253
  setMeta(dbHandle, HISTORY_META_KEYS.indexedRows, indexedRows + inserted);
232
254
  setMeta(dbHandle, HISTORY_META_KEYS.sourceSize, size);
233
- setMeta(dbHandle, HISTORY_META_KEYS.sourceMtimeMs, Number(stat.mtimeMs));
255
+ setMeta(dbHandle, HISTORY_META_KEYS.sourceMtimeMs, Number(stat.mtimeNs) / 1_000_000);
234
256
  setMeta(dbHandle, HISTORY_META_KEYS.builtAtMs, Date.now());
257
+ if (nextOffset < size && tailRevision(fstatSync(fd, { bigint: true })) === revision) {
258
+ tailObservations.set(dbHandle, { path, revision, nextOffset, endOffset: options.endOffset });
259
+ }
235
260
  return inserted;
236
261
  } finally {
237
262
  if (fd !== undefined) closeSync(fd);
@@ -1,5 +1,5 @@
1
1
  import { providerRelativeSendPathConfigError } from "../config/provider-relative-send-path";
2
- import { contextTierRecordConfigError, modelCapabilitiesConfigError } from "../config/provider-validation";
2
+ import { contextTierRecordConfigError, modelCapabilitiesConfigError, providerInputModalitiesConfigError } from "../config/provider-validation";
3
3
  import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
4
4
  import { initialModelSelection } from "../providers/initial-model-selection";
5
5
  import { extractAccountId } from "../oauth/chatgpt";
@@ -747,7 +747,7 @@ export function providerManagementConfigError(
747
747
  }
748
748
  const contextTiersError = contextTierRecordConfigError(raw.modelContextTiers);
749
749
  if (contextTiersError) return contextTiersError;
750
- const capabilitiesError = modelCapabilitiesConfigError(raw.modelCapabilities);
750
+ const capabilitiesError = providerInputModalitiesConfigError(raw.inputModalities) ?? modelCapabilitiesConfigError(raw.modelCapabilities);
751
751
  if (capabilitiesError) return capabilitiesError;
752
752
  const pinsError = providerReasoningPinsConfigError(raw);
753
753
  if (pinsError) return pinsError;
@@ -1110,6 +1110,7 @@ const PROVIDER_CONFIG_FIELD_POLICY = {
1110
1110
  modelContextWindows: "editor",
1111
1111
  modelContextTiers: "editor",
1112
1112
  modelInputModalities: "editor",
1113
+ inputModalities: "editor",
1113
1114
  modelCapabilities: "editor",
1114
1115
  modelMaxInputTokens: "runtime",
1115
1116
  modelAutoCompactTokenLimits: "editor",
@@ -350,6 +350,13 @@ async function handleChatCompletionsWithBudget(
350
350
  // and sends the core only the request settings.
351
351
  if (directRoute) {
352
352
  directConversation = chatConversationToIr(chatBody, chatBody.model as string);
353
+ // Unlike the bridge body below, the settings-only projection does not contain the
354
+ // conversation. Account for the retained IR itself before an adapter materializes it
355
+ // again; reasoning placeholders can be larger than the source Chat message.
356
+ translatorBudget.chargeRetained(
357
+ Buffer.byteLength(JSON.stringify(directConversation), "utf8"),
358
+ { kind: "request_copies" },
359
+ );
353
360
  internalBody = chatSettingsBody(chatBody);
354
361
  } else {
355
362
  internalBody = chatToResponsesBody(chatBody, {
@@ -1,4 +1,5 @@
1
1
  import { chatBodyCarriesImage, chatBodyCarriesToolResultImage } from "../chat/image-parts";
2
+ import { chatBodyCarriesAnthropicReasoningState } from "../chat/reasoning-details";
2
3
  import type { ProtocolReasonCode } from "../protocols/contract";
3
4
  import type { RouteResult } from "../router";
4
5
  import type { OcxConfig } from "../types";
@@ -20,6 +21,7 @@ export type NativeChatDeclineReason = Extract<
20
21
  | "tool-result-image"
21
22
  | "vision-preprocessing"
22
23
  | "hosted-tool"
24
+ | "opaque-state-stripped"
23
25
  >;
24
26
 
25
27
  /**
@@ -40,6 +42,11 @@ export function nativeChatDeclineReason(
40
42
  if (rawBody.store === true || rawBody.background === true) return "responses-only-feature";
41
43
  if (typeof rawBody.previous_response_id === "string" && rawBody.previous_response_id.length > 0) return "responses-only-feature";
42
44
  if (rawBody.compaction_trigger !== undefined) return "responses-only-feature";
45
+ // Native Chat preserves caller message objects verbatim. Anthropic reasoning state — an entry
46
+ // with the anthropic-claude-v1 marker or an unmarked signed reasoning.text the inbound replay
47
+ // accepts — can contain signatures or redacted-thinking ciphertext, so use the bridge that
48
+ // projects it to plaintext rather than disclosing it to an unrelated Chat destination.
49
+ if (chatBodyCarriesAnthropicReasoningState(rawBody)) return "opaque-state-stripped";
43
50
  // A standard Chat tool message accepts a string or text parts, not image_url, so
44
51
  // normalizing a Pi/Anthropic tool image into image_url is not enough on its own —
45
52
  // the part is still inside a tool message. The translated adapter already places
@@ -82,8 +82,13 @@ export function nativeChatReasoningCapture(
82
82
  return previous + fragment;
83
83
  } finally { reservation.release(); }
84
84
  };
85
- if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
86
- const text = append(state.text, delta.reasoning_content);
85
+ const rText = typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0
86
+ ? delta.reasoning_content
87
+ : typeof delta.reasoning === "string" && delta.reasoning.length > 0
88
+ ? delta.reasoning
89
+ : undefined;
90
+ if (rText !== undefined) {
91
+ const text = append(state.text, rText);
87
92
  if (text === undefined) return;
88
93
  state.text = text;
89
94
  }
@@ -121,8 +126,13 @@ export function nativeChatReasoningCapture(
121
126
  for (const choice of value.choices) {
122
127
  if (!isChatRecord(choice) || !isChatRecord(choice.message)) continue;
123
128
  const message = choice.message;
124
- if (typeof message.reasoning_content !== "string" || !Array.isArray(message.tool_calls)) continue;
125
- remember(message.reasoning_content, message.tool_calls.filter(isChatRecord)
129
+ const rText = typeof message.reasoning_content === "string" && message.reasoning_content.length > 0
130
+ ? message.reasoning_content
131
+ : typeof message.reasoning === "string" && message.reasoning.length > 0
132
+ ? message.reasoning
133
+ : undefined;
134
+ if (rText === undefined || !Array.isArray(message.tool_calls)) continue;
135
+ remember(rText, message.tool_calls.filter(isChatRecord)
126
136
  .flatMap(tool => typeof tool.id === "string" ? [tool.id] : []));
127
137
  }
128
138
  },
@@ -7,6 +7,8 @@ type DirectLocalHttpIo = {
7
7
  timeoutMs?: number;
8
8
  connect?: (hostname: string, port: number) => Socket;
9
9
  scheduleDeadline?: (onTimeout: () => void, timeoutMs: number) => () => void;
10
+ /** Observe a parsed response status before reading its bounded body. */
11
+ onResponseStatus?: (status: number) => void;
10
12
  };
11
13
 
12
14
  function abortReason(signal: AbortSignal): Error {
@@ -96,7 +98,7 @@ function parseResponseHead(bytes: Buffer, boundary: number): {
96
98
  return { status, statusText: match[2] ?? "", headers };
97
99
  }
98
100
 
99
- function advanceResponseFraming(bytes: Buffer, initial: ResponseFraming): ResponseFraming {
101
+ function advanceResponseFraming(bytes: Buffer, initial: ResponseFraming, onResponseStatus?: (status: number) => void): ResponseFraming {
100
102
  let framing = initial;
101
103
  for (;;) {
102
104
  if (framing.kind === "complete" || framing.kind === "close") return framing;
@@ -107,6 +109,7 @@ function advanceResponseFraming(bytes: Buffer, initial: ResponseFraming): Respon
107
109
  return { kind: "head", searchFrom: Math.max(0, bytes.length - 3) };
108
110
  }
109
111
  const { status, headers } = parseResponseHead(bytes, boundary);
112
+ onResponseStatus?.(status);
110
113
  const bodyStart = boundary + 4;
111
114
  if (status === 204 || status === 205 || status === 304) {
112
115
  if (bytes.length > bodyStart) {
@@ -350,7 +353,7 @@ export async function directLocalHttpFetch(
350
353
  }
351
354
  bytes.copy(responseBytes, receivedBytes - bytes.byteLength);
352
355
  try {
353
- framing = advanceResponseFraming(responseBytes.subarray(0, receivedBytes), framing);
356
+ framing = advanceResponseFraming(responseBytes.subarray(0, receivedBytes), framing, io.onResponseStatus);
354
357
  if (framing.kind === "complete") finish();
355
358
  } catch (error) {
356
359
  finish(error instanceof Error ? error : new Error(String(error)));
@@ -232,6 +232,7 @@ interface EffortSnapshot {
232
232
  modelId: string;
233
233
  reasoningPresent: boolean;
234
234
  reasoning: OcxParsedRequest["options"]["reasoning"];
235
+ thinkingEnabled: boolean | undefined;
235
236
  rawEffortPresent: boolean;
236
237
  rawEffort: unknown;
237
238
  }
@@ -239,7 +240,7 @@ interface EffortSnapshot {
239
240
  const effortSnapshots = new WeakMap<OcxParsedRequest, EffortSnapshot>();
240
241
 
241
242
  /** Capture effective synthetic/combo defaults before final model namespace rewriting.
242
- * A different destination restores effort alone; intervening summary/options edits survive.
243
+ * A different destination restores effort and thinking choice; intervening summary edits survive.
243
244
  * Credential retries do not change the destination and retain their existing decision.
244
245
  */
245
246
  export function prepareEffortNormalization(
@@ -255,6 +256,7 @@ export function prepareEffortNormalization(
255
256
  modelId: route.modelId,
256
257
  reasoningPresent: Object.hasOwn(parsed.options, "reasoning"),
257
258
  reasoning: parsed.options.reasoning,
259
+ thinkingEnabled: parsed.options.thinkingEnabled,
258
260
  rawEffortPresent: !!raw?.reasoning && Object.hasOwn(raw.reasoning, "effort"),
259
261
  rawEffort: raw?.reasoning?.effort,
260
262
  });
@@ -265,6 +267,8 @@ export function prepareEffortNormalization(
265
267
  }
266
268
  if (previous.reasoningPresent) parsed.options.reasoning = previous.reasoning;
267
269
  else delete parsed.options.reasoning;
270
+ if (previous.thinkingEnabled !== undefined) parsed.options.thinkingEnabled = previous.thinkingEnabled;
271
+ else delete parsed.options.thinkingEnabled;
268
272
  if (raw && previous.rawEffortPresent) {
269
273
  if (!raw.reasoning || typeof raw.reasoning !== "object") raw.reasoning = {};
270
274
  raw.reasoning.effort = previous.rawEffort;
@@ -184,6 +184,19 @@ function finalizeLiveSideband(ws: ServerWebSocket<WsData>, upstream?: WebSocket)
184
184
  finally { releaseLiveSidebandAdmission(ws); }
185
185
  }
186
186
 
187
+ function forceCloseLiveSidebandUpstream(upstream: WebSocket): void {
188
+ // Bun 1.4.4 waits for the peer's closing handshake; another close() while
189
+ // CLOSING does not finish it. Stop the transport after the graceful window,
190
+ // but leave admission release to the close event or an observed CLOSED state.
191
+ try {
192
+ const socket = upstream as WebSocket & { terminate?: () => void };
193
+ if (typeof socket.terminate === "function") socket.terminate();
194
+ else upstream.close(1000, "upstream close timeout");
195
+ } catch {
196
+ /* retain ownership until transport closure is confirmed */
197
+ }
198
+ }
199
+
187
200
  function armLiveSidebandCloseFallback(ws: ServerWebSocket<WsData>, upstream: WebSocket): void {
188
201
  if (ws.data.liveCloseFallback !== undefined) return;
189
202
  ws.data.liveCloseFallback = setTimeout(() => {
@@ -193,13 +206,7 @@ function armLiveSidebandCloseFallback(ws: ServerWebSocket<WsData>, upstream: Web
193
206
  finalizeLiveSideband(ws, upstream);
194
207
  return;
195
208
  }
196
- // A close frame was already sent below. Retry once, but never surrender
197
- // native-main ownership while the authenticated transport remains live.
198
- try {
199
- upstream.close(1000, "upstream close timeout");
200
- } catch {
201
- /* upstream is already unusable */
202
- }
209
+ forceCloseLiveSidebandUpstream(upstream);
203
210
  // Some implementations transition synchronously without delivering the
204
211
  // close event. That is still an observed CLOSED transport and is safe to
205
212
  // finalize. CONNECTING/CLOSING peers keep the lease so profile switching
@@ -238,17 +245,13 @@ export function closeLiveSidebandBeforeUpgrade(
238
245
  releaseOnce();
239
246
  return;
240
247
  }
241
- try {
242
- upstream.close(1000, "upstream close timeout");
243
- } catch {
244
- /* retain ownership until CLOSED is observed */
245
- }
248
+ forceCloseLiveSidebandUpstream(upstream);
246
249
  if ((upstream.readyState as number) === 3) releaseOnce();
247
250
  }, LIVE_SIDEBAND_CLOSE_FALLBACK_MS);
248
251
  try {
249
252
  upstream.close(code, reason);
250
253
  } catch {
251
- /* the bounded fallback retries without releasing ownership */
254
+ /* the bounded fallback stops the transport before releasing ownership */
252
255
  }
253
256
  if ((upstream.readyState as number) === 3) releaseOnce();
254
257
  }
@@ -272,12 +275,12 @@ export function closeLiveSideband(ws: ServerWebSocket<WsData>, code = 1000, reas
272
275
  // The sideband holds a native-main admission lease. Do not release it just
273
276
  // because the downstream left: its authenticated upstream remains live
274
277
  // until the close event arrives or the transport is observed CLOSED. The
275
- // bounded fallback only retries close; it does not release ownership.
278
+ // bounded fallback terminates the transport; it cannot release a live lease.
276
279
  armLiveSidebandCloseFallback(ws, upstream);
277
280
  try {
278
281
  upstream.close(code, reason);
279
282
  } catch {
280
- /* the fallback retries close without releasing ownership */
283
+ /* the fallback stops the transport without releasing a live lease */
281
284
  }
282
285
  }
283
286
  try {
@@ -1304,9 +1304,10 @@ export function createServeOptions(ctx: ServeOptionsContext) {
1304
1304
  ...(effectiveId !== publicId ? { native_id: publicId } : {}),
1305
1305
  ...grokEffortFields(m.reasoningEfforts ?? [], m.defaultReasoningEffort),
1306
1306
  ...modelCapabilityFields({
1307
+ supportsReasoning: m.supportsReasoning, supportsReasoningEffort: m.supportsReasoningEffort,
1308
+ supportsThinkingToggle: m.supportsThinkingToggle, defaultThinkingEnabled: m.defaultThinkingEnabled,
1307
1309
  reasoningEfforts: m.reasoningEfforts,
1308
- // contextWindow is already the post-cap effective value; contextCap is the raw
1309
- // operator knob and over-reports models whose real window sits below it.
1310
+ // Use the post-cap window; the raw contextCap can exceed a model's real window.
1310
1311
  contextWindow: m.contextWindow,
1311
1312
  maxOutputTokens: m.maxOutputTokens,
1312
1313
  inputModalities: m.inputModalities,
@@ -1766,7 +1767,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
1766
1767
  if (audioController) registerTurn(audioController, turnAdmissionLease);
1767
1768
  const acquisition = audioController
1768
1769
  ? clearableDeadline(120_000, AbortSignal.any([req.signal, audioController.signal])) : undefined;
1769
- const detachClientAbort = turnAdmissionLease.bindAbortSignal(req.signal);
1770
+ const detachClientAbort = turnAdmissionLease.bindAbortSignal(req.signal); // detached at the dial; then close/CLOSED owns release
1770
1771
  const releaseAcquisition = () => {
1771
1772
  detachClientAbort();
1772
1773
  acquisition?.clear();
@@ -1819,6 +1820,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
1819
1820
  finally { finalizeLiveRequest(499, { closeReason: "client_cancel" }); }
1820
1821
  return withCors(formatErrorResponse(499, "client_closed_request", "Audio connection canceled"), req, policy);
1821
1822
  }
1823
+ detachClientAbort();
1822
1824
  const upstreamHandshake = await openLiveSidebandUpstream(
1823
1825
  resolved.upstreamWsUrl,
1824
1826
  resolved.headers,
@@ -1887,7 +1889,6 @@ export function createServeOptions(ctx: ServeOptionsContext) {
1887
1889
  return withCors(formatErrorResponse(502, "upstream_error", "Audio WebSocket upgrade failed"), req, policy);
1888
1890
  }
1889
1891
  if (upgraded) {
1890
- detachClientAbort();
1891
1892
  acquisition?.clear();
1892
1893
  finalizeLiveRequest(101);
1893
1894
  return undefined as unknown as Response;