@opengeni/worker-bundle 2.0.1 → 2.0.2-canary.38686408778001

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 (379) hide show
  1. package/dist/activities/agent-run-admission.d.ts +1 -12
  2. package/dist/activities/agent-turn/admission.d.ts +88 -10
  3. package/dist/activities/agent-turn/agent-build.d.ts +14 -3
  4. package/dist/activities/agent-turn/claim.d.ts +4 -1
  5. package/dist/activities/agent-turn/claude-core.d.ts +195 -0
  6. package/dist/activities/agent-turn/code-search.d.ts +60 -0
  7. package/dist/activities/agent-turn/codex-capacity.d.ts +3 -0
  8. package/dist/activities/agent-turn/codex-core-capacity.d.ts +37 -0
  9. package/dist/activities/agent-turn/codex-core-claim.d.ts +40 -0
  10. package/dist/activities/agent-turn/codex-core-errors.d.ts +102 -0
  11. package/dist/activities/agent-turn/codex-core-failover.d.ts +15 -0
  12. package/dist/activities/agent-turn/codex-core-requests.d.ts +28 -0
  13. package/dist/activities/agent-turn/codex-core-settlement.d.ts +77 -0
  14. package/dist/activities/agent-turn/codex-credit-policy.d.ts +30 -0
  15. package/dist/activities/agent-turn/codex-plan-entitlement.d.ts +105 -0
  16. package/dist/activities/agent-turn/codex-usage-policy.d.ts +2 -0
  17. package/dist/activities/agent-turn/codex.d.ts +2 -19
  18. package/dist/activities/agent-turn/compaction-interruption.d.ts +32 -0
  19. package/dist/activities/agent-turn/compaction-prep.d.ts +30 -1
  20. package/dist/activities/agent-turn/credential-leases.d.ts +64 -37
  21. package/dist/activities/agent-turn/credential-restriction.d.ts +3 -0
  22. package/dist/activities/agent-turn/errors.d.ts +172 -28
  23. package/dist/activities/agent-turn/failure-settlement.d.ts +10 -43
  24. package/dist/activities/agent-turn/final-reply.d.ts +18 -0
  25. package/dist/activities/agent-turn/finalization-monitor.d.ts +7 -2
  26. package/dist/activities/agent-turn/finalization.d.ts +2 -0
  27. package/dist/activities/agent-turn/github-repository-bindings.d.ts +2 -0
  28. package/dist/activities/agent-turn/governance-model.d.ts +13 -1
  29. package/dist/activities/agent-turn/history-sink.d.ts +3 -1
  30. package/dist/activities/agent-turn/history.d.ts +2 -0
  31. package/dist/activities/agent-turn/input-wait-reply.d.ts +76 -0
  32. package/dist/activities/agent-turn/meaningful-output.d.ts +9 -0
  33. package/dist/activities/agent-turn/media-artifacts.d.ts +5 -3
  34. package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
  35. package/dist/activities/agent-turn/model-usage.d.ts +56 -14
  36. package/dist/activities/agent-turn/model-wire-dispatch.d.ts +15 -0
  37. package/dist/activities/agent-turn/optional-repositories.d.ts +59 -0
  38. package/dist/activities/agent-turn/prompt-tool-availability.d.ts +17 -0
  39. package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +12 -1
  40. package/dist/activities/agent-turn/provider-recovery-copy.d.ts +24 -0
  41. package/dist/activities/agent-turn/provider-recovery-metrics.d.ts +18 -0
  42. package/dist/activities/agent-turn/provider-recovery-policy.d.ts +6 -0
  43. package/dist/activities/agent-turn/quiescence.d.ts +6 -7
  44. package/dist/activities/agent-turn/recovery-warning.d.ts +6 -5
  45. package/dist/activities/agent-turn/refresh-credentials.d.ts +6 -0
  46. package/dist/activities/agent-turn/run-credentials.d.ts +9 -5
  47. package/dist/activities/agent-turn/run.d.ts +27 -2
  48. package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
  49. package/dist/activities/agent-turn/sandbox-provision.d.ts +25 -1
  50. package/dist/activities/agent-turn/sandbox-route.d.ts +3 -0
  51. package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -1
  52. package/dist/activities/agent-turn/secret-resolver.d.ts +64 -0
  53. package/dist/activities/agent-turn/session-title.d.ts +60 -3
  54. package/dist/activities/agent-turn/session-usage-custody.d.ts +66 -0
  55. package/dist/activities/agent-turn/skill-checkout.d.ts +25 -6
  56. package/dist/activities/agent-turn/skill-read.d.ts +70 -2
  57. package/dist/activities/agent-turn/skill-search.d.ts +2 -0
  58. package/dist/activities/agent-turn/skill-tools.d.ts +41 -4
  59. package/dist/activities/agent-turn/skill-transfer.d.ts +18 -6
  60. package/dist/activities/agent-turn/stream-attempt.d.ts +6 -3
  61. package/dist/activities/agent-turn/subscription-capacity-arming.d.ts +41 -0
  62. package/dist/activities/agent-turn/subscription-core-capacity.d.ts +86 -0
  63. package/dist/activities/agent-turn/subscription-core-failover.d.ts +69 -0
  64. package/dist/activities/agent-turn/subscription-core-placed.d.ts +14 -0
  65. package/dist/activities/agent-turn/subscription-core-requests.d.ts +109 -0
  66. package/dist/activities/agent-turn/subscription-core-settlement.d.ts +112 -0
  67. package/dist/activities/agent-turn/subscription-lease.d.ts +44 -0
  68. package/dist/activities/agent-turn/subscription-serving-capacity.d.ts +6 -0
  69. package/dist/activities/agent-turn/subscription-serving-catalog.d.ts +13 -0
  70. package/dist/activities/agent-turn/subscription-serving-claim.d.ts +30 -0
  71. package/dist/activities/agent-turn/subscription-serving-providers.d.ts +2 -0
  72. package/dist/activities/agent-turn/tool-environment.d.ts +30 -6
  73. package/dist/activities/agent-turn/tool-policy.d.ts +55 -3
  74. package/dist/activities/agent-turn/turn-context.d.ts +104 -5
  75. package/dist/activities/agent-turn/web-search.d.ts +57 -0
  76. package/dist/activities/agent-turn/xai-core.d.ts +96 -0
  77. package/dist/activities/automations.d.ts +3 -1
  78. package/dist/activities/browser-deadline-checkpoint.d.ts +34 -0
  79. package/dist/activities/capabilities.d.ts +8 -20
  80. package/dist/activities/codemode-dispatcher.d.ts +20 -3
  81. package/dist/activities/codex-capacity.d.ts +1 -56
  82. package/dist/activities/codex-image-generation.d.ts +49 -3
  83. package/dist/activities/common.d.ts +3 -1
  84. package/dist/activities/context-compaction.d.ts +41 -2
  85. package/dist/activities/environment.d.ts +1 -19
  86. package/dist/activities/gmail-files.d.ts +50 -0
  87. package/dist/activities/goals.d.ts +1 -9
  88. package/dist/activities/incident-telemetry-authority.d.ts +5 -2
  89. package/dist/activities/incident-telemetry-preflight.d.ts +10 -3
  90. package/dist/activities/knowledge-indexing.d.ts +19 -0
  91. package/dist/activities/mcp-account-routes.d.ts +2 -21
  92. package/dist/activities/model-call-fact-reconciler.d.ts +34 -0
  93. package/dist/activities/open-suffix-resume.d.ts +15 -0
  94. package/dist/activities/parent-wake.d.ts +17 -12
  95. package/dist/activities/programmatic-approvals.d.ts +10 -0
  96. package/dist/activities/requester-unavailable-receipt.d.ts +8 -0
  97. package/dist/activities/retained-screenshots.d.ts +7 -2
  98. package/dist/activities/run-credential-renewal.d.ts +1 -0
  99. package/dist/activities/run-credentials.d.ts +16 -4
  100. package/dist/activities/run-input.d.ts +17 -0
  101. package/dist/activities/sandbox-lease.d.ts +132 -12
  102. package/dist/activities/scheduled-tasks.d.ts +4 -35
  103. package/dist/activities/session-archive.d.ts +58 -0
  104. package/dist/activities/session-state.d.ts +15 -3
  105. package/dist/activities/session-storage.d.ts +44 -0
  106. package/dist/activities/subscription-core-claude-waits.d.ts +2 -0
  107. package/dist/activities/subscription-core-codex-quota.d.ts +25 -0
  108. package/dist/activities/subscription-core-codex-waits.d.ts +153 -0
  109. package/dist/activities/subscription-core-image-operation.d.ts +29 -0
  110. package/dist/activities/subscription-core-usage-recheck.d.ts +49 -0
  111. package/dist/activities/subscription-core-wait-bindings.d.ts +3 -0
  112. package/dist/activities/subscription-core-xai-quota.d.ts +30 -0
  113. package/dist/activities/subscription-core-xai-waits.d.ts +2 -0
  114. package/dist/activities/types.d.ts +68 -5
  115. package/dist/activities/video-generation-admission.d.ts +2 -8
  116. package/dist/activities/video-generation-credential.d.ts +15 -12
  117. package/dist/activities/video-generation-subscription-core.d.ts +70 -0
  118. package/dist/activities/workspace-capture.d.ts +2 -0
  119. package/dist/activities/workspace-credential-provider.d.ts +47 -0
  120. package/dist/activities/xai-auth.d.ts +6 -18
  121. package/dist/activities/xai-image-generation.d.ts +22 -6
  122. package/dist/{activities-control-QA6OLRQY.js → activities-control-NTXZHYET.js} +1552 -2876
  123. package/dist/activities-control-NTXZHYET.js.map +1 -0
  124. package/dist/activities-control.d.ts +64 -4
  125. package/dist/{activities-turn-YVVKCGAK.js → activities-turn-RKRI5GY4.js} +9238 -4392
  126. package/dist/activities-turn-RKRI5GY4.js.map +1 -0
  127. package/dist/activities.d.ts +64 -4
  128. package/dist/artifact-materializer-entry.js +104 -35
  129. package/dist/artifact-materializer-entry.js.map +1 -1
  130. package/dist/artifact-outbox-entry.js +132 -61
  131. package/dist/artifact-outbox-entry.js.map +1 -1
  132. package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
  133. package/dist/{chunk-GDCLDKSH.js → chunk-24GP3BX5.js} +79 -72
  134. package/dist/chunk-24GP3BX5.js.map +1 -0
  135. package/dist/{chunk-RAMNYSAW.js → chunk-4ER3YXOT.js} +22 -4
  136. package/dist/chunk-4ER3YXOT.js.map +1 -0
  137. package/dist/{chunk-I7HKKMUJ.js → chunk-5NNS4327.js} +734 -58
  138. package/dist/chunk-5NNS4327.js.map +1 -0
  139. package/dist/{chunk-M3NVMF2V.js → chunk-7BIHFUGB.js} +2293 -3956
  140. package/dist/chunk-7BIHFUGB.js.map +1 -0
  141. package/dist/chunk-MVESOYFC.js +3746 -0
  142. package/dist/chunk-MVESOYFC.js.map +1 -0
  143. package/dist/chunk-NQDVJ6RI.js +2823 -0
  144. package/dist/chunk-NQDVJ6RI.js.map +1 -0
  145. package/dist/chunk-O7UPBWXK.js +79 -0
  146. package/dist/chunk-O7UPBWXK.js.map +1 -0
  147. package/dist/chunk-W2QSM5HR.js +414 -0
  148. package/dist/chunk-W2QSM5HR.js.map +1 -0
  149. package/dist/chunk-ZN3XJR33.js +227 -0
  150. package/dist/chunk-ZN3XJR33.js.map +1 -0
  151. package/dist/editable-artifact-outbox-dispatcher.d.ts +12 -1
  152. package/dist/editable-artifact-outbox-service.d.ts +3 -1
  153. package/dist/host-export-pump.d.ts +3 -1
  154. package/dist/host-export.d.ts +2 -2
  155. package/dist/host-export.js +1 -1
  156. package/dist/http.d.ts +1 -1
  157. package/dist/index.d.ts +49 -48
  158. package/dist/index.js +835 -256
  159. package/dist/index.js.map +1 -1
  160. package/dist/internal-maintenance.d.ts +63 -0
  161. package/dist/maintenance-cadence.d.ts +43 -0
  162. package/dist/observability-metrics.d.ts +293 -24
  163. package/dist/onepassword-vault-provider.d.ts +7 -0
  164. package/dist/parent-wake-PCLH7A3Y.js +24 -0
  165. package/dist/parent-wake-PCLH7A3Y.js.map +1 -0
  166. package/dist/personal-github-git-credentials.d.ts +1 -1
  167. package/dist/readiness-checks.d.ts +39 -0
  168. package/dist/retained-process-retry.d.ts +7 -0
  169. package/dist/sandbox-lease-BJYU72N3.js +84 -0
  170. package/dist/sandbox-lease-BJYU72N3.js.map +1 -0
  171. package/dist/sandbox-reaper-contract.d.ts +25 -0
  172. package/dist/sandbox-resume.d.ts +72 -4
  173. package/dist/sandbox-routing.d.ts +4 -2
  174. package/dist/session-event-fanout.d.ts +6 -0
  175. package/dist/site-auth-maintenance-WK3MR2PV.js +12 -0
  176. package/dist/site-auth-maintenance-WK3MR2PV.js.map +1 -0
  177. package/dist/telemetry-scheduler.d.ts +14 -0
  178. package/dist/temporal-runtime-logger.d.ts +22 -0
  179. package/dist/turn-task-queue-reader.d.ts +18 -0
  180. package/dist/turn-worker-activity-telemetry.d.ts +47 -0
  181. package/dist/worker-service-lifecycle.d.ts +12 -0
  182. package/dist/workflow-bundle.js +468 -71
  183. package/dist/workflows/activities.d.ts +1 -1
  184. package/dist/workflows/browser-deadline-checkpoint.d.ts +10 -0
  185. package/dist/workflows/sandbox-reaper.d.ts +10 -1
  186. package/dist/workflows/scheduled-tasks.d.ts +4 -0
  187. package/dist/workflows/session-storage.d.ts +2 -0
  188. package/dist/workflows/session.d.ts +36 -0
  189. package/dist/workflows/site-auth-maintenance.d.ts +2 -1
  190. package/dist/workflows/workflow-wake.d.ts +14 -3
  191. package/dist/workflows.d.ts +3 -1
  192. package/package.json +26 -20
  193. package/src/activities/agent-run-admission.ts +1 -82
  194. package/src/activities/agent-turn/admission.ts +175 -24
  195. package/src/activities/agent-turn/agent-build.ts +226 -145
  196. package/src/activities/agent-turn/claim.ts +363 -64
  197. package/src/activities/agent-turn/claude-core.ts +587 -0
  198. package/src/activities/agent-turn/code-search.ts +275 -0
  199. package/src/activities/agent-turn/codex-capacity.ts +30 -757
  200. package/src/activities/agent-turn/codex-core-capacity.ts +190 -0
  201. package/src/activities/agent-turn/codex-core-claim.ts +83 -0
  202. package/src/activities/agent-turn/codex-core-errors.ts +308 -0
  203. package/src/activities/agent-turn/codex-core-failover.ts +73 -0
  204. package/src/activities/agent-turn/codex-core-requests.ts +86 -0
  205. package/src/activities/agent-turn/codex-core-settlement.ts +263 -0
  206. package/src/activities/agent-turn/codex-credit-policy.ts +247 -0
  207. package/src/activities/agent-turn/codex-plan-entitlement.ts +254 -0
  208. package/src/activities/agent-turn/codex-usage-policy.ts +2 -0
  209. package/src/activities/agent-turn/codex.ts +8 -76
  210. package/src/activities/agent-turn/compaction-interruption.ts +56 -0
  211. package/src/activities/agent-turn/compaction-prep.ts +249 -36
  212. package/src/activities/agent-turn/credential-leases.ts +269 -214
  213. package/src/activities/agent-turn/credential-restriction.ts +14 -0
  214. package/src/activities/agent-turn/errors.ts +1134 -82
  215. package/src/activities/agent-turn/failure-settlement.ts +879 -886
  216. package/src/activities/agent-turn/final-reply.ts +46 -0
  217. package/src/activities/agent-turn/finalization-monitor.ts +17 -5
  218. package/src/activities/agent-turn/finalization.ts +107 -88
  219. package/src/activities/agent-turn/github-repository-bindings.ts +3 -1
  220. package/src/activities/agent-turn/governance-model.ts +90 -22
  221. package/src/activities/agent-turn/history-sink.ts +26 -4
  222. package/src/activities/agent-turn/history.ts +25 -5
  223. package/src/activities/agent-turn/input-wait-reply.ts +139 -0
  224. package/src/activities/agent-turn/knowledge-source-tools.ts +2 -0
  225. package/src/activities/agent-turn/meaningful-output.ts +44 -0
  226. package/src/activities/agent-turn/media-artifacts.ts +3 -1
  227. package/src/activities/agent-turn/model-call-admission.ts +94 -0
  228. package/src/activities/agent-turn/model-usage.ts +299 -233
  229. package/src/activities/agent-turn/model-wire-dispatch.ts +27 -0
  230. package/src/activities/agent-turn/optional-repositories.ts +224 -0
  231. package/src/activities/agent-turn/prompt-tool-availability.ts +27 -0
  232. package/src/activities/agent-turn/provider-dispatch-barrier.ts +22 -0
  233. package/src/activities/agent-turn/provider-recovery-copy.ts +76 -0
  234. package/src/activities/agent-turn/provider-recovery-metrics.ts +64 -0
  235. package/src/activities/agent-turn/provider-recovery-policy.ts +25 -0
  236. package/src/activities/agent-turn/quiescence.ts +7 -7
  237. package/src/activities/agent-turn/recovery-warning.ts +6 -8
  238. package/src/activities/agent-turn/refresh-credentials.ts +44 -0
  239. package/src/activities/agent-turn/run-credentials.ts +124 -76
  240. package/src/activities/agent-turn/run.ts +501 -112
  241. package/src/activities/agent-turn/sandbox-establish.ts +152 -75
  242. package/src/activities/agent-turn/sandbox-provision.ts +54 -1
  243. package/src/activities/agent-turn/sandbox-route.ts +4 -1
  244. package/src/activities/agent-turn/sandbox-runtime.ts +319 -11
  245. package/src/activities/agent-turn/secret-resolver.ts +155 -0
  246. package/src/activities/agent-turn/session-title.ts +177 -12
  247. package/src/activities/agent-turn/session-usage-custody.ts +170 -0
  248. package/src/activities/agent-turn/skill-checkout.ts +111 -24
  249. package/src/activities/agent-turn/skill-install.ts +1 -1
  250. package/src/activities/agent-turn/skill-read.ts +374 -28
  251. package/src/activities/agent-turn/skill-save.ts +35 -7
  252. package/src/activities/agent-turn/skill-search.ts +9 -0
  253. package/src/activities/agent-turn/skill-selection.ts +4 -0
  254. package/src/activities/agent-turn/skill-tools.ts +208 -21
  255. package/src/activities/agent-turn/skill-transfer.ts +68 -23
  256. package/src/activities/agent-turn/stream-attempt.ts +599 -110
  257. package/src/activities/agent-turn/subscription-capacity-arming.ts +81 -0
  258. package/src/activities/agent-turn/subscription-core-capacity.ts +439 -0
  259. package/src/activities/agent-turn/subscription-core-failover.ts +229 -0
  260. package/src/activities/agent-turn/subscription-core-placed.ts +37 -0
  261. package/src/activities/agent-turn/subscription-core-requests.ts +271 -0
  262. package/src/activities/agent-turn/subscription-core-settlement.ts +234 -0
  263. package/src/activities/agent-turn/subscription-lease.ts +140 -0
  264. package/src/activities/agent-turn/subscription-serving-capacity.ts +195 -0
  265. package/src/activities/agent-turn/subscription-serving-catalog.ts +71 -0
  266. package/src/activities/agent-turn/subscription-serving-claim.ts +178 -0
  267. package/src/activities/agent-turn/subscription-serving-providers.ts +15 -0
  268. package/src/activities/agent-turn/tool-environment.ts +384 -292
  269. package/src/activities/agent-turn/tool-policy.ts +104 -4
  270. package/src/activities/agent-turn/tool-result-spill.ts +1 -0
  271. package/src/activities/agent-turn/turn-context.ts +124 -8
  272. package/src/activities/agent-turn/web-search.ts +431 -0
  273. package/src/activities/agent-turn/xai-core.ts +301 -0
  274. package/src/activities/automations.ts +81 -6
  275. package/src/activities/browser-deadline-checkpoint.ts +297 -0
  276. package/src/activities/capabilities.ts +53 -213
  277. package/src/activities/codemode-dispatcher.ts +236 -14
  278. package/src/activities/codex-capacity.ts +27 -380
  279. package/src/activities/codex-image-generation.ts +252 -42
  280. package/src/activities/common.ts +12 -0
  281. package/src/activities/connector-attachments.ts +3 -1
  282. package/src/activities/context-compaction.ts +162 -21
  283. package/src/activities/environment.ts +18 -106
  284. package/src/activities/gmail-files.ts +108 -0
  285. package/src/activities/goals.ts +120 -204
  286. package/src/activities/image-generation-operation.ts +1 -1
  287. package/src/activities/incident-telemetry-authority.ts +80 -50
  288. package/src/activities/incident-telemetry-preflight.ts +27 -15
  289. package/src/activities/knowledge-indexing.ts +287 -17
  290. package/src/activities/knowledge-source-sync.ts +10 -0
  291. package/src/activities/mcp-account-routes.ts +2 -124
  292. package/src/activities/model-call-fact-reconciler.ts +112 -0
  293. package/src/activities/open-suffix-resume.ts +122 -88
  294. package/src/activities/parent-wake.ts +89 -21
  295. package/src/activities/programmatic-approvals.ts +26 -0
  296. package/src/activities/requester-unavailable-receipt.ts +14 -0
  297. package/src/activities/retained-screenshots.ts +135 -24
  298. package/src/activities/run-credential-renewal.ts +13 -1
  299. package/src/activities/run-credentials.ts +61 -19
  300. package/src/activities/run-input.ts +116 -9
  301. package/src/activities/sandbox-lease.ts +1615 -73
  302. package/src/activities/scheduled-tasks.ts +758 -141
  303. package/src/activities/session-archive.ts +382 -0
  304. package/src/activities/session-state.ts +219 -10
  305. package/src/activities/session-storage.ts +124 -0
  306. package/src/activities/site-auth-maintenance.ts +5 -2
  307. package/src/activities/subscription-core-claude-waits.ts +49 -0
  308. package/src/activities/subscription-core-codex-quota.ts +46 -0
  309. package/src/activities/subscription-core-codex-waits.ts +488 -0
  310. package/src/activities/subscription-core-image-operation.ts +126 -0
  311. package/src/activities/subscription-core-usage-recheck.ts +146 -0
  312. package/src/activities/subscription-core-wait-bindings.ts +12 -0
  313. package/src/activities/subscription-core-xai-quota.ts +85 -0
  314. package/src/activities/subscription-core-xai-waits.ts +48 -0
  315. package/src/activities/types.ts +85 -9
  316. package/src/activities/video-generation-admission.ts +1 -36
  317. package/src/activities/video-generation-credential.ts +38 -56
  318. package/src/activities/video-generation-reconciliation.ts +150 -131
  319. package/src/activities/video-generation-subscription-core.ts +180 -0
  320. package/src/activities/workspace-capture.ts +13 -2
  321. package/src/activities/workspace-credential-provider.ts +302 -0
  322. package/src/activities/xai-auth.ts +34 -112
  323. package/src/activities/xai-image-generation.ts +84 -36
  324. package/src/activities-control.ts +8 -0
  325. package/src/activities-turn.ts +5 -0
  326. package/src/activities.ts +17 -0
  327. package/src/activity-services.ts +29 -4
  328. package/src/browser-deadline-checkpoint-contract.ts +5 -0
  329. package/src/editable-artifact-hint-broker.ts +3 -0
  330. package/src/editable-artifact-materializer-service.ts +79 -38
  331. package/src/editable-artifact-materializer-subprocess.ts +47 -2
  332. package/src/editable-artifact-outbox-dispatcher.ts +107 -46
  333. package/src/editable-artifact-outbox-service.ts +55 -25
  334. package/src/github-rest-mcp.ts +1 -1
  335. package/src/host-export-pump.ts +26 -4
  336. package/src/host-export.ts +4 -1
  337. package/src/http.ts +4 -2
  338. package/src/index.ts +222 -282
  339. package/src/internal-maintenance.ts +347 -0
  340. package/src/maintenance-cadence.ts +156 -0
  341. package/src/observability-metrics.ts +1173 -73
  342. package/src/onepassword-vault-provider.ts +11 -0
  343. package/src/personal-github-git-credentials.ts +3 -1
  344. package/src/pr-review-credentials.ts +1 -1
  345. package/src/readiness-checks.ts +113 -0
  346. package/src/retained-process-retry.ts +36 -0
  347. package/src/sandbox-reaper-contract.ts +33 -0
  348. package/src/sandbox-resume.ts +444 -73
  349. package/src/sandbox-routing.ts +230 -75
  350. package/src/session-event-fanout.ts +23 -0
  351. package/src/telemetry-scheduler.ts +53 -0
  352. package/src/temporal-runtime-logger.ts +44 -0
  353. package/src/turn-task-queue-reader.ts +110 -0
  354. package/src/turn-worker-activity-telemetry.ts +209 -0
  355. package/src/worker-service-lifecycle.ts +54 -1
  356. package/src/workflows/activities.ts +16 -1
  357. package/src/workflows/browser-deadline-checkpoint.ts +55 -0
  358. package/src/workflows/file-upload-reaper.ts +2 -0
  359. package/src/workflows/sandbox-reaper.ts +88 -0
  360. package/src/workflows/scheduled-tasks.ts +26 -13
  361. package/src/workflows/session-storage.ts +19 -0
  362. package/src/workflows/session.ts +238 -33
  363. package/src/workflows/site-auth-maintenance.ts +2 -1
  364. package/src/workflows/workflow-wake.ts +26 -4
  365. package/src/workflows.ts +7 -0
  366. package/dist/activities/agent-turn/xai-capacity.d.ts +0 -2
  367. package/dist/activities/codex-fleet-shadow.d.ts +0 -74
  368. package/dist/activities/codex-rotation.d.ts +0 -200
  369. package/dist/activities/xai-quota.d.ts +0 -3
  370. package/dist/activities-control-QA6OLRQY.js.map +0 -1
  371. package/dist/activities-turn-YVVKCGAK.js.map +0 -1
  372. package/dist/chunk-GDCLDKSH.js.map +0 -1
  373. package/dist/chunk-I7HKKMUJ.js.map +0 -1
  374. package/dist/chunk-M3NVMF2V.js.map +0 -1
  375. package/dist/chunk-RAMNYSAW.js.map +0 -1
  376. package/src/activities/agent-turn/xai-capacity.ts +0 -257
  377. package/src/activities/codex-fleet-shadow.ts +0 -306
  378. package/src/activities/codex-rotation.ts +0 -685
  379. package/src/activities/xai-quota.ts +0 -35
@@ -0,0 +1,27 @@
1
+ import type { ModelTransportDispatchClock } from "@opengeni/runtime";
2
+
3
+ type DispatchIdentity = { provider: string; dispatchId: string };
4
+
5
+ /** One immutable physical fetch-entry observation per worker attempt. Generic
6
+ * fallback events already carry that attempt's dispatch/execution identity. */
7
+ export class InitialModelWireDispatchClock {
8
+ private initial: (DispatchIdentity & { initialWireDispatchedAt: string }) | null = null;
9
+
10
+ record(identity: DispatchIdentity, clock: ModelTransportDispatchClock): void {
11
+ if (this.initial !== null) return;
12
+ const timestamp = new Date(clock.dispatchedAtUnixMs);
13
+ if (!Number.isFinite(timestamp.getTime())) return;
14
+ this.initial = { ...identity, initialWireDispatchedAt: timestamp.toISOString() };
15
+ }
16
+
17
+ payload(identity: DispatchIdentity): { initialWireDispatchedAt?: string } {
18
+ if (
19
+ this.initial === null ||
20
+ this.initial.provider !== identity.provider ||
21
+ this.initial.dispatchId !== identity.dispatchId
22
+ ) {
23
+ return {};
24
+ }
25
+ return { initialWireDispatchedAt: this.initial.initialWireDispatchedAt };
26
+ }
27
+ }
@@ -0,0 +1,224 @@
1
+ import type { Settings } from "@opengeni/config";
2
+ import { resourceMountPath, type ResourceRef } from "@opengeni/contracts";
3
+ import { prReviewRegistrationIdFromCredentialBinding } from "@opengeni/core";
4
+ import { areGitHubRepositoriesAllowedForWorkspace, type Database } from "@opengeni/db";
5
+ import {
6
+ findInaccessibleGitHubAppInstallationRepositories,
7
+ githubAppMissingSettings,
8
+ } from "@opengeni/github";
9
+ import { gitHubTokenAuthorizationSelections } from "../environment";
10
+
11
+ /**
12
+ * Turn-time access check for automatically attached (`optional: true`) GitHub
13
+ * App repositories.
14
+ *
15
+ * A Slack-started session attaches the caller's recently used repositories as
16
+ * optional resources. The per-turn workspace-allowlist recheck and the
17
+ * installation-token mint both cover every GitHub repository of the session in
18
+ * one request, so one optional repository that loses access after the session
19
+ * started (an admin removes it from the allowlist, or it is deleted or removed
20
+ * from the App on GitHub) would fail every later turn. Before those checks, this
21
+ * drops each optional repository that is no longer allowlisted or no longer
22
+ * reachable through its installation, for this turn only, and reports it the
23
+ * same way a skipped optional clone is reported. It only ever removes
24
+ * repositories: a remaining repository still passes the unchanged strict
25
+ * allowlist recheck and mint, and an explicitly attached repository is never
26
+ * dropped, so it keeps failing the turn when its access is gone.
27
+ */
28
+
29
+ export const OPTIONAL_REPOSITORY_ACCESS_OPERATION = "optional-repository-access";
30
+
31
+ type OptionalRepositoryCandidate = {
32
+ resource: Extract<ResourceRef, { kind: "repository" }>;
33
+ installationId: number;
34
+ repositoryId: number;
35
+ };
36
+
37
+ export type OptionalRepositoryDropReason = "not_allowlisted" | "inaccessible" | "unverified";
38
+
39
+ export type DropUnavailableOptionalRepositoriesInput = {
40
+ db: Database;
41
+ settings: Settings;
42
+ workspaceId: string;
43
+ activeSandboxBackend: Settings["sandboxBackend"] | undefined;
44
+ /**
45
+ * True when a host `gitCredentials` port mints the Git tokens: the host may
46
+ * use another GitHub App, so this deployment's App is not asked.
47
+ */
48
+ hostMintsGitCredentials: boolean;
49
+ turnResources: readonly ResourceRef[];
50
+ runtimeResources: readonly ResourceRef[];
51
+ /** Publishes one attempt-fenced session event batch. */
52
+ publish: (
53
+ events: Array<{
54
+ type: "sandbox.operation.completed";
55
+ payload: {
56
+ name: typeof OPTIONAL_REPOSITORY_ACCESS_OPERATION;
57
+ repositoryCount: number;
58
+ skippedOptionalRepositories: string[];
59
+ };
60
+ }>,
61
+ ) => Promise<void>;
62
+ /** Operational log line; counts only, never repository names. */
63
+ warn: (message: string, fields: Record<string, string>) => void;
64
+ /** Test seam; defaults to the workspace allowlist under RLS. */
65
+ isAllowlisted?: (installationId: number, repositoryId: number) => Promise<boolean>;
66
+ /** Test seam; defaults to a live GitHub App token-mint probe. */
67
+ findInaccessible?: (installationId: number, repositoryIds: number[]) => Promise<number[]>;
68
+ };
69
+
70
+ function optionalGitHubAppRepositoryCandidate(
71
+ resource: ResourceRef,
72
+ ): OptionalRepositoryCandidate | null {
73
+ if (resource.kind !== "repository" || resource.optional !== true) return null;
74
+ let selections: ReturnType<typeof gitHubTokenAuthorizationSelections>;
75
+ try {
76
+ // The exact selection the allowlist recheck and the mint derive, so the
77
+ // decision here covers precisely what those strict steps would check.
78
+ selections = gitHubTokenAuthorizationSelections([resource]);
79
+ } catch {
80
+ return null;
81
+ }
82
+ const [selection] = selections;
83
+ if (!selection || selections.length !== 1 || selection.repositoryIds.length !== 1) return null;
84
+ // PR-review bindings are authorized by their own registration, not the
85
+ // workspace allowlist; they are never automatically attached.
86
+ if (prReviewRegistrationIdFromCredentialBinding(selection.credentialBindingId)) return null;
87
+ return {
88
+ resource,
89
+ installationId: selection.installationId,
90
+ repositoryId: selection.repositoryIds[0]!,
91
+ };
92
+ }
93
+
94
+ function repositoryIdentity(resource: ResourceRef): string | null {
95
+ return resource.kind === "repository"
96
+ ? `${resource.uri}\u0000${resourceMountPath(resource)}`
97
+ : null;
98
+ }
99
+
100
+ export async function dropUnavailableOptionalRepositories(
101
+ input: DropUnavailableOptionalRepositoriesInput,
102
+ ): Promise<{
103
+ turnResources: ResourceRef[];
104
+ runtimeResources: ResourceRef[];
105
+ /**
106
+ * The same decision for another view of this turn's resources (the GitHub
107
+ * REST tool surface is built from the unbound session resources).
108
+ */
109
+ retainsResource: (resource: ResourceRef) => boolean;
110
+ }> {
111
+ const passthrough = {
112
+ turnResources: [...input.turnResources],
113
+ runtimeResources: [...input.runtimeResources],
114
+ retainsResource: () => true,
115
+ };
116
+ // A Connected Machine receives no platform Git credential and runs neither
117
+ // the allowlist recheck nor the mint, so nothing can fail there.
118
+ if (input.activeSandboxBackend === "selfhosted") return passthrough;
119
+ const candidates = input.turnResources.flatMap(
120
+ (resource) => optionalGitHubAppRepositoryCandidate(resource) ?? [],
121
+ );
122
+ if (candidates.length === 0) return passthrough;
123
+
124
+ const isAllowlisted =
125
+ input.isAllowlisted ??
126
+ ((installationId: number, repositoryId: number) =>
127
+ areGitHubRepositoriesAllowedForWorkspace(input.db, input.workspaceId, installationId, [
128
+ repositoryId,
129
+ ]));
130
+ const dropped = new Map<OptionalRepositoryCandidate, OptionalRepositoryDropReason>();
131
+ const allowlisted: OptionalRepositoryCandidate[] = [];
132
+ const admitted = await Promise.all(
133
+ candidates.map(async (candidate) => {
134
+ try {
135
+ return (await isAllowlisted(candidate.installationId, candidate.repositoryId))
136
+ ? ("allowlisted" as const)
137
+ : ("not_allowlisted" as const);
138
+ } catch {
139
+ // The check itself failed: an optional repository must not fail the
140
+ // turn, so it sits this turn out like an unverifiable GitHub answer.
141
+ return "unverified" as const;
142
+ }
143
+ }),
144
+ );
145
+ candidates.forEach((candidate, index) => {
146
+ const outcome = admitted[index]!;
147
+ if (outcome === "allowlisted") allowlisted.push(candidate);
148
+ else dropped.set(candidate, outcome);
149
+ });
150
+
151
+ const findInaccessible =
152
+ input.findInaccessible ??
153
+ (!input.hostMintsGitCredentials && githubAppMissingSettings(input.settings).length === 0
154
+ ? (installationId: number, repositoryIds: number[]) =>
155
+ findInaccessibleGitHubAppInstallationRepositories(input.settings, {
156
+ installationId,
157
+ repositoryIds,
158
+ })
159
+ : null);
160
+ if (findInaccessible && allowlisted.length > 0) {
161
+ const byInstallation = new Map<number, OptionalRepositoryCandidate[]>();
162
+ for (const candidate of allowlisted) {
163
+ const group = byInstallation.get(candidate.installationId) ?? [];
164
+ group.push(candidate);
165
+ byInstallation.set(candidate.installationId, group);
166
+ }
167
+ await Promise.all(
168
+ [...byInstallation].map(async ([installationId, group]) => {
169
+ try {
170
+ const inaccessible = new Set(
171
+ await findInaccessible(
172
+ installationId,
173
+ group.map((candidate) => candidate.repositoryId),
174
+ ),
175
+ );
176
+ for (const candidate of group) {
177
+ if (inaccessible.has(candidate.repositoryId)) dropped.set(candidate, "inaccessible");
178
+ }
179
+ } catch {
180
+ // GitHub could not answer. An optional repository must never fail
181
+ // the turn, and keeping it would put it into a mint GitHub may then
182
+ // refuse, so it sits this turn out and is checked again next turn.
183
+ for (const candidate of group) dropped.set(candidate, "unverified");
184
+ }
185
+ }),
186
+ );
187
+ }
188
+ if (dropped.size === 0) return passthrough;
189
+
190
+ const droppedIdentities = new Set(
191
+ [...dropped.keys()].flatMap((candidate) => repositoryIdentity(candidate.resource) ?? []),
192
+ );
193
+ const keep = (resource: ResourceRef): boolean => {
194
+ if (resource.kind !== "repository" || resource.optional !== true) return true;
195
+ const identity = repositoryIdentity(resource);
196
+ return identity === null || !droppedIdentities.has(identity);
197
+ };
198
+ const reasons = [...dropped.values()];
199
+ input.warn("optional repository resources were dropped for this turn", {
200
+ droppedCount: String(dropped.size),
201
+ notAllowlistedCount: String(reasons.filter((reason) => reason === "not_allowlisted").length),
202
+ inaccessibleCount: String(reasons.filter((reason) => reason === "inaccessible").length),
203
+ unverifiedCount: String(reasons.filter((reason) => reason === "unverified").length),
204
+ origin: "worker",
205
+ });
206
+ await input.publish([
207
+ {
208
+ type: "sandbox.operation.completed",
209
+ payload: {
210
+ name: OPTIONAL_REPOSITORY_ACCESS_OPERATION,
211
+ repositoryCount: input.turnResources.filter((resource) => resource.kind === "repository")
212
+ .length,
213
+ skippedOptionalRepositories: [
214
+ ...new Set([...dropped.keys()].map((candidate) => resourceMountPath(candidate.resource))),
215
+ ].sort(),
216
+ },
217
+ },
218
+ ]);
219
+ return {
220
+ turnResources: input.turnResources.filter(keep),
221
+ runtimeResources: input.runtimeResources.filter(keep),
222
+ retainsResource: keep,
223
+ };
224
+ }
@@ -0,0 +1,27 @@
1
+ import {
2
+ deriveAgentPromptToolAvailability,
3
+ type AgentPromptToolAvailability,
4
+ } from "@opengeni/runtime";
5
+ import type { FirstPartyMcpToolName, Permission, ResolvedAgentConfig } from "@opengeni/contracts";
6
+
7
+ /**
8
+ * The frozen clause-availability view for one attempt's modular instructions.
9
+ * Derived from the same accepted first-party selection and permission ceiling
10
+ * the worker signs into the delegated token and hands to in-process adapters,
11
+ * so it can only describe tools the executable catalog already excludes. It is
12
+ * a rendering input, never authority.
13
+ *
14
+ * Sessions without an agent configuration keep the legacy composition, which
15
+ * does not read availability; they receive undefined so nothing changes.
16
+ */
17
+ export function promptToolAvailabilityForTurn(input: {
18
+ agentConfig: ResolvedAgentConfig | null | undefined;
19
+ selectedFirstPartyMcpTools: readonly FirstPartyMcpToolName[];
20
+ firstPartyPermissions: readonly Permission[] | null | undefined;
21
+ }): AgentPromptToolAvailability | undefined {
22
+ if (!input.agentConfig) return undefined;
23
+ return deriveAgentPromptToolAvailability({
24
+ selectedFirstPartyTools: input.selectedFirstPartyMcpTools,
25
+ firstPartyPermissions: input.firstPartyPermissions,
26
+ });
27
+ }
@@ -1,4 +1,14 @@
1
1
  import type { TurnHistorySink } from "./history-sink";
2
+ import type { Settings } from "@opengeni/config";
3
+
4
+ export class SandboxCapabilitiesChangedError extends Error {
5
+ readonly code = "native_capabilities_changed_this_attempt";
6
+
7
+ constructor() {
8
+ super("The attached sandbox requires rebuilding this attempt's native capabilities.");
9
+ this.name = "SandboxCapabilitiesChangedError";
10
+ }
11
+ }
2
12
 
3
13
  /**
4
14
  * Persist the SDK's complete prior model/tool history before another provider
@@ -8,6 +18,18 @@ import type { TurnHistorySink } from "./history-sink";
8
18
  */
9
19
  export async function checkpointHistoryBeforeProviderDispatch(
10
20
  historySink: Pick<TurnHistorySink, "reconcileConversationTruth">,
21
+ route?: {
22
+ effectiveSandboxBackend: Settings["sandboxBackend"];
23
+ routingEnabled: boolean;
24
+ readActiveSandbox: () => Promise<{ activeSandboxId: string | null } | null>;
25
+ },
11
26
  ): Promise<void> {
12
27
  await historySink.reconcileConversationTruth({ requireDurable: true });
28
+ // A plain Agent cannot acquire SandboxAgent capabilities in place. Preserve
29
+ // its completed tool batch before recovering the same logical turn; the next
30
+ // attempt resolves and authorizes the route normally.
31
+ if (route?.effectiveSandboxBackend === "none" && route.routingEnabled) {
32
+ const active = await route.readActiveSandbox();
33
+ if (active?.activeSandboxId) throw new SandboxCapabilitiesChangedError();
34
+ }
13
35
  }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Person-facing copy for finite same-turn provider recovery. Presentation only:
3
+ * retry authority, pacing and the recovery budget stay in `errors.ts`.
4
+ *
5
+ * `@opengeni/react` (`lib/provider-recovery.ts`) composes the same sentences
6
+ * from the structured event fields, so live retry status and historical
7
+ * failures read identically in every surface. Keep the two in step.
8
+ */
9
+
10
+ /** Closed provider condition recorded on model-provider recovery payloads. */
11
+ export type ProviderCondition = "overloaded" | "unavailable" | "unresponsive" | "rate_limited";
12
+
13
+ /** Failure codes whose transient condition belongs to the turn's model route. */
14
+ export const MODEL_PROVIDER_RECOVERY_CODES: ReadonlySet<string> = new Set([
15
+ "provider_unavailable",
16
+ "provider_rate_limited",
17
+ "provider_unknown_finish_reason",
18
+ "post_compaction_continuation_empty",
19
+ ]);
20
+
21
+ export type ProviderRecoveryCopyInput = {
22
+ code?: string | null | undefined;
23
+ providerCondition?: ProviderCondition | null | undefined;
24
+ modelLabel?: string | null | undefined;
25
+ providerLabel?: string | null | undefined;
26
+ };
27
+
28
+ function label(value: string | null | undefined): string | null {
29
+ const trimmed = typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
30
+ return trimmed ? trimmed.slice(0, 120) : null;
31
+ }
32
+
33
+ /** One present-tense clause naming what is unavailable, without a trailing period. */
34
+ export function providerRecoverySubject(input: ProviderRecoveryCopyInput): string {
35
+ const model = label(input.modelLabel) ?? "The model";
36
+ const provider = label(input.providerLabel);
37
+ const at = provider ? ` at the provider (${provider})` : " at the provider";
38
+ switch (input.code) {
39
+ case "provider_rate_limited":
40
+ return `${model} is rate limited${at}`;
41
+ case "provider_unavailable":
42
+ return input.providerCondition === "overloaded"
43
+ ? `${model} is overloaded${at}`
44
+ : input.providerCondition === "unresponsive"
45
+ ? `${model} stopped responding${at}`
46
+ : `${model} is temporarily unavailable${at}`;
47
+ case "provider_unknown_finish_reason":
48
+ return `${model} ended its response unexpectedly`;
49
+ case "post_compaction_continuation_empty":
50
+ return `${model} stopped right after compacting the conversation`;
51
+ case "upstream_connectivity_unavailable":
52
+ return "Opengeni can't reach an upstream service";
53
+ case "mcp_transport_timeout":
54
+ return "A required MCP server isn't responding";
55
+ case "mcp_transport_unavailable":
56
+ return "A required MCP server is unreachable";
57
+ case "sandbox_command_start_unavailable":
58
+ return "The sandbox isn't ready yet";
59
+ case "turn_execution_policy_definition_mismatch":
60
+ return "Opengeni is applying a configuration update";
61
+ default:
62
+ return "A service this turn depends on is temporarily unavailable";
63
+ }
64
+ }
65
+
66
+ /** Terminal copy once the finite automatic recovery budget is spent. */
67
+ export function providerRecoveryExhaustedMessage(
68
+ input: ProviderRecoveryCopyInput & { providerRecoveryCount: number },
69
+ ): string {
70
+ const count = input.providerRecoveryCount;
71
+ const retried = `Opengeni retried ${count} ${count === 1 ? "time" : "times"} without success.`;
72
+ const remedy = MODEL_PROVIDER_RECOVERY_CODES.has(input.code ?? "")
73
+ ? "Try again in a few minutes, or switch to another model."
74
+ : "Try again in a few minutes.";
75
+ return `${providerRecoverySubject(input)}. ${retried} ${remedy}`;
76
+ }
@@ -0,0 +1,64 @@
1
+ import type { Observability } from "@opengeni/observability";
2
+
3
+ export type ProviderRecoveryObservation = {
4
+ startedAt: number;
5
+ cause: "rate_limited" | "unavailable" | "connectivity";
6
+ };
7
+
8
+ export function providerRecoveryCause(code: unknown): ProviderRecoveryObservation["cause"] | null {
9
+ if (code === "provider_rate_limited") return "rate_limited";
10
+ if (code === "provider_unavailable" || code === "provider_overloaded") return "unavailable";
11
+ if (code === "upstream_connectivity_unavailable") return "connectivity";
12
+ return null;
13
+ }
14
+
15
+ export function readProviderRecoveryObservation(
16
+ metadata: Record<string, unknown>,
17
+ ): ProviderRecoveryObservation | undefined {
18
+ const cause = providerRecoveryCause(metadata.providerRecoveryReason);
19
+ const startedAt =
20
+ typeof metadata.providerRecoveryStartedAt === "string"
21
+ ? Date.parse(metadata.providerRecoveryStartedAt)
22
+ : Number.NaN;
23
+ return cause && Number.isFinite(startedAt) ? { cause, startedAt } : undefined;
24
+ }
25
+
26
+ /** Operational observations only; never retry authority, billing or diagnostics. */
27
+ export function recordProviderRecoveryOutcome(
28
+ observability: Observability,
29
+ input: {
30
+ route?: { provider: string; model: string } | undefined;
31
+ cause: ProviderRecoveryObservation["cause"];
32
+ outcome: "scheduled" | "recovered" | "exhausted";
33
+ delayMs?: number;
34
+ elapsedMs?: number;
35
+ },
36
+ ): void {
37
+ if (!input.route) return;
38
+ const labels = { ...input.route, cause: input.cause, outcome: input.outcome };
39
+ try {
40
+ observability.incrementCounter({
41
+ name: "opengeni_model_recovery_total",
42
+ help: "Observed model recovery decisions and successful resumptions.",
43
+ labels,
44
+ });
45
+ if (input.delayMs !== undefined) {
46
+ observability.observeHistogram({
47
+ name: "opengeni_model_recovery_delay_seconds",
48
+ help: "Scheduled model recovery delay, including provider hints and jitter.",
49
+ labels: { ...input.route, cause: input.cause },
50
+ value: Math.max(0, input.delayMs) / 1_000,
51
+ });
52
+ }
53
+ if (input.elapsedMs !== undefined) {
54
+ observability.observeHistogram({
55
+ name: "opengeni_model_recovery_duration_seconds",
56
+ help: "Elapsed recovery episode including backoff, preparation and model requests.",
57
+ labels,
58
+ value: Math.max(0, input.elapsedMs) / 1_000,
59
+ });
60
+ }
61
+ } catch {
62
+ // Metrics cannot interrupt settlement or model progress.
63
+ }
64
+ }
@@ -0,0 +1,25 @@
1
+ /** Closed policy facts shared with the workflow's content-free recovery wire. */
2
+ export const PROVIDER_OVERLOAD_RECOVERY_CODE = "provider_overloaded";
3
+ export const MAX_AUTOMATIC_PROVIDER_OVERLOAD_RECOVERIES = 15;
4
+ export const PROVIDER_OVERLOAD_RECOVERY_WINDOW_MS = 15 * 60_000;
5
+
6
+ export function validProviderOverloadRecoveryDelay(code: unknown, delay: unknown): boolean {
7
+ if (delay === undefined) return code !== PROVIDER_OVERLOAD_RECOVERY_CODE;
8
+ return (
9
+ code === PROVIDER_OVERLOAD_RECOVERY_CODE &&
10
+ typeof delay === "number" &&
11
+ Number.isSafeInteger(delay) &&
12
+ delay > 0 &&
13
+ delay < PROVIDER_OVERLOAD_RECOVERY_WINDOW_MS
14
+ );
15
+ }
16
+
17
+ export function readProviderRecoveryStartedAt(
18
+ metadata: Record<string, unknown>,
19
+ ): number | undefined {
20
+ const value =
21
+ typeof metadata.providerRecoveryStartedAt === "string"
22
+ ? Date.parse(metadata.providerRecoveryStartedAt)
23
+ : NaN;
24
+ return Number.isFinite(value) ? value : undefined;
25
+ }
@@ -91,10 +91,9 @@ export const QUIESCENCE_PROOF_SIGNAL_MAX_RETRY_MS = 5_000;
91
91
  export const TURN_QUIESCENCE_WATCHDOG_MS = 5 * 60_000;
92
92
  export const TURN_FINALIZER_STEP_TIMEOUT_MS = 30_000;
93
93
 
94
- /** A fenced activity must never heartbeat forever while its physical writer
95
- * drain is stuck. The last-resort worker exit stops every in-process writer;
96
- * Kubernetes replaces the pod and the workflow's heartbeat-lease reconciler
97
- * then commits the exact quiescence receipt. */
94
+ /** A fenced activity must never heartbeat forever while physical cleanup is
95
+ * stuck. The callback requests host-owned containment, which drains peer turns
96
+ * before applying its final exit policy. A timeout is never quiescence proof. */
98
97
  export function armTurnQuiescenceWatchdog(input: {
99
98
  enabled: boolean;
100
99
  timeoutMs?: number;
@@ -435,13 +434,14 @@ export async function runMandatoryHistoryPersistenceStep<T>(
435
434
  }
436
435
 
437
436
  export type OpStreamFinalizer = {
438
- finalizeOpStreamOps(): Promise<void>;
437
+ finalizeOpStreamOps(toolCallIds?: readonly string[]): Promise<void>;
439
438
  };
440
439
 
441
- /** Release retained Connected Machine output only after the turn is durable. */
440
+ /** Release only durably recorded tool results, or the complete durable turn. */
442
441
  export async function finalizeDurableTurnOpStreams(
443
442
  sessions: readonly unknown[],
444
443
  fallback: OpStreamFinalizer | null,
444
+ toolCallIds?: readonly string[],
445
445
  ): Promise<void> {
446
446
  const candidates = new Set<OpStreamFinalizer>();
447
447
  for (const session of sessions) {
@@ -455,7 +455,7 @@ export async function finalizeDurableTurnOpStreams(
455
455
  }
456
456
  for (const candidate of candidates) {
457
457
  try {
458
- await candidate.finalizeOpStreamOps();
458
+ await candidate.finalizeOpStreamOps(toolCallIds);
459
459
  } catch {
460
460
  // The runner's retention TTL owns the fallback.
461
461
  }
@@ -1,18 +1,16 @@
1
1
  import { getSandboxRecoveryDiscontinuity, type Database } from "@opengeni/db";
2
2
 
3
- /** Opt-in belongs to this warning-aware worker implementation, not the DB
4
- * client, role defaults or deployment configuration. Claim stamps it locally. */
5
- export const FILESYSTEM_DISCONTINUITY_PROTOCOL = 1 as const;
3
+ /** v2 also recognizes system-selected checkpoint fallback receipts, and v3
4
+ * the empty-workspace continuation receipts. A worker below the version a
5
+ * session's receipts require cannot claim it (migrations 0526 and 0548). */
6
+ export const FILESYSTEM_DISCONTINUITY_PROTOCOL = 3 as const;
6
7
 
7
8
  export async function recoveryAwareSessionInstructions(
8
9
  db: Database,
9
10
  workspaceId: string,
10
11
  session: { id: string; instructions?: string | null },
12
+ readDiscontinuity: typeof getSandboxRecoveryDiscontinuity = getSandboxRecoveryDiscontinuity,
11
13
  ): Promise<string> {
12
- const filesystemDiscontinuity = await getSandboxRecoveryDiscontinuity(
13
- db,
14
- workspaceId,
15
- session.id,
16
- );
14
+ const filesystemDiscontinuity = await readDiscontinuity(db, workspaceId, session.id);
17
15
  return [session.instructions, filesystemDiscontinuity].filter(Boolean).join("\n\n");
18
16
  }
@@ -0,0 +1,44 @@
1
+ import type { AttemptToolDefinition } from "@opengeni/codemode";
2
+
3
+ export const REFRESH_CREDENTIALS_TOOL_NAME = "refresh_credentials";
4
+
5
+ export const REFRESH_CREDENTIALS_TOOL_DESCRIPTION =
6
+ "Fetch fresh host-managed credentials for this sandbox now. Use it when a command fails because a token or credential file provided by the workspace has expired or been revoked. The environment variables and credential files that the host manages are replaced for the next command; commands that are already running keep what they started with.";
7
+
8
+ export function createRefreshCredentialsAttemptToolDefinition(input: {
9
+ refresh: () => Promise<"completed" | "auth_needed" | "error" | "not_provisioned">;
10
+ }): AttemptToolDefinition {
11
+ return {
12
+ identity: { serverId: "opengeni", toolName: REFRESH_CREDENTIALS_TOOL_NAME },
13
+ modelName: REFRESH_CREDENTIALS_TOOL_NAME,
14
+ codemodePath: ["opengeni", REFRESH_CREDENTIALS_TOOL_NAME],
15
+ title: "Refresh credentials",
16
+ description: REFRESH_CREDENTIALS_TOOL_DESCRIPTION,
17
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
18
+ annotations: {
19
+ title: "Refresh credentials",
20
+ readOnlyHint: false,
21
+ destructiveHint: false,
22
+ idempotentHint: true,
23
+ openWorldHint: true,
24
+ },
25
+ source: "opengeni",
26
+ approval: "none",
27
+ execute: async (args) => {
28
+ if (Object.keys(args).length !== 0) {
29
+ throw new Error(`${REFRESH_CREDENTIALS_TOOL_NAME} accepts no arguments`);
30
+ }
31
+ const outcome = await input.refresh();
32
+ const text = {
33
+ completed: "Credentials refreshed. Retry the command that failed.",
34
+ auth_needed:
35
+ "The host returned credentials that need user attention (reconnect or grant access). Continue with what is available and tell the user which service needs reconnecting.",
36
+ error:
37
+ "The credential provider could not be reached. The previous credentials are still in place and a retry is scheduled.",
38
+ not_provisioned:
39
+ "Credentials are provisioned when the sandbox first starts; run a command and they will be fetched then.",
40
+ }[outcome];
41
+ return { isError: outcome === "error", content: [{ type: "text", text }] };
42
+ },
43
+ };
44
+ }