@oscharko-dev/keiko 1.1.5 → 1.1.7

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 (243) hide show
  1. package/dist/ui/csp-hashes.json +6 -6
  2. package/dist/ui/static/404.html +1 -1
  3. package/dist/ui/static/__next.__PAGE__.txt +10 -10
  4. package/dist/ui/static/__next._full.txt +12 -12
  5. package/dist/ui/static/__next._tree.txt +1 -1
  6. package/dist/ui/static/_next/static/chunks/{1gb6os129fico.js → 01rp_j2a-73pp.js} +1 -1
  7. package/dist/ui/static/_next/static/chunks/02i0eppipph7e.js +1 -0
  8. package/dist/ui/static/_next/static/chunks/0hc828_gdkyek.js +3 -0
  9. package/dist/ui/static/_next/static/chunks/0hq0i12hw0ypm.js +1 -0
  10. package/dist/ui/static/_next/static/chunks/{0xqxs7rppw_o5.css → 0xxx56s32tn9r.css} +1 -1
  11. package/dist/ui/static/_next/static/chunks/{0ak5o5brryicl.js → 18grpx4tuavds.js} +1 -1
  12. package/dist/ui/static/_next/static/chunks/1be0-x1mk56wu.js +1 -0
  13. package/dist/ui/static/_next/static/chunks/{0bbv42deftomm.js → 1c1gbfapof8m0.js} +1 -1
  14. package/dist/ui/static/_next/static/chunks/{3d-10944zk2o9.js → 1lj5se4u-t-e9.js} +1 -1
  15. package/dist/ui/static/_next/static/chunks/{1th8j9weqwhgx.js → 1o2cihsnxhmh6.js} +1 -1
  16. package/dist/ui/static/_next/static/chunks/22x3pxeia7hk_.js +1 -0
  17. package/dist/ui/static/_next/static/chunks/{0e6em7dg4gr6q.js → 25lgzefdnbdh6.js} +1 -1
  18. package/dist/ui/static/_next/static/chunks/{3pfnjbbr6jydb.js → 29p86cxry0h-l.js} +1 -1
  19. package/dist/ui/static/_next/static/chunks/2ctd04x-fzbwc.js +1 -0
  20. package/dist/ui/static/_next/static/chunks/2jfg687n_mvf8.js +1 -0
  21. package/dist/ui/static/_next/static/chunks/{1r6n6x3-e27ud.js → 2mnldrncbucm0.js} +1 -1
  22. package/dist/ui/static/_next/static/chunks/{21t1klb1thn76.js → 306ima8lxo17-.js} +1 -1
  23. package/dist/ui/static/_next/static/chunks/{2dpxapmdvqlh1.js → 36-tv3y56oau8.js} +1 -1
  24. package/dist/ui/static/_next/static/chunks/{0ks_l2sa4nfn0.js → 3aizxizjzdddj.js} +1 -1
  25. package/dist/ui/static/_next/static/chunks/3fuqgie3p2068.js +1 -0
  26. package/dist/ui/static/_next/static/chunks/3k6g7nzn589fs.js +1 -0
  27. package/dist/ui/static/_next/static/chunks/3r4fz572q3l7s.js +1 -0
  28. package/dist/ui/static/_next/static/chunks/{1lb8ju8qa0d9m.js → 40g2_9ovqiuiu.js} +1 -1
  29. package/dist/ui/static/_not-found/__next._full.txt +9 -9
  30. package/dist/ui/static/_not-found/__next._not-found.__PAGE__.txt +8 -8
  31. package/dist/ui/static/_not-found/__next._tree.txt +1 -1
  32. package/dist/ui/static/_not-found.html +1 -1
  33. package/dist/ui/static/_not-found.txt +9 -9
  34. package/dist/ui/static/atlassian-connectors/__next._full.txt +13 -13
  35. package/dist/ui/static/atlassian-connectors/__next._tree.txt +1 -1
  36. package/dist/ui/static/atlassian-connectors/__next.atlassian-connectors.__PAGE__.txt +10 -10
  37. package/dist/ui/static/atlassian-connectors.html +1 -1
  38. package/dist/ui/static/atlassian-connectors.txt +13 -13
  39. package/dist/ui/static/index.html +1 -1
  40. package/dist/ui/static/index.txt +12 -12
  41. package/dist/ui/static/launch/__next._full.txt +12 -12
  42. package/dist/ui/static/launch/__next._tree.txt +1 -1
  43. package/dist/ui/static/launch/__next.launch.__PAGE__.txt +10 -10
  44. package/dist/ui/static/launch.html +1 -1
  45. package/dist/ui/static/launch.txt +12 -12
  46. package/dist/ui/static/local-knowledge/__next._full.txt +12 -12
  47. package/dist/ui/static/local-knowledge/__next._tree.txt +1 -1
  48. package/dist/ui/static/local-knowledge/__next.local-knowledge.__PAGE__.txt +10 -10
  49. package/dist/ui/static/local-knowledge/capsule/__next._full.txt +13 -13
  50. package/dist/ui/static/local-knowledge/capsule/__next._tree.txt +1 -1
  51. package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.__PAGE__.txt +10 -10
  52. package/dist/ui/static/local-knowledge/capsule.html +1 -1
  53. package/dist/ui/static/local-knowledge/capsule.txt +13 -13
  54. package/dist/ui/static/local-knowledge.html +1 -1
  55. package/dist/ui/static/local-knowledge.txt +12 -12
  56. package/node_modules/@oscharko-dev/keiko-cli/dist/support-analyze.d.ts.map +1 -1
  57. package/node_modules/@oscharko-dev/keiko-cli/dist/support-analyze.js +52 -11
  58. package/node_modules/@oscharko-dev/keiko-cli/package.json +14 -14
  59. package/node_modules/@oscharko-dev/keiko-connectors/dist/version.d.ts +1 -1
  60. package/node_modules/@oscharko-dev/keiko-connectors/dist/version.js +1 -1
  61. package/node_modules/@oscharko-dev/keiko-connectors/package.json +3 -3
  62. package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-failure-class-contracts.d.ts +71 -11
  63. package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-failure-class-contracts.d.ts.map +1 -1
  64. package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-failure-class-contracts.js +133 -11
  65. package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-registry.generated.d.ts +1098 -21
  66. package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-registry.generated.d.ts.map +1 -1
  67. package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-registry.generated.js +1314 -20
  68. package/node_modules/@oscharko-dev/keiko-contracts/dist/bff-wire.d.ts +7 -2
  69. package/node_modules/@oscharko-dev/keiko-contracts/dist/bff-wire.d.ts.map +1 -1
  70. package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-api-validation.d.ts.map +1 -1
  71. package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-api-validation.js +15 -8
  72. package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-api.d.ts +3 -1
  73. package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-api.d.ts.map +1 -1
  74. package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-constants.d.ts +2 -0
  75. package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-constants.d.ts.map +1 -1
  76. package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench.d.ts +1 -1
  77. package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench.d.ts.map +1 -1
  78. package/node_modules/@oscharko-dev/keiko-contracts/dist/context-engineering.d.ts +3 -0
  79. package/node_modules/@oscharko-dev/keiko-contracts/dist/context-engineering.d.ts.map +1 -1
  80. package/node_modules/@oscharko-dev/keiko-contracts/dist/context-engineering.js +20 -4
  81. package/node_modules/@oscharko-dev/keiko-contracts/dist/version.d.ts +2 -2
  82. package/node_modules/@oscharko-dev/keiko-contracts/dist/version.js +2 -2
  83. package/node_modules/@oscharko-dev/keiko-contracts/package.json +1 -1
  84. package/node_modules/@oscharko-dev/keiko-evaluations/package.json +9 -9
  85. package/node_modules/@oscharko-dev/keiko-evidence/dist/version.d.ts +1 -1
  86. package/node_modules/@oscharko-dev/keiko-evidence/dist/version.js +1 -1
  87. package/node_modules/@oscharko-dev/keiko-evidence/package.json +4 -4
  88. package/node_modules/@oscharko-dev/keiko-git/dist/version.d.ts +1 -1
  89. package/node_modules/@oscharko-dev/keiko-git/dist/version.js +1 -1
  90. package/node_modules/@oscharko-dev/keiko-git/package.json +1 -1
  91. package/node_modules/@oscharko-dev/keiko-harness/dist/version.d.ts +1 -1
  92. package/node_modules/@oscharko-dev/keiko-harness/dist/version.js +1 -1
  93. package/node_modules/@oscharko-dev/keiko-harness/package.json +7 -7
  94. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.d.ts +1 -1
  95. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.js +1 -1
  96. package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +5 -5
  97. package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.d.ts +1 -1
  98. package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.js +1 -1
  99. package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +3 -3
  100. package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.d.ts +1 -1
  101. package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.js +1 -1
  102. package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +3 -3
  103. package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.d.ts +1 -1
  104. package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.js +1 -1
  105. package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +3 -3
  106. package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.d.ts +1 -1
  107. package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.js +1 -1
  108. package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +3 -3
  109. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.d.ts +1 -1
  110. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.js +1 -1
  111. package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +3 -3
  112. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.d.ts.map +1 -1
  113. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.js +4 -1
  114. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway.d.ts +3 -0
  115. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway.d.ts.map +1 -1
  116. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway.js +147 -30
  117. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts +1 -1
  118. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts.map +1 -1
  119. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.js +7 -6
  120. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/observability.d.ts.map +1 -1
  121. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/observability.js +1 -0
  122. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-adapter.d.ts +7 -0
  123. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-adapter.d.ts.map +1 -1
  124. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-adapter.js +285 -19
  125. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-embedding-adapter.d.ts.map +1 -1
  126. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-embedding-adapter.js +12 -3
  127. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/realtime-voice-adapter.d.ts.map +1 -1
  128. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/realtime-voice-adapter.js +3 -1
  129. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/rerank-adapter.d.ts.map +1 -1
  130. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/rerank-adapter.js +4 -1
  131. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/resilience.d.ts +10 -0
  132. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/resilience.d.ts.map +1 -1
  133. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/resilience.js +89 -3
  134. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/speech-to-text-adapter.d.ts +1 -0
  135. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/speech-to-text-adapter.d.ts.map +1 -1
  136. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/speech-to-text-adapter.js +158 -10
  137. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/text-to-speech-adapter.d.ts.map +1 -1
  138. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/text-to-speech-adapter.js +176 -12
  139. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.d.ts +1 -1
  140. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.js +1 -1
  141. package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +4 -4
  142. package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +3 -3
  143. package/node_modules/@oscharko-dev/keiko-sandbox/dist/darwin-git.d.ts +3 -0
  144. package/node_modules/@oscharko-dev/keiko-sandbox/dist/darwin-git.d.ts.map +1 -1
  145. package/node_modules/@oscharko-dev/keiko-sandbox/dist/darwin-git.js +30 -6
  146. package/node_modules/@oscharko-dev/keiko-sandbox/package.json +2 -2
  147. package/node_modules/@oscharko-dev/keiko-sdk/package.json +9 -9
  148. package/node_modules/@oscharko-dev/keiko-security/dist/errors/gateway.d.ts +7 -1
  149. package/node_modules/@oscharko-dev/keiko-security/dist/errors/gateway.d.ts.map +1 -1
  150. package/node_modules/@oscharko-dev/keiko-security/dist/errors/gateway.js +21 -0
  151. package/node_modules/@oscharko-dev/keiko-security/dist/version.d.ts +1 -1
  152. package/node_modules/@oscharko-dev/keiko-security/dist/version.js +1 -1
  153. package/node_modules/@oscharko-dev/keiko-security/package.json +2 -2
  154. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeActivityOperations.d.ts +24 -0
  155. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeActivityOperations.d.ts.map +1 -1
  156. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeActivityOperations.js +22 -0
  157. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeEventHub.d.ts +8 -1
  158. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeEventHub.d.ts.map +1 -1
  159. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeEventHub.js +28 -1
  160. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/devLaneRuntimeProcessBackend.d.ts.map +1 -1
  161. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/devLaneRuntimeProcessBackend.js +39 -13
  162. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/opencodeFunctionalHarness/_governedTools.d.ts +1 -0
  163. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/opencodeFunctionalHarness/_governedTools.d.ts.map +1 -1
  164. package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/opencodeFunctionalHarness/_governedTools.js +59 -8
  165. package/node_modules/@oscharko-dev/keiko-server/dist/coding-sidecar-gateway.d.ts +6 -0
  166. package/node_modules/@oscharko-dev/keiko-server/dist/coding-sidecar-gateway.d.ts.map +1 -1
  167. package/node_modules/@oscharko-dev/keiko-server/dist/coding-sidecar-gateway.js +592 -119
  168. package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts +15 -0
  169. package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts.map +1 -1
  170. package/node_modules/@oscharko-dev/keiko-server/dist/diagnostics-log.d.ts +5 -1
  171. package/node_modules/@oscharko-dev/keiko-server/dist/diagnostics-log.d.ts.map +1 -1
  172. package/node_modules/@oscharko-dev/keiko-server/dist/diagnostics-log.js +11 -0
  173. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.d.ts +24 -2
  174. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.d.ts.map +1 -1
  175. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.js +215 -38
  176. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-route-deadline.d.ts +6 -0
  177. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-route-deadline.d.ts.map +1 -0
  178. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-route-deadline.js +27 -0
  179. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts +33 -0
  180. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts.map +1 -1
  181. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.js +256 -25
  182. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-tool-calling-probe.d.ts +2 -1
  183. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-tool-calling-probe.d.ts.map +1 -1
  184. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-tool-calling-probe.js +11 -4
  185. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitRoutes.d.ts +2 -1
  186. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitRoutes.d.ts.map +1 -1
  187. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitRoutes.js +221 -38
  188. package/node_modules/@oscharko-dev/keiko-server/package.json +22 -22
  189. package/node_modules/@oscharko-dev/keiko-tool-catalog/package.json +3 -3
  190. package/node_modules/@oscharko-dev/keiko-tools/dist/version.d.ts +1 -1
  191. package/node_modules/@oscharko-dev/keiko-tools/dist/version.js +1 -1
  192. package/node_modules/@oscharko-dev/keiko-tools/package.json +7 -7
  193. package/node_modules/@oscharko-dev/keiko-verification/package.json +5 -5
  194. package/node_modules/@oscharko-dev/keiko-workflows/package.json +10 -10
  195. package/node_modules/@oscharko-dev/keiko-workspace/dist/version.d.ts +1 -1
  196. package/node_modules/@oscharko-dev/keiko-workspace/dist/version.js +1 -1
  197. package/node_modules/@oscharko-dev/keiko-workspace/package.json +3 -3
  198. package/package.json +27 -26
  199. package/release-impact.catalog.json +129 -23
  200. package/vendor/oscharko-dev-keiko-cli-1.1.7.tgz +0 -0
  201. package/vendor/{oscharko-dev-keiko-connectors-1.1.5.tgz → oscharko-dev-keiko-connectors-1.1.7.tgz} +0 -0
  202. package/vendor/oscharko-dev-keiko-contracts-1.1.7.tgz +0 -0
  203. package/vendor/{oscharko-dev-keiko-evaluations-1.1.5.tgz → oscharko-dev-keiko-evaluations-1.1.7.tgz} +0 -0
  204. package/vendor/{oscharko-dev-keiko-evidence-1.1.5.tgz → oscharko-dev-keiko-evidence-1.1.7.tgz} +0 -0
  205. package/vendor/{oscharko-dev-keiko-git-1.1.5.tgz → oscharko-dev-keiko-git-1.1.7.tgz} +0 -0
  206. package/vendor/{oscharko-dev-keiko-harness-1.1.5.tgz → oscharko-dev-keiko-harness-1.1.7.tgz} +0 -0
  207. package/vendor/{oscharko-dev-keiko-local-knowledge-1.1.5.tgz → oscharko-dev-keiko-local-knowledge-1.1.7.tgz} +0 -0
  208. package/vendor/{oscharko-dev-keiko-memory-capture-1.1.5.tgz → oscharko-dev-keiko-memory-capture-1.1.7.tgz} +0 -0
  209. package/vendor/{oscharko-dev-keiko-memory-consolidation-1.1.5.tgz → oscharko-dev-keiko-memory-consolidation-1.1.7.tgz} +0 -0
  210. package/vendor/{oscharko-dev-keiko-memory-governance-1.1.5.tgz → oscharko-dev-keiko-memory-governance-1.1.7.tgz} +0 -0
  211. package/vendor/{oscharko-dev-keiko-memory-retrieval-1.1.5.tgz → oscharko-dev-keiko-memory-retrieval-1.1.7.tgz} +0 -0
  212. package/vendor/{oscharko-dev-keiko-memory-vault-1.1.5.tgz → oscharko-dev-keiko-memory-vault-1.1.7.tgz} +0 -0
  213. package/vendor/oscharko-dev-keiko-model-gateway-1.1.7.tgz +0 -0
  214. package/vendor/{oscharko-dev-keiko-quality-intelligence-1.1.5.tgz → oscharko-dev-keiko-quality-intelligence-1.1.7.tgz} +0 -0
  215. package/vendor/oscharko-dev-keiko-sandbox-1.1.7.tgz +0 -0
  216. package/vendor/oscharko-dev-keiko-sdk-1.1.7.tgz +0 -0
  217. package/vendor/oscharko-dev-keiko-security-1.1.7.tgz +0 -0
  218. package/vendor/oscharko-dev-keiko-server-1.1.7.tgz +0 -0
  219. package/vendor/{oscharko-dev-keiko-tool-catalog-1.1.5.tgz → oscharko-dev-keiko-tool-catalog-1.1.7.tgz} +0 -0
  220. package/vendor/{oscharko-dev-keiko-tools-1.1.5.tgz → oscharko-dev-keiko-tools-1.1.7.tgz} +0 -0
  221. package/vendor/{oscharko-dev-keiko-verification-1.1.5.tgz → oscharko-dev-keiko-verification-1.1.7.tgz} +0 -0
  222. package/vendor/{oscharko-dev-keiko-workflows-1.1.5.tgz → oscharko-dev-keiko-workflows-1.1.7.tgz} +0 -0
  223. package/vendor/{oscharko-dev-keiko-workspace-1.1.5.tgz → oscharko-dev-keiko-workspace-1.1.7.tgz} +0 -0
  224. package/dist/ui/static/_next/static/chunks/0c3w2ubla6ek6.js +0 -1
  225. package/dist/ui/static/_next/static/chunks/0fbt5i1tfqbr3.js +0 -1
  226. package/dist/ui/static/_next/static/chunks/0gnizm29lk3ll.js +0 -1
  227. package/dist/ui/static/_next/static/chunks/0nmcnzva3p40l.js +0 -1
  228. package/dist/ui/static/_next/static/chunks/19fesd0w1gjhp.js +0 -3
  229. package/dist/ui/static/_next/static/chunks/1pze64zkvx8vt.js +0 -1
  230. package/dist/ui/static/_next/static/chunks/2h_zvmb272ozs.js +0 -1
  231. package/dist/ui/static/_next/static/chunks/2onl4czrdod2d.js +0 -1
  232. package/dist/ui/static/_next/static/chunks/2thq7sr8sysu-.js +0 -1
  233. package/dist/ui/static/_next/static/chunks/3-l-8qt163_y6.js +0 -1
  234. package/vendor/oscharko-dev-keiko-cli-1.1.5.tgz +0 -0
  235. package/vendor/oscharko-dev-keiko-contracts-1.1.5.tgz +0 -0
  236. package/vendor/oscharko-dev-keiko-model-gateway-1.1.5.tgz +0 -0
  237. package/vendor/oscharko-dev-keiko-sandbox-1.1.5.tgz +0 -0
  238. package/vendor/oscharko-dev-keiko-sdk-1.1.5.tgz +0 -0
  239. package/vendor/oscharko-dev-keiko-security-1.1.5.tgz +0 -0
  240. package/vendor/oscharko-dev-keiko-server-1.1.5.tgz +0 -0
  241. /package/dist/ui/static/_next/static/{IH07azjG4tKvS8qRk-uMI → nXnJJ05BP_rtUCiZsedfT}/_buildManifest.js +0 -0
  242. /package/dist/ui/static/_next/static/{IH07azjG4tKvS8qRk-uMI → nXnJJ05BP_rtUCiZsedfT}/_clientMiddlewareManifest.js +0 -0
  243. /package/dist/ui/static/_next/static/{IH07azjG4tKvS8qRk-uMI → nXnJJ05BP_rtUCiZsedfT}/_ssgManifest.js +0 -0
@@ -1,9 +1,9 @@
1
1
  import { gatewaySpendRejectionReason } from "./gateway-spend-budget.js";
2
+ import { AuthenticationError, CircuitOpenError, ContextOverflowError, ModelRefusalError, ProviderError, ProviderOutputExhaustedError, RateLimitError, TimeoutError, TransportError, } from "@oscharko-dev/keiko-security/errors/gateway";
2
3
  import { createHash, randomUUID } from "node:crypto";
3
4
  import { findConfiguredCapability, resolveCodingSafeSidecarGatewayProfile, } from "@oscharko-dev/keiko-model-gateway";
4
5
  import { countGatewayPromptTokens, } from "@oscharko-dev/keiko-model-gateway/internal/prompt-token-accounting";
5
- import { providerRequestBudgetMs } from "@oscharko-dev/keiko-model-gateway/internal/resilience";
6
- import { MAX_TIMER_DELAY_MS } from "./abort-race.js";
6
+ import { gatewayRouteDeadlineMs } from "./gateway-route-deadline.js";
7
7
  import { compareStrings } from "@oscharko-dev/keiko-contracts/runtime/comparators";
8
8
  import { CODING_WORKBENCH_MINIMUM_CODING_CONTEXT_PROMPT_TOKENS } from "@oscharko-dev/keiko-contracts/runtime/coding-workbench";
9
9
  import { activityLogEvent, defineActivityLogOperation, } from "@oscharko-dev/keiko-contracts/runtime/observability";
@@ -14,9 +14,11 @@ import { createOpenCodeGatewayToolCatalogAdvertisement, opencodeGatewayOfferLife
14
14
  import { correlationIdOrUnknown, UNKNOWN_CORRELATION_ID } from "./correlation.js";
15
15
  import { emitServerDiagnostic, serverDiagnosticFromError } from "./diagnostics-log.js";
16
16
  import { readJsonObject } from "./files.js";
17
- import { ensureCodingWorkbenchContextWindows } from "./gateway-readiness.js";
17
+ import { safetyMarginTokensFor } from "@oscharko-dev/keiko-contracts/context-engineering";
18
+ import { ensureCodingWorkbenchContextWindows, isAnyCodingWorkbenchProbePending, isCodingWorkbenchProbePending, } from "./gateway-readiness.js";
18
19
  import { getServerLogger } from "./observability/index.js";
19
20
  import { STREAMING, errorBody } from "./routes.js";
21
+ import { sseBackpressureReporter, writeOrDestroy, } from "./sse-write.js";
20
22
  import { startSseHeartbeat } from "./sse.js";
21
23
  import { createCanonicalOpenCodeHandlerCoverage } from "./tool-catalog/catalogToolFacadeBridge.js";
22
24
  const ENABLE_TOKENS = new Set(["1", "true", "on", "yes", "enabled"]);
@@ -43,6 +45,15 @@ function maxActiveCodingGatewayRequests(env = process.env) {
43
45
  export function _resetActiveCodingGatewayRequestsForTests() {
44
46
  activeCodingGatewayRequests = 0;
45
47
  }
48
+ function observedPromptSettlement(outcome, selected, unverified) {
49
+ if (!isRecord(outcome))
50
+ return unverified;
51
+ if (outcome.ok === true)
52
+ return selected;
53
+ if (outcome.ok === false)
54
+ return { ...unverified, status: "retained-after-refusal" };
55
+ return unverified;
56
+ }
46
57
  /**
47
58
  * Settles a runtime prompt-token reservation. `actualPromptTokens` is the provider's real reported
48
59
  * usage when known; when the outcome is uncertain (dispatched but no usage was ever observed — a
@@ -52,10 +63,47 @@ export function _resetActiveCodingGatewayRequestsForTests() {
52
63
  * authenticator (not every deployment wires it) is a silent no-op, never a failure.
53
64
  */
54
65
  function settlePromptTokenReservation(deps, reservation, actualPromptTokens) {
55
- if (reservation.settled)
56
- return;
66
+ const providerReported = actualPromptTokens !== undefined && actualPromptTokens > 0;
67
+ return applyPromptTokenSettlement(deps, reservation, {
68
+ promptTokens: providerReported ? actualPromptTokens : reservation.reservedPromptTokens,
69
+ source: providerReported ? "provider-reported" : "reserved-estimate",
70
+ });
71
+ }
72
+ /**
73
+ * Releases a reservation whose provider call never ran — the client would not take the opening
74
+ * SSE frame, so the buffered path never called the chat factory and the streamed path never pulled
75
+ * the gateway's generator. The conservative rule above keeps the estimate only for a call that WAS
76
+ * dispatched; here nothing was spent, so the whole reservation goes back to the run's budget
77
+ * (#3602 review). Same idempotence and same not-wired fallback as a settlement.
78
+ */
79
+ function releasePromptTokenReservation(deps, reservation) {
80
+ return applyPromptTokenSettlement(deps, reservation, {
81
+ promptTokens: 0,
82
+ source: "released-unspent",
83
+ });
84
+ }
85
+ function applyPromptTokenSettlement(deps, reservation, usage) {
86
+ if (reservation.settled) {
87
+ if (reservation.settlement === undefined)
88
+ throw new TypeError("missing prompt settlement");
89
+ return reservation.settlement;
90
+ }
57
91
  reservation.settled = true;
58
- runtimeCapabilityAuthenticator(deps)?.settlePromptTokens?.(reservation.capability, reservation.reservedPromptTokens, actualPromptTokens ?? reservation.reservedPromptTokens);
92
+ const unverified = {
93
+ promptTokens: reservation.reservedPromptTokens,
94
+ source: "reserved-estimate",
95
+ status: "unverified",
96
+ };
97
+ const selected = { ...usage, status: "settled" };
98
+ reservation.settlement = unverified;
99
+ const authenticator = runtimeCapabilityAuthenticator(deps);
100
+ if (authenticator?.settlePromptTokens === undefined) {
101
+ reservation.settlement = { ...selected, status: "not-wired" };
102
+ return reservation.settlement;
103
+ }
104
+ const outcome = authenticator.settlePromptTokens(reservation.capability, reservation.reservedPromptTokens, usage.promptTokens);
105
+ reservation.settlement = observedPromptSettlement(outcome, selected, unverified);
106
+ return reservation.settlement;
59
107
  }
60
108
  const CODING_SIDECAR_GATEWAY_ERROR_CODE = "CODING_SIDECAR_UNAVAILABLE";
61
109
  const CODING_SIDECAR_GATEWAY_ROUTE = "POST /api/coding-sidecar/gateway/chat/completions";
@@ -81,6 +129,9 @@ const CODING_SIDECAR_GATEWAY_REQUEST_VALIDATED_OPERATION = defineActivityLogOper
81
129
  maxRequestBytes: { type: "integer", dataClass: "count", required: true },
82
130
  maxPromptTokens: { type: "integer", dataClass: "count", required: true },
83
131
  estimatedPromptTokens: { type: "integer", dataClass: "count", required: true },
132
+ // #3591 (1.1.7): the output allowance sent with this request, clamped to the window that
133
+ // remains after the prompt — the value an output-exhausted turn has to be read against.
134
+ maxOutputTokens: { type: "integer", dataClass: "count", required: false },
84
135
  inputMessageCount: { type: "integer", dataClass: "count", required: true },
85
136
  completeness: { type: "string", dataClass: "completeness-state", required: true },
86
137
  loss: { type: "string", dataClass: "loss-state", required: true },
@@ -104,11 +155,21 @@ const CODING_SIDECAR_GATEWAY_READINESS_INSUFFICIENT_OPERATION = defineActivityLo
104
155
  type: "string",
105
156
  dataClass: "closed-enum",
106
157
  required: true,
107
- values: ["model-context-window-insufficient", "no-tool-calling", "tool-calling-unverified"],
158
+ values: [
159
+ "model-context-window-insufficient",
160
+ "no-tool-calling",
161
+ "tool-calling-unverified",
162
+ "model-verification-pending",
163
+ ],
108
164
  },
109
165
  maxPromptTokens: { type: "integer", dataClass: "count", required: false },
110
166
  minimumRequiredPromptTokens: { type: "integer", dataClass: "count", required: false },
111
- probeMode: { type: "string", dataClass: "closed-enum", required: true, values: ["passive"] },
167
+ probeMode: {
168
+ type: "string",
169
+ dataClass: "closed-enum",
170
+ required: true,
171
+ values: ["passive", "pending"],
172
+ },
112
173
  completeness: { type: "string", dataClass: "completeness-state", required: true },
113
174
  loss: { type: "string", dataClass: "loss-state", required: true },
114
175
  },
@@ -207,6 +268,9 @@ const CODING_SIDECAR_GATEWAY_REJECTED_OPERATION = defineActivityLogOperation({
207
268
  },
208
269
  estimatedPromptTokens: { type: "integer", dataClass: "count", required: false },
209
270
  maxPromptTokens: { type: "integer", dataClass: "count", required: false },
271
+ // #3591 review: the bound the prompt was actually admitted against — `maxPromptTokens` less
272
+ // the safety margin and the minimum output allowance (`admissiblePromptTokens`).
273
+ admissiblePromptTokens: { type: "integer", dataClass: "count", required: false },
210
274
  inputMessageCount: { type: "integer", dataClass: "count", required: false },
211
275
  maxInputMessages: { type: "integer", dataClass: "count", required: false },
212
276
  completeness: { type: "string", dataClass: "completeness-state", required: true },
@@ -219,6 +283,130 @@ const CODING_SIDECAR_GATEWAY_REJECTED_OPERATION = defineActivityLogOperation({
219
283
  proofIds: ["coding-sidecar.gateway.rejected.line"],
220
284
  releaseImpact: "patch",
221
285
  });
286
+ const CODING_SIDECAR_GATEWAY_TURN_FAILED_OPERATION = defineActivityLogOperation({
287
+ contractKind: "activity-log-operation",
288
+ schemaVersion: 1,
289
+ op: "coding-sidecar.gateway.turn-failed",
290
+ category: "gateway",
291
+ owner: "keiko-server",
292
+ emitter: "coding-sidecar-gateway.reportGatewayTurnFailure",
293
+ fields: {
294
+ runId: { type: "string", dataClass: "opaque-id", required: true, maxLength: 128 },
295
+ revision: { type: "integer", dataClass: "count", required: true },
296
+ state: {
297
+ type: "string",
298
+ dataClass: "closed-enum",
299
+ required: true,
300
+ values: ["running", "paused"],
301
+ },
302
+ failureCode: {
303
+ type: "string",
304
+ dataClass: "closed-enum",
305
+ required: true,
306
+ values: ["provider-failed", "stream-incomplete", "turn-rejected", "output-exhausted"],
307
+ },
308
+ published: { type: "boolean", dataClass: "closed-enum", required: true },
309
+ publicationReason: {
310
+ type: "string",
311
+ dataClass: "closed-enum",
312
+ required: true,
313
+ values: [
314
+ "published",
315
+ "event-hub-unavailable",
316
+ "terminal-run",
317
+ "invalid-event",
318
+ "sequence-exhausted",
319
+ "capacity-pressure",
320
+ ],
321
+ },
322
+ completeness: { type: "string", dataClass: "completeness-state", required: true },
323
+ loss: { type: "string", dataClass: "loss-state", required: true },
324
+ },
325
+ causal: "correlation",
326
+ lifecycle: "failure",
327
+ analyzerProjection: "failure-cluster",
328
+ failureClasses: ["coding-sidecar-gateway-turn-failure"],
329
+ proofIds: ["coding-sidecar.gateway.turn-failed.emitted-line"],
330
+ releaseImpact: "patch",
331
+ });
332
+ const CODING_SIDECAR_GATEWAY_USAGE_SETTLED_OPERATION = defineActivityLogOperation({
333
+ contractKind: "activity-log-operation",
334
+ schemaVersion: 1,
335
+ op: "coding-sidecar.gateway.usage-settled",
336
+ category: "gateway",
337
+ owner: "keiko-server",
338
+ emitter: "coding-sidecar-gateway.logGatewayCompletionUsage",
339
+ fields: {
340
+ runId: { type: "string", dataClass: "opaque-id", required: true, maxLength: 128 },
341
+ completionTokens: { type: "integer", dataClass: "count", required: true },
342
+ promptTokens: { type: "integer", dataClass: "count", required: true },
343
+ // `released-unspent`: the provider call never ran, the whole reservation went back (#3602).
344
+ promptSource: {
345
+ type: "string",
346
+ dataClass: "closed-enum",
347
+ required: true,
348
+ values: ["provider-reported", "reserved-estimate", "released-unspent"],
349
+ },
350
+ promptSettlementStatus: {
351
+ type: "string",
352
+ dataClass: "closed-enum",
353
+ required: true,
354
+ values: ["settled", "retained-after-refusal", "unverified", "not-wired"],
355
+ },
356
+ outputBytes: { type: "integer", dataClass: "count", required: true },
357
+ source: {
358
+ type: "string",
359
+ dataClass: "closed-enum",
360
+ required: true,
361
+ values: ["provider-reported", "streamed-byte-estimate", "output-byte-estimate"],
362
+ },
363
+ completeness: { type: "string", dataClass: "completeness-state", required: true },
364
+ loss: { type: "string", dataClass: "loss-state", required: true },
365
+ },
366
+ causal: "correlation",
367
+ lifecycle: "end",
368
+ analyzerProjection: "timeline",
369
+ failureClasses: ["coding-sidecar-gateway-request"],
370
+ proofIds: ["coding-sidecar.gateway.usage-settled.line"],
371
+ releaseImpact: "patch",
372
+ });
373
+ const CODING_SIDECAR_GATEWAY_OUTCOME_OPERATION = defineActivityLogOperation({
374
+ contractKind: "activity-log-operation",
375
+ schemaVersion: 1,
376
+ op: "coding-sidecar.gateway.outcome",
377
+ category: "gateway",
378
+ owner: "keiko-server",
379
+ emitter: "coding-sidecar-gateway.recordGatewayOutcome",
380
+ fields: {
381
+ runId: { type: "string", dataClass: "opaque-id", required: true, maxLength: 128 },
382
+ outcome: {
383
+ type: "string",
384
+ dataClass: "closed-enum",
385
+ required: true,
386
+ values: ["accepted", "cancelled", "failed", "output-limit"],
387
+ },
388
+ completionTokens: { type: "integer", dataClass: "count", required: true },
389
+ outputBytes: { type: "integer", dataClass: "count", required: true },
390
+ // The route backstop armed for this turn (#3602 review); absent on lines written before 1.1.7.
391
+ deadlineMs: { type: "integer", dataClass: "duration", required: false },
392
+ // On a cancelled outcome only: which armed abort source ended the turn, so a stall that ran into
393
+ // the backstop, or a slow client the shared SSE path killed, never reads like a client that left.
394
+ cancellationCause: {
395
+ type: "string",
396
+ dataClass: "closed-enum",
397
+ required: false,
398
+ values: ["client-disconnect", "route-deadline", "backpressure-killed", "run-stopped"],
399
+ },
400
+ completeness: { type: "string", dataClass: "completeness-state", required: true },
401
+ loss: { type: "string", dataClass: "loss-state", required: true },
402
+ },
403
+ causal: "correlation",
404
+ lifecycle: "end",
405
+ analyzerProjection: "timeline",
406
+ failureClasses: ["coding-sidecar-gateway-request"],
407
+ proofIds: ["coding-sidecar.gateway.outcome.line"],
408
+ releaseImpact: "patch",
409
+ });
222
410
  function gatewayRejectionErrorKind(reason) {
223
411
  if (reason === "capability-missing" || reason === "capability-invalid") {
224
412
  return "permission-denied";
@@ -238,6 +426,7 @@ function gatewayRejectionErrorKind(reason) {
238
426
  function logGatewayRejection(ctx, runId, status, reason, evidence = {}) {
239
427
  getServerLogger().warn(activityLogEvent(CODING_SIDECAR_GATEWAY_REJECTED_OPERATION, {
240
428
  correlationId: correlationIdOrUnknown(ctx.correlationId),
429
+ ...(runId === undefined ? {} : { parentCorrelationId: runId }),
241
430
  status,
242
431
  errorKind: gatewayRejectionErrorKind(reason),
243
432
  }, {
@@ -389,12 +578,12 @@ function chatFactoryFor(deps, gateway) {
389
578
  }
390
579
  function defaultChatFactoryFor(gateway) {
391
580
  return (_config, modelId) => {
392
- return (request) => gateway.chat({ ...request, modelId });
581
+ return (request) => gateway.chat({ ...request, modelId, latencyProfile: "coding-workbench" });
393
582
  };
394
583
  }
395
584
  function defaultChatStreamFactoryFor(gateway) {
396
585
  return (_config, modelId) => {
397
- return (request) => gateway.chatStream({ ...request, modelId });
586
+ return (request) => gateway.chatStream({ ...request, modelId, latencyProfile: "coding-workbench" });
398
587
  };
399
588
  }
400
589
  function chatStreamFactoryFor(deps, gateway) {
@@ -748,7 +937,25 @@ function emitGatewayEvidenceAggregationDiagnostic(deps, runId) {
748
937
  message: "sidecar-gateway-evidence-aggregation-failed",
749
938
  });
750
939
  }
751
- function recordGatewayOutcome(deps, runId, outcome, completionTokens, outputBytes) {
940
+ // A cancelled outcome names the abort source that ended the turn. Without an aborted source it is
941
+ // the transport path — an SSE or terminal write found the response gone before its `close`
942
+ // listener ran — which is the client leaving, never the deadline.
943
+ function gatewayOutcomeCancellationCause(cancellation, outcome) {
944
+ if (outcome !== "cancelled")
945
+ return undefined;
946
+ return { cancellationCause: cancellation.cause() ?? "client-disconnect" };
947
+ }
948
+ function recordGatewayOutcome(ctx, deps, runId, cancellation, outcome, completionTokens, outputBytes) {
949
+ getServerLogger().info(activityLogEvent(CODING_SIDECAR_GATEWAY_OUTCOME_OPERATION, { correlationId: correlationIdOrUnknown(ctx.correlationId), parentCorrelationId: runId }, {
950
+ runId,
951
+ outcome,
952
+ completionTokens,
953
+ outputBytes,
954
+ deadlineMs: cancellation.deadlineMs,
955
+ ...gatewayOutcomeCancellationCause(cancellation, outcome),
956
+ completeness: "complete",
957
+ loss: "none",
958
+ }));
752
959
  try {
753
960
  void Promise.resolve(evidenceAggregator(deps)?.record({ runId, outcome, completionTokens, outputBytes })).catch(() => {
754
961
  emitGatewayEvidenceAggregationDiagnostic(deps, runId);
@@ -821,8 +1028,9 @@ function budgetValidationError(parsed, runMetadata, estimatedPromptTokens) {
821
1028
  if (parsed.messages.length > runMetadata.maxInputMessages) {
822
1029
  return contextOverflowRequest(`Request body messages exceed profile maxInputMessages (${String(runMetadata.maxInputMessages)}).`);
823
1030
  }
824
- if (estimatedPromptTokens > runMetadata.maxPromptTokens) {
825
- return contextOverflowRequest(`Request body estimated prompt tokens exceed profile maxPromptTokens (${String(runMetadata.maxPromptTokens)}).`);
1031
+ const admissible = admissiblePromptTokens(runMetadata);
1032
+ if (estimatedPromptTokens > admissible) {
1033
+ return contextOverflowRequest(`Request body estimated prompt tokens exceed profile maxPromptTokens (${String(runMetadata.maxPromptTokens)}) less the reserved output allowance (${String(admissible)} admissible).`);
826
1034
  }
827
1035
  return undefined;
828
1036
  }
@@ -859,27 +1067,85 @@ function validationErrorForChatRequest(parsed, modelAlias, runMetadata, runtimeA
859
1067
  }
860
1068
  return undefined;
861
1069
  }
862
- function emitGatewayFailureDiagnostic(ctx, deps, error) {
1070
+ function gatewayDiagnosticCorrelation(ctx, runId) {
1071
+ const correlationId = ctx.correlationId ?? runId;
1072
+ return correlationId === runId
1073
+ ? { correlationId }
1074
+ : { correlationId, parentCorrelationId: runId };
1075
+ }
1076
+ function emitGatewayFailureDiagnostic(ctx, deps, error, runId) {
863
1077
  emitServerDiagnostic(deps.diagnostics, serverDiagnosticFromError({
864
- correlationId: ctx.correlationId ?? UNKNOWN_CORRELATION_ID,
1078
+ ...gatewayDiagnosticCorrelation(ctx, runId),
865
1079
  operation: CODING_SIDECAR_GATEWAY_ROUTE,
866
1080
  source: "coding-sidecar-gateway.chat",
867
1081
  error,
868
1082
  redact: (message) => String(deps.redactor(message)),
869
1083
  }));
870
1084
  }
1085
+ function reportGatewayTurnFailure(ctx, deps, runId, failureCode) {
1086
+ const snapshot = deps.codingRuntimeOrchestrator?.getSnapshot(runId);
1087
+ if (snapshot?.state !== "running" && snapshot?.state !== "paused")
1088
+ return;
1089
+ const publicationReason = gatewayTurnFailurePublication(deps, runId, snapshot, failureCode);
1090
+ logGatewayTurnFailure(ctx, runId, snapshot.revision, snapshot.state, failureCode, publicationReason);
1091
+ }
1092
+ function gatewayTurnFailurePublication(deps, runId, snapshot, failureCode) {
1093
+ const publication = deps.codingRuntimeEventHub?.publishTurnFailure(runId, snapshot.state, snapshot.revision, failureCode);
1094
+ const publicationReason = publication?.ok === true ? "published" : (publication?.reason ?? "event-hub-unavailable");
1095
+ return publicationReason;
1096
+ }
1097
+ function logGatewayTurnFailure(ctx, runId, revision, state, failureCode, publicationReason) {
1098
+ getServerLogger().warn(activityLogEvent(CODING_SIDECAR_GATEWAY_TURN_FAILED_OPERATION, {
1099
+ ...gatewayDiagnosticCorrelation(ctx, runId),
1100
+ errorKind: failureCode === "turn-rejected" ? "validation-failed" : "unavailable",
1101
+ }, {
1102
+ runId,
1103
+ revision,
1104
+ state,
1105
+ failureCode,
1106
+ published: publicationReason === "published",
1107
+ publicationReason,
1108
+ completeness: "complete",
1109
+ loss: "none",
1110
+ }));
1111
+ }
1112
+ function gatewayTurnFailureCode(error) {
1113
+ if (error instanceof ContextOverflowError || error instanceof ModelRefusalError)
1114
+ return "turn-rejected";
1115
+ if (error instanceof ProviderOutputExhaustedError)
1116
+ return "output-exhausted";
1117
+ if (error instanceof TimeoutError ||
1118
+ error instanceof TransportError ||
1119
+ (error instanceof ProviderError && error.httpStatus === 200))
1120
+ return "stream-incomplete";
1121
+ return "provider-failed";
1122
+ }
1123
+ function gatewayStreamFailureCode(error) {
1124
+ if (gatewaySpendRejectionReason(error) !== undefined)
1125
+ return "turn-rejected";
1126
+ if (error instanceof ContextOverflowError || error instanceof ModelRefusalError)
1127
+ return "turn-rejected";
1128
+ if (error instanceof ProviderOutputExhaustedError)
1129
+ return "output-exhausted";
1130
+ if (error instanceof AuthenticationError ||
1131
+ error instanceof RateLimitError ||
1132
+ error instanceof CircuitOpenError ||
1133
+ (error instanceof ProviderError && error.httpStatus !== 200))
1134
+ return "provider-failed";
1135
+ return "stream-incomplete";
1136
+ }
871
1137
  /**
872
1138
  * A mid-stream failure aborts an in-flight coding turn. Before this the cause went into a bare
873
1139
  * `catch {}` — the pattern AGENTS.md §7 forbids — leaving `settleGatewayStreamError` to emit the SSE
874
1140
  * error frame with nothing recorded anywhere, on the coding path. The frame and the run outcome are
875
- * unchanged; only the redacted cause is added, keyed by the request correlation id and separated from
876
- * the pre-stream failure by `source` so an operator can tell "the stream never opened" from "the
1141
+ * unchanged; only the redacted cause is added, keyed by the request and linked to its run,
1142
+ * separated from the pre-stream failure by `source` so an operator can tell "the stream never opened" from "the
877
1143
  * stream died after N deltas". `partialUsage` rides along through `serverDiagnosticFromError`, so an
878
1144
  * interrupted turn's accumulated token counts stay visible instead of vanishing with the error.
879
1145
  */
880
- function emitGatewayStreamFailureDiagnostic(ctx, deps, error) {
1146
+ function emitGatewayStreamFailureDiagnostic(ctx, deps, error, runId) {
881
1147
  emitServerDiagnostic(deps.diagnostics, serverDiagnosticFromError({
882
- correlationId: ctx.correlationId ?? UNKNOWN_CORRELATION_ID,
1148
+ ...gatewayDiagnosticCorrelation(ctx, runId),
883
1149
  operation: CODING_SIDECAR_GATEWAY_ROUTE,
884
1150
  source: "coding-sidecar-gateway.stream",
885
1151
  error,
@@ -985,6 +1251,7 @@ function emitGatewayToolContractDiagnostic(ctx, deps, runId, tools) {
985
1251
  const { code, reason } = toolContractRejectionReason(tools);
986
1252
  emitServerDiagnostic(deps.diagnostics, {
987
1253
  correlationId: ctx.correlationId ?? UNKNOWN_CORRELATION_ID,
1254
+ parentCorrelationId: runId,
988
1255
  timestamp: new Date(Date.now()).toISOString(),
989
1256
  operation: CODING_SIDECAR_GATEWAY_ROUTE,
990
1257
  source: "coding-sidecar-gateway.tool-contract",
@@ -993,6 +1260,7 @@ function emitGatewayToolContractDiagnostic(ctx, deps, runId, tools) {
993
1260
  code,
994
1261
  });
995
1262
  logGatewayRejection(ctx, runId, 403, reason, toolContractMismatch(tools));
1263
+ reportGatewayTurnFailure(ctx, deps, runId, "turn-rejected");
996
1264
  }
997
1265
  /**
998
1266
  * True when a long managed-tool-set history never invoked one governed keiko_* tool: the model is
@@ -1114,6 +1382,7 @@ function unavailableGatewayProfile(ctx, deps, resolved, authentication) {
1114
1382
  message: "coding-sidecar-gateway-profile-unavailable",
1115
1383
  code: unavailableGatewayProfileCode(resolved, selectedModelId, authentication),
1116
1384
  });
1385
+ reportGatewayTurnFailure(ctx, deps, authentication.runId, "turn-rejected");
1117
1386
  return unavailableError();
1118
1387
  }
1119
1388
  function unavailableGatewayProfileCode(resolved, selectedModelId, authentication) {
@@ -1146,20 +1415,37 @@ function gatewayAuthorityKind(authentication) {
1146
1415
  function unavailableGatewayReason(resolved) {
1147
1416
  return resolved.result.status === "unavailable" ? resolved.result.reason : "missing-provider";
1148
1417
  }
1418
+ function sidecarSseTransport(ctx, deps) {
1419
+ const correlationId = correlationIdOrUnknown(ctx.correlationId);
1420
+ return {
1421
+ backpressure: new AbortController(),
1422
+ onBackpressure: sseBackpressureReporter(deps, "coding-sidecar-gateway", correlationId),
1423
+ correlationId,
1424
+ };
1425
+ }
1426
+ // `AbortSignal.any` carries the reason of the source that aborted first, so a client that leaves
1427
+ // after the deadline already fired still reads as the deadline, never the other way round.
1428
+ function gatewayCancellationCause(signal, sources) {
1429
+ if (!signal.aborted)
1430
+ return undefined;
1431
+ if (signal.reason === sources.client.reason)
1432
+ return "client-disconnect";
1433
+ if (signal.reason === sources.deadline.reason)
1434
+ return "route-deadline";
1435
+ if (signal.reason === sources.backpressure.reason)
1436
+ return "backpressure-killed";
1437
+ return "run-stopped";
1438
+ }
1149
1439
  // The route's deadline is a backstop BEHIND the gateway's own end-to-end budget, never the budget
1150
- // itself. It used to be the provider's per-attempt `timeoutMs`: the first attempt that hung spent
1151
- // it, and this deadline, armed before the gateway started its own clock, aborted the retry the
1152
- // gateway had just scheduled, so a provider timeout surfaced as a cancellation nobody had asked
1153
- // for and failed the run (coding run 23, 2026-09-11). The grace lets the gateway settle its own
1154
- // timeout or exhausted-retry error first.
1155
- const GATEWAY_ROUTE_DEADLINE_GRACE_MS = 1_000;
1440
+ // itself (`gateway-route-deadline.ts`, shared with the commit draft since the #3602 review). It used
1441
+ // to be the provider's per-attempt `timeoutMs`: the first attempt that hung spent it, and this
1442
+ // deadline, armed before the gateway started its own clock, aborted the retry the gateway had just
1443
+ // scheduled, so a provider timeout surfaced as a cancellation nobody had asked for and failed the
1444
+ // run (coding run 23, 2026-09-11).
1156
1445
  export function codingSidecarGatewayRequestDeadlineMs(config, modelId) {
1157
- const provider = config.providers.find((candidate) => candidate.modelId === modelId);
1158
- // An unconfigured model is refused before any provider call; 30 s only bounds that refusal.
1159
- const budget = provider === undefined ? 30_000 : providerRequestBudgetMs(provider);
1160
- // Armed with AbortSignal.timeout, which fires at once past 2^31 - 1 ms: an absurd budget must not
1161
- // turn the backstop into an immediate abort.
1162
- return Math.min(budget + GATEWAY_ROUTE_DEADLINE_GRACE_MS, MAX_TIMER_DELAY_MS);
1446
+ // The sidecar reaches the gateway both ways — a buffered `chat()` answer or a `chatStream()`
1447
+ // read — so its backstop sits behind the longer of the two budgets.
1448
+ return gatewayRouteDeadlineMs(config, modelId, ["buffered", "streamed"]);
1163
1449
  }
1164
1450
  function gatewayRequestCancellation(ctx, deps, config, modelId, runId) {
1165
1451
  const client = new AbortController();
@@ -1168,11 +1454,18 @@ function gatewayRequestCancellation(ctx, deps, config, modelId, runId) {
1168
1454
  };
1169
1455
  ctx.req.once("aborted", abortClient);
1170
1456
  ctx.res.once("close", abortClient);
1171
- const deadline = AbortSignal.timeout(codingSidecarGatewayRequestDeadlineMs(config, modelId));
1457
+ const deadlineMs = codingSidecarGatewayRequestDeadlineMs(config, modelId);
1458
+ const deadline = AbortSignal.timeout(deadlineMs);
1459
+ const transport = sidecarSseTransport(ctx, deps);
1172
1460
  const runSignal = cancellationRegistry(deps)?.signalFor(runId);
1173
- const signals = [client.signal, deadline, runSignal].filter((signal) => signal !== undefined);
1461
+ const signals = [client.signal, deadline, transport.backpressure.signal, runSignal].filter((signal) => signal !== undefined);
1462
+ const signal = AbortSignal.any(signals);
1463
+ const sources = { client: client.signal, deadline, backpressure: transport.backpressure.signal };
1174
1464
  return {
1175
- signal: AbortSignal.any(signals),
1465
+ signal,
1466
+ deadlineMs,
1467
+ transport,
1468
+ cause: () => gatewayCancellationCause(signal, sources),
1176
1469
  dispose: () => {
1177
1470
  ctx.req.removeListener("aborted", abortClient);
1178
1471
  ctx.res.removeListener("close", abortClient);
@@ -1185,23 +1478,23 @@ function requestForGatewayDelivery(ctx, parsed, delivery, signal) {
1185
1478
  async function executeGatewayChat(ctx, deps, binding, parsed, runId, delivery) {
1186
1479
  const cancellation = gatewayRequestCancellation(ctx, deps, binding.config, delivery.modelAlias, runId);
1187
1480
  try {
1188
- return await dispatchGatewayChat(ctx, deps, binding, parsed, runId, delivery, cancellation.signal);
1481
+ return await dispatchGatewayChat(ctx, deps, binding, parsed, runId, delivery, cancellation);
1189
1482
  }
1190
1483
  finally {
1191
1484
  cancellation.dispose();
1192
1485
  }
1193
1486
  }
1194
1487
  // Extracted so `executeGatewayChat` stays under AGENTS.md §6's 50-line ceiling.
1195
- async function dispatchGatewayChat(ctx, deps, binding, parsed, runId, delivery, cancellationSignal) {
1488
+ async function dispatchGatewayChat(ctx, deps, binding, parsed, runId, delivery, cancellation) {
1196
1489
  const { modelAlias, upstreamStreamingSupported } = delivery;
1197
- const request = requestForGatewayDelivery(ctx, parsed, delivery, cancellationSignal);
1490
+ const request = requestForGatewayDelivery(ctx, parsed, delivery, cancellation.signal);
1198
1491
  const dispatch = {
1199
1492
  deps,
1200
1493
  binding,
1201
1494
  modelAlias,
1202
1495
  request,
1203
1496
  runId,
1204
- cancellationSignal,
1497
+ cancellation,
1205
1498
  promptTokenReservation: delivery.promptTokenReservation,
1206
1499
  };
1207
1500
  let bufferedStream;
@@ -1209,20 +1502,42 @@ async function dispatchGatewayChat(ctx, deps, binding, parsed, runId, delivery,
1209
1502
  if (parsed.stream && upstreamStreamingSupported) {
1210
1503
  return await streamGatewayChat(ctx, dispatch);
1211
1504
  }
1212
- if (parsed.stream)
1213
- bufferedStream = beginBufferedOpenAiStream(ctx, modelAlias);
1214
- return await executeBufferedGatewayChat(dispatch, bufferedStream);
1505
+ if (parsed.stream) {
1506
+ bufferedStream = beginBufferedOpenAiStream(ctx, modelAlias, cancellation.transport);
1507
+ if (bufferedStream === undefined)
1508
+ return settleUndeliverableBufferedStream(ctx, dispatch);
1509
+ }
1510
+ return await executeBufferedGatewayChat(ctx, dispatch, bufferedStream);
1215
1511
  }
1216
1512
  catch (error) {
1217
- return settleFailedGatewayChat(ctx, deps, runId, cancellationSignal, error, delivery, bufferedStream);
1513
+ return settleFailedGatewayChat(ctx, deps, runId, cancellation, error, delivery, bufferedStream);
1218
1514
  }
1219
1515
  }
1516
+ // The opening frame never reached the client — the shared path killed the stream, or the response
1517
+ // was already gone — so no provider call is started for an answer nobody can receive, exactly as
1518
+ // `beginGatewayStream` ends the streamed path (#3602 review). The outcome names the abort source.
1519
+ function settleUndeliverableBufferedStream(ctx, dispatch) {
1520
+ const { deps, runId, cancellation, promptTokenReservation } = dispatch;
1521
+ recordGatewayOutcome(ctx, deps, runId, cancellation, "cancelled", 0, 0);
1522
+ releaseUndispatchedPromptBudget(ctx, deps, runId, promptTokenReservation);
1523
+ return STREAMING;
1524
+ }
1525
+ // A handshake the client would not take leaves no provider call behind, so the reservation is
1526
+ // released rather than kept as spent, and the usage line records the release (zero prompt tokens,
1527
+ // `released-unspent`) so the ledger movement is reconstructible from the log.
1528
+ function releaseUndispatchedPromptBudget(ctx, deps, runId, reservation) {
1529
+ const settlement = releasePromptTokenReservation(deps, reservation);
1530
+ logGatewayCompletionUsage(ctx, runId, { completionTokens: 0, outputBytes: 0 }, "output-byte-estimate", settlement);
1531
+ }
1220
1532
  // Extracted so `executeGatewayChat` stays under AGENTS.md §6's 50-line ceiling.
1221
- function settleFailedGatewayChat(ctx, deps, runId, cancellationSignal, error, delivery, bufferedStream) {
1222
- recordGatewayOutcome(deps, runId, cancellationSignal.aborted ? "cancelled" : "failed", 0, 0);
1223
- emitGatewayFailureDiagnostic(ctx, deps, error);
1224
- settlePromptTokenReservation(deps, delivery.promptTokenReservation);
1533
+ function settleFailedGatewayChat(ctx, deps, runId, cancellation, error, delivery, bufferedStream) {
1534
+ const cancelled = cancellation.signal.aborted;
1535
+ recordGatewayOutcome(ctx, deps, runId, cancellation, cancelled ? "cancelled" : "failed", 0, 0);
1536
+ emitGatewayFailureDiagnostic(ctx, deps, error, runId);
1225
1537
  const spendReason = gatewaySpendRejectionReason(error);
1538
+ if (!cancelled)
1539
+ reportGatewayTurnFailure(ctx, deps, runId, spendReason === undefined ? gatewayTurnFailureCode(error) : "turn-rejected");
1540
+ settlePromptTokenReservation(deps, delivery.promptTokenReservation);
1226
1541
  if (spendReason !== undefined && bufferedStream === undefined) {
1227
1542
  logGatewayRejection(ctx, runId, 403, spendReason);
1228
1543
  return forbiddenGatewayRequest();
@@ -1231,27 +1546,43 @@ function settleFailedGatewayChat(ctx, deps, runId, cancellationSignal, error, de
1231
1546
  ? unavailableError()
1232
1547
  : settleBufferedOpenAiStreamError(bufferedStream, "error");
1233
1548
  }
1234
- async function executeBufferedGatewayChat(dispatch, stream) {
1235
- const { deps, binding, modelAlias, request, runId, cancellationSignal, promptTokenReservation } = dispatch;
1549
+ async function executeBufferedGatewayChat(ctx, dispatch, stream) {
1550
+ const { deps, binding, modelAlias, request, runId, cancellation, promptTokenReservation } = dispatch;
1236
1551
  const response = await chatFactoryFor(deps, binding.gateway)(binding.config, modelAlias)(request);
1237
- settlePromptTokenReservation(deps, promptTokenReservation, response.usage.promptTokens);
1238
- const metrics = outputMetrics(response);
1239
- if (cancellationSignal.aborted) {
1240
- recordGatewayOutcome(deps, runId, "cancelled", metrics.completionTokens, metrics.outputBytes);
1552
+ const promptSettlement = settlePromptTokenReservation(deps, promptTokenReservation, response.usage.promptTokens);
1553
+ const output = outputMetrics(response);
1554
+ const usage = completionUsage(response, output.outputBytes, 0);
1555
+ const metrics = { ...output, completionTokens: usage.completionTokens };
1556
+ const settledResponse = {
1557
+ ...response,
1558
+ usage: { ...response.usage, completionTokens: usage.completionTokens },
1559
+ };
1560
+ logGatewayCompletionUsage(ctx, runId, metrics, usage.source, promptSettlement);
1561
+ const record = (outcome) => {
1562
+ recordGatewayOutcome(ctx, deps, runId, cancellation, outcome, metrics.completionTokens, metrics.outputBytes);
1563
+ };
1564
+ if (cancellation.signal.aborted) {
1565
+ record("cancelled");
1241
1566
  return stream === undefined
1242
1567
  ? unavailableError()
1243
1568
  : settleBufferedOpenAiStreamError(stream, "error");
1244
1569
  }
1245
1570
  if (exceedsOutputBudget(metrics, request.maxOutputTokens ?? 1)) {
1246
- recordGatewayOutcome(deps, runId, "output-limit", metrics.completionTokens, metrics.outputBytes);
1571
+ record("output-limit");
1247
1572
  return stream === undefined
1248
1573
  ? unavailableError()
1249
1574
  : settleBufferedOpenAiStreamError(stream, "length");
1250
1575
  }
1251
- recordGatewayOutcome(deps, runId, "accepted", metrics.completionTokens, metrics.outputBytes);
1252
- return stream === undefined
1253
- ? openAiResponse(modelAlias, response)
1254
- : completeBufferedOpenAiStream(stream, response);
1576
+ return deliverBufferedGatewayAnswer(ctx, modelAlias, stream, settledResponse, record);
1577
+ }
1578
+ function deliverBufferedGatewayAnswer(ctx, modelAlias, stream, response, record) {
1579
+ if (stream === undefined) {
1580
+ record("accepted");
1581
+ return openAiResponse(modelAlias, response);
1582
+ }
1583
+ completeBufferedOpenAiStream(stream, response);
1584
+ record(ctx.res.writableEnded && !ctx.res.destroyed ? "accepted" : "cancelled");
1585
+ return STREAMING;
1255
1586
  }
1256
1587
  // Closed stream state machine keeps iterator, cancellation, and SSE backpressure transitions together.
1257
1588
  async function streamGatewayChat(ctx, dispatch) {
@@ -1261,15 +1592,22 @@ async function streamGatewayChat(ctx, dispatch) {
1261
1592
  iterator = chatStreamFactoryFor(deps, binding.gateway)(binding.config, modelAlias)(request)[Symbol.asyncIterator]();
1262
1593
  }
1263
1594
  catch (error) {
1264
- recordGatewayOutcome(deps, runId, "failed", 0, 0);
1265
- emitGatewayFailureDiagnostic(ctx, deps, error);
1595
+ recordGatewayOutcome(ctx, deps, runId, dispatch.cancellation, "failed", 0, 0);
1596
+ emitGatewayFailureDiagnostic(ctx, deps, error, runId);
1597
+ reportGatewayTurnFailure(ctx, deps, runId, gatewayTurnFailureCode(error));
1266
1598
  settlePromptTokenReservation(deps, promptTokenReservation);
1267
1599
  return unavailableError();
1268
1600
  }
1269
1601
  const session = createGatewayStreamSession(ctx, dispatch, iterator);
1270
1602
  try {
1271
- if (beginGatewayStream(session))
1272
- await pumpGatewayStreamWithCancellation(ctx, deps, session);
1603
+ if (beginGatewayStream(session)) {
1604
+ await pumpGatewayStreamWithCancellation(deps, session);
1605
+ }
1606
+ else {
1607
+ // The gateway's stream is an async generator: nothing was sent before the first pull, and
1608
+ // the handshake failed before it, so the reservation is released, not kept as spent.
1609
+ releaseUndispatchedPromptBudget(ctx, deps, runId, promptTokenReservation);
1610
+ }
1273
1611
  return STREAMING;
1274
1612
  }
1275
1613
  finally {
@@ -1279,8 +1617,9 @@ async function streamGatewayChat(ctx, dispatch) {
1279
1617
  settlePromptTokenReservation(session.deps, session.promptTokenReservation);
1280
1618
  }
1281
1619
  }
1282
- async function pumpGatewayStreamWithCancellation(ctx, deps, session) {
1283
- const { cancellationSignal, iterator } = session;
1620
+ async function pumpGatewayStreamWithCancellation(deps, session) {
1621
+ const { cancellation, iterator } = session;
1622
+ const cancellationSignal = cancellation.signal;
1284
1623
  const cancelIterator = () => {
1285
1624
  void iterator.return?.();
1286
1625
  };
@@ -1289,7 +1628,10 @@ async function pumpGatewayStreamWithCancellation(ctx, deps, session) {
1289
1628
  await pumpGatewayStream(session);
1290
1629
  }
1291
1630
  catch (error) {
1292
- emitGatewayStreamFailureDiagnostic(ctx, deps, error);
1631
+ emitGatewayStreamFailureDiagnostic(session.ctx, deps, error, session.runId);
1632
+ if (!cancellationSignal.aborted) {
1633
+ reportGatewayTurnFailure(session.ctx, deps, session.runId, gatewayStreamFailureCode(error));
1634
+ }
1293
1635
  settleGatewayStreamError(session);
1294
1636
  }
1295
1637
  finally {
@@ -1297,7 +1639,7 @@ async function pumpGatewayStreamWithCancellation(ctx, deps, session) {
1297
1639
  }
1298
1640
  }
1299
1641
  function createGatewayStreamSession(ctx, dispatch, iterator) {
1300
- const { deps, modelAlias, request, runId, cancellationSignal, promptTokenReservation } = dispatch;
1642
+ const { deps, modelAlias, request, runId, cancellation, promptTokenReservation } = dispatch;
1301
1643
  return {
1302
1644
  ctx,
1303
1645
  deps,
@@ -1306,7 +1648,7 @@ function createGatewayStreamSession(ctx, dispatch, iterator) {
1306
1648
  modelId: modelAlias,
1307
1649
  request,
1308
1650
  runId,
1309
- cancellationSignal,
1651
+ cancellation,
1310
1652
  iterator,
1311
1653
  promptTokenReservation,
1312
1654
  metrics: {
@@ -1325,7 +1667,8 @@ function beginGatewayStream(session) {
1325
1667
  "Cache-Control": "no-store",
1326
1668
  Connection: "keep-alive",
1327
1669
  });
1328
- if (!writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, { role: "assistant" }, null))) {
1670
+ const opened = writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, { role: "assistant" }, null), session.cancellation.transport);
1671
+ if (!opened) {
1329
1672
  ctx.res.destroy();
1330
1673
  recordSessionOutcome(session, "cancelled");
1331
1674
  return false;
@@ -1333,15 +1676,16 @@ function beginGatewayStream(session) {
1333
1676
  return true;
1334
1677
  }
1335
1678
  function recordSessionOutcome(session, outcome) {
1336
- const { deps, runId, metrics } = session;
1337
- recordGatewayOutcome(deps, runId, outcome, metrics.completionTokens, metrics.outputBytes);
1679
+ const { ctx, deps, runId, cancellation, metrics } = session;
1680
+ recordGatewayOutcome(ctx, deps, runId, cancellation, outcome, metrics.completionTokens, metrics.outputBytes);
1338
1681
  }
1339
1682
  function writeSessionTerminal(session, finishReason) {
1340
- const { ctx, id, created, modelId, metrics } = session;
1341
- writeStreamTerminal(ctx, id, created, modelId, finishReason, metrics.promptTokens, metrics.completionTokens);
1683
+ const { ctx, id, created, modelId, metrics, cancellation } = session;
1684
+ writeStreamTerminal({ ctx, id, created, modelId, transport: cancellation.transport }, finishReason, metrics.promptTokens, metrics.completionTokens);
1342
1685
  }
1343
1686
  async function pumpGatewayStream(session) {
1344
- const { cancellationSignal, iterator } = session;
1687
+ const { cancellation, iterator } = session;
1688
+ const cancellationSignal = cancellation.signal;
1345
1689
  for (;;) {
1346
1690
  if (isGatewayRequestCancelled(cancellationSignal)) {
1347
1691
  await iterator.return?.();
@@ -1364,8 +1708,8 @@ async function pumpGatewayStream(session) {
1364
1708
  await streamGatewayResponse(session, chunk.response);
1365
1709
  return;
1366
1710
  }
1367
- recordSessionOutcome(session, "failed");
1368
- writeSessionTerminal(session, "error");
1711
+ // A stream without a terminal response must reach the shared diagnostic and turn-event path.
1712
+ throw new ProviderError("provider stream ended without a terminal response", 200);
1369
1713
  }
1370
1714
  /** Returns true when the stream may continue with the next chunk. */
1371
1715
  async function streamGatewayDelta(session, token) {
@@ -1381,7 +1725,8 @@ async function streamGatewayDelta(session, token) {
1381
1725
  writeSessionTerminal(session, "length");
1382
1726
  return false;
1383
1727
  }
1384
- if (!writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, { content: token }, null))) {
1728
+ const wrote = writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, { content: token }, null), session.cancellation.transport);
1729
+ if (!wrote) {
1385
1730
  ctx.res.destroy();
1386
1731
  await iterator.return?.();
1387
1732
  recordSessionOutcome(session, "cancelled");
@@ -1392,18 +1737,18 @@ async function streamGatewayDelta(session, token) {
1392
1737
  async function streamGatewayResponse(session, response) {
1393
1738
  const { ctx, id, created, modelId, request, iterator, metrics, promptTokenReservation } = session;
1394
1739
  const outcome = outputMetrics(response);
1395
- metrics.completionTokens = outcome.completionTokens;
1396
- metrics.outputBytes = outcome.outputBytes;
1740
+ metrics.outputBytes = Math.max(outcome.outputBytes, metrics.outputBytes);
1397
1741
  metrics.promptTokens = response.usage.promptTokens;
1398
- settlePromptTokenReservation(session.deps, promptTokenReservation, response.usage.promptTokens);
1399
- if (exceedsOutputBudget(outcome, request.maxOutputTokens ?? 1)) {
1742
+ const promptSettlement = settlePromptTokenReservation(session.deps, promptTokenReservation, response.usage.promptTokens);
1743
+ settleStreamCompletionUsage(session, response, outcome, promptSettlement);
1744
+ if (exceedsOutputBudget(metrics, request.maxOutputTokens ?? 1)) {
1400
1745
  await iterator.return?.();
1401
1746
  recordSessionOutcome(session, "output-limit");
1402
1747
  writeSessionTerminal(session, "length");
1403
1748
  return;
1404
1749
  }
1405
1750
  if (response.toolCalls.length > 0) {
1406
- const wrote = writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, { tool_calls: openAiToolCalls(response.toolCalls) }, null));
1751
+ const wrote = writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, { tool_calls: openAiToolCalls(response.toolCalls) }, null), session.cancellation.transport);
1407
1752
  if (!wrote) {
1408
1753
  ctx.res.destroy();
1409
1754
  await iterator.return?.();
@@ -1411,11 +1756,52 @@ async function streamGatewayResponse(session, response) {
1411
1756
  return;
1412
1757
  }
1413
1758
  }
1414
- recordSessionOutcome(session, "accepted");
1415
1759
  writeSessionTerminal(session, response.finishReason);
1760
+ recordSessionOutcome(session, ctx.res.writableEnded && !ctx.res.destroyed ? "accepted" : "cancelled");
1761
+ }
1762
+ function settleStreamCompletionUsage(session, response, outcome, promptSettlement) {
1763
+ const { metrics, ctx, runId } = session;
1764
+ const usage = completionUsage(response, outcome.outputBytes, metrics.completionTokens);
1765
+ metrics.completionTokens = usage.completionTokens;
1766
+ logGatewayCompletionUsage(ctx, runId, {
1767
+ completionTokens: metrics.completionTokens,
1768
+ outputBytes: Math.max(outcome.outputBytes, metrics.outputBytes),
1769
+ }, usage.source, promptSettlement);
1770
+ }
1771
+ function completionUsage(response, outputBytes, streamedCompletionTokens) {
1772
+ if (response.usage.completionTokens > 0) {
1773
+ return { completionTokens: response.usage.completionTokens, source: "provider-reported" };
1774
+ }
1775
+ if (response.toolCalls.length > 0 || response.structuredOutput !== null) {
1776
+ return {
1777
+ completionTokens: Math.ceil(outputBytes / OUTPUT_BYTES_PER_TOKEN_LIMIT),
1778
+ source: "output-byte-estimate",
1779
+ };
1780
+ }
1781
+ if (streamedCompletionTokens > 0) {
1782
+ return { completionTokens: streamedCompletionTokens, source: "streamed-byte-estimate" };
1783
+ }
1784
+ const hasOutput = response.content.length > 0;
1785
+ return {
1786
+ completionTokens: hasOutput ? Math.ceil(outputBytes / OUTPUT_BYTES_PER_TOKEN_LIMIT) : 0,
1787
+ source: "output-byte-estimate",
1788
+ };
1789
+ }
1790
+ function logGatewayCompletionUsage(ctx, runId, metrics, source, promptSettlement) {
1791
+ getServerLogger().info(activityLogEvent(CODING_SIDECAR_GATEWAY_USAGE_SETTLED_OPERATION, { correlationId: correlationIdOrUnknown(ctx.correlationId), parentCorrelationId: runId }, {
1792
+ runId,
1793
+ completionTokens: metrics.completionTokens,
1794
+ promptTokens: promptSettlement.promptTokens,
1795
+ promptSource: promptSettlement.source,
1796
+ promptSettlementStatus: promptSettlement.status,
1797
+ outputBytes: metrics.outputBytes,
1798
+ source,
1799
+ completeness: "complete",
1800
+ loss: "none",
1801
+ }));
1416
1802
  }
1417
1803
  function settleGatewayStreamError(session) {
1418
- if (!session.cancellationSignal.aborted) {
1804
+ if (!session.cancellation.signal.aborted) {
1419
1805
  recordSessionOutcome(session, "failed");
1420
1806
  writeSessionTerminal(session, "error");
1421
1807
  }
@@ -1426,7 +1812,8 @@ function settleGatewayStreamError(session) {
1426
1812
  function isGatewayRequestCancelled(signal) {
1427
1813
  return signal.aborted;
1428
1814
  }
1429
- function beginBufferedOpenAiStream(ctx, modelId) {
1815
+ /** Returns undefined when the opening SSE frame could not be delivered; the response is destroyed. */
1816
+ function beginBufferedOpenAiStream(ctx, modelId, transport) {
1430
1817
  const id = `chatcmpl-${randomUUID()}`;
1431
1818
  const created = Math.floor(Date.now() / 1000);
1432
1819
  ctx.res.writeHead(200, {
@@ -1434,19 +1821,26 @@ function beginBufferedOpenAiStream(ctx, modelId) {
1434
1821
  "Cache-Control": "no-store",
1435
1822
  Connection: "keep-alive",
1436
1823
  });
1437
- if (!writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, { role: "assistant" }, null))) {
1824
+ const opened = writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, { role: "assistant" }, null), transport);
1825
+ if (!opened) {
1438
1826
  ctx.res.destroy();
1827
+ return undefined;
1439
1828
  }
1440
1829
  return {
1441
1830
  ctx,
1442
1831
  id,
1443
1832
  created,
1444
1833
  modelId,
1445
- stopHeartbeat: startSseHeartbeat(ctx.res, BUFFERED_STREAM_HEARTBEAT_MS),
1834
+ transport,
1835
+ stopHeartbeat: startSseHeartbeat(ctx.res, BUFFERED_STREAM_HEARTBEAT_MS, undefined, {
1836
+ controller: transport.backpressure,
1837
+ onBackpressure: transport.onBackpressure,
1838
+ correlationId: transport.correlationId,
1839
+ }),
1446
1840
  };
1447
1841
  }
1448
1842
  function completeBufferedOpenAiStream(session, response) {
1449
- const { ctx, id, created, modelId, stopHeartbeat } = session;
1843
+ const { ctx, id, created, modelId, transport, stopHeartbeat } = session;
1450
1844
  stopHeartbeat();
1451
1845
  if (response.content.length > 0 || response.toolCalls.length > 0) {
1452
1846
  const wrote = writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, {
@@ -1454,32 +1848,35 @@ function completeBufferedOpenAiStream(session, response) {
1454
1848
  ...(response.toolCalls.length === 0
1455
1849
  ? {}
1456
1850
  : { tool_calls: openAiToolCalls(response.toolCalls) }),
1457
- }, null));
1851
+ }, null), transport);
1458
1852
  if (!wrote) {
1459
1853
  ctx.res.destroy();
1460
1854
  return STREAMING;
1461
1855
  }
1462
1856
  }
1463
- writeStreamTerminal(ctx, id, created, modelId, response.finishReason, response.usage.promptTokens, response.usage.completionTokens);
1857
+ writeStreamTerminal(session, response.finishReason, response.usage.promptTokens, response.usage.completionTokens);
1464
1858
  return STREAMING;
1465
1859
  }
1466
1860
  function settleBufferedOpenAiStreamError(session, finishReason) {
1467
- const { ctx, id, created, modelId, stopHeartbeat } = session;
1468
- stopHeartbeat();
1469
- writeStreamTerminal(ctx, id, created, modelId, finishReason, 0, 0);
1861
+ session.stopHeartbeat();
1862
+ writeStreamTerminal(session, finishReason, 0, 0);
1470
1863
  return STREAMING;
1471
1864
  }
1472
- function bufferedOpenAiStream(ctx, modelId, response) {
1473
- return completeBufferedOpenAiStream(beginBufferedOpenAiStream(ctx, modelId), response);
1865
+ function bufferedOpenAiStream(ctx, deps, modelId, response) {
1866
+ const session = beginBufferedOpenAiStream(ctx, modelId, sidecarSseTransport(ctx, deps));
1867
+ return session === undefined ? STREAMING : completeBufferedOpenAiStream(session, response);
1474
1868
  }
1475
- function writeOpenAiSse(ctx, payload) {
1476
- if (!ctx.res.writableEnded && !ctx.res.destroyed) {
1477
- return ctx.res.write(`data: ${JSON.stringify(payload)}\n\n`);
1478
- }
1479
- return false;
1869
+ // False means the frame did not reach the client: either the response was already gone (the
1870
+ // client's own `close` is the abort source that names it) or the shared path killed the stream for
1871
+ // backpressure (its controller is). A caller that sees false stops producing; it never resumes.
1872
+ function writeOpenAiSse(ctx, payload, transport) {
1873
+ if (ctx.res.writableEnded || ctx.res.destroyed)
1874
+ return false;
1875
+ return writeOrDestroy(ctx.res, `data: ${JSON.stringify(payload)}\n\n`, transport.backpressure, transport.onBackpressure, transport.correlationId);
1480
1876
  }
1481
- function writeStreamTerminal(ctx, id, created, modelId, finishReason, promptTokens, completionTokens) {
1482
- writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, {}, finishReason));
1877
+ function writeStreamTerminal(stream, finishReason, promptTokens, completionTokens) {
1878
+ const { ctx, id, created, modelId, transport } = stream;
1879
+ writeOpenAiSse(ctx, openAiStreamChunk(id, created, modelId, {}, finishReason), transport);
1483
1880
  writeOpenAiSse(ctx, {
1484
1881
  id,
1485
1882
  object: "chat.completion.chunk",
@@ -1491,7 +1888,7 @@ function writeStreamTerminal(ctx, id, created, modelId, finishReason, promptToke
1491
1888
  completion_tokens: completionTokens,
1492
1889
  total_tokens: promptTokens + completionTokens,
1493
1890
  },
1494
- });
1891
+ }, transport);
1495
1892
  if (!ctx.res.writableEnded && !ctx.res.destroyed)
1496
1893
  ctx.res.end("data: [DONE]\n\n");
1497
1894
  }
@@ -1518,17 +1915,44 @@ function gatewayReadinessProjection(ctx, deps) {
1518
1915
  if (result.status === "available" &&
1519
1916
  result.runMetadata.maxPromptTokens >= CODING_WORKBENCH_MINIMUM_CODING_CONTEXT_PROMPT_TOKENS)
1520
1917
  return result;
1521
- const reason = result.status === "available" ? "model-context-window-insufficient" : result.reason;
1522
- if (reason !== "model-context-window-insufficient" &&
1523
- reason !== "no-tool-calling" &&
1524
- reason !== "tool-calling-unverified")
1918
+ const shortfall = result.status === "available" ? "model-context-window-insufficient" : result.reason;
1919
+ if (shortfall !== "model-context-window-insufficient" &&
1920
+ shortfall !== "no-tool-calling" &&
1921
+ shortfall !== "tool-calling-unverified")
1525
1922
  return result;
1923
+ // #3591 (1.1.7): while the automatic probe is still running against a slow gateway the shortfall
1924
+ // is not a verdict. The profile says so, and the Workbench re-reads it instead of refusing.
1925
+ const pending = readinessProbePending(deps, result, shortfall);
1926
+ const reason = pending
1927
+ ? "model-verification-pending"
1928
+ : shortfall;
1929
+ logReadinessShortfall(ctx, result, reason, pending);
1930
+ // An open verification replaces the stored shortfall for an unavailable projection too (an
1931
+ // unverified tool-calling proof whose probe is still running), or the Workbench would stop
1932
+ // reading and keep the refusal until an unrelated refresh.
1933
+ if (result.status === "available" || pending)
1934
+ return { status: "unavailable", reason };
1935
+ return result;
1936
+ }
1937
+ function readinessProbePending(deps, result, shortfall) {
1938
+ if (shortfall === "no-tool-calling")
1939
+ return false;
1940
+ const config = currentGatewayConfig(deps);
1941
+ if (config === undefined)
1942
+ return false;
1943
+ // An unavailable projection (an unverified tool-calling proof) names no model: its verification
1944
+ // is open while any model the Workbench could still elect has an open probe.
1945
+ return result.status === "available"
1946
+ ? isCodingWorkbenchProbePending(config, result.modelAlias)
1947
+ : isAnyCodingWorkbenchProbePending(config);
1948
+ }
1949
+ function logReadinessShortfall(ctx, result, reason, pending) {
1526
1950
  getServerLogger().warn(activityLogEvent(CODING_SIDECAR_GATEWAY_READINESS_INSUFFICIENT_OPERATION, {
1527
1951
  correlationId: correlationIdOrUnknown(ctx.correlationId),
1528
1952
  errorKind: "unavailable",
1529
1953
  }, {
1530
1954
  reason,
1531
- probeMode: "passive",
1955
+ probeMode: pending ? "pending" : "passive",
1532
1956
  ...(result.status === "available"
1533
1957
  ? {
1534
1958
  maxPromptTokens: result.runMetadata.maxPromptTokens,
@@ -1538,9 +1962,6 @@ function gatewayReadinessProjection(ctx, deps) {
1538
1962
  completeness: "complete",
1539
1963
  loss: "none",
1540
1964
  }));
1541
- return result.status === "available"
1542
- ? { status: "unavailable", reason: "model-context-window-insufficient" }
1543
- : result;
1544
1965
  }
1545
1966
  export async function handleCodingSidecarGatewayProfile(ctx, deps) {
1546
1967
  // What Keiko can determine itself it determines itself: a model whose gateway declared no token
@@ -1549,10 +1970,25 @@ export async function handleCodingSidecarGatewayProfile(ctx, deps) {
1549
1970
  // Only while the gateway is the usable source: a subscription source, a disabled policy or a
1550
1971
  // missing configuration must never cause a paid provider probe (ADR-0124 D5).
1551
1972
  if (elected.status === "available" || elected.reason === "tool-calling-unverified") {
1552
- await ensureCodingWorkbenchContextWindows(deps, elected.status === "available" ? elected.modelAlias : undefined, ctx.correlationId);
1973
+ // #3591 (1.1.7): the browser reads this profile with a 15 s deadline while a probe against a
1974
+ // slow gateway may take minutes. Wait a bounded moment for the elected model's proof; past it,
1975
+ // answer with the projection (`model-verification-pending` while the probe runs) and let
1976
+ // the Workbench read again — never leave the read hanging until the browser gives up.
1977
+ await Promise.race([
1978
+ ensureCodingWorkbenchContextWindows(deps, elected.status === "available" ? elected.modelAlias : undefined, ctx.correlationId),
1979
+ boundedProfileWait(),
1980
+ ]);
1553
1981
  }
1554
1982
  return { status: 200, body: gatewayReadinessProjection(ctx, deps) };
1555
1983
  }
1984
+ // Under the browser's 15 s read deadline for this profile (keiko-ui `DEFAULT_READ_TIMEOUT_MS`).
1985
+ export const PROFILE_PROBE_WAIT_MS = 8_000;
1986
+ function boundedProfileWait() {
1987
+ return new Promise((resolve) => {
1988
+ const timer = setTimeout(resolve, PROFILE_PROBE_WAIT_MS);
1989
+ timer.unref();
1990
+ });
1991
+ }
1556
1992
  function upstreamGatewayStreamingSupported(deps, advertisedSupport) {
1557
1993
  return advertisedSupport || deps.codingSidecarGatewayChatStreamFactory !== undefined;
1558
1994
  }
@@ -1586,7 +2022,7 @@ function authenticatedGatewayAdmission(ctx, deps, parsed, authentication, modelA
1586
2022
  registry?.claim(authentication.runId) === true) {
1587
2023
  return {
1588
2024
  kind: "handled",
1589
- result: fixedReadinessResponse(ctx, modelAlias, parsed.stream === true),
2025
+ result: fixedReadinessResponse(ctx, deps, modelAlias, parsed.stream === true),
1590
2026
  };
1591
2027
  }
1592
2028
  if (isExactManagedToolSet(parsed.tools))
@@ -1613,27 +2049,29 @@ export async function handleCodingSidecarGatewayChatCompletions(ctx, deps) {
1613
2049
  activeCodingGatewayRequests -= 1;
1614
2050
  }
1615
2051
  }
1616
- function logChatRequestRejection(ctx, runId, validationError, observed) {
2052
+ function logChatRequestRejection(ctx, deps, runId, validationError, observed) {
1617
2053
  const reason = classifyBadRequestReason(validationError);
1618
2054
  const boundedEvidence = observed !== undefined &&
1619
2055
  (reason === "input-messages-exceeded" || reason === "prompt-tokens-exceeded")
1620
2056
  ? {
1621
2057
  estimatedPromptTokens: observed.estimatedPromptTokens,
1622
2058
  maxPromptTokens: observed.bounds.maxPromptTokens,
2059
+ admissiblePromptTokens: admissiblePromptTokens(observed.bounds),
1623
2060
  inputMessageCount: observed.parsed.messages.length,
1624
2061
  maxInputMessages: observed.bounds.maxInputMessages,
1625
2062
  }
1626
2063
  : undefined;
1627
2064
  logGatewayRejection(ctx, runId, validationError.status, reason, boundedEvidence);
2065
+ reportGatewayTurnFailure(ctx, deps, runId, "turn-rejected");
1628
2066
  }
1629
- async function readValidatedChatRequest(ctx, resolved, authentication) {
2067
+ async function readValidatedChatRequest(ctx, deps, resolved, authentication) {
1630
2068
  const parsed = await readChatCompletionRequest(ctx, resolved.result.runMetadata.maxRequestBytes);
1631
2069
  const estimatedPromptTokens = isRouteResult(parsed)
1632
2070
  ? 0
1633
2071
  : promptTokenEstimate(parsed, promptTokenAccounting(resolved));
1634
2072
  const validationError = validationErrorForChatRequest(parsed, resolved.result.modelAlias, resolved.result.runMetadata, authentication.runtimeAuthenticated, estimatedPromptTokens);
1635
2073
  if (validationError !== undefined) {
1636
- logChatRequestRejection(ctx, authentication.runId, validationError, isRouteResult(parsed)
2074
+ logChatRequestRejection(ctx, deps, authentication.runId, validationError, isRouteResult(parsed)
1637
2075
  ? undefined
1638
2076
  : { parsed, bounds: resolved.result.runMetadata, estimatedPromptTokens });
1639
2077
  return validationError;
@@ -1649,7 +2087,7 @@ async function runHandleCodingSidecarGatewayChatCompletions(ctx, deps) {
1649
2087
  const resolved = resolveAuthenticatedGatewayProfile(deps, authentication);
1650
2088
  if (!isAvailableGatewayProfile(resolved))
1651
2089
  return unavailableGatewayProfile(ctx, deps, resolved, authentication);
1652
- const validated = await readValidatedChatRequest(ctx, resolved, authentication);
2090
+ const validated = await readValidatedChatRequest(ctx, deps, resolved, authentication);
1653
2091
  if (isRouteResult(validated))
1654
2092
  return validated;
1655
2093
  const { parsed, estimatedPromptTokens } = validated;
@@ -1659,19 +2097,51 @@ async function runHandleCodingSidecarGatewayChatCompletions(ctx, deps) {
1659
2097
  return admission.result;
1660
2098
  return executeBudgetedGatewayChat(ctx, deps, resolved, parsed, authentication, estimatedPromptTokens, {
1661
2099
  modelAlias: resolved.result.modelAlias,
1662
- maxOutputTokens: resolved.result.runMetadata.maxOutputTokens,
2100
+ maxOutputTokens: admittedOutputTokens(resolved.result.runMetadata, estimatedPromptTokens),
1663
2101
  upstreamStreamingSupported: upstreamGatewayStreamingSupported(deps, resolved.result.supportsStreaming),
1664
2102
  ...(authentication.reasoningEffort === undefined
1665
2103
  ? {}
1666
2104
  : { reasoningEffort: authentication.reasoningEffort }),
1667
2105
  });
1668
2106
  }
2107
+ // #3591 (1.1.7): the run's output reserve (8k for an undeclared limit) is a reserve against the
2108
+ // whole window, and `maxPromptTokens` IS that whole window. A prompt close to the window would
2109
+ // leave the provider a request larger than its window, so the allowance actually sent is what
2110
+ // remains after the prompt and the safety margin — and the least allowance that still lets the
2111
+ // model answer (and report an exhausted budget instead of failing silently) is reserved at
2112
+ // admission, never added on top of a prompt that already fills the window.
2113
+ export const MINIMUM_ADMITTED_OUTPUT_TOKENS = 512;
2114
+ // What a prompt must leave free of `maxPromptTokens`: the window's safety margin plus the minimum
2115
+ // allowance (or the whole reserve, when that is smaller).
2116
+ function reservedWindowTokens(bounds) {
2117
+ return (safetyMarginTokensFor(bounds.maxPromptTokens, bounds.maxOutputTokens) +
2118
+ Math.min(MINIMUM_ADMITTED_OUTPUT_TOKENS, bounds.maxOutputTokens));
2119
+ }
2120
+ // Review of #3591 (P1): admission used to check the prompt against `maxPromptTokens` alone while
2121
+ // the allowance floored at 512, so a prompt just under the window was sent WITH 512 output tokens
2122
+ // — past the window the probe had proven, and the provider refused the turn. The prompt must
2123
+ // leave the margin and the minimum allowance free, or the turn is refused before any call.
2124
+ export function admissiblePromptTokens(bounds) {
2125
+ return bounds.maxPromptTokens - reservedWindowTokens(bounds);
2126
+ }
2127
+ // The allowance an ADMITTED turn sends: the run's reserve, shrunk to what the prompt leaves after
2128
+ // the safety margin. Admission (`admissiblePromptTokens`) guarantees at least the minimum.
2129
+ export function admittedOutputTokens(bounds, estimatedPromptTokens) {
2130
+ const remaining = bounds.maxPromptTokens -
2131
+ estimatedPromptTokens -
2132
+ safetyMarginTokensFor(bounds.maxPromptTokens, bounds.maxOutputTokens);
2133
+ return Math.min(bounds.maxOutputTokens, remaining);
2134
+ }
1669
2135
  function logValidatedRequestBounds(ctx, runId, request, bounds, estimatedPromptTokens) {
1670
- getServerLogger().info(activityLogEvent(CODING_SIDECAR_GATEWAY_REQUEST_VALIDATED_OPERATION, { correlationId: correlationIdOrUnknown(ctx.correlationId) }, {
2136
+ getServerLogger().info(activityLogEvent(CODING_SIDECAR_GATEWAY_REQUEST_VALIDATED_OPERATION, {
2137
+ correlationId: correlationIdOrUnknown(ctx.correlationId),
2138
+ parentCorrelationId: runId,
2139
+ }, {
1671
2140
  runId,
1672
2141
  maxRequestBytes: bounds.maxRequestBytes,
1673
2142
  maxPromptTokens: bounds.maxPromptTokens,
1674
2143
  estimatedPromptTokens,
2144
+ maxOutputTokens: admittedOutputTokens(bounds, estimatedPromptTokens),
1675
2145
  inputMessageCount: request.messages.length,
1676
2146
  completeness: "complete",
1677
2147
  loss: "none",
@@ -1681,6 +2151,7 @@ function executeBudgetedGatewayChat(ctx, deps, binding, parsed, authentication,
1681
2151
  const promptTokenReservation = reserveGatewayPromptBudget(deps, authentication.capability, authentication.runId, estimatedPromptTokens);
1682
2152
  if (promptTokenReservation === undefined) {
1683
2153
  logGatewayRejection(ctx, authentication.runId, 403, "runtime-prompt-budget-denied");
2154
+ reportGatewayTurnFailure(ctx, deps, authentication.runId, "turn-rejected");
1684
2155
  return Promise.resolve(forbiddenGatewayRequest());
1685
2156
  }
1686
2157
  return executeGatewayChat(ctx, deps, binding, parsed, authentication.runId, {
@@ -1690,7 +2161,7 @@ function executeBudgetedGatewayChat(ctx, deps, binding, parsed, authentication,
1690
2161
  offerLifetimeMs: opencodeGatewayOfferLifetimeMs(codingSidecarGatewayRequestDeadlineMs(binding.config, profile.modelAlias)),
1691
2162
  });
1692
2163
  }
1693
- function fixedReadinessResponse(ctx, modelId, stream) {
2164
+ function fixedReadinessResponse(ctx, deps, modelId, stream) {
1694
2165
  const response = {
1695
2166
  modelId,
1696
2167
  content: "",
@@ -1705,5 +2176,7 @@ function fixedReadinessResponse(ctx, modelId, stream) {
1705
2176
  costClass: "low",
1706
2177
  },
1707
2178
  };
1708
- return stream ? bufferedOpenAiStream(ctx, modelId, response) : openAiResponse(modelId, response);
2179
+ return stream
2180
+ ? bufferedOpenAiStream(ctx, deps, modelId, response)
2181
+ : openAiResponse(modelId, response);
1709
2182
  }