@bitkyc08/opencodex 2.97.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.
Files changed (290) hide show
  1. package/bin/ocx.mjs +1 -1
  2. package/gui/dist/assets/App-6TFtZsUF.css +1 -0
  3. package/gui/dist/assets/App-B8_sOxoz.js +59 -0
  4. package/gui/dist/assets/Tray-DpWEp6ee.js +1 -0
  5. package/gui/dist/assets/WantedSansVariable.split.0-Dwvb1WRx.woff2 +0 -0
  6. package/gui/dist/assets/WantedSansVariable.split.1-1wKD2RxI.woff2 +0 -0
  7. package/gui/dist/assets/WantedSansVariable.split.10-CAKA6LIP.woff2 +0 -0
  8. package/gui/dist/assets/WantedSansVariable.split.11-k5H85R4b.woff2 +0 -0
  9. package/gui/dist/assets/WantedSansVariable.split.12-BHboLsUv.woff2 +0 -0
  10. package/gui/dist/assets/WantedSansVariable.split.13-9GV377ix.woff2 +0 -0
  11. package/gui/dist/assets/WantedSansVariable.split.14-DovDXnrj.woff2 +0 -0
  12. package/gui/dist/assets/WantedSansVariable.split.15-DTdykCig.woff2 +0 -0
  13. package/gui/dist/assets/WantedSansVariable.split.16-CKz2ccgK.woff2 +0 -0
  14. package/gui/dist/assets/WantedSansVariable.split.17-Z2RD_KRZ.woff2 +0 -0
  15. package/gui/dist/assets/WantedSansVariable.split.18-BcKtfonJ.woff2 +0 -0
  16. package/gui/dist/assets/WantedSansVariable.split.19-DEQPOSZn.woff2 +0 -0
  17. package/gui/dist/assets/WantedSansVariable.split.2-DryboyuA.woff2 +0 -0
  18. package/gui/dist/assets/WantedSansVariable.split.20-Bia5JMls.woff2 +0 -0
  19. package/gui/dist/assets/WantedSansVariable.split.21-Cr4jFw-E.woff2 +0 -0
  20. package/gui/dist/assets/WantedSansVariable.split.22-DjjB69TZ.woff2 +0 -0
  21. package/gui/dist/assets/WantedSansVariable.split.23-CvUzJskt.woff2 +0 -0
  22. package/gui/dist/assets/WantedSansVariable.split.24-i_eMg5ox.woff2 +0 -0
  23. package/gui/dist/assets/WantedSansVariable.split.25-2aKHwPX-.woff2 +0 -0
  24. package/gui/dist/assets/WantedSansVariable.split.26-B6wXoCEL.woff2 +0 -0
  25. package/gui/dist/assets/WantedSansVariable.split.27-D4h1WfGM.woff2 +0 -0
  26. package/gui/dist/assets/WantedSansVariable.split.28-kvRPCStd.woff2 +0 -0
  27. package/gui/dist/assets/WantedSansVariable.split.29-DHAiwleD.woff2 +0 -0
  28. package/gui/dist/assets/WantedSansVariable.split.3-7H--eyZi.woff2 +0 -0
  29. package/gui/dist/assets/WantedSansVariable.split.30-C66cfAY2.woff2 +0 -0
  30. package/gui/dist/assets/WantedSansVariable.split.31-FDmtiNim.woff2 +0 -0
  31. package/gui/dist/assets/WantedSansVariable.split.32-DouHt2Dd.woff2 +0 -0
  32. package/gui/dist/assets/WantedSansVariable.split.33-B8HVvkJX.woff2 +0 -0
  33. package/gui/dist/assets/WantedSansVariable.split.34-BtkRu1FN.woff2 +0 -0
  34. package/gui/dist/assets/WantedSansVariable.split.35-DBylQbtk.woff2 +0 -0
  35. package/gui/dist/assets/WantedSansVariable.split.36-Sg089Kgh.woff2 +0 -0
  36. package/gui/dist/assets/WantedSansVariable.split.37-CYtvbriS.woff2 +0 -0
  37. package/gui/dist/assets/WantedSansVariable.split.38-DKkSLf8Z.woff2 +0 -0
  38. package/gui/dist/assets/WantedSansVariable.split.39-CecotKZD.woff2 +0 -0
  39. package/gui/dist/assets/WantedSansVariable.split.4-Bv8O3ZMb.woff2 +0 -0
  40. package/gui/dist/assets/WantedSansVariable.split.40-DdCvkmOU.woff2 +0 -0
  41. package/gui/dist/assets/WantedSansVariable.split.41-ESn674Hc.woff2 +0 -0
  42. package/gui/dist/assets/WantedSansVariable.split.42-DL9V7NNV.woff2 +0 -0
  43. package/gui/dist/assets/WantedSansVariable.split.43-yipO0cyk.woff2 +0 -0
  44. package/gui/dist/assets/WantedSansVariable.split.44-6rTmLZhm.woff2 +0 -0
  45. package/gui/dist/assets/WantedSansVariable.split.45-BJAj8lrm.woff2 +0 -0
  46. package/gui/dist/assets/WantedSansVariable.split.46-BDTzMn2c.woff2 +0 -0
  47. package/gui/dist/assets/WantedSansVariable.split.47-Bxd4wGgi.woff2 +0 -0
  48. package/gui/dist/assets/WantedSansVariable.split.48-DxnFBLnH.woff2 +0 -0
  49. package/gui/dist/assets/WantedSansVariable.split.49-DnVD0aOD.woff2 +0 -0
  50. package/gui/dist/assets/WantedSansVariable.split.5-B1wI2pp5.woff2 +0 -0
  51. package/gui/dist/assets/WantedSansVariable.split.50-D9JlkZd6.woff2 +0 -0
  52. package/gui/dist/assets/WantedSansVariable.split.51-D9Vw6Bu3.woff2 +0 -0
  53. package/gui/dist/assets/WantedSansVariable.split.52-ClEJk4kn.woff2 +0 -0
  54. package/gui/dist/assets/WantedSansVariable.split.53-BSXU0vh-.woff2 +0 -0
  55. package/gui/dist/assets/WantedSansVariable.split.54-EcuxkR9v.woff2 +0 -0
  56. package/gui/dist/assets/WantedSansVariable.split.55-CYiFhQX8.woff2 +0 -0
  57. package/gui/dist/assets/WantedSansVariable.split.56--Gk9g8BK.woff2 +0 -0
  58. package/gui/dist/assets/WantedSansVariable.split.57-DnkOPZcy.woff2 +0 -0
  59. package/gui/dist/assets/WantedSansVariable.split.58-9MB8504z.woff2 +0 -0
  60. package/gui/dist/assets/WantedSansVariable.split.59-ByxIsN72.woff2 +0 -0
  61. package/gui/dist/assets/WantedSansVariable.split.6-Bmk0dRVw.woff2 +0 -0
  62. package/gui/dist/assets/WantedSansVariable.split.60-Bxwx_aWQ.woff2 +0 -0
  63. package/gui/dist/assets/WantedSansVariable.split.61-DA2z5sm7.woff2 +0 -0
  64. package/gui/dist/assets/WantedSansVariable.split.62-C5iJPJZn.woff2 +0 -0
  65. package/gui/dist/assets/WantedSansVariable.split.63-DAqrmaEc.woff2 +0 -0
  66. package/gui/dist/assets/WantedSansVariable.split.64-BgXFsljb.woff2 +0 -0
  67. package/gui/dist/assets/WantedSansVariable.split.65-DKiWujvu.woff2 +0 -0
  68. package/gui/dist/assets/WantedSansVariable.split.66-8po4vUZ4.woff2 +0 -0
  69. package/gui/dist/assets/WantedSansVariable.split.67-Cy5qyI9O.woff2 +0 -0
  70. package/gui/dist/assets/WantedSansVariable.split.68-BKny7Fy3.woff2 +0 -0
  71. package/gui/dist/assets/WantedSansVariable.split.69-B4VU4u_b.woff2 +0 -0
  72. package/gui/dist/assets/WantedSansVariable.split.7-BuqwNpgA.woff2 +0 -0
  73. package/gui/dist/assets/WantedSansVariable.split.70-BCd4n346.woff2 +0 -0
  74. package/gui/dist/assets/WantedSansVariable.split.71-CkQppaWn.woff2 +0 -0
  75. package/gui/dist/assets/WantedSansVariable.split.72-Db7vaoFs.woff2 +0 -0
  76. package/gui/dist/assets/WantedSansVariable.split.73-DI80TYWl.woff2 +0 -0
  77. package/gui/dist/assets/WantedSansVariable.split.74-tMCtDAHB.woff2 +0 -0
  78. package/gui/dist/assets/WantedSansVariable.split.75-Ciw0D5WG.woff2 +0 -0
  79. package/gui/dist/assets/WantedSansVariable.split.76-DoLjFgp-.woff2 +0 -0
  80. package/gui/dist/assets/WantedSansVariable.split.77-CpT2uvMy.woff2 +0 -0
  81. package/gui/dist/assets/WantedSansVariable.split.78-CkcJ4iZ1.woff2 +0 -0
  82. package/gui/dist/assets/WantedSansVariable.split.79-DsOUJjEM.woff2 +0 -0
  83. package/gui/dist/assets/WantedSansVariable.split.8-DsjypPd6.woff2 +0 -0
  84. package/gui/dist/assets/WantedSansVariable.split.80-C0VwHTte.woff2 +0 -0
  85. package/gui/dist/assets/WantedSansVariable.split.81-DTelu57i.woff2 +0 -0
  86. package/gui/dist/assets/WantedSansVariable.split.82-BiMndGN1.woff2 +0 -0
  87. package/gui/dist/assets/WantedSansVariable.split.83-CVcC6eDG.woff2 +0 -0
  88. package/gui/dist/assets/WantedSansVariable.split.84-DlhZVt_O.woff2 +0 -0
  89. package/gui/dist/assets/WantedSansVariable.split.85-S8I2D3pA.woff2 +0 -0
  90. package/gui/dist/assets/WantedSansVariable.split.86-DozXXpH5.woff2 +0 -0
  91. package/gui/dist/assets/WantedSansVariable.split.87-Dsn0Vuuo.woff2 +0 -0
  92. package/gui/dist/assets/WantedSansVariable.split.88-iNwxxDCr.woff2 +0 -0
  93. package/gui/dist/assets/WantedSansVariable.split.89-B63u_9CZ.woff2 +0 -0
  94. package/gui/dist/assets/WantedSansVariable.split.9-Bi3IzpMI.woff2 +0 -0
  95. package/gui/dist/assets/WantedSansVariable.split.90-ByeH1Pqf.woff2 +0 -0
  96. package/gui/dist/assets/WantedSansVariable.split.91-UQLlagpm.woff2 +0 -0
  97. package/gui/dist/assets/brand-mark-VPhzz-WE.js +1 -0
  98. package/gui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  99. package/gui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  100. package/gui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  101. package/gui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  102. package/gui/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
  103. package/gui/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
  104. package/gui/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
  105. package/gui/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
  106. package/gui/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
  107. package/gui/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
  108. package/gui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  109. package/gui/dist/assets/index-5REODpG3.css +2 -0
  110. package/gui/dist/assets/index-BWKBeK77.js +94 -0
  111. package/gui/dist/assets/segment-thumb-features-BQYzrze9.js +1 -0
  112. package/gui/dist/classic/assets/App-Bz65x1J6.js +58 -0
  113. package/gui/dist/{assets/Tray-CEw0y0jR.js → classic/assets/Tray-kk7mdO6I.js} +1 -1
  114. package/gui/dist/classic/assets/index-Dp2j8bSc.js +94 -0
  115. package/gui/dist/classic/assets/quota-summary-CvamtHjB.js +1 -0
  116. package/gui/dist/classic/index.html +47 -0
  117. package/gui/dist/favicon.png +0 -0
  118. package/gui/dist/favicon.svg +14 -0
  119. package/gui/dist/index.html +15 -2
  120. package/package.json +1 -1
  121. package/src/adapters/anthropic.ts +17 -8
  122. package/src/adapters/google.ts +7 -7
  123. package/src/adapters/kiro/adapter.ts +18 -3
  124. package/src/adapters/kiro/conversation.ts +8 -8
  125. package/src/adapters/kiro/payload.ts +45 -12
  126. package/src/adapters/kiro/stream.ts +169 -12
  127. package/src/adapters/kiro/structured-output-json.ts +191 -0
  128. package/src/adapters/kiro/structured-output-schema.ts +542 -0
  129. package/src/adapters/kiro/structured-output.ts +367 -0
  130. package/src/adapters/kiro-constants.ts +9 -0
  131. package/src/adapters/kiro-tools.ts +14 -9
  132. package/src/adapters/kiro-wire.ts +9 -5
  133. package/src/adapters/openai-chat/messages.ts +58 -5
  134. package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
  135. package/src/adapters/openai-chat/passthrough.ts +5 -3
  136. package/src/adapters/openai-chat/tool-schema.ts +83 -13
  137. package/src/adapters/openai-responses/opengateway-input.ts +18 -6
  138. package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
  139. package/src/adapters/qoder/live-models.ts +115 -1
  140. package/src/claude/failure-verdict.ts +21 -0
  141. package/src/claude/inbound-content-options.ts +15 -2
  142. package/src/claude/inbound-model-options.ts +2 -1
  143. package/src/claude/inbound-records.ts +2 -0
  144. package/src/claude/inbound.ts +17 -11
  145. package/src/claude/outbound.ts +52 -23
  146. package/src/cli/capabilities-access-remote.ts +13 -0
  147. package/src/cli/capabilities-base.ts +1 -0
  148. package/src/cli/capabilities-provider-models.ts +3 -3
  149. package/src/cli/codex-shim-autorestore.ts +7 -0
  150. package/src/cli/config-command.ts +11 -2
  151. package/src/cli/connect.ts +17 -2
  152. package/src/cli/dispatch.ts +3 -1
  153. package/src/cli/doctor.ts +95 -7
  154. package/src/cli/index.ts +12 -7
  155. package/src/cli/link-apply-restart.ts +9 -2
  156. package/src/cli/models.ts +124 -38
  157. package/src/cli/registry.ts +1 -1
  158. package/src/cli/restart-failure.ts +17 -0
  159. package/src/cli/stop-approval.ts +2 -2
  160. package/src/cli/sync-command.ts +1 -1
  161. package/src/cli/sync-fanout.ts +15 -4
  162. package/src/cli/system-restart-client.ts +5 -0
  163. package/src/cli/uninstall-client-state.ts +12 -1
  164. package/src/cli/update-restart-child.ts +13 -3
  165. package/src/cli/update-restart-home.ts +6 -3
  166. package/src/cli/update-restart.ts +36 -19
  167. package/src/client/connect.ts +4 -1
  168. package/src/client/hub-client.ts +5 -0
  169. package/src/client/link-management-relay.ts +39 -2
  170. package/src/client/link-readiness.ts +3 -1
  171. package/src/client/machine-api.ts +2 -1
  172. package/src/client/machine-listener.ts +7 -0
  173. package/src/client/orphan-token-recovery.ts +322 -0
  174. package/src/codex/catalog/provider-models.ts +12 -4
  175. package/src/codex/native-profile-api.ts +27 -1
  176. package/src/codex/shim-diagnostics.ts +7 -0
  177. package/src/codex/shim-legacy-record.ts +290 -0
  178. package/src/codex/shim-windows-refresh.ts +9 -2
  179. package/src/codex/shim-wrapper-write.ts +7 -0
  180. package/src/codex/shim.ts +80 -21
  181. package/src/config/diagnostics.ts +9 -9
  182. package/src/config/load-degrade.ts +27 -27
  183. package/src/config/provider-validation.ts +9 -2
  184. package/src/config/removed-opencode-free-backup.ts +6 -3
  185. package/src/config/tracked-runtime-inspection.ts +3 -3
  186. package/src/generated/compatibility-version.json +219 -147
  187. package/src/images/loop.ts +2 -2
  188. package/src/lib/client-error-body.ts +37 -6
  189. package/src/lib/config-ownership-removal.ts +422 -0
  190. package/src/lib/config-ownership.ts +646 -81
  191. package/src/lib/context-overflow-verdict.ts +3 -3
  192. package/src/lib/crash-guard.ts +4 -2
  193. package/src/lib/desktop-cli-handoff.d.mts +3 -4
  194. package/src/lib/desktop-cli-handoff.mjs +7 -16
  195. package/src/lib/errors.ts +1 -0
  196. package/src/lib/local-management-capability.ts +3 -1
  197. package/src/lib/messages-error-body.ts +162 -0
  198. package/src/lib/messages-sse-error-presentation.ts +93 -0
  199. package/src/lib/passive-read.ts +9 -4
  200. package/src/lib/socks5-fetch.ts +21 -9
  201. package/src/lib/upstream-retry.ts +81 -1
  202. package/src/lib/windows-owner-acl.ts +9 -3
  203. package/src/lib/winsw.ts +5 -5
  204. package/src/lib/workflow-budget.ts +3 -1
  205. package/src/oauth/index.ts +7 -0
  206. package/src/oauth/store.ts +20 -10
  207. package/src/protocols/codecs/messages-ir.ts +15 -9
  208. package/src/protocols/encoders/adapter-events.ts +26 -7
  209. package/src/protocols/encoders/messages.ts +72 -28
  210. package/src/providers/antigravity-models.ts +45 -12
  211. package/src/providers/free-directory.ts +2 -2
  212. package/src/providers/reasoning-metadata.ts +2 -1
  213. package/src/providers/registry/entries-extended.ts +9 -0
  214. package/src/reasoning-effort.ts +7 -2
  215. package/src/remote/hub-usage.ts +3 -0
  216. package/src/server/admission-model-scope.ts +1 -1
  217. package/src/server/admitted-http-turn.ts +2 -1
  218. package/src/server/anthropic-rate-limit-headers.ts +75 -3
  219. package/src/server/claude-messages.ts +130 -67
  220. package/src/server/gui-static.ts +4 -1
  221. package/src/server/hub-usage.ts +7 -2
  222. package/src/server/index/link-management.ts +8 -0
  223. package/src/server/index/ollama-routes.ts +2 -0
  224. package/src/server/index/serve-options.ts +23 -20
  225. package/src/server/index/startup-warnings.ts +5 -12
  226. package/src/server/index/websocket-handler.ts +1 -0
  227. package/src/server/inference/client-encoder-delivery.ts +5 -1
  228. package/src/server/management/logs-usage-routes.ts +89 -4
  229. package/src/server/management/provider-routes.ts +2 -22
  230. package/src/server/management/qoder-provider-probe.ts +105 -0
  231. package/src/server/management/route-registry.ts +3 -0
  232. package/src/server/management/usage-aggregate-cache.ts +15 -5
  233. package/src/server/management/usage-source-facets.ts +38 -0
  234. package/src/server/messages-native-tool-guard.ts +11 -3
  235. package/src/server/messages-native.ts +111 -40
  236. package/src/server/messages-response-headers.ts +25 -11
  237. package/src/server/messages-shared.ts +94 -64
  238. package/src/server/messages-sse-error-filter.ts +199 -0
  239. package/src/server/request-log.ts +12 -0
  240. package/src/server/responses/adapter-continuation.ts +11 -5
  241. package/src/server/responses/adapter-delivery.ts +14 -8
  242. package/src/server/responses/adapter-dispatch.ts +8 -8
  243. package/src/server/responses/anthropic-thinking-recovery.ts +2 -2
  244. package/src/server/responses/codex-auth-error.ts +8 -4
  245. package/src/server/responses/codex-ws-wire.ts +19 -3
  246. package/src/server/responses/compact.ts +4 -1
  247. package/src/server/responses/core-auth.ts +1 -1
  248. package/src/server/responses/core-combo-failure.ts +2 -0
  249. package/src/server/responses/core-combo.ts +2 -0
  250. package/src/server/responses/core-errors.ts +5 -4
  251. package/src/server/responses/core-options.ts +2 -0
  252. package/src/server/responses/empty-completion-guard.ts +4 -1
  253. package/src/server/responses/pacing-overload.ts +1 -1
  254. package/src/server/responses/passthrough-dispatch.ts +5 -5
  255. package/src/server/responses/request-prepare.ts +3 -1
  256. package/src/server/responses/request-transport.ts +9 -8
  257. package/src/server/responses/response-effects.ts +3 -2
  258. package/src/server/responses/terminal-guard.ts +30 -0
  259. package/src/server/restart-replacement.ts +3 -1
  260. package/src/server/sse-payload-rewrite.ts +23 -11
  261. package/src/server/workflow-refusal.ts +1 -1
  262. package/src/server/ws-bridge.ts +4 -0
  263. package/src/service/definition.ts +36 -4
  264. package/src/service/launchd.ts +89 -32
  265. package/src/service/logging.ts +34 -7
  266. package/src/service/plist-xml.ts +59 -0
  267. package/src/service/state.ts +8 -0
  268. package/src/service/systemd-env.ts +2 -0
  269. package/src/service/systemd.ts +31 -7
  270. package/src/service/windows-taskxml.ts +16 -7
  271. package/src/service-manager-probe.ts +4 -10
  272. package/src/types/provider.ts +2 -0
  273. package/src/types/request.ts +13 -1
  274. package/src/update/config-preflight.ts +48 -0
  275. package/src/update/index.ts +15 -1
  276. package/src/usage/client.ts +43 -0
  277. package/src/usage/error-detail.ts +1 -1
  278. package/src/usage/log.ts +4 -0
  279. package/src/usage/source-facets.ts +51 -0
  280. package/src/usage/source-filter.ts +65 -0
  281. package/src/usage/summary.ts +50 -8
  282. package/src/web-search/anthropic-executor.ts +105 -24
  283. package/src/web-search/executor.ts +5 -3
  284. package/src/web-search/loop.ts +2 -1
  285. package/src/web-search/progress-stream.ts +64 -5
  286. package/gui/dist/assets/App-DuNhggE1.js +0 -58
  287. package/gui/dist/assets/index-CynE_Rue.js +0 -94
  288. package/gui/dist/assets/quota-summary-VHFSlUuM.js +0 -1
  289. /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
  290. /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
@@ -1,4 +1,4 @@
1
- import { isProxyError, rememberProxyErrorMessage } from "../../lib/client-error-body";
1
+ import { proxyErrorPresentation, isProxyError, rememberProxyErrorMessage } from "../../lib/client-error-body";
2
2
  import type { ResponsesRequestContext } from "./core-options";
3
3
  import type { PreparedResponsesRequest } from "./request-prepare";
4
4
  import type { ResponsesTransport } from "./request-transport";
@@ -57,7 +57,7 @@ export async function deliverAdapterResponse(
57
57
  >,
58
58
  completionPolicy: Pick<ResponsesCompletionPolicy, "emptyCompletionGuardEnabled">,
59
59
  adapterExchange: Pick<AdapterExchange, "upstreamResponse" | "upstream" | "cleanupUpstreamAbort" | "localUpstream" | "thinkingSignatureRecovery" | "refetchThinkingSignature">,
60
- continuationState: Pick<AdapterContinuations, "terminalGuardEnabled" | "fetchTerminalGuardContinuation" | "fetchGuardedEmptyCompletionRetry">,
60
+ continuationState: Pick<AdapterContinuations, "terminalGuardEnabled" | "fetchTerminalGuardContinuation" | "fetchGuardedEmptyCompletionRetry" | "isContinuationBodyStall">,
61
61
  ): Promise<Response> {
62
62
  const { logCtx, options, config } = requestContext;
63
63
  const {
@@ -73,6 +73,7 @@ export async function deliverAdapterResponse(
73
73
  terminalGuardEnabled,
74
74
  fetchTerminalGuardContinuation,
75
75
  fetchGuardedEmptyCompletionRetry,
76
+ isContinuationBodyStall,
76
77
  } = continuationState;
77
78
  const { emptyCompletionGuardEnabled } = completionPolicy;
78
79
  const {
@@ -97,7 +98,7 @@ export async function deliverAdapterResponse(
97
98
  if (nonReplayable) response = await sanitizeNonReplayableUpstreamError(response, errorSignal);
98
99
  const body = await readDisplaySafeErrorText(response, errorSignal, "Upstream recovery failed");
99
100
  const error = normalizeUpstreamErrorText(body, "Upstream recovery failed");
100
- if (isProxyError(response)) rememberProxyErrorMessage(logCtx, error.message ?? error.safeText, { status: response.status, type: error.type ?? "upstream_error", code: error.code });
101
+ if (isProxyError(response)) rememberProxyErrorMessage(logCtx, error.message ?? error.safeText, { status: response.status, type: error.type ?? "upstream_error", code: error.code, presentation: proxyErrorPresentation(response) });
101
102
  yield { type: "error", status: response.status, message: error.message ?? error.safeText,
102
103
  errorType: error.type ?? "upstream_error", ...(error.code ? { code: error.code } : {}),
103
104
  ...(nonReplayable ? { retryable: false } : {}) };
@@ -118,8 +119,8 @@ export async function deliverAdapterResponse(
118
119
  }
119
120
  } catch (error) {
120
121
  if (!(error instanceof ResponseBodyInactivityError)) throw error;
121
- yield { type: "error", message: "Upstream recovery response body stalled before completing",
122
- status: 504, errorType: "upstream_error" };
122
+ yield { type: "error", message: error.message,
123
+ status: 504, errorType: "upstream_error", code: "upstream_stall_timeout" };
123
124
  }
124
125
  }, () => transportState.activeAdapter.name, !isNonReplayableResponse(upstreamResponse), upstreamResponse);
125
126
 
@@ -155,9 +156,10 @@ export async function deliverAdapterResponse(
155
156
  if (error instanceof ResponseBodyInactivityError) {
156
157
  yield {
157
158
  type: "error",
158
- message: "Upstream response body stalled before completing",
159
+ message: error.message,
159
160
  status: 504,
160
161
  errorType: "upstream_error",
162
+ code: "upstream_stall_timeout",
161
163
  };
162
164
  return;
163
165
  }
@@ -195,6 +197,7 @@ export async function deliverAdapterResponse(
195
197
  ? guardEmptyCompletionEventStream({
196
198
  firstEvents: advisorStream,
197
199
  continuation: fetchGuardedEmptyCompletionRetry,
200
+ preserveRetryError: isContinuationBodyStall,
198
201
  })
199
202
  : advisorStream;
200
203
  const catalogGuardedEventStream = guardEmptyToolCatalogStream(completionGuardedEventStream, clientToolCatalog, translatorBudget);
@@ -345,6 +348,7 @@ export async function deliverAdapterResponse(
345
348
  for await (const event of guardEmptyCompletionEventStream({
346
349
  firstEvents: (async function* () { yield* guardedEvents; })(),
347
350
  continuation: fetchGuardedEmptyCompletionRetry,
351
+ preserveRetryError: isContinuationBodyStall,
348
352
  })) events.push(event);
349
353
  } else {
350
354
  events = guardedEvents;
@@ -358,7 +362,7 @@ export async function deliverAdapterResponse(
358
362
  }
359
363
  } catch (error) {
360
364
  if (error instanceof ResponseBodyInactivityError) {
361
- return formatErrorResponse(504, "upstream_error", "Upstream response body stalled before completing");
365
+ return formatErrorResponse(504, "upstream_error", error.message);
362
366
  }
363
367
  throw error;
364
368
  } finally {
@@ -408,7 +412,9 @@ export async function deliverAdapterResponse(
408
412
  commitReasoningReplayServingRoute();
409
413
  }
410
414
  notifyResponseComplete(json);
411
- return new Response(JSON.stringify(json), { headers: { "Content-Type": "application/json" } });
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" } });
412
418
  }
413
419
 
414
420
  return formatErrorResponse(400, "invalid_request_error", "Non-streaming not supported by this adapter");
@@ -63,7 +63,7 @@ import { describeUpstreamConnectFailure } from "./upstream-error";
63
63
  import type { OpaqueBlobRecoveryGuard } from "./core-opaque-recovery";
64
64
  import type { AttemptRecoveryKind } from "../../usage/log";
65
65
  import type { OAuthAccessSnapshot } from "../../oauth";
66
- import { OAuthAccountPausedError, OAuthLoginRequiredError, OAuthTokenRefreshBusyError, publicOAuthAuthenticationErrorMessage } from "../../oauth";
66
+ import { publicOAuthErrorPresentation, OAuthAccountPausedError, OAuthLoginRequiredError, OAuthTokenRefreshBusyError, publicOAuthAuthenticationErrorMessage } from "../../oauth";
67
67
  import { getAccountSet, markAccountNeedsReauthIfGeneration } from "../../oauth/store";
68
68
  import { tryKiroAlternateAfterTerminalRefresh } from "../../oauth/kiro-terminal-failover";
69
69
  import { classifyKiroRefusal } from "../../adapters/kiro-refusal";
@@ -569,10 +569,10 @@ export async function prepareAdapterExchange(
569
569
  }
570
570
  // A pause committed during pacing is local admission policy, not a failed upstream.
571
571
  if (refusal instanceof OAuthAccountPausedError) {
572
- return markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(refusal)));
572
+ return markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(refusal)), publicOAuthErrorPresentation(refusal));
573
573
  }
574
574
  if (refusal instanceof OAuthLoginRequiredError) {
575
- return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(refusal)));
575
+ return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(refusal)), publicOAuthErrorPresentation(refusal));
576
576
  }
577
577
  if (refusal instanceof AnthropicAccountCooldownError) {
578
578
  return anthropicPoolCooldownResponse(refusal, { comboAttempt: options.comboAttempt, logCtx });
@@ -861,10 +861,10 @@ export async function prepareAdapterExchange(
861
861
  }
862
862
  const refusal = err instanceof UpstreamRetryEvidenceError ? err.cause : err;
863
863
  if (refusal instanceof OAuthAccountPausedError) {
864
- return { failed: markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(refusal))) };
864
+ return { failed: markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(refusal)), publicOAuthErrorPresentation(refusal)) };
865
865
  }
866
866
  if (refusal instanceof OAuthLoginRequiredError) {
867
- return { failed: markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(refusal))) };
867
+ return { failed: markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(refusal)), publicOAuthErrorPresentation(refusal)) };
868
868
  }
869
869
  if (refusal instanceof AnthropicAccountCooldownError) {
870
870
  return { failed: anthropicPoolCooldownResponse(refusal, { comboAttempt: options.comboAttempt, logCtx }) };
@@ -975,7 +975,7 @@ export async function prepareAdapterExchange(
975
975
  try { void upstreamResponse.body?.cancel().catch(() => {}); } catch { /* already closed */ }
976
976
  releaseCodexAuthContextProbeLease(admissionState.authCtx);
977
977
  return cancelled ? clientCancelledResponse()
978
- : markProxyError(formatErrorResponse(503, "server_error", publicOAuthAuthenticationErrorMessage(err), { retryAfter: "1" }));
978
+ : markProxyError(formatErrorResponse(503, "server_error", publicOAuthAuthenticationErrorMessage(err), { retryAfter: "1" }), publicOAuthErrorPresentation(err));
979
979
  }
980
980
  const failed = transportState.sentOAuthSnapshot;
981
981
  if (route.providerName === "google-antigravity" && !antigravityAuthRotationAttempted
@@ -1027,9 +1027,9 @@ export async function prepareAdapterExchange(
1027
1027
  }
1028
1028
  cleanupUpstreamAbort();
1029
1029
  if (err instanceof OAuthAccountPausedError) {
1030
- return markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(err)));
1030
+ return markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(err)), publicOAuthErrorPresentation(err));
1031
1031
  }
1032
- return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(err)));
1032
+ return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(err)), publicOAuthErrorPresentation(err));
1033
1033
  }
1034
1034
  if (route.provider.googleMode === "cloud-code-assist" && !refreshed.projectId) {
1035
1035
  cleanupUpstreamAbort();
@@ -1,4 +1,4 @@
1
- import { isProxyError, rememberProxyErrorMessage } from "../../lib/client-error-body";
1
+ import { proxyErrorPresentation, isProxyError, rememberProxyErrorMessage } from "../../lib/client-error-body";
2
2
  import { anthropicRejectionPolicy, bindAnthropicRejectionPolicy, rejectedAnthropicPayloads } from "../../adapters/anthropic-rejection-memo";
3
3
  import { normalizeUpstreamErrorText, readDisplaySafeErrorText } from "./core-errors";
4
4
  import { sanitizeNonReplayableUpstreamError } from "./non-replayable-error";
@@ -148,7 +148,7 @@ export function createAnthropicThinkingRecovery(
148
148
  if (nonReplayable) response = await sanitizeNonReplayableUpstreamError(response, abortSignal);
149
149
  const text = await readDisplaySafeErrorText(response, abortSignal, `Provider error ${response.status}`);
150
150
  const error = normalizeUpstreamErrorText(text, `Provider error ${response.status}`);
151
- if (proxyErrorContext && isProxyError(response)) rememberProxyErrorMessage(proxyErrorContext, error.message ?? error.safeText, { status: response.status, type: error.type ?? "upstream_error", code: error.code });
151
+ if (proxyErrorContext && isProxyError(response)) rememberProxyErrorMessage(proxyErrorContext, error.message ?? error.safeText, { status: response.status, type: error.type ?? "upstream_error", code: error.code, presentation: proxyErrorPresentation(response) });
152
152
  return { type: "error", status: response.status, message: error.message ?? error.safeText,
153
153
  errorType: error.type ?? "upstream_error", ...(error.code ? { code: error.code } : {}),
154
154
  ...(nonReplayable ? { retryable: false } : {}) };
@@ -2,7 +2,7 @@ import { markProxyError } from "../../lib/client-error-body";
2
2
  import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
3
3
  import { formatErrorResponse } from "../../bridge";
4
4
  import {
5
- CodexAccountCooldownError,
5
+ CodexAccountCooldownError, CodexMainAccountHardLockError, CodexMainAccountCreditsOffError, CodexPoolAccountCreditsOffError, CodexReserveUnavailableError, CodexRecoveryWithheldError,
6
6
  codexMainProfileDrainingResponse,
7
7
  cooldownErrorResponse,
8
8
  CodexAuthContextError,
@@ -28,9 +28,9 @@ export interface CodexAuthContextErrorResponseOptions {
28
28
 
29
29
  export function codexModelAvailabilityErrorResponse(error: CodexModelAvailabilityError): Response {
30
30
  if (error.reason === "temporarily_unavailable") {
31
- return markProxyError(formatErrorResponse(429, "rate_limit_error", error.message));
31
+ return markProxyError(formatErrorResponse(429, "rate_limit_error", error.message), "model_availability");
32
32
  }
33
- return markProxyError(formatErrorResponse(400, "invalid_request_error", error.message));
33
+ return markProxyError(formatErrorResponse(400, "invalid_request_error", error.message), "model_availability");
34
34
  }
35
35
 
36
36
  /** Actionable sign-in guidance without guessing which upstream revocation cause occurred. */
@@ -87,7 +87,11 @@ export function mapCodexAuthContextErrorToResponse(
87
87
  const response = cooldownErrorResponse(error, options.now, options.accountSelector);
88
88
  // Exact class only (#7850): main hard-lock, credit, Reserve, recovery-withheld and future
89
89
  // policy subclasses keep their own retry semantics, including in combo target cooldowns.
90
- return markProxyError(error.constructor === CodexAccountCooldownError ? markCodexAccountCooldownResponse(response) : response);
90
+ const presentation = error instanceof CodexMainAccountHardLockError ? "hard_lock"
91
+ : error instanceof CodexRecoveryWithheldError ? "recovery"
92
+ : error instanceof CodexMainAccountCreditsOffError || error instanceof CodexPoolAccountCreditsOffError || error instanceof CodexReserveUnavailableError ? undefined
93
+ : options.accountSelector ? "cooldown_pinned" : "cooldown";
94
+ return markProxyError(error.constructor === CodexAccountCooldownError ? markCodexAccountCooldownResponse(response) : response, presentation);
91
95
  }
92
96
  if (error instanceof CodexMainProfileDrainingError) {
93
97
  return markProxyError(codexMainProfileDrainingResponse());
@@ -203,13 +203,29 @@ export function codexWsPreOutputRefusalHold(connectMs: number, now = Date.now())
203
203
 
204
204
  /**
205
205
  * A lifecycle frame that commits nothing the client could see or act on (#6969): created,
206
- * in-progress or queued, carrying a response object whose output is absent or empty. A snapshot
207
- * with any output item, an unknown event, or a frame addressed to another stream is not one.
206
+ * in-progress or queued, carrying a response object whose output is absent or empty, or the
207
+ * heartbeat that only keeps the connection alive. A snapshot with any output item,
208
+ * an unknown event, or a frame addressed to another stream is not one.
209
+ *
210
+ * A heartbeat qualifies only while it carries no output, no field this contract does not know, and
211
+ * at most its numeric sequence marker. A replay-unsafe mark already ran a side effect and is never
212
+ * held; only an absent mark or the boolean false proves there was none, so any other value fails
213
+ * closed rather than trusting a malformed type.
208
214
  */
209
215
  export function isEmptyCodexWsLifecycleEvent(payload: Record<string, unknown>): boolean {
216
+ if (payload.stream_id !== undefined) return false;
217
+ if (payload.type === "response.heartbeat") {
218
+ if ((Object.hasOwn(payload, "replayUnsafe") && payload.replayUnsafe !== false)
219
+ || Object.keys(payload).some(key =>
220
+ key !== "type" && key !== "response" && key !== "replayUnsafe" && key !== "sequence_number")) return false;
221
+ if (payload.sequence_number !== undefined
222
+ && !(typeof payload.sequence_number === "number" && Number.isSafeInteger(payload.sequence_number)
223
+ && payload.sequence_number >= 0)) return false;
224
+ return payload.response === undefined
225
+ || (plainRecord(payload.response) && emptyOutput(payload.response));
226
+ }
210
227
  if (payload.type !== "response.created" && payload.type !== "response.in_progress"
211
228
  && payload.type !== "response.queued") return false;
212
- if (payload.stream_id !== undefined) return false;
213
229
  return plainRecord(payload.response) && emptyOutput(payload.response);
214
230
  }
215
231
 
@@ -1186,6 +1186,9 @@ export async function handleResponsesCompact(
1186
1186
  });
1187
1187
  const requireSendPlaintextReasoning = !isOpenAiOperatedResponsesDestination(sendProvider)
1188
1188
  && requiresPlaintextReasoningReplay(sendProvider);
1189
+ // #8042: `ocx1:`/`ocx2:` are OpenCodex's own transparent envelopes, which no upstream can
1190
+ // decode, so canonical and official sends must lower them like ordinary turns do. `false`
1191
+ // leaves native blobs to the account-change scrub that already owns them on this path.
1189
1192
  let replayBody = gatewayReplayParsed ? sanitizeReasoningInputContent(scrubOcxCompactionItems(
1190
1193
  compactBody, destinationDecodesNativeCompactionBlob(sendProvider),
1191
1194
  gatewayReplayParsed._stripReasoningEncryptedContent === true,
@@ -1196,7 +1199,7 @@ export async function handleResponsesCompact(
1196
1199
  stripEncryptedContent: gatewayReplayParsed._stripReasoningEncryptedContent === true || requireSendPlaintextReasoning,
1197
1200
  dropForeignItemId: gatewayReplayParsed._dropForeignReasoningItemIds === true,
1198
1201
  requirePlaintextReasoning: requireSendPlaintextReasoning,
1199
- }) : compactBody;
1202
+ }) : scrubOcxCompactionItems(compactBody, destinationDecodesNativeCompactionBlob(sendProvider), false) as typeof compactBody;
1200
1203
  if (!isOpenAiOperatedResponsesDestination(sendProvider) && sendProvider.dropResponsesReasoningItems === true) {
1201
1204
  replayBody = dropResponsesReasoningInputItems(replayBody) as typeof replayBody;
1202
1205
  }
@@ -464,7 +464,7 @@ export function poolCredentialRefreshIncompleteResponse(args: {
464
464
  ));
465
465
  const headers = new Headers(response.headers);
466
466
  headers.set("Retry-After", "1");
467
- return markProxyError(new Response(response.body, { status: response.status, headers }));
467
+ return markProxyError(new Response(response.body, { status: response.status, headers }), "pool_refresh");
468
468
  }
469
469
 
470
470
 
@@ -1,3 +1,4 @@
1
+ import { carryProxyErrorPresentation } from "../../lib/client-error-body";
1
2
  import { comboFailureEvidence, carryProxyError } from "../../lib/client-error-body";
2
3
  import { codexAccountModelRefusal, codexAccountModelRefusalHardStopCode, type CodexAccountModelRefusal } from "../../combos/failover";
3
4
  import { parseRetryAfterMs } from "../../combos";
@@ -144,6 +145,7 @@ export async function consumeComboFailure(
144
145
  if (nonReplayable) markResponseNonReplayable(failureResponse);
145
146
  carryProxyError(response, failureResponse);
146
147
  carryReplayRefusal(response, failureResponse);
148
+ carryProxyErrorPresentation(response, failureResponse);
147
149
  if (verifiedPlanRefusal) markVerifiedModelNotInPlanResponse(failureResponse);
148
150
  carryAnthropicRefusalCredential(response, failureResponse);
149
151
  carryCodexAccountCooldownResponse(response, failureResponse);
@@ -518,6 +518,7 @@ export async function executeComboResponses(
518
518
  }
519
519
  carryProxyErrorContext(childLog, logCtx);
520
520
  Object.assign(logCtx, childLog, {
521
+ client: logCtx.client,
521
522
  requestedModel: responseModel,
522
523
  model: responseModel,
523
524
  provider: "combo",
@@ -1302,6 +1303,7 @@ export async function executeComboResponses(
1302
1303
  settleComboReprobeSuccess(pick);
1303
1304
  carryProxyErrorContext(childLog, logCtx);
1304
1305
  Object.assign(logCtx, childLog, {
1306
+ client: logCtx.client,
1305
1307
  requestedModel: responseModel,
1306
1308
  model: responseModel,
1307
1309
  provider: "combo",
@@ -91,7 +91,7 @@ export function decodeRequestErrorResponse(err: unknown, label: string): Respons
91
91
  return markProxyError(formatErrorResponse(415, "invalid_request_error", err.message));
92
92
  }
93
93
  if (err instanceof DecompressedBodyTooLargeError) {
94
- return markProxyError(formatErrorResponse(413, "inbound_body_too_large", describeInboundBodyRefusal(err)));
94
+ return markProxyError(formatErrorResponse(413, "inbound_body_too_large", describeInboundBodyRefusal(err)), "inbound");
95
95
  }
96
96
  console.warn(`[${label}] request body decode/parse failed: ${err instanceof Error ? `${err.name}: ${err.message}` : String(err)}`);
97
97
  return markProxyError(formatErrorResponse(400, "invalid_request_error", "Invalid JSON body"));
@@ -102,7 +102,7 @@ export function decodeRequestErrorResponse(err: unknown, label: string): Respons
102
102
 
103
103
  export function comboUnavailableResponse(
104
104
  message: string,
105
- options?: { retryAfter?: string | null },
105
+ options?: { retryAfter?: string | null; presentation?: "combo" },
106
106
  ): Response {
107
107
  const headers = new Headers({ "Content-Type": "application/json" });
108
108
  // Advice leaves in this proxy's format, whatever form the earliest cooldown was recorded in.
@@ -113,13 +113,14 @@ export function comboUnavailableResponse(
113
113
  error: { message, type: "server_error", code: "combo_unavailable" },
114
114
  }),
115
115
  { status: 503, headers },
116
- ));
116
+ ), options?.presentation);
117
117
  }
118
118
 
119
119
 
120
120
  export function comboUnavailable(comboId: string, now = Date.now(), reasons?: ComboExclusionReasons): Response {
121
121
  return comboUnavailableResponse(new NoAvailableComboTargetsError(comboId, reasons).message, {
122
122
  retryAfter: comboCooldownRetryAfterSeconds(comboId, now),
123
+ presentation: reasons === undefined ? undefined : "combo",
123
124
  });
124
125
  }
125
126
 
@@ -156,7 +157,7 @@ export function anthropicPoolCooldownResponse(
156
157
  ): Response {
157
158
  if (refusal.usageLimit !== null && !options.comboAttempt) {
158
159
  if (options.logCtx) options.logCtx.errorCode = "usage_limit_reached";
159
- return markProxyError(formatUsageLimitReachedResponse(refusal.message, refusal.usageLimit.resetsAt, refusal.retryAfterSeconds));
160
+ return markProxyError(formatUsageLimitReachedResponse(refusal.message, refusal.usageLimit.resetsAt, refusal.retryAfterSeconds), refusal.usageLimit.resetsAt === null ? undefined : "usage");
160
161
  }
161
162
  return markProxyError(formatErrorResponse(429, "rate_limit_error", refusal.retryableMessage,
162
163
  refusal.retryAfterSeconds === null ? undefined : { retryAfter: String(refusal.retryAfterSeconds) }));
@@ -198,6 +198,8 @@ export interface HandleResponsesOptions {
198
198
  anthropicServerTools?: readonly Record<string, unknown>[];
199
199
  /** The Claude client's replayable server-tool exchanges (`replayedAnthropicServerBlocks`); same scope. */
200
200
  anthropicServerReplay?: ReadonlyMap<string, readonly Record<string, unknown>[]>;
201
+ /** The caller's cached system prefix (`systemCachePrefix`); same scope. */
202
+ anthropicSystemCachePrefix?: string;
201
203
  /** Metadata-qualified Messages discovery evidence, never caller JSON or a preselected destination. */
202
204
  anthropicToolLoadingSource?: Readonly<Record<string, unknown>>;
203
205
  /** Droid's per-request effort default; each concrete combo or policy target applies it only if its ladder allows it. */
@@ -204,6 +204,8 @@ export interface EmptyCompletionGuardOptions {
204
204
  * Receives no arguments — the request must not be modified between attempts.
205
205
  */
206
206
  continuation: () => AsyncIterable<AdapterEvent> | Promise<AsyncIterable<AdapterEvent>>;
207
+ /** Preserve locally classified retry failures whose precise status must reach the caller. */
208
+ preserveRetryError?: (event: AdapterEvent) => boolean;
207
209
  /** How many times an empty completion is retried; default 1 (the router's single retry). */
208
210
  maxRetries?: number;
209
211
  }
@@ -317,7 +319,8 @@ export async function* guardEmptyCompletionEventStream(
317
319
  terminalSeen = true;
318
320
  break;
319
321
  }
320
- if (retries > 0 && event.status !== 499 && event.replaySafeBeforeOutput !== true) {
322
+ if (retries > 0 && event.status !== 499 && event.replaySafeBeforeOutput !== true
323
+ && !options.preserveRetryError?.(event)) {
321
324
  // The retry failed upstream. Its body cannot reach the client (the
322
325
  // 200 head went out with the first attempt), so state the failure in
323
326
  // the stream's own error framing — same move as the router's
@@ -10,5 +10,5 @@ export function requestPacingOverloadResponse(error: unknown): Response | undefi
10
10
  "rate_limit_error",
11
11
  error.message,
12
12
  { retryAfter: String(error.retryAfterSeconds) },
13
- ));
13
+ ), error.reason === "keys_exhausted" ? undefined : "pacing");
14
14
  }
@@ -147,7 +147,7 @@ import { resolveWireProtocolOverride } from "../adapter-resolve";
147
147
  import { refreshPoolForwardAuth, refreshNativeMainForwardAuth, withClaudeNativeSession } from "./core-auth";
148
148
  import { bindRouteReasoningReplayScope } from "./core-replay";
149
149
  import type { OAuthAccessSnapshot } from "../../oauth";
150
- import { OAuthAccountPausedError, OAuthLoginRequiredError, OAuthTokenRefreshBusyError, publicOAuthAuthenticationErrorMessage } from "../../oauth";
150
+ import { publicOAuthErrorPresentation, OAuthAccountPausedError, OAuthLoginRequiredError, OAuthTokenRefreshBusyError, publicOAuthAuthenticationErrorMessage } from "../../oauth";
151
151
  import { AnthropicAccountCooldownError } from "../../oauth/anthropic-routing";
152
152
  import { resolveCopilotApiBaseUrl } from "../../oauth/github-copilot";
153
153
  import {
@@ -934,12 +934,12 @@ export async function preparePassthroughExchange(
934
934
  nativeHostState.lease = null;
935
935
  releaseCodexAuthContextProbeLease(admissionState.authCtx);
936
936
  if (refusal instanceof OAuthLoginRequiredError) {
937
- return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(refusal)));
937
+ return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(refusal)), publicOAuthErrorPresentation(refusal));
938
938
  }
939
939
  if (refusal instanceof AnthropicAccountCooldownError) {
940
940
  return anthropicPoolCooldownResponse(refusal, { comboAttempt: options.comboAttempt, logCtx });
941
941
  }
942
- return markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(refusal)));
942
+ return markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(refusal)), publicOAuthErrorPresentation(refusal));
943
943
  }
944
944
  const localRefusal = spendLedgerStorageErrorResponse(err, logCtx) ?? mapCodexAuthContextErrorToResponse(refusal, {
945
945
  now: Date.now(), accountSelector: route.codexAccountNamespace,
@@ -1350,8 +1350,8 @@ export async function preparePassthroughExchange(
1350
1350
  upstream.abort();
1351
1351
  releaseCodexAuthContextProbeLease(admissionState.authCtx);
1352
1352
  if (options.abortSignal?.aborted || req.signal.aborted) return clientCancelledResponse();
1353
- if (err instanceof OAuthTokenRefreshBusyError) return markProxyError(formatErrorResponse(503, "server_error", publicOAuthAuthenticationErrorMessage(err), { retryAfter: "1" }));
1354
- return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(err)));
1353
+ if (err instanceof OAuthTokenRefreshBusyError) return markProxyError(formatErrorResponse(503, "server_error", publicOAuthAuthenticationErrorMessage(err), { retryAfter: "1" }), publicOAuthErrorPresentation(err));
1354
+ return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(err)), publicOAuthErrorPresentation(err));
1355
1355
  }
1356
1356
  if (route.provider.googleMode === "cloud-code-assist" && !refreshed.projectId) {
1357
1357
  upstream.abort();
@@ -515,6 +515,8 @@ export async function prepareResponsesRequest(
515
515
  parsed._nativeReasoningMint = options.nativeReasoningMint;
516
516
  parsed._anthropicServerTools = options.anthropicServerTools;
517
517
  parsed._anthropicServerReplay = options.anthropicServerReplay;
518
+ parsed._anthropicSystemCachePrefix = options.anthropicSystemCachePrefix;
519
+ if (parsed.options.textFormat?.type === "json_schema") parsed._structuredOutputConformance = true;
518
520
  }
519
521
  parsed._promptCacheKeyIsSharedCohort = options.promptCacheKeyIsSharedCohort;
520
522
  // The body may have been rebuilt since the inbound observation (previous-response
@@ -1544,7 +1546,7 @@ export async function prepareResponsesRequest(
1544
1546
  413,
1545
1547
  "input_admission_refused",
1546
1548
  inputAdmissionRefusalMessage(inputAdmission, inboundSelector),
1547
- ));
1549
+ ), "input");
1548
1550
  }
1549
1551
  }
1550
1552
  const preAuthHostKey = preAuthUpstreamHostCircuitKey(route, config);
@@ -1,3 +1,4 @@
1
+ import { publicOAuthErrorPresentation } from "../../oauth";
1
2
  import { projectLocalModelRefusalLog } from "../request-log-failure-detail";
2
3
  import { markProxyError } from "../../lib/client-error-body";
3
4
  import { formatClientRetryAfter } from "../../lib/client-retry-after";
@@ -350,7 +351,7 @@ export async function prepareResponsesTransport(
350
351
  if (error instanceof AdmissionModelDeniedError) return admissionModelDeniedResponse(projectAdmissionModelDeniedLog(error, logCtx));
351
352
  if (!(error instanceof CopilotAutoHttpError) || ![401, 403, 429].includes(error.status)) return;
352
353
  const response = markProxyError(formatErrorResponse(error.status, error.status === 429 ? "rate_limit_error" : "authentication_error",
353
- error.message));
354
+ error.message), "copilot");
354
355
  const advice = formatClientRetryAfter(error.retryAfter);
355
356
  if (advice !== undefined) response.headers.set("retry-after", advice);
356
357
  return response;
@@ -954,7 +955,7 @@ export async function prepareResponsesTransport(
954
955
  const bodySize = checkOutboundBodySize(rebuilt.body, config.maxUpstreamBodyBytes);
955
956
  if (!bodySize.admitted) {
956
957
  rebuilt.releaseBodyObservation?.();
957
- return markProxyError(formatErrorResponse(413, "outbound_body_too_large", describeOutboundBodyRefusal(bodySize)));
958
+ return markProxyError(formatErrorResponse(413, "outbound_body_too_large", describeOutboundBodyRefusal(bodySize)), "outbound");
958
959
  }
959
960
  const headers = new Headers(dispatchInit.headers);
960
961
  for (const name of Object.keys(wireRequest.headers)) headers.delete(name);
@@ -992,7 +993,7 @@ export async function prepareResponsesTransport(
992
993
  try {
993
994
  if (anthropicInstance !== undefined && anthropicRouting!.isAnthropicAccountPoolEnabled(config)) {
994
995
  const routeResult = resolveAnthropicModelRouteForInstance(anthropicInstance, config, route.modelId);
995
- if (routeResult.error) return markProxyError(formatErrorResponse(400, "invalid_request_error", `Invalid Anthropic model routes: ${routeResult.error}`));
996
+ if (routeResult.error) return markProxyError(formatErrorResponse(400, "invalid_request_error", "Invalid Anthropic model routes"));
996
997
  anthropicRouteDecision = routeResult.decision;
997
998
  const selection = anthropicRouting!.resolveAnthropicAccountForSession(anthropicSessionKey, config, Date.now(), anthropicRouteDecision, route.modelId);
998
999
  if (!selection.accountId) {
@@ -1030,7 +1031,7 @@ export async function prepareResponsesTransport(
1030
1031
  // A usable listing (or not-yet-discovered) sibling replaces it, or the request is refused.
1031
1032
  const modelRoute = routeAntigravityModel(config, route.providerName,
1032
1033
  proposedAccountId ?? oauthSelection?.accountId, route.modelId, undefined, requestState.inboundSelector);
1033
- if (modelRoute.kind === "refuse") { projectLocalModelRefusalLog(logCtx, requestState.inboundSelector); return markProxyError(formatErrorResponse(403, "permission_error", modelRoute.message)); }
1034
+ if (modelRoute.kind === "refuse") { projectLocalModelRefusalLog(logCtx, requestState.inboundSelector); return markProxyError(formatErrorResponse(403, "permission_error", modelRoute.message), "roster"); }
1034
1035
  const routedAccountId = modelRoute.kind === "reroute" ? modelRoute.accountId : proposedAccountId;
1035
1036
  // An unchanged active choice must retain the ordinary resolver's terminal-refresh
1036
1037
  // recovery (not the speculative-preference fallback that resolves the same dead grant).
@@ -1098,7 +1099,7 @@ export async function prepareResponsesTransport(
1098
1099
  // Resolution fallbacks can still land on an omitting account; answer with the refusal
1099
1100
  // here, since the commit below would only report it as a changed selection.
1100
1101
  const unlisted = antigravityModelRefusal(config, route.providerName, resolved.accountId, route.modelId, undefined, requestState.inboundSelector);
1101
- if (unlisted) { projectLocalModelRefusalLog(logCtx, requestState.inboundSelector); return markProxyError(formatErrorResponse(403, "permission_error", unlisted)); }
1102
+ if (unlisted) { projectLocalModelRefusalLog(logCtx, requestState.inboundSelector); return markProxyError(formatErrorResponse(403, "permission_error", unlisted), "roster"); }
1102
1103
  const admitted = await commitResolvedOAuthSelection(resolved, safetyAlternateId === null);
1103
1104
  if (!admitted) return markProxyError(formatErrorResponse(409, "conflict_error", "OAuth account selection changed; retry the request"));
1104
1105
  if (safetyAlternateId && admitted.accountId !== safetyAlternateId)
@@ -1180,16 +1181,16 @@ export async function prepareResponsesTransport(
1180
1181
  400,
1181
1182
  "invalid_request_error",
1182
1183
  `${redactSecretString(err.message)}. Remove or reconfigure provider '${safeProviderName}' in the OpenCodex configuration.`,
1183
- ));
1184
+ ), "config");
1184
1185
  }
1185
1186
  if (err instanceof OAuthTokenRefreshBusyError) {
1186
1187
  return options.abortSignal?.aborted || req.signal.aborted ? clientCancelledResponse()
1187
1188
  : markProxyError(formatErrorResponse(503, "server_error", err.message, { retryAfter: "1" }));
1188
1189
  }
1189
1190
  if (err instanceof OAuthAccountPausedError) {
1190
- return markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(err)));
1191
+ return markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(err)), publicOAuthErrorPresentation(err));
1191
1192
  }
1192
- return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(err)));
1193
+ return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(err)), publicOAuthErrorPresentation(err));
1193
1194
  }
1194
1195
  }
1195
1196
  // Key-auth twin of the OAuth preference above: pick a warm key BEFORE the first attempt when
@@ -106,8 +106,9 @@ export function createResponsesEffects(
106
106
  // The compaction turn is a plain prose summary; a surviving structured-output format
107
107
  // would force schema-constrained JSON into the synthetic compaction item. The flag and
108
108
  // the raw `text` control go too: the key-mode openai-responses adapter builds from
109
- // _rawBody, so a surviving format there would still reach the upstream. (The Kiro
110
- // guard no longer reads _rawBody.text; it refuses structured output only.)
109
+ // _rawBody, so a surviving format there would still reach the upstream. (Kiro reads
110
+ // options.textFormat, never _rawBody.text, and would emulate a surviving format through
111
+ // its structured-output tool, so it must go here too.)
111
112
  delete parsed.options.textFormat;
112
113
  delete parsed._structuredOutput;
113
114
  if (parsed._rawBody && typeof parsed._rawBody === "object") {
@@ -82,6 +82,27 @@ function recentTurnHasToolActivity(parsed: OcxParsedRequest): boolean {
82
82
  return false;
83
83
  }
84
84
 
85
+ /**
86
+ * Reports whether the current turn already executed tools: a tool call or tool result after the
87
+ * latest user message. A text-only plan announcement after the last tool activity means the turn
88
+ * stalled there, so it does not count, matching `recentTurnHasToolActivity`.
89
+ */
90
+ function toolActivitySinceLatestUser(parsed: OcxParsedRequest): boolean {
91
+ for (let i = parsed.context.messages.length - 1; i >= 0; i -= 1) {
92
+ const message = parsed.context.messages[i];
93
+ if (message.role === "user") return false;
94
+ if (message.role === "toolResult") return true;
95
+ if (message.role !== "assistant") continue;
96
+ if (message.content.some(part => part.type === "toolCall")) return true;
97
+ const text = message.content
98
+ .filter(part => part.type === "text")
99
+ .map(part => part.text)
100
+ .join("");
101
+ if (PLAN_INTENT_RE.test(text)) return false;
102
+ }
103
+ return false;
104
+ }
105
+
85
106
  function assistantText(events: readonly AdapterEvent[]): string {
86
107
  return events
87
108
  .filter((event): event is Extract<AdapterEvent, { type: "text_delta" }> => event.type === "text_delta")
@@ -89,6 +110,12 @@ function assistantText(events: readonly AdapterEvent[]): string {
89
110
  .join("");
90
111
  }
91
112
 
113
+ /**
114
+ * Classifies a finished upstream turn that made no tool call. `continue` means the model only
115
+ * announced work for an actionable request, so the relay re-asks it with `TERMINAL_GUARD_NUDGE`.
116
+ * A completion summary after tool activity in the same turn passes; a renewed first-person plan
117
+ * announcement (`PLAN_INTENT_RE`) after that activity is still continued.
118
+ */
92
119
  export function analyzeTerminalTurn(parsed: OcxParsedRequest, events: readonly AdapterEvent[]): TerminalTurnAnalysis {
93
120
  const userText = latestUserText(parsed);
94
121
  const text = assistantText(events);
@@ -105,6 +132,9 @@ export function analyzeTerminalTurn(parsed: OcxParsedRequest, events: readonly A
105
132
  if (PLAN_ONLY_REQUEST_RE.test(userText)) {
106
133
  return { decision: "pass", reason: "no_actionable_request", assistantText: text, userText, hasToolCall };
107
134
  }
135
+ if (toolActivitySinceLatestUser(parsed) && !PLAN_INTENT_RE.test(text)) {
136
+ return { decision: "pass", reason: "recent_tool_activity", assistantText: text, userText, hasToolCall };
137
+ }
108
138
  if (EXPLICIT_CONTINUE_RE.test(userText) && recentTurnHasToolActivity(parsed)) {
109
139
  return { decision: "pass", reason: "recent_tool_activity", assistantText: text, userText, hasToolCall };
110
140
  }
@@ -202,7 +202,9 @@ function openDefaultRestartHandoffLog(now: () => number): RestartHandoffLog | nu
202
202
  const configDir = getConfigDir();
203
203
  const path = restartHandoffLogPath(configDir);
204
204
  // Owned like crash.log, so uninstall removes it with the rest of the config directory.
205
- try { recordOwnedConfigPath(configDir, path); } catch { /* the log is optional */ }
205
+ // The log is optional: a refused registration (uninstall in progress) skips it rather than
206
+ // creating a file uninstall does not know about.
207
+ try { recordOwnedConfigPath(configDir, path); } catch { return null; }
206
208
  return openRestartHandoffLog(path, now);
207
209
  }
208
210