@caupulican/pi-adaptative 0.81.41 → 0.81.42

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 (237) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +5 -1
  3. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +3 -3
  4. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +8 -0
  5. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +26 -3
  6. package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +3 -0
  7. package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +4 -1
  8. package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +2 -1
  9. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +2 -0
  10. package/dist/core/agent-paths.d.ts +32 -0
  11. package/dist/core/agent-paths.d.ts.map +1 -1
  12. package/dist/core/agent-paths.js +65 -0
  13. package/dist/core/agent-paths.js.map +1 -1
  14. package/dist/core/agent-session-contracts.d.ts +19 -1
  15. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  16. package/dist/core/agent-session-contracts.js.map +1 -1
  17. package/dist/core/agent-session.d.ts.map +1 -1
  18. package/dist/core/agent-session.js +4 -9
  19. package/dist/core/agent-session.js.map +1 -1
  20. package/dist/core/autonomy/contracts.d.ts +2 -0
  21. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  22. package/dist/core/autonomy/contracts.js.map +1 -1
  23. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  24. package/dist/core/autonomy/envelope-enforcement.js +4 -9
  25. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  26. package/dist/core/autonomy/lane-tool-surface.d.ts +3 -1
  27. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  28. package/dist/core/autonomy/lane-tool-surface.js +17 -4
  29. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  30. package/dist/core/autonomy/path-scope.d.ts +14 -0
  31. package/dist/core/autonomy/path-scope.d.ts.map +1 -1
  32. package/dist/core/autonomy/path-scope.js +37 -6
  33. package/dist/core/autonomy/path-scope.js.map +1 -1
  34. package/dist/core/background-lane-controller.d.ts +27 -1
  35. package/dist/core/background-lane-controller.d.ts.map +1 -1
  36. package/dist/core/background-lane-controller.js +32 -1
  37. package/dist/core/background-lane-controller.js.map +1 -1
  38. package/dist/core/delegation/managed-lane-controller.d.ts +11 -1
  39. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
  40. package/dist/core/delegation/managed-lane-controller.js +84 -41
  41. package/dist/core/delegation/managed-lane-controller.js.map +1 -1
  42. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
  43. package/dist/core/delegation/session-worker-claim.js +4 -3
  44. package/dist/core/delegation/session-worker-claim.js.map +1 -1
  45. package/dist/core/delegation/worker-action-journal.d.ts +73 -0
  46. package/dist/core/delegation/worker-action-journal.d.ts.map +1 -0
  47. package/dist/core/delegation/worker-action-journal.js +297 -0
  48. package/dist/core/delegation/worker-action-journal.js.map +1 -0
  49. package/dist/core/delegation/worker-actions.d.ts +36 -1
  50. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  51. package/dist/core/delegation/worker-actions.js +171 -46
  52. package/dist/core/delegation/worker-actions.js.map +1 -1
  53. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +75 -0
  54. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -0
  55. package/dist/core/delegation/worker-agent-control-coordinator.js +218 -0
  56. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -0
  57. package/dist/core/delegation/worker-agent-control.d.ts +66 -0
  58. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -0
  59. package/dist/core/delegation/worker-agent-control.js +163 -0
  60. package/dist/core/delegation/worker-agent-control.js.map +1 -0
  61. package/dist/core/delegation/worker-attempt-executor.d.ts +80 -0
  62. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -0
  63. package/dist/core/delegation/worker-attempt-executor.js +343 -0
  64. package/dist/core/delegation/worker-attempt-executor.js.map +1 -0
  65. package/dist/core/delegation/worker-claim.d.ts +30 -0
  66. package/dist/core/delegation/worker-claim.d.ts.map +1 -1
  67. package/dist/core/delegation/worker-claim.js +205 -53
  68. package/dist/core/delegation/worker-claim.js.map +1 -1
  69. package/dist/core/delegation/worker-conversation-store.d.ts +116 -0
  70. package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -0
  71. package/dist/core/delegation/worker-conversation-store.js +442 -0
  72. package/dist/core/delegation/worker-conversation-store.js.map +1 -0
  73. package/dist/core/delegation/worker-delegation-controller.d.ts +21 -5
  74. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  75. package/dist/core/delegation/worker-delegation-controller.js +386 -251
  76. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  77. package/dist/core/delegation/worker-delegation-request.d.ts +14 -0
  78. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  79. package/dist/core/delegation/worker-delegation-request.js.map +1 -1
  80. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +4 -2
  81. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
  82. package/dist/core/delegation/worker-dispatch-scheduler.js +16 -6
  83. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
  84. package/dist/core/delegation/worker-execution-policy.d.ts +2 -1
  85. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  86. package/dist/core/delegation/worker-execution-policy.js +5 -7
  87. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  88. package/dist/core/delegation/worker-lifecycle.d.ts +44 -1
  89. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  90. package/dist/core/delegation/worker-lifecycle.js +120 -0
  91. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  92. package/dist/core/delegation/worker-process-owner.d.ts +18 -0
  93. package/dist/core/delegation/worker-process-owner.d.ts.map +1 -0
  94. package/dist/core/delegation/worker-process-owner.js +54 -0
  95. package/dist/core/delegation/worker-process-owner.js.map +1 -0
  96. package/dist/core/delegation/worker-profile-resolver.d.ts +5 -1
  97. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  98. package/dist/core/delegation/worker-profile-resolver.js +8 -0
  99. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  100. package/dist/core/delegation/worker-recovery-coordinator.d.ts +54 -0
  101. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -0
  102. package/dist/core/delegation/worker-recovery-coordinator.js +181 -0
  103. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -0
  104. package/dist/core/delegation/worker-resource-catalog.d.ts +32 -0
  105. package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -0
  106. package/dist/core/delegation/worker-resource-catalog.js +116 -0
  107. package/dist/core/delegation/worker-resource-catalog.js.map +1 -0
  108. package/dist/core/delegation/worker-resource-materializer.d.ts +47 -0
  109. package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -0
  110. package/dist/core/delegation/worker-resource-materializer.js +137 -0
  111. package/dist/core/delegation/worker-resource-materializer.js.map +1 -0
  112. package/dist/core/delegation/worker-runner.d.ts +3 -1
  113. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  114. package/dist/core/delegation/worker-runner.js +189 -54
  115. package/dist/core/delegation/worker-runner.js.map +1 -1
  116. package/dist/core/delegation/worker-terminal-finalizer.d.ts +23 -0
  117. package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -0
  118. package/dist/core/delegation/worker-terminal-finalizer.js +12 -0
  119. package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -0
  120. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +38 -0
  121. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -0
  122. package/dist/core/delegation/worker-write-reservation-coordinator.js +107 -0
  123. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -0
  124. package/dist/core/delegation/worker-write-reservation.d.ts +90 -0
  125. package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -0
  126. package/dist/core/delegation/worker-write-reservation.js +348 -0
  127. package/dist/core/delegation/worker-write-reservation.js.map +1 -0
  128. package/dist/core/models/model-endpoint.d.ts +3 -0
  129. package/dist/core/models/model-endpoint.d.ts.map +1 -0
  130. package/dist/core/models/model-endpoint.js +11 -0
  131. package/dist/core/models/model-endpoint.js.map +1 -0
  132. package/dist/core/orchestration/agent-resume.d.ts +2 -0
  133. package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
  134. package/dist/core/orchestration/agent-resume.js +7 -0
  135. package/dist/core/orchestration/agent-resume.js.map +1 -1
  136. package/dist/core/orchestration/attempt-usage.d.ts +28 -0
  137. package/dist/core/orchestration/attempt-usage.d.ts.map +1 -0
  138. package/dist/core/orchestration/attempt-usage.js +168 -0
  139. package/dist/core/orchestration/attempt-usage.js.map +1 -0
  140. package/dist/core/orchestration/capability-gateway.d.ts +19 -1
  141. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  142. package/dist/core/orchestration/capability-gateway.js +128 -28
  143. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  144. package/dist/core/orchestration/contracts.d.ts +35 -0
  145. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  146. package/dist/core/orchestration/contracts.js +17 -0
  147. package/dist/core/orchestration/contracts.js.map +1 -1
  148. package/dist/core/orchestration/delegation-ledger.d.ts +17 -2
  149. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  150. package/dist/core/orchestration/delegation-ledger.js +78 -3
  151. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  152. package/dist/core/orchestration/event-store.d.ts +1 -0
  153. package/dist/core/orchestration/event-store.d.ts.map +1 -1
  154. package/dist/core/orchestration/event-store.js +78 -38
  155. package/dist/core/orchestration/event-store.js.map +1 -1
  156. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  157. package/dist/core/orchestration/profile-registry.js +81 -41
  158. package/dist/core/orchestration/profile-registry.js.map +1 -1
  159. package/dist/core/orchestration/profile-store.d.ts.map +1 -1
  160. package/dist/core/orchestration/profile-store.js +18 -4
  161. package/dist/core/orchestration/profile-store.js.map +1 -1
  162. package/dist/core/orchestration/risk-budget.d.ts +2 -0
  163. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  164. package/dist/core/orchestration/risk-budget.js +26 -0
  165. package/dist/core/orchestration/risk-budget.js.map +1 -1
  166. package/dist/core/orchestration/task-runtime.d.ts +13 -1
  167. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  168. package/dist/core/orchestration/task-runtime.js +127 -16
  169. package/dist/core/orchestration/task-runtime.js.map +1 -1
  170. package/dist/core/orchestration/worker-execution-contract.d.ts +3 -1
  171. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  172. package/dist/core/orchestration/worker-execution-contract.js +75 -23
  173. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  174. package/dist/core/orchestration/worker-result-adapter.d.ts +9 -3
  175. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
  176. package/dist/core/orchestration/worker-result-adapter.js +167 -14
  177. package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
  178. package/dist/core/reflection-controller.d.ts +1 -1
  179. package/dist/core/reflection-controller.d.ts.map +1 -1
  180. package/dist/core/reflection-controller.js +90 -54
  181. package/dist/core/reflection-controller.js.map +1 -1
  182. package/dist/core/research/evidence-bundle.d.ts +20 -0
  183. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  184. package/dist/core/research/evidence-bundle.js +173 -69
  185. package/dist/core/research/evidence-bundle.js.map +1 -1
  186. package/dist/core/runtime-builder.d.ts +7 -0
  187. package/dist/core/runtime-builder.d.ts.map +1 -1
  188. package/dist/core/runtime-builder.js +15 -1
  189. package/dist/core/runtime-builder.js.map +1 -1
  190. package/dist/core/session-artifact-bundle.d.ts +35 -0
  191. package/dist/core/session-artifact-bundle.d.ts.map +1 -0
  192. package/dist/core/session-artifact-bundle.js +61 -0
  193. package/dist/core/session-artifact-bundle.js.map +1 -0
  194. package/dist/core/tools/delegate-status.d.ts +6 -1
  195. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  196. package/dist/core/tools/delegate-status.js +100 -18
  197. package/dist/core/tools/delegate-status.js.map +1 -1
  198. package/dist/core/tools/delegate.d.ts +9 -1
  199. package/dist/core/tools/delegate.d.ts.map +1 -1
  200. package/dist/core/tools/delegate.js +323 -61
  201. package/dist/core/tools/delegate.js.map +1 -1
  202. package/dist/core/tools/run-process.d.ts +1 -1
  203. package/dist/core/tools/run-process.d.ts.map +1 -1
  204. package/dist/core/tools/run-process.js +69 -9
  205. package/dist/core/tools/run-process.js.map +1 -1
  206. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  207. package/dist/core/tools/shell-contract-router.js +12 -5
  208. package/dist/core/tools/shell-contract-router.js.map +1 -1
  209. package/dist/core/util/bounded-file.d.ts +15 -0
  210. package/dist/core/util/bounded-file.d.ts.map +1 -0
  211. package/dist/core/util/bounded-file.js +120 -0
  212. package/dist/core/util/bounded-file.js.map +1 -0
  213. package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
  214. package/dist/core/util/bounded-jsonl.js +119 -9
  215. package/dist/core/util/bounded-jsonl.js.map +1 -1
  216. package/dist/core/util/bounded-value.d.ts +3 -0
  217. package/dist/core/util/bounded-value.d.ts.map +1 -0
  218. package/dist/core/util/bounded-value.js +12 -0
  219. package/dist/core/util/bounded-value.js.map +1 -0
  220. package/dist/core/util/value-guards.d.ts +2 -0
  221. package/dist/core/util/value-guards.d.ts.map +1 -1
  222. package/dist/core/util/value-guards.js +5 -0
  223. package/dist/core/util/value-guards.js.map +1 -1
  224. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  225. package/dist/modes/interactive/components/session-selector.js +27 -44
  226. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  227. package/docs/tool-repair.md +3 -0
  228. package/docs/windows.md +4 -2
  229. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  230. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  231. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  232. package/examples/extensions/sandbox/package-lock.json +2 -2
  233. package/examples/extensions/sandbox/package.json +1 -1
  234. package/examples/extensions/with-deps/package-lock.json +2 -2
  235. package/examples/extensions/with-deps/package.json +1 -1
  236. package/npm-shrinkwrap.json +12 -12
  237. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"worker-delegation-controller.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-controller.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAU7B,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,8BAA8B,EAA+B,MAAM,iCAAiC,CAAC;AAE9G,OAAO,EAAE,4BAA4B,EAA+B,MAAM,wBAAwB,CAAC;AAKnG,OAAO,EACN,6BAA6B,EAC7B,+BAA+B,GAC/B,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAgC,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACvG,OAAO,EACN,wBAAwB,EACxB,2BAA2B,EAC3B,yBAAyB,EAEzB,gCAAgC,GAChC,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAA8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AC,CAAC;YACvD,IAAI,MAAM,EAAE,MAAM,KAAK,QAAQ,IAAI,MAAM,EAAE,MAAM,KAAK,SAAS,EAAE,CAAC;gBACjE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;YAC5E,CAAC;YACD,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;gBAAE,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;YAC1E,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,6BAA6B,OAAO,EAAE,EAAE,CAAC,CAAC;YACrF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAClC,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YAClD,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACvD,kBAAkB,EAAE,CAAC;QACtB,CAAC;IAAA,CACD;IAED,mGAAmG;IACnG,KAAK,GAAS;QACb,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAAA,CACvB;CACD","sourcesContent":["import path from \"node:path\";\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { Api, Model, Usage } from \"@caupulican/pi-ai\";\nimport type {\n\tAgentSessionEvent,\n\tIsolatedCompletionOptions,\n\tIsolatedCompletionResult,\n\tWorkerDelegationRunOutcome,\n} from \"../agent-session.ts\";\nimport type { CapabilityEnvelope, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport { getPrivateLaneDeniedPaths } from \"../autonomy/lane-private-paths.ts\";\nimport { createLaneToolSurface } from \"../autonomy/lane-tool-surface.ts\";\nimport type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport { safeRealpathSync } from \"../autonomy/path-scope.ts\";\nimport { appendLaneRecordSnapshot } from \"../autonomy/session-lane-record.ts\";\nimport { composeSubagentSystemPrompt } from \"../autonomy/subagent-prompt.ts\";\nimport { AUTONOMY_TELEMETRY_EVENT_TYPES, type AutonomyTelemetryEvent } from \"../autonomy/telemetry-events.ts\";\nimport type { GoalState } from \"../goals/goal-state.ts\";\nimport { deriveModelCapabilityProfile, type ModelCapabilityProfile } from \"../model-capability.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport type { OrchestrationProfile, WorkerExecutionContract } from \"../orchestration/contracts.ts\";\nimport type { StartedDelegationAttempt } from \"../orchestration/delegation-ledger.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\nimport {\n\tcreateWorkerExecutionContract,\n\tverifierWorkerExecutionContract,\n} from \"../orchestration/worker-execution-contract.ts\";\nimport { createWorkerResultContract } from \"../orchestration/worker-result-adapter.ts\";\nimport { registerInFlightWork } from \"../reload-blockers.ts\";\nimport type { ResolvedWorkerDelegationSettings, SettingsManager } from \"../settings-manager.ts\";\nimport { applyWorkerActions } from \"./worker-actions.ts\";\nimport type { WorkerDelegationRequest } from \"./worker-delegation-request.ts\";\nimport { type WorkerDispatchAdmission, WorkerDispatchScheduler } from \"./worker-dispatch-scheduler.ts\";\nimport {\n\tbuildWorkerExecutionPlan,\n\tcompileWorkerExecutionGrant,\n\tnarrowWorkerExecutionPlan,\n\ttype WorkerExecutionPlan,\n\tworkerExecutionAuthorityFromPlan,\n} from \"./worker-execution-policy.ts\";\nimport type { WorkerLifecycle } from \"./worker-lifecycle.ts\";\nimport type { WorkerNotificationCoordinator } from \"./worker-notification-coordinator.ts\";\nimport { type ResolvedWorkerProfile, WorkerProfileResolver } from \"./worker-profile-resolver.ts\";\nimport { runWorker } from \"./worker-runner.ts\";\n\nexport function isLocalExecutionModel(model: Pick<Model<Api>, \"provider\" | \"baseUrl\">): boolean {\n\tif (model.provider === \"ollama\" || model.provider === \"transformers\" || model.provider === \"llama-cpp\") {\n\t\treturn true;\n\t}\n\ttry {\n\t\tconst hostname = new URL(model.baseUrl).hostname.toLowerCase();\n\t\treturn hostname === \"localhost\" || hostname === \"127.0.0.1\" || hostname === \"::1\" || hostname === \"[::1]\";\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport interface WorkerDelegationControllerDeps {\n\tisDisposed(): boolean;\n\tgetSessionId(): string;\n\tgetCwd(): string;\n\tgetAgentDir(): string;\n\tgetSessionManager(): SessionManager;\n\tgetSettingsManager(): SettingsManager;\n\tgetActiveOrchestrationProfile?(): OrchestrationProfile | undefined;\n\tgetModelRegistry(): ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n\tgetModel(): Model<Api> | undefined;\n\tisDelegateToolActive(): boolean;\n\tgetCapabilityEnvelope(): CapabilityEnvelope | undefined;\n\temit(event: AgentSessionEvent): void;\n\tnotifyWorkerTerminalHandoff(\n\t\trecords: readonly { laneId: string; status: LaneTerminalStatus; reasonCode?: string }[],\n\t): Promise<void>;\n\temitAutonomyTelemetry(event: AutonomyTelemetryEvent): void;\n\tgetGoalStateSnapshot(): GoalState | undefined;\n\tsaveWorkerClaimSnapshot(claim: WorkerClaim, request?: WorkerRequest): string;\n\tqueueWorkerHumanInput(request: { workerRequestId: string; message: string; blockers: readonly string[] }): void;\n\treadMemoryForLane(query: string): Promise<string>;\n\taddSpawnedUsage(\n\t\tusage: Usage,\n\t\topts: { label?: string; sourceSessionId?: string; reportId: string },\n\t): string | undefined;\n\trunIsolatedCompletion(opts: IsolatedCompletionOptions): Promise<IsolatedCompletionResult>;\n}\n\ntype WorkerAdmission =\n\t| {\n\t\t\tok: true;\n\t\t\tinstructions: string;\n\t\t\tsettings: ResolvedWorkerDelegationSettings;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t\t\tverifierShipment?: ResolvedWorkerProfile;\n\t\t\texecutionContract: WorkerExecutionContract;\n\t\t\texecutionPlan: WorkerExecutionPlan;\n\t }\n\t| { ok: false; skipReason: string };\n\ninterface PreparedWorkerAttempt {\n\texecutionPlan: WorkerExecutionPlan;\n\tlifecycle: WorkerLifecycle;\n\trecord: LaneRecord;\n\tattempt?: AttemptRuntimeState;\n}\n\nexport class WorkerDelegationController {\n\tprivate readonly deps: WorkerDelegationControllerDeps;\n\tprivate readonly workerAbort = new AbortController();\n\tprivate readonly lifecycle: WorkerLifecycle;\n\tprivate profileResolver: WorkerProfileResolver | undefined;\n\tprivate queueRecovered = false;\n\tprivate recoveringDurableState = false;\n\tprivate readonly verificationRecoveryFailures = new Map<string, string>();\n\tprivate readonly notifications: WorkerNotificationCoordinator;\n\tprivate readonly scheduler: WorkerDispatchScheduler;\n\tprivate readonly laneAbortControllers = new Map<string, AbortController>();\n\tprivate readonly publishedTerminalAttemptIds = new Set<string>();\n\tprivate readonly inFlightLedgers = new Map<\n\t\tstring,\n\t\t{\n\t\t\tchangedFiles: Set<string>;\n\t\t\tgetSpend: () => Usage | undefined;\n\t\t\tgetToolCalls: () => number;\n\t\t\trequest: WorkerRequest;\n\t\t\thandle: StartedDelegationAttempt;\n\t\t\tstartedAt: number;\n\t\t}\n\t>();\n\n\tconstructor(\n\t\tdeps: WorkerDelegationControllerDeps,\n\t\tnotifications: WorkerNotificationCoordinator,\n\t\tlifecycle: WorkerLifecycle,\n\t) {\n\t\tthis.deps = deps;\n\t\tthis.notifications = notifications;\n\t\tthis.lifecycle = lifecycle;\n\t\tthis.scheduler = new WorkerDispatchScheduler({\n\t\t\tagentDir: this.deps.getAgentDir?.() ?? \"\",\n\t\t\tisDisposed: () => this.deps.isDisposed(),\n\t\t\tadmit: (request, record) => this.workerDispatchAdmission(request, record),\n\t\t\tgetRecord: (laneId) => this.getWorkerLifecycle().getRecord(laneId),\n\t\t\trun: (request, record) => this.runOnce(request, undefined, record),\n\t\t\tcancel: (laneId, reasonCode) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst terminal = this.getWorkerLifecycle().cancel(laneId, reasonCode);\n\t\t\t\t\tif (terminal) this.publishTerminalRecord(terminal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t`Failed to cancel durable worker ${laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t\twarn: (message) => this.safeWarn(message),\n\t\t});\n\t}\n\n\tprivate safeWarn(message: string): void {\n\t\ttry {\n\t\t\tthis.deps.emit({ type: \"warning\", message });\n\t\t} catch {\n\t\t\t// Disposal and recovery diagnostics must never throw.\n\t\t}\n\t}\n\n\trecordTerminal(record: LaneRecord): void {\n\t\tif (record.status === \"queued\" || record.status === \"running\") return;\n\t\tif (record.type === \"worker\") {\n\t\t\tconst notification = this.lifecycle.getTerminalNotification(record.laneId);\n\t\t\tif (notification?.status === \"delivered\") return;\n\t\t\tif (notification) {\n\t\t\t\tthis.notifications.recordTerminal(record, notification.notificationId);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.notifications.recordTerminal(record);\n\t}\n\n\tgetRecords(): LaneRecord[] {\n\t\tif (this.deps.isDelegateToolActive?.()) this.recoverDurableQueue();\n\t\treturn this.lifecycle.getRecords();\n\t}\n\n\t/** Process-local worker records for the shared terminal notifier; never triggers durable recovery. */\n\tgetLoadedRecords(): LaneRecord[] {\n\t\treturn this.lifecycle.getRecords();\n\t}\n\n\tmarkNotificationsDelivered(notificationIds: readonly string[]): void {\n\t\tthis.lifecycle.markNotificationsDelivered(notificationIds);\n\t}\n\n\tabort(): void {\n\t\tthis.workerAbort.abort();\n\t\tfor (const record of this.lifecycle.getRecords()) {\n\t\t\tif (record.status !== \"queued\" && record.status !== \"running\") continue;\n\t\t\tconst ledger = this.inFlightLedgers.get(record.laneId);\n\t\t\tif (!ledger) {\n\t\t\t\ttry {\n\t\t\t\t\tconst canceled = this.lifecycle.cancel(record.laneId, \"session_disposed\");\n\t\t\t\t\tif (canceled) {\n\t\t\t\t\t\tthis.publishTerminalRecord(canceled);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t`Failed to cancel durable queued worker ${record.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.inFlightLedgers.delete(record.laneId);\n\t\t\ttry {\n\t\t\t\tconst spend = ledger.getSpend();\n\t\t\t\tconst reportId = `worker:${this.deps.getSessionId()}:${record.laneId}`;\n\t\t\t\tconst claim: WorkerClaim = {\n\t\t\t\t\trequestId: ledger.request.id,\n\t\t\t\t\tstatus: \"cancelled\",\n\t\t\t\t\tsummary: \"canceled on session dispose\",\n\t\t\t\t\tchangedFiles: [...ledger.changedFiles],\n\t\t\t\t\tusageReportId: reportId,\n\t\t\t\t\tcreatedAt: new Date().toISOString(),\n\t\t\t\t};\n\t\t\t\tconst canceled = this.getWorkerLifecycle().finish(\n\t\t\t\t\tcreateWorkerResultContract({\n\t\t\t\t\t\thandle: ledger.handle,\n\t\t\t\t\t\tclaim,\n\t\t\t\t\t\taccepted: false,\n\t\t\t\t\t\tcostUsd: spend?.cost.total ?? 0,\n\t\t\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\t\t\t...(spend\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tinputTokens: spend.input,\n\t\t\t\t\t\t\t\t\toutputTokens: spend.output,\n\t\t\t\t\t\t\t\t\ttotalTokens: spend.totalTokens,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\twallClockMs: Date.now() - ledger.startedAt,\n\t\t\t\t\t\ttoolCalls: ledger.getToolCalls(),\n\t\t\t\t\t\treasonCode: \"session_disposed\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tthis.publishTerminalRecord(canceled);\n\t\t\t\t// Bounded honesty: spend may be incomplete (it lands only when the isolated completion\n\t\t\t\t// returns, which a mid-flight abort preempts) — record what `getSpend()` knows. Same\n\t\t\t\t// deterministic reportId scheme as the normal path, so a later duplicate report (there\n\t\t\t\t// is none in practice here, since the lane is now terminal) stays idempotent.\n\t\t\t\tthis.deps.saveWorkerClaimSnapshot(claim, ledger.request);\n\t\t\t\tif (spend && (spend.cost.total > 0 || spend.totalTokens > 0)) {\n\t\t\t\t\tthis.deps.addSpawnedUsage(spend, { label: \"worker-delegation\", reportId });\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.safeWarn(\n\t\t\t\t\t`Failed to persist canceled worker claim ${record.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tthis.scheduler.cancelQueued();\n\t}\n\n\tprivate getWorkerLifecycle(): WorkerLifecycle {\n\t\treturn this.lifecycle;\n\t}\n\n\tprivate getWorkerProfileResolver(): WorkerProfileResolver {\n\t\tif (this.profileResolver) return this.profileResolver;\n\t\tthis.profileResolver = new WorkerProfileResolver({\n\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\tcwd: this.deps.getCwd(),\n\t\t\tgetSettingsManager: () => this.deps.getSettingsManager(),\n\t\t\tgetModelRegistry: () => this.deps.getModelRegistry(),\n\t\t\tisModelExhausted: (model) => this.deps.isModelExhausted(model),\n\t\t\tgetActiveOrchestrationProfile: () => this.deps.getActiveOrchestrationProfile?.(),\n\t\t\tonDiagnostic: (message) => this.safeWarn(message),\n\t\t});\n\t\treturn this.profileResolver;\n\t}\n\n\t/** Read-only durable worker projection. Undefined means the delegate capability never loaded. */\n\tgetTaskRuntimeSnapshot(): TaskRuntimeProjection | undefined {\n\t\treturn this.lifecycle.getTaskRuntimeSnapshot();\n\t}\n\n\t/** Reconcile the session goal into an already-loaded worker runtime without defeating lazy UAC. */\n\tsynchronizeGoalState(goal: GoalState): void {\n\t\tthis.publishGoalTerminalRecords(this.lifecycle.synchronizeGoalState(goal));\n\t}\n\n\tprivate publishGoalTerminalRecords(records: readonly LaneRecord[]): void {\n\t\tfor (const record of records) {\n\t\t\tthis.scheduler.dropQueued(record.laneId);\n\t\t\tthis.laneAbortControllers.get(record.laneId)?.abort(\"goal_terminal\");\n\t\t\tthis.publishTerminalRecord(record);\n\t\t}\n\t}\n\n\tprivate recoverDurableQueue(): void {\n\t\tif (this.recoveringDurableState) return;\n\t\tthis.recoveringDurableState = true;\n\t\tconst lifecycle = this.getWorkerLifecycle();\n\t\ttry {\n\t\t\tif (!this.queueRecovered) {\n\t\t\t\tfor (const { attempt, record, verificationOfTaskId } of lifecycle.recoverQueued()) {\n\t\t\t\t\tconst request: WorkerDelegationRequest = {\n\t\t\t\t\t\tinstructions: attempt.dispatch.instructions,\n\t\t\t\t\t\tprofileId: attempt.dispatch.profileId,\n\t\t\t\t\t\t...(verificationOfTaskId ? { verificationOfTaskId } : {}),\n\t\t\t\t\t};\n\t\t\t\t\tthis.scheduler.enqueue(record, request, true, verificationOfTaskId !== undefined);\n\t\t\t\t}\n\t\t\t\tthis.queueRecovered = true;\n\t\t\t}\n\t\t\tfor (const recovery of lifecycle.getPendingVerificationRecoveries()) {\n\t\t\t\tif (recovery.action === \"reconcile\") {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tthis.publishTerminalRecord(lifecycle.reconcileVerification(recovery));\n\t\t\t\t\t\tthis.verificationRecoveryFailures.delete(recovery.subjectTaskId);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t\t`Failed to reconcile recovered verification for ${recovery.subjectTaskId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst legacyImplementation = recovery.verifierExecutionContract\n\t\t\t\t\t? undefined\n\t\t\t\t\t: this.resolveWorkerAdmission({\n\t\t\t\t\t\t\tinstructions: recovery.summary,\n\t\t\t\t\t\t\tprofileId: recovery.implementationProfileId,\n\t\t\t\t\t\t});\n\t\t\t\tconst verifierProfileId =\n\t\t\t\t\trecovery.verifierExecutionContract?.worker.profile.profileId ??\n\t\t\t\t\t(legacyImplementation?.ok ? legacyImplementation.verifierShipment?.profile.profileId : undefined);\n\t\t\t\tconst started = verifierProfileId\n\t\t\t\t\t? this.startInternal(\n\t\t\t\t\t\t\tthis.buildVerifierRequest({\n\t\t\t\t\t\t\t\tsubjectTaskId: recovery.subjectTaskId,\n\t\t\t\t\t\t\t\tverifierProfileId,\n\t\t\t\t\t\t\t\tsummary: recovery.summary,\n\t\t\t\t\t\t\t\tartifactUris: recovery.artifactUris,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\trecovery.verifierExecutionContract,\n\t\t\t\t\t\t)\n\t\t\t\t\t: { started: false as const, skipReason: \"independent_verifier_unavailable\" };\n\t\t\t\tif (started.started) {\n\t\t\t\t\tthis.verificationRecoveryFailures.delete(recovery.subjectTaskId);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (this.verificationRecoveryFailures.get(recovery.subjectTaskId) !== started.skipReason) {\n\t\t\t\t\tthis.verificationRecoveryFailures.set(recovery.subjectTaskId, started.skipReason);\n\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t`Recovered verification for ${recovery.subjectTaskId} did not start: ${started.skipReason}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const notification of lifecycle.getPendingTerminalNotifications()) {\n\t\t\t\tthis.notifications.recordTerminal(notification.record, notification.notificationId);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.recoveringDurableState = false;\n\t\t}\n\t}\n\n\tprivate laneCapabilityProfile(model: Model<Api>): ModelCapabilityProfile {\n\t\treturn deriveModelCapabilityProfile({\n\t\t\tcontextWindow: model.contextWindow,\n\t\t\tmode: this.deps.getSettingsManager().getModelCapabilitySettings().mode,\n\t\t});\n\t}\n\n\tgetProfileCatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\treturn this.getWorkerProfileResolver().catalog();\n\t}\n\n\tprivate resolveWorkerShipment(\n\t\trequest: WorkerDelegationRequest,\n\t\tsettings: ResolvedWorkerDelegationSettings,\n\t): { ok: true; shipment: ResolvedWorkerProfile } | { ok: false; skipReason: string } {\n\t\tconst resolved = this.getWorkerProfileResolver().resolve(request, settings.orchestrationProfile);\n\t\treturn resolved.ok ? { ok: true, shipment: resolved.resolved } : { ok: false, skipReason: resolved.reason };\n\t}\n\n\tprivate resolveRequiredVerifier(\n\t\tprofile: OrchestrationProfile,\n\t): { ok: true; shipment?: ResolvedWorkerProfile } | { ok: false; skipReason: string } {\n\t\tif (!profile.requireIndependentVerification) return { ok: true };\n\t\tconst resolved = this.getWorkerProfileResolver().resolveVerifier(profile);\n\t\treturn resolved.ok\n\t\t\t? { ok: true, shipment: resolved.resolved }\n\t\t\t: { ok: false, skipReason: `independent_verifier_unavailable:${resolved.reason}` };\n\t}\n\n\t/** Single admission contract shared by enqueue, scheduler revalidation, and execution. */\n\tprivate resolveWorkerAdmission(\n\t\trequest: WorkerDelegationRequest,\n\t\tpinnedContract?: WorkerExecutionContract,\n\t): WorkerAdmission {\n\t\tif (this.deps.isDisposed()) return { ok: false, skipReason: \"session_disposed\" };\n\t\tconst instructions = request.instructions.trim();\n\t\tif (!instructions) return { ok: false, skipReason: \"missing_instructions\" };\n\t\tif (!this.deps.isDelegateToolActive()) return { ok: false, skipReason: \"delegate_tool_inactive\" };\n\t\tconst settings = this.deps.getSettingsManager().getWorkerDelegationSettings();\n\t\tif (!settings.enabled) return { ok: false, skipReason: \"worker_delegation_disabled\" };\n\t\tif (pinnedContract && request.profileId && request.profileId !== pinnedContract.worker.profile.profileId) {\n\t\t\treturn { ok: false, skipReason: \"orchestration_execution_contract_mismatch\" };\n\t\t}\n\t\tconst resolved = pinnedContract\n\t\t\t? this.getWorkerProfileResolver().resolveContract(pinnedContract.worker)\n\t\t\t: this.resolveWorkerShipment(request, settings);\n\t\tif (!resolved.ok) {\n\t\t\treturn { ok: false, skipReason: \"skipReason\" in resolved ? resolved.skipReason : resolved.reason };\n\t\t}\n\t\tconst shipment = \"shipment\" in resolved ? resolved.shipment : resolved.resolved;\n\t\tif (request.verificationOfTaskId && shipment.profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, skipReason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\tif (!request.verificationOfTaskId && shipment.profile.role === \"verifier\") {\n\t\t\treturn { ok: false, skipReason: \"verifier_profile_requires_runtime_dispatch\" };\n\t\t}\n\t\tlet verifierShipment: ResolvedWorkerProfile | undefined;\n\t\tif (pinnedContract?.verifier) {\n\t\t\tconst verifier = this.getWorkerProfileResolver().resolveContract(pinnedContract.verifier);\n\t\t\tif (!verifier.ok) {\n\t\t\t\treturn { ok: false, skipReason: `independent_verifier_unavailable:${verifier.reason}` };\n\t\t\t}\n\t\t\tverifierShipment = verifier.resolved;\n\t\t} else {\n\t\t\tconst verifier = this.resolveRequiredVerifier(shipment.profile);\n\t\t\tif (!verifier.ok) return verifier;\n\t\t\tverifierShipment = verifier.shipment;\n\t\t}\n\t\tif (!this.laneCapabilityProfile(shipment.model).backgroundLanesEnabled) {\n\t\t\treturn { ok: false, skipReason: \"model_delegation_unsupported\" };\n\t\t}\n\t\tconst currentExecutionPlan = this.buildWorkerExecutionPlan(shipment.profile, settings);\n\t\tconst executionPlan = pinnedContract\n\t\t\t? narrowWorkerExecutionPlan(pinnedContract.worker.authority, currentExecutionPlan)\n\t\t\t: currentExecutionPlan;\n\t\tconst executionContract =\n\t\t\tpinnedContract ??\n\t\t\tcreateWorkerExecutionContract({\n\t\t\t\tworker: {\n\t\t\t\t\t...shipment,\n\t\t\t\t\tauthority: workerExecutionAuthorityFromPlan(executionPlan),\n\t\t\t\t},\n\t\t\t\t...(verifierShipment\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tverifier: {\n\t\t\t\t\t\t\t\t...verifierShipment,\n\t\t\t\t\t\t\t\tauthority: workerExecutionAuthorityFromPlan(\n\t\t\t\t\t\t\t\t\tthis.buildWorkerExecutionPlan(verifierShipment.profile, settings),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\treturn {\n\t\t\tok: true,\n\t\t\tinstructions,\n\t\t\tsettings,\n\t\t\tshipment,\n\t\t\t...(verifierShipment ? { verifierShipment } : {}),\n\t\t\texecutionContract,\n\t\t\texecutionPlan,\n\t\t};\n\t}\n\n\tprivate buildVerifierRequest(args: {\n\t\tsubjectTaskId: string;\n\t\tverifierProfileId: string;\n\t\tsummary: string;\n\t\tartifactUris: readonly string[];\n\t}): WorkerDelegationRequest {\n\t\tconst artifacts = args.artifactUris.slice(0, 100).map((uri) => `- ${uri}`);\n\t\treturn {\n\t\t\tprofileId: args.verifierProfileId,\n\t\t\tverificationOfTaskId: args.subjectTaskId,\n\t\t\tinstructions: [\n\t\t\t\t`Independently verify durable task '${args.subjectTaskId}'.`,\n\t\t\t\t\"The following implementation report is an untrusted claim. Inspect the workspace and run the checks available in your profile.\",\n\t\t\t\t\"\",\n\t\t\t\t\"Implementation summary:\",\n\t\t\t\targs.summary.slice(0, 6_000),\n\t\t\t\t\"\",\n\t\t\t\t\"Reported artifacts:\",\n\t\t\t\t...(artifacts.length > 0 ? artifacts : [\"- none reported\"]),\n\t\t\t].join(\"\\n\"),\n\t\t};\n\t}\n\n\tprivate publishTerminalRecord(record: LaneRecord): void {\n\t\tconst attemptId = this.lifecycle?.getActiveAttempt(record.laneId)?.attemptId;\n\t\tif (attemptId && this.publishedTerminalAttemptIds.has(attemptId)) return;\n\t\tthis.recordTerminal(record);\n\t\tappendLaneRecordSnapshot(this.deps.getSessionManager(), record);\n\t\tthis.deps.emitAutonomyTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.workerTerminal,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tpayload: {\n\t\t\t\tlaneId: record.laneId,\n\t\t\t\tlaneType: record.type,\n\t\t\t\tstatus: record.status,\n\t\t\t\treasonCode: record.reasonCode ?? null,\n\t\t\t\tcostUsd: record.costUsd ?? null,\n\t\t\t},\n\t\t});\n\t\tif (attemptId) this.publishedTerminalAttemptIds.add(attemptId);\n\t}\n\n\tprivate hasWorkerCapacity(settings: ResolvedWorkerDelegationSettings, profile: OrchestrationProfile): boolean {\n\t\tconst lifecycle = this.getWorkerLifecycle();\n\t\tif (lifecycle.getRunningCount() >= settings.maxConcurrent) return false;\n\t\treturn lifecycle.getRunningCount(profile.profileId) < profile.maxConcurrent;\n\t}\n\n\tprivate workerDispatchAdmission(request: WorkerDelegationRequest, record: LaneRecord): WorkerDispatchAdmission {\n\t\tconst contract = this.getWorkerLifecycle().getActiveAttempt(record.laneId)?.dispatch.executionContract;\n\t\tconst admission = this.resolveWorkerAdmission(request, contract);\n\t\tif (!admission.ok) return { action: \"cancel\", reasonCode: admission.skipReason };\n\t\treturn this.hasWorkerCapacity(admission.settings, admission.shipment.profile)\n\t\t\t? { action: \"start\" }\n\t\t\t: { action: \"wait\" };\n\t}\n\n\tprivate buildWorkerExecutionPlan(\n\t\tprofile: OrchestrationProfile,\n\t\tsettings: ResolvedWorkerDelegationSettings,\n\t): WorkerExecutionPlan {\n\t\treturn buildWorkerExecutionPlan({\n\t\t\tprofile,\n\t\t\tsettings,\n\t\t\tcwd: this.deps.getCwd(),\n\t\t\tdeniedPaths: getPrivateLaneDeniedPaths(this.deps.getCwd(), this.deps.getAgentDir()),\n\t\t\tforegroundMaxCostUsd: this.deps.getCapabilityEnvelope()?.maxEstimatedUsd,\n\t\t\tmemoryEnabled: this.deps.getSettingsManager().getMemoryRetrievalSettings().enabled,\n\t\t});\n\t}\n\n\t/** One durable preparation path for queued, immediate, and recovered execution. */\n\tprivate prepareWorkerAttempt(\n\t\trequest: WorkerDelegationRequest,\n\t\tadmission: Extract<WorkerAdmission, { ok: true }>,\n\t\texistingRecord?: LaneRecord,\n\t): PreparedWorkerAttempt {\n\t\tconst lifecycle = this.getWorkerLifecycle();\n\t\tif (existingRecord) {\n\t\t\treturn {\n\t\t\t\texecutionPlan: admission.executionPlan,\n\t\t\t\tlifecycle,\n\t\t\t\trecord: existingRecord,\n\t\t\t\tattempt: lifecycle.getActiveAttempt(existingRecord.laneId),\n\t\t\t};\n\t\t}\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\t\tconst prepared = lifecycle.prepare({\n\t\t\tinstructions: admission.instructions,\n\t\t\texecutionContract: admission.executionContract,\n\t\t\trequiredCapabilities: admission.executionPlan.requiredCapabilities,\n\t\t\t...(request.verificationOfTaskId ? { verificationOfTaskId: request.verificationOfTaskId } : {}),\n\t\t\t...(goal ? { goal } : {}),\n\t\t});\n\t\treturn { executionPlan: admission.executionPlan, lifecycle, ...prepared };\n\t}\n\n\tstart(\n\t\trequest: WorkerDelegationRequest,\n\t): { started: false; skipReason: string } | { started: true; record: LaneRecord } {\n\t\treturn this.startInternal(request);\n\t}\n\n\tprivate startInternal(\n\t\trequest: WorkerDelegationRequest,\n\t\tpinnedContract?: WorkerExecutionContract,\n\t): { started: false; skipReason: string } | { started: true; record: LaneRecord } {\n\t\tconst admission = this.resolveWorkerAdmission(request, pinnedContract);\n\t\tif (!admission.ok) return { started: false, skipReason: admission.skipReason };\n\t\tif (!request.verificationOfTaskId) this.recoverDurableQueue();\n\t\tconst { settings, shipment } = admission;\n\n\t\tconst foreground = this.deps.getModel();\n\t\tconst contendsWithLocalForeground =\n\t\t\tforeground !== undefined && isLocalExecutionModel(foreground) && isLocalExecutionModel(shipment.model);\n\t\tif (contendsWithLocalForeground || !this.hasWorkerCapacity(settings, shipment.profile)) {\n\t\t\t// A mandatory verifier is the continuation of an already admitted implementation, not a\n\t\t\t// new owner request. Reserve its queue admission so a burst of ordinary work cannot strand\n\t\t\t// the subject behind `independent_verification_required` with no terminal handoff.\n\t\t\tif (this.scheduler.queuedCount >= 8 && !request.verificationOfTaskId) {\n\t\t\t\treturn { started: false, skipReason: \"worker_delegation_queue_full\" };\n\t\t\t}\n\t\t\tlet record: LaneRecord;\n\t\t\ttry {\n\t\t\t\trecord = this.prepareWorkerAttempt(request, admission).record;\n\t\t\t} catch (error) {\n\t\t\t\tthis.safeWarn(\n\t\t\t\t\t`Worker dispatch was not persisted: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t\treturn { started: false, skipReason: \"orchestration_ledger_error\" };\n\t\t\t}\n\t\t\tthis.scheduler.enqueue(\n\t\t\t\trecord,\n\t\t\t\t{ ...request, profileId: shipment.profile.profileId },\n\t\t\t\tfalse,\n\t\t\t\trequest.verificationOfTaskId !== undefined,\n\t\t\t);\n\t\t\tthis.notifications.statusChanged();\n\t\t\treturn { started: true, record };\n\t\t}\n\t\tlet startedRecord: LaneRecord | undefined;\n\t\tconst promise = this.runOnceWithAdmission(\n\t\t\trequest,\n\t\t\t(record) => {\n\t\t\t\tstartedRecord = record;\n\t\t\t},\n\t\t\tundefined,\n\t\t\tadmission,\n\t\t);\n\t\tif (!startedRecord) {\n\t\t\t// Preparation is synchronous up to the first isolated completion await. A promise that\n\t\t\t// rejected before producing a lane is still observed below, so it cannot become unhandled.\n\t\t\tvoid promise.catch(() => undefined);\n\t\t\treturn { started: false, skipReason: \"worker_not_started\" };\n\t\t}\n\t\tthis.scheduler.track(startedRecord.laneId, promise);\n\t\treturn { started: true, record: startedRecord };\n\t}\n\n\tasync runOnce(\n\t\trequest: WorkerDelegationRequest,\n\t\tonStarted?: (record: LaneRecord) => void,\n\t\texistingRecord?: LaneRecord,\n\t): Promise<WorkerDelegationRunOutcome> {\n\t\treturn this.runOnceWithAdmission(request, onStarted, existingRecord);\n\t}\n\n\tprivate async runOnceWithAdmission(\n\t\trequest: WorkerDelegationRequest,\n\t\tonStarted?: (record: LaneRecord) => void,\n\t\texistingRecord?: LaneRecord,\n\t\tpreparedAdmission?: Extract<WorkerAdmission, { ok: true }>,\n\t): Promise<WorkerDelegationRunOutcome> {\n\t\tconst pinnedContract = existingRecord\n\t\t\t? this.getWorkerLifecycle().getActiveAttempt(existingRecord.laneId)?.dispatch.executionContract\n\t\t\t: undefined;\n\t\tconst admission = preparedAdmission ?? this.resolveWorkerAdmission(request, pinnedContract);\n\t\tif (!admission.ok) return { started: false, skipReason: admission.skipReason };\n\t\tif (!request.verificationOfTaskId) this.recoverDurableQueue();\n\t\tconst { instructions, settings, verifierShipment } = admission;\n\t\tconst { model, modelBinding, profile: orchestrationProfile, soul } = admission.shipment;\n\t\tif (!this.hasWorkerCapacity(settings, orchestrationProfile)) {\n\t\t\treturn { started: false, skipReason: \"worker_delegation_already_running\" };\n\t\t}\n\t\tconst laneCapability = this.laneCapabilityProfile(model);\n\t\tconst prepared = this.prepareWorkerAttempt(request, admission, existingRecord);\n\t\tconst { executionPlan, lifecycle } = prepared;\n\t\tif (!prepared.attempt) return { started: false, skipReason: \"orchestration_attempt_missing\" };\n\t\tconst durableTask = lifecycle.getTask(prepared.record.laneId);\n\t\tif (!durableTask) return { started: false, skipReason: \"orchestration_task_missing\" };\n\t\tconst compiled = compileWorkerExecutionGrant({\n\t\t\ttarget: {\n\t\t\t\tobjectiveId: durableTask.task.objectiveId,\n\t\t\t\ttaskId: prepared.attempt.taskId,\n\t\t\t\tattemptId: prepared.attempt.attemptId,\n\t\t\t},\n\t\t\tprofile: orchestrationProfile,\n\t\t\tplan: executionPlan,\n\t\t});\n\t\tif (!compiled.ok) {\n\t\t\tlifecycle.cancel(prepared.record.laneId, compiled.reasonCodes.join(\",\"));\n\t\t\treturn { started: false, skipReason: `execution_policy_denied:${compiled.reasonCodes.join(\",\")}` };\n\t\t}\n\t\tlifecycle.bindGrant(prepared.attempt.attemptId, compiled.grant);\n\t\tconst durableHandle = lifecycle.start(prepared.record.laneId, orchestrationProfile.leaseTtlMs);\n\t\tconst startedRecord = lifecycle.getRecord(prepared.record.laneId);\n\t\tif (!startedRecord) return { started: false, skipReason: \"orchestration_projection_missing\" };\n\t\tonStarted?.(startedRecord);\n\t\tconst maxUsd = compiled.grant.budget.maxCostUsd;\n\t\tconst executionPolicy = orchestrationProfile.executionPolicy;\n\t\tconst toolSurface = createLaneToolSurface({\n\t\t\tcwd: this.deps.getCwd(),\n\t\t\treadMemory: executionPlan.readMemory ? (query) => this.deps.readMemoryForLane(query) : undefined,\n\t\t\twriteEnabled: executionPlan.writeEnabled,\n\t\t\twritePaths: executionPlan.writePaths,\n\t\t\t...(executionPlan.processEnabled && executionPolicy ? { executionPolicy } : {}),\n\t\t\tprocessMaxWallClockMs: compiled.grant.budget.maxWallClockMs ?? 0,\n\t\t\tgrant: compiled.grant,\n\t\t\ttoolManifests: executionPlan.toolManifests,\n\t\t});\n\t\tconst writeGranted =\n\t\t\texecutionPlan.writeEnabled &&\n\t\t\ttoolSurface.gateway !== undefined &&\n\t\t\ttoolSurface.allowedTools.some((name) => name === \"write\" || name === \"edit\");\n\t\tconst workerRequest: WorkerRequest = {\n\t\t\tid: startedRecord.laneId,\n\t\t\tinstructions,\n\t\t\troute: {\n\t\t\t\ttier: \"cheap\",\n\t\t\t\trisk: writeGranted ? \"scoped-write\" : \"read-only\",\n\t\t\t\tconfidence: 1,\n\t\t\t\treasonCode: \"profile_worker\",\n\t\t\t\treasons: [writeGranted ? \"Path-scoped worker delegation\" : \"Read-only worker delegation\"],\n\t\t\t},\n\t\t\tenvelope: {\n\t\t\t\tid: `worker-${this.deps.getSessionId()}-${startedRecord.laneId}`,\n\t\t\t\tprofileId: orchestrationProfile.profileId,\n\t\t\t\t// filesystem.write requires BOTH the opt-in AND an explicit non-empty path scope —\n\t\t\t\t// an unscoped write grant is refused here, not discovered at validation time.\n\t\t\t\tcapabilities: [...compiled.grant.capabilities],\n\t\t\t\t...(writeGranted ? { allowedPaths: [...compiled.grant.writePaths] } : {}),\n\t\t\t\tdeniedPaths: [...compiled.grant.deniedPaths],\n\t\t\t\tallowedTools: [...toolSurface.allowedTools],\n\t\t\t\tdeniedTools: [...toolSurface.deniedTools],\n\t\t\t\t...(maxUsd !== undefined ? { maxEstimatedUsd: maxUsd } : {}),\n\t\t\t\tcreatedAt: new Date().toISOString(),\n\t\t\t},\n\t\t\t...(maxUsd !== undefined ? { maxEstimatedUsd: maxUsd } : {}),\n\t\t\tcreatedAt: new Date().toISOString(),\n\t\t};\n\t\t// Worker delegation START. Routing/scope codes + budget only — never the instructions text.\n\t\tthis.deps.emitAutonomyTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.workerRequest,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tpayload: {\n\t\t\t\tid: workerRequest.id,\n\t\t\t\ttier: workerRequest.route.tier,\n\t\t\t\tcapabilities: [...workerRequest.envelope.capabilities],\n\t\t\t\tmaxEstimatedUsd: workerRequest.maxEstimatedUsd ?? null,\n\t\t\t},\n\t\t});\n\t\tconst usageReportId = `worker:${this.deps.getSessionId()}:${startedRecord.laneId}`;\n\t\tconst laneAbortController = new AbortController();\n\t\tthis.laneAbortControllers.set(startedRecord.laneId, laneAbortController);\n\t\tconst workerSignal = AbortSignal.any([this.workerAbort.signal, laneAbortController.signal]);\n\n\t\t// Registered for the lane's full run so the reload gate waits it out; deregistered in the\n\t\t// finally below no matter how this lane terminates (success, disposal, or a thrown error).\n\t\t// registerInFlightWork is a pure sync map op (cannot throw), so placing it as the last\n\t\t// statement before `try` still guarantees the matching finally always runs.\n\t\tconst deregisterInFlight = registerInFlightWork(\n\t\t\tthis.deps.getAgentDir(),\n\t\t\t\"lane\",\n\t\t\t`worker:${startedRecord.laneId}`,\n\t\t);\n\t\tconst durableStartedAt = Date.now();\n\t\ttry {\n\t\t\tlet spentUsage: Usage | undefined;\n\t\t\tconst toolChangedFiles = new Set<string>();\n\t\t\tconst toolIssues = new Set<string>();\n\t\t\t// Register the live mutation ledger BEFORE the suspend point below so a synchronous\n\t\t\t// disposal cutoff (`abortInFlightLanes`) can read a race-free snapshot of whatever this\n\t\t\t// worker has already applied — the worker is suspended at the `await runWorker(...)` below\n\t\t\t// whenever abort runs, and the abort signal stops further tool calls. Deleted in the\n\t\t\t// `finally` on every exit path (normal completion, throw, or already consumed by abort).\n\t\t\tthis.inFlightLedgers.set(startedRecord.laneId, {\n\t\t\t\tchangedFiles: toolChangedFiles,\n\t\t\t\tgetSpend: () => spentUsage,\n\t\t\t\tgetToolCalls: () => toolSurface.gateway?.getUsage().toolCalls ?? 0,\n\t\t\t\trequest: workerRequest,\n\t\t\t\thandle: durableHandle,\n\t\t\t\tstartedAt: durableStartedAt,\n\t\t\t});\n\t\t\tconst maxToolCalls = compiled.grant.budget.maxToolCalls ?? 0;\n\t\t\tconst rawOutcome = await runWorker({\n\t\t\t\trequest: workerRequest,\n\t\t\t\tmaxUsd,\n\t\t\t\tmaxWallClockMs: compiled.grant.budget.maxWallClockMs ?? 0,\n\t\t\t\tusageReportId,\n\t\t\t\tgetChangedFiles: () => [...toolChangedFiles],\n\t\t\t\tsignal: workerSignal,\n\t\t\t\t// Parent validation must use the same relative-path baseline the runner reports in.\n\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\tprocessCapable: executionPlan.processEnabled,\n\t\t\t\t...(request.verificationOfTaskId ? { verificationSubjectTaskId: request.verificationOfTaskId } : {}),\n\t\t\t\t// Write lane: runner-side action application through the envelope path scope.\n\t\t\t\tapplyActions: workerRequest.envelope.capabilities.includes(\"filesystem.write\")\n\t\t\t\t\t? (actions) => {\n\t\t\t\t\t\t\treturn applyWorkerActions({\n\t\t\t\t\t\t\t\tactions,\n\t\t\t\t\t\t\t\tgateway: toolSurface.gateway!,\n\t\t\t\t\t\t\t\ttoolManifests: executionPlan.toolManifests,\n\t\t\t\t\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t\tcomplete: async ({ systemPrompt, userPrompt, signal }) => {\n\t\t\t\t\tconst completion = await this.deps.runIsolatedCompletion({\n\t\t\t\t\t\t// Level-0 core and owner-authored profile remain authoritative. The delegating\n\t\t\t\t\t\t// model supplies task instructions only; it cannot replace the worker role prompt.\n\t\t\t\t\t\tsystemPrompt: composeSubagentSystemPrompt({\n\t\t\t\t\t\t\tsoul,\n\t\t\t\t\t\t\trolePrompt: systemPrompt,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tmessages: [{ role: \"user\", content: [{ type: \"text\", text: userPrompt }], timestamp: Date.now() }],\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tthinkingLevel: modelBinding.thinkingLevel,\n\t\t\t\t\t\tmaxTokens: Math.min(\n\t\t\t\t\t\t\tlaneCapability.laneMaxOutputTokens,\n\t\t\t\t\t\t\tcompiled.grant.budget.maxTokens ?? Number.POSITIVE_INFINITY,\n\t\t\t\t\t\t),\n\t\t\t\t\t\ttools: toolSurface.tools,\n\t\t\t\t\t\tmaxTurns: Math.max(1, Math.min(6, maxToolCalls + 1)),\n\t\t\t\t\t\tfinalTextPrompt:\n\t\t\t\t\t\t\t\"The tool-turn budget is exhausted. Do not call more tools. Return the required worker-claim JSON envelope now using only evidence already gathered. If the investigation is incomplete, say so in the summary or blockers instead of omitting the envelope.\",\n\t\t\t\t\t\tbeforeToolCall: async (context, toolSignal) => {\n\t\t\t\t\t\t\tconst decision = await toolSurface.beforeToolCall(context, toolSignal);\n\t\t\t\t\t\t\tif (decision?.block) {\n\t\t\t\t\t\t\t\ttoolIssues.add(`${context.toolCall.name} blocked: ${decision.reason ?? \"capability denied\"}`);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn decision;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tafterToolCall: async ({ toolCall, args, isError }) => {\n\t\t\t\t\t\t\t// This hook runs only for a validated, gate-approved tool that actually entered\n\t\t\t\t\t\t\t// execution. Record a direct mutation target before inspecting `isError`: write/edit\n\t\t\t\t\t\t\t// may have changed disk and then observed cancellation, timeout, or a late I/O error.\n\t\t\t\t\t\t\t// Pre-gate/profile/path refusals never reach afterToolCall, so they remain unreported.\n\t\t\t\t\t\t\tif (toolCall.name === \"write\" || toolCall.name === \"edit\") {\n\t\t\t\t\t\t\t\tif (args && typeof args === \"object\" && !Array.isArray(args)) {\n\t\t\t\t\t\t\t\t\tconst rawPath = (args as Record<string, unknown>).path;\n\t\t\t\t\t\t\t\t\tif (typeof rawPath === \"string\" && rawPath.length > 0) {\n\t\t\t\t\t\t\t\t\t\tconst absolutePath = path.isAbsolute(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t? path.resolve(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t: path.resolve(this.deps.getCwd(), rawPath);\n\t\t\t\t\t\t\t\t\t\tlet canonicalPath = absolutePath;\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tcanonicalPath = safeRealpathSync(absolutePath);\n\t\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\t\t// Execution was attempted; preserve conservative accounting with the lexical path.\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ttoolChangedFiles.add(\n\t\t\t\t\t\t\t\t\t\t\tpath.relative(this.deps.getCwd(), canonicalPath).split(path.sep).join(\"/\"),\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (isError) {\n\t\t\t\t\t\t\t\ttoolIssues.add(`${toolCall.name} failed during isolated execution`);\n\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t// Core/soul/role are all static per configuration — the provider can cache the prefix.\n\t\t\t\t\t\tcacheRetention: \"short\",\n\t\t\t\t\t\t// Stable per-lane synthetic affinity key so repeat worker-delegation calls route to\n\t\t\t\t\t\t// the same cache-warm backend without carrying the real session id.\n\t\t\t\t\t\tlaneKind: \"worker\",\n\t\t\t\t\t});\n\t\t\t\t\tspentUsage = completion.usage;\n\t\t\t\t\ttoolSurface.gateway?.recordUsage({\n\t\t\t\t\t\tinputTokens: completion.usage.input,\n\t\t\t\t\t\toutputTokens: completion.usage.output,\n\t\t\t\t\t\tcostUsd: completion.usage.cost.total,\n\t\t\t\t\t});\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttext: completion.text,\n\t\t\t\t\t\tcostUsd: completion.usage.cost.total,\n\t\t\t\t\t\tstopReason: String(completion.stopReason),\n\t\t\t\t\t\tchangedFiles: [...toolChangedFiles],\n\t\t\t\t\t\tblockers: [...toolIssues],\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst verificationRequired =\n\t\t\t\torchestrationProfile.requireIndependentVerification &&\n\t\t\t\torchestrationProfile.role !== \"verifier\" &&\n\t\t\t\trawOutcome.claim.status === \"completed\";\n\t\t\tconst outcome = verificationRequired\n\t\t\t\t? {\n\t\t\t\t\t\t...rawOutcome,\n\t\t\t\t\t\taccepted: false,\n\t\t\t\t\t\treasonCode: \"independent_verification_required\",\n\t\t\t\t\t\tacceptance: {\n\t\t\t\t\t\t\toutcome: \"ask-user\" as const,\n\t\t\t\t\t\t\tgate: \"independent_verification\",\n\t\t\t\t\t\t\treasonCode: \"independent_verification_required\",\n\t\t\t\t\t\t\tmessage: \"The owner-authored profile requires an independent verifier before acceptance.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tclaim: {\n\t\t\t\t\t\t\t...rawOutcome.claim,\n\t\t\t\t\t\t\tparentReviewRequired: true,\n\t\t\t\t\t\t\tblockers: [\n\t\t\t\t\t\t\t\t...(rawOutcome.claim.blockers ?? []),\n\t\t\t\t\t\t\t\t\"independent verification is required before acceptance\",\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: rawOutcome;\n\n\t\t\t// Never persist against a disposed session. When disposal raced this\n\t\t\t// await, `abortInFlightLanes()`'s synchronous cutoff already completed this lane, persisted\n\t\t\t// its durable lane record + bounded WorkerClaim, and consumed (deleted) the ledger —\n\t\t\t// `.complete()` below is then a no-op (the lane is already terminal, so it returns\n\t\t\t// undefined) and no double persistence or duplicate terminal notification can happen here.\n\t\t\tif (this.deps.isDisposed()) {\n\t\t\t\tconst record = lifecycle.getRecord(startedRecord.laneId);\n\t\t\t\treturn { started: true, record, outcome };\n\t\t\t}\n\n\t\t\tconst verificationSubject = request.verificationOfTaskId\n\t\t\t\t? lifecycle.getTask(request.verificationOfTaskId)\n\t\t\t\t: undefined;\n\t\t\tlet record = lifecycle.finish(\n\t\t\t\tcreateWorkerResultContract({\n\t\t\t\t\thandle: durableHandle,\n\t\t\t\t\tclaim: outcome.claim,\n\t\t\t\t\taccepted: outcome.accepted,\n\t\t\t\t\tcostUsd: outcome.costUsd,\n\t\t\t\t\treasonCode: outcome.reasonCode,\n\t\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\t\t...(spentUsage\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tinputTokens: spentUsage.input,\n\t\t\t\t\t\t\t\toutputTokens: spentUsage.output,\n\t\t\t\t\t\t\t\ttotalTokens: spentUsage.totalTokens,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t\twallClockMs: Date.now() - durableStartedAt,\n\t\t\t\t\ttoolCalls: toolSurface.gateway?.getUsage().toolCalls ?? 0,\n\t\t\t\t\tverificationRequired,\n\t\t\t\t\tverificationCriterionIds: verificationSubject?.task.acceptanceCriterionIds,\n\t\t\t\t}),\n\t\t\t\t{ notify: !verificationRequired },\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tthis.deps.saveWorkerClaimSnapshot(outcome.claim, workerRequest);\n\t\t\t} catch (error) {\n\t\t\t\tthis.safeWarn(\n\t\t\t\t\t`Failed to persist worker claim ${startedRecord.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (spentUsage && (spentUsage.cost.total > 0 || spentUsage.totalTokens > 0)) {\n\t\t\t\tthis.deps.addSpawnedUsage(spentUsage, { label: \"worker-delegation\", reportId: usageReportId });\n\t\t\t}\n\n\t\t\tconst terminalRecords: LaneRecord[] = [record];\n\t\t\tif (request.verificationOfTaskId) {\n\t\t\t\tconst decision = outcome.accepted ? outcome.claim.verification : undefined;\n\t\t\t\tconst subject = lifecycle.reconcileVerification({\n\t\t\t\t\tsubjectTaskId: request.verificationOfTaskId,\n\t\t\t\t\tverifierTaskId: startedRecord.laneId,\n\t\t\t\t\tverifierAttemptId: durableHandle.attemptId,\n\t\t\t\t\tverdict: decision?.verdict ?? \"inconclusive\",\n\t\t\t\t\treasonCode: decision\n\t\t\t\t\t\t? decision.verdict === \"accepted\"\n\t\t\t\t\t\t\t? \"independent_verification_accepted\"\n\t\t\t\t\t\t\t: `independent_verification_rejected:${decision.reasonCodes.join(\",\")}`\n\t\t\t\t\t\t: `independent_verification_inconclusive:${outcome.reasonCode}`,\n\t\t\t\t});\n\t\t\t\tterminalRecords.push(subject);\n\t\t\t} else if (verificationRequired) {\n\t\t\t\tconst verifierStart = verifierShipment\n\t\t\t\t\t? this.startInternal(\n\t\t\t\t\t\t\tthis.buildVerifierRequest({\n\t\t\t\t\t\t\t\tsubjectTaskId: startedRecord.laneId,\n\t\t\t\t\t\t\t\tverifierProfileId: verifierShipment.profile.profileId,\n\t\t\t\t\t\t\t\tsummary: rawOutcome.claim.summary,\n\t\t\t\t\t\t\t\tartifactUris: rawOutcome.claim.changedFiles,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tverifierWorkerExecutionContract(admission.executionContract),\n\t\t\t\t\t\t)\n\t\t\t\t\t: { started: false as const, skipReason: \"independent_verifier_unavailable\" };\n\t\t\t\tif (verifierStart.started) {\n\t\t\t\t\t// The durable verifier dispatch is now the terminal-work owner. The subject remains\n\t\t\t\t\t// blocked and emits no compatibility terminal snapshot until reconciliation.\n\t\t\t\t\tterminalRecords.length = 0;\n\t\t\t\t\tthis.scheduler.drain();\n\t\t\t\t} else {\n\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t`Independent verifier for ${startedRecord.laneId} did not start: ${verifierStart.skipReason}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (outcome.acceptance.outcome === \"ask-user\" && terminalRecords.length > 0) {\n\t\t\t\tthis.deps.queueWorkerHumanInput({\n\t\t\t\t\tworkerRequestId: startedRecord.laneId,\n\t\t\t\t\tmessage: outcome.acceptance.message ?? \"Worker output requires owner review.\",\n\t\t\t\t\tblockers: outcome.claim.blockers ?? [],\n\t\t\t\t});\n\t\t\t}\n\t\t\tfor (const terminalRecord of terminalRecords) {\n\t\t\t\tthis.publishTerminalRecord(terminalRecord);\n\t\t\t}\n\t\t\tif (request.verificationOfTaskId) {\n\t\t\t\trecord = lifecycle.getRecord(startedRecord.laneId) ?? record;\n\t\t\t}\n\t\t\treturn { started: true, record, outcome };\n\t\t} catch (error) {\n\t\t\tconst durableState = lifecycle.ledger.runtime.getSnapshot().attempts[durableHandle.attemptId];\n\t\t\tif (durableState?.status === \"cancelled\" && (laneAbortController.signal.aborted || this.deps.isDisposed())) {\n\t\t\t\treturn { started: true, record: lifecycle.getRecord(startedRecord.laneId) };\n\t\t\t}\n\t\t\tif (durableState?.status === \"running\" || durableState?.status === \"leased\") {\n\t\t\t\tconst failureClaim: WorkerClaim = {\n\t\t\t\t\trequestId: startedRecord.laneId,\n\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\tsummary: `Worker delegation failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\tchangedFiles: [],\n\t\t\t\t\tcreatedAt: new Date().toISOString(),\n\t\t\t\t};\n\t\t\t\ttry {\n\t\t\t\t\tlifecycle.finish(\n\t\t\t\t\t\tcreateWorkerResultContract({\n\t\t\t\t\t\t\thandle: durableHandle,\n\t\t\t\t\t\t\tclaim: failureClaim,\n\t\t\t\t\t\t\taccepted: false,\n\t\t\t\t\t\t\tcostUsd: 0,\n\t\t\t\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\t\t\t\twallClockMs: Date.now() - durableStartedAt,\n\t\t\t\t\t\t\ttoolCalls: toolSurface.gateway?.getUsage().toolCalls ?? 0,\n\t\t\t\t\t\t\treasonCode: \"worker_delegation_error\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t} catch (persistError) {\n\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t`Failed to persist durable worker failure ${startedRecord.laneId}: ${persistError instanceof Error ? persistError.message : String(persistError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet record = lifecycle.getRecord(startedRecord.laneId);\n\t\t\tif (record?.status === \"queued\" || record?.status === \"running\") {\n\t\t\t\trecord = lifecycle.cancel(startedRecord.laneId, \"worker_delegation_error\");\n\t\t\t}\n\t\t\tif (record && !this.deps.isDisposed()) this.publishTerminalRecord(record);\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthis.deps.emit({ type: \"warning\", message: `Worker delegation failed: ${message}` });\n\t\t\treturn { started: true, record };\n\t\t} finally {\n\t\t\tthis.inFlightLedgers.delete(startedRecord.laneId);\n\t\t\tthis.laneAbortControllers.delete(startedRecord.laneId);\n\t\t\tderegisterInFlight();\n\t\t}\n\t}\n\n\t/** Start every capacity-eligible queued worker at the owner session's foreground-idle boundary. */\n\tdrain(): void {\n\t\tthis.recoverDurableQueue();\n\t\tthis.scheduler.drain();\n\t}\n}\n"]}
1
+ {"version":3,"file":"worker-delegation-controller.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,a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AC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,6BAA6B,OAAO,EAAE,EAAE,CAAC,CAAC;YACrF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAClC,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,SAAS,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;YAC1G,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YAClD,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACvD,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,CAAC;YACvC,kBAAkB,EAAE,CAAC;QACtB,CAAC;IAAA,CACD;IAED,mGAAmG;IACnG,KAAK,GAAS;QACb,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAAA,CACvB;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { Api, Model, Usage } from \"@caupulican/pi-ai\";\nimport type {\n\tAgentSessionEvent,\n\tIsolatedCompletionOptions,\n\tIsolatedCompletionResult,\n\tWorkerDelegationRunOutcome,\n} from \"../agent-session-contracts.ts\";\nimport type { CapabilityEnvelope, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport { getPrivateLaneDeniedPaths } from \"../autonomy/lane-private-paths.ts\";\nimport { createLaneToolSurface } from \"../autonomy/lane-tool-surface.ts\";\nimport type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport { appendLaneRecordSnapshot } from \"../autonomy/session-lane-record.ts\";\nimport { AUTONOMY_TELEMETRY_EVENT_TYPES, type AutonomyTelemetryEvent } from \"../autonomy/telemetry-events.ts\";\nimport type { GoalState } from \"../goals/goal-state.ts\";\nimport { deriveModelCapabilityProfile, type ModelCapabilityProfile } from \"../model-capability.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport { isLoopbackModelEndpoint } from \"../models/model-endpoint.ts\";\nimport { providerUsageFromAttemptUsage } from \"../orchestration/attempt-usage.ts\";\nimport type {\n\tAttemptUsageSnapshot,\n\tExecutionGrant,\n\tOrchestrationProfile,\n\tWorkerExecutionContract,\n} from \"../orchestration/contracts.ts\";\nimport type { StartedDelegationAttempt } from \"../orchestration/delegation-ledger.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\nimport {\n\tcreateWorkerExecutionContract,\n\tverifierWorkerExecutionContract,\n} from \"../orchestration/worker-execution-contract.ts\";\nimport { registerInFlightWork } from \"../reload-blockers.ts\";\nimport type { ResourceLoader } from \"../resource-loader.ts\";\nimport type { ResolvedWorkerDelegationSettings, SettingsManager } from \"../settings-manager.ts\";\nimport { applyWorkerActions } from \"./worker-actions.ts\";\nimport type { WorkerAgentControlPort } from \"./worker-agent-control.ts\";\nimport { WorkerAgentControlCoordinator } from \"./worker-agent-control-coordinator.ts\";\nimport { createWorkerAttemptExecutor } from \"./worker-attempt-executor.ts\";\nimport {\n\ttype WorkerConversation,\n\ttype WorkerConversationRetentionPolicy,\n\tWorkerConversationStore,\n} from \"./worker-conversation-store.ts\";\nimport type { WorkerDelegationRequest } from \"./worker-delegation-request.ts\";\nimport { type WorkerDispatchAdmission, WorkerDispatchScheduler } from \"./worker-dispatch-scheduler.ts\";\nimport {\n\tbuildWorkerExecutionPlan,\n\tcompileWorkerExecutionGrant,\n\tnarrowWorkerExecutionPlan,\n\ttype WorkerExecutionPlan,\n\tworkerExecutionAuthorityFromPlan,\n} from \"./worker-execution-policy.ts\";\nimport type { PendingVerificationRecovery, WorkerLifecycle } from \"./worker-lifecycle.ts\";\nimport type { WorkerNotificationCoordinator } from \"./worker-notification-coordinator.ts\";\nimport { createLocalWorkerProcessOwnerId } from \"./worker-process-owner.ts\";\nimport { type ResolvedWorkerProfile, WorkerProfileResolver } from \"./worker-profile-resolver.ts\";\nimport { WorkerRecoveryCoordinator, type WorkerRecoveryDispatchResult } from \"./worker-recovery-coordinator.ts\";\nimport { selectWorkerResourcePointers } from \"./worker-resource-catalog.ts\";\nimport { materializeWorkerResourceBundle } from \"./worker-resource-materializer.ts\";\nimport { finalizeWorkerClaim } from \"./worker-terminal-finalizer.ts\";\nimport { WorkerWriteReservationCoordinator } from \"./worker-write-reservation-coordinator.ts\";\n\nexport function isLocalExecutionModel(model: Pick<Model<Api>, \"provider\" | \"baseUrl\">): boolean {\n\tif (model.provider === \"ollama\" || model.provider === \"transformers\" || model.provider === \"llama-cpp\") {\n\t\treturn true;\n\t}\n\treturn isLoopbackModelEndpoint(model.baseUrl);\n}\n\nfunction workerConversationRetentionPolicy(\n\tmodel: Model<Api>,\n\tsettingsManager: SettingsManager,\n): WorkerConversationRetentionPolicy | undefined {\n\tconst settings = settingsManager.getCompactionSettings();\n\tconst contextWindow = Math.floor(model.contextWindow ?? 0);\n\tif (!settings.enabled || contextWindow < 4) return undefined;\n\tconst reserveTokens = Math.min(settings.reserveTokens, Math.floor(contextWindow * 0.25));\n\tconst reserveTrigger = contextWindow - reserveTokens;\n\tconst fractionalTrigger =\n\t\tsettings.triggerPercent > 0 && settings.triggerPercent < 1\n\t\t\t? Math.floor(contextWindow * settings.triggerPercent)\n\t\t\t: reserveTrigger;\n\tconst modelTrigger =\n\t\tmodel.autoCompactionTriggerTokens && model.autoCompactionTriggerTokens > 0\n\t\t\t? Math.floor(model.autoCompactionTriggerTokens)\n\t\t\t: reserveTrigger;\n\tconst maxContextTokens = Math.min(reserveTrigger, fractionalTrigger, modelTrigger);\n\tif (maxContextTokens < 2) return undefined;\n\treturn {\n\t\tmaxContextTokens,\n\t\tkeepRecentTokens: Math.max(\n\t\t\t1,\n\t\t\tMath.min(settings.keepRecentTokens, Math.floor(contextWindow * 0.5), maxContextTokens - 1),\n\t\t),\n\t};\n}\n\nexport interface WorkerDelegationControllerDeps {\n\tisDisposed(): boolean;\n\tgetSessionId(): string;\n\tgetCwd(): string;\n\tgetAgentDir(): string;\n\tgetSessionManager(): SessionManager;\n\tgetSettingsManager(): SettingsManager;\n\tgetResourceLoader(): ResourceLoader;\n\tgetActiveOrchestrationProfile?(): OrchestrationProfile | undefined;\n\tgetModelRegistry(): ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n\tgetModel(): Model<Api> | undefined;\n\tisDelegateToolActive(): boolean;\n\tgetCapabilityEnvelope(): CapabilityEnvelope | undefined;\n\temit(event: AgentSessionEvent): void;\n\tnotifyWorkerTerminalHandoff(\n\t\trecords: readonly { laneId: string; status: LaneTerminalStatus; reasonCode?: string }[],\n\t): Promise<void>;\n\temitAutonomyTelemetry(event: AutonomyTelemetryEvent): void;\n\tgetGoalStateSnapshot(): GoalState | undefined;\n\tsaveWorkerClaimSnapshot(claim: WorkerClaim, request?: WorkerRequest): string;\n\tqueueWorkerHumanInput(request: { workerRequestId: string; message: string; blockers: readonly string[] }): void;\n\treadMemoryForLane(query: string): Promise<string>;\n\taddSpawnedUsage(\n\t\tusage: Usage,\n\t\topts: { label?: string; sourceSessionId?: string; reportId: string },\n\t): string | undefined;\n\trunIsolatedCompletion(opts: IsolatedCompletionOptions): Promise<IsolatedCompletionResult>;\n}\n\ntype WorkerAdmission =\n\t| {\n\t\t\tok: true;\n\t\t\tinstructions: string;\n\t\t\tsettings: ResolvedWorkerDelegationSettings;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t\t\tverifierShipment?: ResolvedWorkerProfile;\n\t\t\t/** Exact pointer selection persisted when this request is admitted. */\n\t\t\tresourcePointerIds: readonly string[];\n\t\t\texecutionContract: WorkerExecutionContract;\n\t\t\texecutionPlan: WorkerExecutionPlan;\n\t }\n\t| { ok: false; skipReason: string };\n\ninterface PreparedWorkerAttempt {\n\texecutionPlan: WorkerExecutionPlan;\n\tlifecycle: WorkerLifecycle;\n\trecord: LaneRecord;\n\tattempt?: AttemptRuntimeState;\n}\n\nexport class WorkerDelegationController {\n\tprivate readonly deps: WorkerDelegationControllerDeps;\n\tprivate readonly workerAbort = new AbortController();\n\tprivate readonly lifecycle: WorkerLifecycle;\n\tprivate profileResolver: WorkerProfileResolver | undefined;\n\tprivate readonly recovery: WorkerRecoveryCoordinator;\n\tprivate readonly notifications: WorkerNotificationCoordinator;\n\tprivate readonly scheduler: WorkerDispatchScheduler;\n\tprivate readonly laneAbortControllers = new Map<string, AbortController>();\n\t/** Sole logical-agent control/mailbox owner; execution only calls its narrow delivery hooks. */\n\tprivate readonly agentControl: WorkerAgentControlCoordinator;\n\tprivate readonly publishedTerminalAttemptIds = new Set<string>();\n\tprivate readonly conversations = new WorkerConversationStore();\n\tprivate readonly writeReservations: WorkerWriteReservationCoordinator;\n\tprivate readonly inFlightLedgers = new Map<\n\t\tstring,\n\t\t{\n\t\t\tchangedFiles: Set<string>;\n\t\t\tgetUsage: () => AttemptUsageSnapshot;\n\t\t\trequest: WorkerRequest;\n\t\t\thandle: StartedDelegationAttempt;\n\t\t}\n\t>();\n\n\tconstructor(\n\t\tdeps: WorkerDelegationControllerDeps,\n\t\tnotifications: WorkerNotificationCoordinator,\n\t\tlifecycle: WorkerLifecycle,\n\t) {\n\t\tthis.deps = deps;\n\t\tthis.notifications = notifications;\n\t\tthis.lifecycle = lifecycle;\n\t\tthis.scheduler = new WorkerDispatchScheduler({\n\t\t\tagentDir: this.deps.getAgentDir?.() ?? \"\",\n\t\t\tisDisposed: () => this.deps.isDisposed(),\n\t\t\tadmit: (request, record) => this.workerDispatchAdmission(request, record),\n\t\t\tgetRecord: (laneId) => this.getWorkerLifecycle().getRecord(laneId),\n\t\t\trun: (request, record) => this.runOnce(request, undefined, record),\n\t\t\tcancel: (laneId, reasonCode) => {\n\t\t\t\ttry {\n\t\t\t\t\tthis.writeReservations.release(laneId);\n\t\t\t\t\tconst terminal = this.getWorkerLifecycle().cancel(laneId, reasonCode);\n\t\t\t\t\tif (terminal) this.publishTerminalRecord(terminal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t`Failed to cancel durable worker ${laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t\twarn: (message) => this.safeWarn(message),\n\t\t});\n\t\tthis.recovery = new WorkerRecoveryCoordinator({\n\t\t\tlifecycle: this.lifecycle,\n\t\t\tscheduler: this.scheduler,\n\t\t\trecoverWriteReservations: () => this.writeReservations.recoverProvenStale(),\n\t\t\tpublishTerminalRecord: (record) => this.publishTerminalRecord(record),\n\t\t\tdispatchVerification: (recovery) => this.dispatchRecoveredVerification(recovery),\n\t\t\twarn: (message) => this.safeWarn(message),\n\t\t});\n\t\tthis.agentControl = new WorkerAgentControlCoordinator({\n\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\tparentSessionId: this.deps.getSessionId(),\n\t\t\tprocessOwnerId: createLocalWorkerProcessOwnerId(process.pid, randomUUID()),\n\t\t\tisControlAvailable: () => this.deps.isDelegateToolActive(),\n\t\t\tgetLifecycle: () => this.getWorkerLifecycle(),\n\t\t\trecoveredRequest: (attempt) => this.recovery.recoveredRequest(attempt),\n\t\t\trun: (request, record) => this.runOnce(request, undefined, record),\n\t\t\tscheduler: this.scheduler,\n\t\t\tstatusChanged: () => this.notifications.statusChanged(),\n\t\t\tabortLane: (laneId, reasonCode) => this.laneAbortControllers.get(laneId)?.abort(reasonCode),\n\t\t\tcancelLane: (laneId, reasonCode) => {\n\t\t\t\tthis.scheduler.dropQueued(laneId);\n\t\t\t\tthis.writeReservations.release(laneId);\n\t\t\t\tconst terminal = this.getWorkerLifecycle().cancel(laneId, reasonCode);\n\t\t\t\tif (terminal) this.publishTerminalRecord(terminal);\n\t\t\t\treturn terminal;\n\t\t\t},\n\t\t});\n\t\tthis.writeReservations = new WorkerWriteReservationCoordinator({\n\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\tgetCwd: () => this.deps.getCwd(),\n\t\t\tgetParentSessionId: () => this.deps.getSessionId(),\n\t\t\townerId: this.agentControl.getProcessOwnerId(),\n\t\t\tdrainQueuedWorkers: () => {\n\t\t\t\tif (!this.deps.isDisposed()) this.scheduler.drain(true);\n\t\t\t},\n\t\t\twarn: (message) => this.safeWarn(message),\n\t\t});\n\t}\n\n\tprivate safeWarn(message: string): void {\n\t\ttry {\n\t\t\tthis.deps.emit({ type: \"warning\", message });\n\t\t} catch {\n\t\t\t// Disposal and recovery diagnostics must never throw.\n\t\t}\n\t}\n\n\t/** Narrow model-facing control port. It owns control state; this controller only composes it. */\n\tgetAgentControl(): WorkerAgentControlPort {\n\t\treturn this.agentControl;\n\t}\n\n\t/** The coordinator's process identity is also the durable execution lease owner. */\n\tgetAgentControlProcessOwnerId(): string {\n\t\treturn this.agentControl.getProcessOwnerId();\n\t}\n\n\trecordTerminal(record: LaneRecord): void {\n\t\tif (record.status === \"queued\" || record.status === \"running\") return;\n\t\tif (record.type === \"worker\") {\n\t\t\tconst notification = this.lifecycle.getTerminalNotification(record.laneId);\n\t\t\tif (notification?.status === \"delivered\") return;\n\t\t\tif (notification) {\n\t\t\t\tthis.notifications.recordTerminal(record, notification.notificationId);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.notifications.recordTerminal(record);\n\t}\n\n\tgetRecords(): LaneRecord[] {\n\t\tif (this.deps.isDelegateToolActive?.()) this.recovery.recover();\n\t\treturn this.lifecycle.getRecords();\n\t}\n\n\t/** Process-local worker records for the shared terminal notifier; never triggers durable recovery. */\n\tgetLoadedRecords(): LaneRecord[] {\n\t\treturn this.lifecycle.getRecords();\n\t}\n\n\tmarkNotificationsDelivered(notificationIds: readonly string[]): void {\n\t\tthis.lifecycle.markNotificationsDelivered(notificationIds);\n\t}\n\n\tabort(): void {\n\t\tthis.workerAbort.abort();\n\t\t// Bound attempts have an authoritative transcript and agent identity. A normal owner-session\n\t\t// shutdown is an execution interruption, not an explicit worker cancellation: fence it into\n\t\t// suspended state before the abort continuation can observe the signal.\n\t\tconst suspendedAttemptIds = new Set(\n\t\t\tthis.lifecycle.suspendBoundInProcessAttemptsForRestart(this.agentControl.getProcessOwnerId()),\n\t\t);\n\t\tfor (const record of this.lifecycle.getRecords()) {\n\t\t\tif (record.status !== \"queued\" && record.status !== \"running\") continue;\n\t\t\tconst ledger = this.inFlightLedgers.get(record.laneId);\n\t\t\tif (ledger && suspendedAttemptIds.has(ledger.handle.attemptId)) {\n\t\t\t\tthis.inFlightLedgers.delete(record.laneId);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!ledger) {\n\t\t\t\ttry {\n\t\t\t\t\tconst canceled = this.lifecycle.cancel(record.laneId, \"session_disposed\");\n\t\t\t\t\tif (canceled) {\n\t\t\t\t\t\tthis.publishTerminalRecord(canceled);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t`Failed to cancel durable queued worker ${record.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.inFlightLedgers.delete(record.laneId);\n\t\t\ttry {\n\t\t\t\tconst usage = ledger.getUsage();\n\t\t\t\tconst reportedUsage = providerUsageFromAttemptUsage(usage);\n\t\t\t\tconst reportId = `worker:${this.deps.getSessionId()}:${record.laneId}`;\n\t\t\t\tconst claim: WorkerClaim = {\n\t\t\t\t\trequestId: ledger.request.id,\n\t\t\t\t\tstatus: \"cancelled\",\n\t\t\t\t\tsummary: \"canceled on session dispose\",\n\t\t\t\t\tchangedFiles: [...ledger.changedFiles],\n\t\t\t\t\tusageReportId: reportId,\n\t\t\t\t\tcreatedAt: new Date().toISOString(),\n\t\t\t\t};\n\t\t\t\tconst canceled = finalizeWorkerClaim(this.getWorkerLifecycle(), {\n\t\t\t\t\thandle: ledger.handle,\n\t\t\t\t\tclaim,\n\t\t\t\t\taccepted: false,\n\t\t\t\t\tcostUsd: usage.costUsd,\n\t\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\t\tinputTokens: usage.inputTokens,\n\t\t\t\t\toutputTokens: usage.outputTokens,\n\t\t\t\t\ttotalTokens: reportedUsage.totalTokens,\n\t\t\t\t\twallClockMs: usage.activeWallClockMs,\n\t\t\t\t\ttoolCalls: usage.toolCalls,\n\t\t\t\t\treasonCode: \"session_disposed\",\n\t\t\t\t}).record;\n\t\t\t\tthis.publishTerminalRecord(canceled);\n\t\t\t\t// The terminal result and owner usage report share the same fenced cumulative snapshot.\n\t\t\t\tthis.deps.saveWorkerClaimSnapshot(claim, ledger.request);\n\t\t\t\tif (reportedUsage.cost.total > 0 || reportedUsage.totalTokens > 0) {\n\t\t\t\t\tthis.deps.addSpawnedUsage(reportedUsage, { label: \"worker-delegation\", reportId });\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.safeWarn(\n\t\t\t\t\t`Failed to persist canceled worker claim ${record.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tthis.scheduler.cancelQueued();\n\t\tthis.writeReservations.dispose();\n\t}\n\n\tprivate getWorkerLifecycle(): WorkerLifecycle {\n\t\treturn this.lifecycle;\n\t}\n\n\tprivate getWorkerProfileResolver(): WorkerProfileResolver {\n\t\tif (this.profileResolver) return this.profileResolver;\n\t\tthis.profileResolver = new WorkerProfileResolver({\n\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\tcwd: this.deps.getCwd(),\n\t\t\tgetSettingsManager: () => this.deps.getSettingsManager(),\n\t\t\tgetResourceLoader: () => this.deps.getResourceLoader(),\n\t\t\tgetModelRegistry: () => this.deps.getModelRegistry(),\n\t\t\tisModelExhausted: (model) => this.deps.isModelExhausted(model),\n\t\t\tgetActiveOrchestrationProfile: () => this.deps.getActiveOrchestrationProfile?.(),\n\t\t\tonDiagnostic: (message) => this.safeWarn(message),\n\t\t});\n\t\treturn this.profileResolver;\n\t}\n\n\t/** Read-only durable worker projection. Undefined means the delegate capability never loaded. */\n\tgetTaskRuntimeSnapshot(): TaskRuntimeProjection | undefined {\n\t\treturn this.lifecycle.getTaskRuntimeSnapshot();\n\t}\n\n\t/** Reconcile the session goal into an already-loaded worker runtime without defeating lazy UAC. */\n\tsynchronizeGoalState(goal: GoalState): void {\n\t\tthis.publishGoalTerminalRecords(this.lifecycle.synchronizeGoalState(goal));\n\t}\n\n\tprivate publishGoalTerminalRecords(records: readonly LaneRecord[]): void {\n\t\tfor (const record of records) {\n\t\t\tthis.scheduler.dropQueued(record.laneId);\n\t\t\tthis.laneAbortControllers.get(record.laneId)?.abort(\"goal_terminal\");\n\t\t\tthis.publishTerminalRecord(record);\n\t\t}\n\t}\n\n\tprivate dispatchRecoveredVerification(\n\t\trecovery: Extract<PendingVerificationRecovery, { action: \"dispatch\" }>,\n\t): WorkerRecoveryDispatchResult {\n\t\tconst legacyImplementation = recovery.verifierExecutionContract\n\t\t\t? undefined\n\t\t\t: this.resolveWorkerAdmission({\n\t\t\t\t\tinstructions: recovery.summary,\n\t\t\t\t\tprofileId: recovery.implementationProfileId,\n\t\t\t\t});\n\t\tconst verifierProfileId =\n\t\t\trecovery.verifierExecutionContract?.worker.profile.profileId ??\n\t\t\t(legacyImplementation?.ok ? legacyImplementation.verifierShipment?.profile.profileId : undefined);\n\t\treturn verifierProfileId\n\t\t\t? this.startInternal(\n\t\t\t\t\tthis.buildVerifierRequest({\n\t\t\t\t\t\tsubjectTaskId: recovery.subjectTaskId,\n\t\t\t\t\t\tverifierProfileId,\n\t\t\t\t\t\tsummary: recovery.summary,\n\t\t\t\t\t\tartifactUris: recovery.artifactUris,\n\t\t\t\t\t}),\n\t\t\t\t\trecovery.verifierExecutionContract,\n\t\t\t\t)\n\t\t\t: { started: false, skipReason: \"independent_verifier_unavailable\" };\n\t}\n\n\tprivate laneCapabilityProfile(model: Model<Api>): ModelCapabilityProfile {\n\t\treturn deriveModelCapabilityProfile({\n\t\t\tcontextWindow: model.contextWindow,\n\t\t\tmode: this.deps.getSettingsManager().getModelCapabilitySettings().mode,\n\t\t});\n\t}\n\n\tgetProfileCatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\treturn this.getWorkerProfileResolver().catalog();\n\t}\n\n\tprivate resolveWorkerShipment(\n\t\trequest: WorkerDelegationRequest,\n\t\tsettings: ResolvedWorkerDelegationSettings,\n\t): { ok: true; shipment: ResolvedWorkerProfile } | { ok: false; skipReason: string } {\n\t\tconst resolved = this.getWorkerProfileResolver().resolve(request, settings.orchestrationProfile);\n\t\treturn resolved.ok ? { ok: true, shipment: resolved.resolved } : { ok: false, skipReason: resolved.reason };\n\t}\n\n\tprivate resolveRequiredVerifier(\n\t\tprofile: OrchestrationProfile,\n\t): { ok: true; shipment?: ResolvedWorkerProfile } | { ok: false; skipReason: string } {\n\t\tif (!profile.requireIndependentVerification) return { ok: true };\n\t\tconst resolved = this.getWorkerProfileResolver().resolveVerifier(profile);\n\t\treturn resolved.ok\n\t\t\t? { ok: true, shipment: resolved.resolved }\n\t\t\t: { ok: false, skipReason: `independent_verifier_unavailable:${resolved.reason}` };\n\t}\n\n\t/** Single admission contract shared by enqueue, scheduler revalidation, and execution. */\n\tprivate resolveWorkerAdmission(\n\t\trequest: WorkerDelegationRequest,\n\t\tpinnedContract?: WorkerExecutionContract,\n\t): WorkerAdmission {\n\t\tif (this.deps.isDisposed()) return { ok: false, skipReason: \"session_disposed\" };\n\t\tconst instructions = request.instructions.trim();\n\t\tif (!instructions) return { ok: false, skipReason: \"missing_instructions\" };\n\t\tif (!this.deps.isDelegateToolActive()) return { ok: false, skipReason: \"delegate_tool_inactive\" };\n\t\tconst settings = this.deps.getSettingsManager().getWorkerDelegationSettings();\n\t\tif (!settings.enabled) return { ok: false, skipReason: \"worker_delegation_disabled\" };\n\t\tif (pinnedContract && request.profileId && request.profileId !== pinnedContract.worker.profile.profileId) {\n\t\t\treturn { ok: false, skipReason: \"orchestration_execution_contract_mismatch\" };\n\t\t}\n\t\tconst resolved = pinnedContract\n\t\t\t? this.getWorkerProfileResolver().resolveContract(pinnedContract.worker)\n\t\t\t: this.resolveWorkerShipment(request, settings);\n\t\tif (!resolved.ok) {\n\t\t\treturn { ok: false, skipReason: \"skipReason\" in resolved ? resolved.skipReason : resolved.reason };\n\t\t}\n\t\tconst shipment = \"shipment\" in resolved ? resolved.shipment : resolved.resolved;\n\t\tif (request.verificationOfTaskId && shipment.profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, skipReason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\tif (!request.verificationOfTaskId && shipment.profile.role === \"verifier\") {\n\t\t\treturn { ok: false, skipReason: \"verifier_profile_requires_runtime_dispatch\" };\n\t\t}\n\t\tlet verifierShipment: ResolvedWorkerProfile | undefined;\n\t\tif (pinnedContract?.verifier) {\n\t\t\tconst verifier = this.getWorkerProfileResolver().resolveContract(pinnedContract.verifier);\n\t\t\tif (!verifier.ok) {\n\t\t\t\treturn { ok: false, skipReason: `independent_verifier_unavailable:${verifier.reason}` };\n\t\t\t}\n\t\t\tverifierShipment = verifier.resolved;\n\t\t} else {\n\t\t\tconst verifier = this.resolveRequiredVerifier(shipment.profile);\n\t\t\tif (!verifier.ok) return verifier;\n\t\t\tverifierShipment = verifier.shipment;\n\t\t}\n\t\tif (!this.laneCapabilityProfile(shipment.model).backgroundLanesEnabled) {\n\t\t\treturn { ok: false, skipReason: \"model_delegation_unsupported\" };\n\t\t}\n\t\t// The model-facing delegate surface cannot name profile resources. An absent or empty\n\t\t// runtime selection therefore means \"use the owner-admitted profile set\", not \"drop it\".\n\t\t// Non-empty task metadata is an exact narrowing and remains fail-closed for unknown or\n\t\t// duplicate ids before any durable task or provider request is created.\n\t\tconst requestedResourcePointerIds = request.taskContext?.resourcePointerIds ?? [];\n\t\tconst selectedResources = selectWorkerResourcePointers(\n\t\t\tshipment.resourcePointers,\n\t\t\trequestedResourcePointerIds.length > 0\n\t\t\t\t? requestedResourcePointerIds\n\t\t\t\t: shipment.resourcePointers.map((pointer) => pointer.id),\n\t\t);\n\t\tif (!selectedResources.ok) return { ok: false, skipReason: selectedResources.reason };\n\t\tconst currentExecutionPlan = this.buildWorkerExecutionPlan(shipment.profile, settings);\n\t\tconst executionPlan = pinnedContract\n\t\t\t? narrowWorkerExecutionPlan(pinnedContract.worker.authority, currentExecutionPlan)\n\t\t\t: currentExecutionPlan;\n\t\tconst executionContract =\n\t\t\tpinnedContract ??\n\t\t\tcreateWorkerExecutionContract({\n\t\t\t\tworker: {\n\t\t\t\t\t...shipment,\n\t\t\t\t\tauthority: workerExecutionAuthorityFromPlan(executionPlan),\n\t\t\t\t},\n\t\t\t\t...(verifierShipment\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tverifier: {\n\t\t\t\t\t\t\t\t...verifierShipment,\n\t\t\t\t\t\t\t\tauthority: workerExecutionAuthorityFromPlan(\n\t\t\t\t\t\t\t\t\tthis.buildWorkerExecutionPlan(verifierShipment.profile, settings),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\treturn {\n\t\t\tok: true,\n\t\t\tinstructions,\n\t\t\tsettings,\n\t\t\tshipment,\n\t\t\t...(verifierShipment ? { verifierShipment } : {}),\n\t\t\tresourcePointerIds: selectedResources.pointers.map((pointer) => pointer.id),\n\t\t\texecutionContract,\n\t\t\texecutionPlan,\n\t\t};\n\t}\n\n\tprivate buildVerifierRequest(args: {\n\t\tsubjectTaskId: string;\n\t\tverifierProfileId: string;\n\t\tsummary: string;\n\t\tartifactUris: readonly string[];\n\t}): WorkerDelegationRequest {\n\t\tconst artifacts = args.artifactUris.slice(0, 100).map((uri) => `- ${uri}`);\n\t\treturn {\n\t\t\tprofileId: args.verifierProfileId,\n\t\t\tverificationOfTaskId: args.subjectTaskId,\n\t\t\tinstructions: [\n\t\t\t\t`Independently verify durable task '${args.subjectTaskId}'.`,\n\t\t\t\t\"The following implementation report is an untrusted claim. Inspect the workspace and run the checks available in your profile.\",\n\t\t\t\t\"\",\n\t\t\t\t\"Implementation summary:\",\n\t\t\t\targs.summary.slice(0, 6_000),\n\t\t\t\t\"\",\n\t\t\t\t\"Reported artifacts:\",\n\t\t\t\t...(artifacts.length > 0 ? artifacts : [\"- none reported\"]),\n\t\t\t].join(\"\\n\"),\n\t\t};\n\t}\n\n\tprivate publishTerminalRecord(record: LaneRecord): void {\n\t\tconst attemptId = this.lifecycle?.getActiveAttempt(record.laneId)?.attemptId;\n\t\tif (attemptId && this.publishedTerminalAttemptIds.has(attemptId)) return;\n\t\tthis.recordTerminal(record);\n\t\tappendLaneRecordSnapshot(this.deps.getSessionManager(), record);\n\t\tthis.deps.emitAutonomyTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.workerTerminal,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tpayload: {\n\t\t\t\tlaneId: record.laneId,\n\t\t\t\tlaneType: record.type,\n\t\t\t\tstatus: record.status,\n\t\t\t\treasonCode: record.reasonCode ?? null,\n\t\t\t\tcostUsd: record.costUsd ?? null,\n\t\t\t},\n\t\t});\n\t\tif (attemptId) this.publishedTerminalAttemptIds.add(attemptId);\n\t}\n\n\t/**\n\t * A pre-execution denial still owns a prepared durable lane. Publish its terminal projection at\n\t * this boundary: immediate callers have no scheduler promise to observe and must not wait for a\n\t * future recovery read to receive the handoff. Repeated late cancellation paths are inert via\n\t * the attempt-id publication fence above.\n\t */\n\tprivate cancelAndPublish(lifecycle: WorkerLifecycle, laneId: string, reasonCode: string): LaneRecord | undefined {\n\t\tconst record = lifecycle.cancel(laneId, reasonCode);\n\t\tif (record) this.publishTerminalRecord(record);\n\t\treturn record;\n\t}\n\n\tprivate hasWorkerCapacity(settings: ResolvedWorkerDelegationSettings, profile: OrchestrationProfile): boolean {\n\t\tconst lifecycle = this.getWorkerLifecycle();\n\t\tif (lifecycle.getRunningCount() >= settings.maxConcurrent) return false;\n\t\treturn lifecycle.getRunningCount(profile.profileId) < profile.maxConcurrent;\n\t}\n\n\tprivate workerDispatchAdmission(request: WorkerDelegationRequest, record: LaneRecord): WorkerDispatchAdmission {\n\t\tconst contract = this.getWorkerLifecycle().getActiveAttempt(record.laneId)?.dispatch.executionContract;\n\t\tconst admission = this.resolveWorkerAdmission(request, contract);\n\t\tif (!admission.ok) return { action: \"cancel\", reasonCode: admission.skipReason };\n\t\tif (!this.hasWorkerCapacity(admission.settings, admission.shipment.profile))\n\t\t\treturn { action: \"wait\", reason: \"capacity\" };\n\t\tconst attempt = this.getWorkerLifecycle().getActiveAttempt(record.laneId);\n\t\tif (!attempt) return { action: \"cancel\", reasonCode: \"orchestration_attempt_missing\" };\n\t\tconst reservation = this.writeReservations.acquire(record.laneId, attempt, admission.executionPlan);\n\t\tif (reservation.kind === \"denied\") return { action: \"cancel\", reasonCode: reservation.reasonCode };\n\t\treturn reservation.kind === \"granted\" ? { action: \"start\" } : { action: \"wait\", reason: \"write_reservation\" };\n\t}\n\n\tprivate buildWorkerExecutionPlan(\n\t\tprofile: OrchestrationProfile,\n\t\tsettings: ResolvedWorkerDelegationSettings,\n\t): WorkerExecutionPlan {\n\t\treturn buildWorkerExecutionPlan({\n\t\t\tprofile,\n\t\t\tsettings,\n\t\t\tcwd: this.deps.getCwd(),\n\t\t\tdeniedPaths: getPrivateLaneDeniedPaths(this.deps.getCwd(), this.deps.getAgentDir()),\n\t\t\tforegroundMaxCostUsd: this.deps.getCapabilityEnvelope()?.maxEstimatedUsd,\n\t\t\tmemoryEnabled: this.deps.getSettingsManager().getMemoryRetrievalSettings().enabled,\n\t\t});\n\t}\n\n\t/** One durable preparation path for queued, immediate, and recovered execution. */\n\tprivate prepareWorkerAttempt(\n\t\trequest: WorkerDelegationRequest,\n\t\tadmission: Extract<WorkerAdmission, { ok: true }>,\n\t\texistingRecord?: LaneRecord,\n\t): PreparedWorkerAttempt {\n\t\tconst lifecycle = this.getWorkerLifecycle();\n\t\tif (existingRecord) {\n\t\t\treturn {\n\t\t\t\texecutionPlan: admission.executionPlan,\n\t\t\t\tlifecycle,\n\t\t\t\trecord: existingRecord,\n\t\t\t\tattempt: lifecycle.getActiveAttempt(existingRecord.laneId),\n\t\t\t};\n\t\t}\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\t\tconst prepared = lifecycle.prepare({\n\t\t\tinstructions: admission.instructions,\n\t\t\texecutionContract: admission.executionContract,\n\t\t\trequiredCapabilities: admission.executionPlan.requiredCapabilities,\n\t\t\t...(request.verificationOfTaskId ? { verificationOfTaskId: request.verificationOfTaskId } : {}),\n\t\t\ttaskContext: {\n\t\t\t\trequirementIds: request.taskContext?.requirementIds ?? [],\n\t\t\t\tdependsOnTaskIds: request.taskContext?.dependsOnTaskIds ?? [],\n\t\t\t\tacceptanceCriterionIds: request.taskContext?.acceptanceCriterionIds ?? [],\n\t\t\t\tresourcePointerIds: admission.resourcePointerIds,\n\t\t\t},\n\t\t\t...(goal ? { goal } : {}),\n\t\t});\n\t\treturn { executionPlan: admission.executionPlan, lifecycle, ...prepared };\n\t}\n\n\tstart(\n\t\trequest: WorkerDelegationRequest,\n\t): { started: false; skipReason: string } | { started: true; record: LaneRecord } {\n\t\treturn this.startInternal(request);\n\t}\n\n\tprivate startInternal(\n\t\trequest: WorkerDelegationRequest,\n\t\tpinnedContract?: WorkerExecutionContract,\n\t): { started: false; skipReason: string } | { started: true; record: LaneRecord } {\n\t\tconst admission = this.resolveWorkerAdmission(request, pinnedContract);\n\t\tif (!admission.ok) return { started: false, skipReason: admission.skipReason };\n\t\tif (!request.verificationOfTaskId) this.recovery.recover();\n\t\tconst { settings, shipment } = admission;\n\n\t\tconst foreground = this.deps.getModel();\n\t\tconst contendsWithLocalForeground =\n\t\t\tforeground !== undefined && isLocalExecutionModel(foreground) && isLocalExecutionModel(shipment.model);\n\t\tif (contendsWithLocalForeground || !this.hasWorkerCapacity(settings, shipment.profile)) {\n\t\t\t// A mandatory verifier is the continuation of an already admitted implementation, not a\n\t\t\t// new owner request. Reserve its queue admission so a burst of ordinary work cannot strand\n\t\t\t// the subject behind `independent_verification_required` with no terminal handoff.\n\t\t\tif (this.scheduler.queuedCount >= 8 && !request.verificationOfTaskId) {\n\t\t\t\treturn { started: false, skipReason: \"worker_delegation_queue_full\" };\n\t\t\t}\n\t\t\tlet record: LaneRecord;\n\t\t\ttry {\n\t\t\t\trecord = this.prepareWorkerAttempt(request, admission).record;\n\t\t\t} catch (error) {\n\t\t\t\tthis.safeWarn(\n\t\t\t\t\t`Worker dispatch was not persisted: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t\treturn { started: false, skipReason: \"orchestration_ledger_error\" };\n\t\t\t}\n\t\t\tthis.scheduler.enqueue(\n\t\t\t\trecord,\n\t\t\t\t{ ...request, profileId: shipment.profile.profileId },\n\t\t\t\tfalse,\n\t\t\t\trequest.verificationOfTaskId !== undefined,\n\t\t\t);\n\t\t\tthis.notifications.statusChanged();\n\t\t\treturn { started: true, record };\n\t\t}\n\t\tlet startedRecord: LaneRecord | undefined;\n\t\tconst promise = this.runOnceWithAdmission(\n\t\t\trequest,\n\t\t\t(record) => {\n\t\t\t\tstartedRecord = record;\n\t\t\t},\n\t\t\tundefined,\n\t\t\tadmission,\n\t\t);\n\t\tif (!startedRecord) {\n\t\t\t// Preparation is synchronous up to the first isolated completion await. A promise that\n\t\t\t// rejected before producing a lane is still observed below, so it cannot become unhandled.\n\t\t\tvoid promise.catch(() => undefined);\n\t\t\treturn { started: false, skipReason: \"worker_not_started\" };\n\t\t}\n\t\tthis.scheduler.track(startedRecord.laneId, promise);\n\t\treturn { started: true, record: startedRecord };\n\t}\n\n\tasync runOnce(\n\t\trequest: WorkerDelegationRequest,\n\t\tonStarted?: (record: LaneRecord) => void,\n\t\texistingRecord?: LaneRecord,\n\t): Promise<WorkerDelegationRunOutcome> {\n\t\treturn this.runOnceWithAdmission(request, onStarted, existingRecord);\n\t}\n\n\tprivate async runOnceWithAdmission(\n\t\trequest: WorkerDelegationRequest,\n\t\tonStarted?: (record: LaneRecord) => void,\n\t\texistingRecord?: LaneRecord,\n\t\tpreparedAdmission?: Extract<WorkerAdmission, { ok: true }>,\n\t): Promise<WorkerDelegationRunOutcome> {\n\t\tconst pinnedContract = existingRecord\n\t\t\t? this.getWorkerLifecycle().getActiveAttempt(existingRecord.laneId)?.dispatch.executionContract\n\t\t\t: undefined;\n\t\tconst admission = preparedAdmission ?? this.resolveWorkerAdmission(request, pinnedContract);\n\t\tif (!admission.ok) return { started: false, skipReason: admission.skipReason };\n\t\tif (!request.verificationOfTaskId) this.recovery.recover();\n\t\tconst { instructions, settings, verifierShipment } = admission;\n\t\tconst { model, modelBinding, profile: orchestrationProfile, soul } = admission.shipment;\n\t\tif (!this.hasWorkerCapacity(settings, orchestrationProfile)) {\n\t\t\treturn { started: false, skipReason: \"worker_delegation_already_running\" };\n\t\t}\n\t\tconst laneCapability = this.laneCapabilityProfile(model);\n\t\tconst retentionPolicy = workerConversationRetentionPolicy(model, this.deps.getSettingsManager());\n\t\tconst prepared = this.prepareWorkerAttempt(request, admission, existingRecord);\n\t\tconst { executionPlan, lifecycle } = prepared;\n\t\tif (!prepared.attempt) return { started: false, skipReason: \"orchestration_attempt_missing\" };\n\t\tconst durableTask = lifecycle.getTask(prepared.record.laneId);\n\t\tif (!durableTask) return { started: false, skipReason: \"orchestration_task_missing\" };\n\t\tconst immutableWorker = prepared.attempt.dispatch.executionContract?.worker;\n\t\tif (!immutableWorker) return { started: false, skipReason: \"orchestration_execution_contract_missing\" };\n\t\tconst selectedResources = selectWorkerResourcePointers(\n\t\t\timmutableWorker.resourcePointers,\n\t\t\tprepared.attempt.dispatch.resourcePointerIds.length > 0\n\t\t\t\t? prepared.attempt.dispatch.resourcePointerIds\n\t\t\t\t: admission.resourcePointerIds,\n\t\t);\n\t\tif (!selectedResources.ok) {\n\t\t\tthis.cancelAndPublish(lifecycle, prepared.record.laneId, selectedResources.reason);\n\t\t\treturn { started: false, skipReason: selectedResources.reason };\n\t\t}\n\t\tlet grant: ExecutionGrant;\n\t\tlet workerResourceSystemPrompt: string;\n\t\tif (prepared.attempt.grant) {\n\t\t\tif (\n\t\t\t\t!this.recovery.durableGrantIsStillPermitted(\n\t\t\t\t\tprepared.attempt.grant,\n\t\t\t\t\texecutionPlan,\n\t\t\t\t\tselectedResources.pointers,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthis.cancelAndPublish(lifecycle, prepared.record.laneId, \"recovered_grant_revoked\");\n\t\t\t\treturn { started: false, skipReason: \"recovered_grant_revoked\" };\n\t\t\t}\n\t\t\tgrant = prepared.attempt.grant;\n\t\t\tconst materialized = materializeWorkerResourceBundle(grant.resources);\n\t\t\tif (!materialized.ok) {\n\t\t\t\tconst reason = `worker_resource_materialization_${materialized.code}`;\n\t\t\t\tthis.cancelAndPublish(lifecycle, prepared.record.laneId, reason);\n\t\t\t\treturn { started: false, skipReason: reason };\n\t\t\t}\n\t\t\tworkerResourceSystemPrompt = materialized.systemPrompt;\n\t\t} else {\n\t\t\tconst materialized = materializeWorkerResourceBundle(selectedResources.pointers);\n\t\t\tif (!materialized.ok) {\n\t\t\t\tconst reason = `worker_resource_materialization_${materialized.code}`;\n\t\t\t\tthis.cancelAndPublish(lifecycle, prepared.record.laneId, reason);\n\t\t\t\treturn { started: false, skipReason: reason };\n\t\t\t}\n\t\t\tconst compiled = compileWorkerExecutionGrant({\n\t\t\t\ttarget: {\n\t\t\t\t\tobjectiveId: durableTask.task.objectiveId,\n\t\t\t\t\ttaskId: prepared.attempt.taskId,\n\t\t\t\t\tattemptId: prepared.attempt.attemptId,\n\t\t\t\t},\n\t\t\t\tprofile: orchestrationProfile,\n\t\t\t\tplan: executionPlan,\n\t\t\t\tresources: materialized.pointers,\n\t\t\t});\n\t\t\tif (!compiled.ok) {\n\t\t\t\tthis.cancelAndPublish(lifecycle, prepared.record.laneId, compiled.reasonCodes.join(\",\"));\n\t\t\t\treturn { started: false, skipReason: `execution_policy_denied:${compiled.reasonCodes.join(\",\")}` };\n\t\t\t}\n\t\t\tlifecycle.bindGrant(prepared.attempt.attemptId, compiled.grant);\n\t\t\tgrant = compiled.grant;\n\t\t\tworkerResourceSystemPrompt = materialized.systemPrompt;\n\t\t}\n\t\tconst immutableProfile = immutableWorker.profile;\n\t\t// Follow-up tasks deliberately receive unique task ids while retaining the original logical\n\t\t// agent id in dispatch metadata. Never derive a new agent identity from a follow-up task id.\n\t\tconst agentId = prepared.attempt.agentId ?? prepared.attempt.dispatch.logicalLaneId ?? prepared.record.laneId;\n\t\tconst registeredAgent = lifecycle.getAgent(agentId);\n\t\tif (prepared.attempt.agentId && !registeredAgent) {\n\t\t\tthis.cancelAndPublish(lifecycle, prepared.record.laneId, \"orchestration_agent_missing\");\n\t\t\treturn { started: false, skipReason: \"orchestration_agent_missing\" };\n\t\t}\n\t\tlet conversation: WorkerConversation;\n\t\ttry {\n\t\t\tif (registeredAgent) {\n\t\t\t\t// Recovery must trust only the registered resume context; reconstructing one here could\n\t\t\t\t// silently redirect a logical worker to a different transcript or resource scope.\n\t\t\t\tconversation = this.conversations.open({\n\t\t\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\t\t\tresumeContext: registeredAgent.resumeContext,\n\t\t\t\t\texpectedLogicalAgentId: registeredAgent.agentId,\n\t\t\t\t});\n\t\t\t\tif (prepared.attempt.status === \"suspended\") this.recovery.repairInterruptedToolResults(conversation);\n\t\t\t} else {\n\t\t\t\tconversation = this.conversations.ensure({\n\t\t\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\t\t\tparentSessionId: this.deps.getSessionId(),\n\t\t\t\t\tlogicalAgentId: agentId,\n\t\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\t\torchestrationProfileId: immutableProfile.profileId,\n\t\t\t\t\tmodelRef: `${prepared.attempt.dispatch.executionContract!.worker.modelBinding.provider}/${prepared.attempt.dispatch.executionContract!.worker.modelBinding.modelId}`,\n\t\t\t\t\tresourceProfileNames: immutableProfile.resourceProfileNames,\n\t\t\t\t\tcontextPointers: grant.resources,\n\t\t\t\t});\n\t\t\t\tlifecycle.ensureAgent({\n\t\t\t\t\tagentId,\n\t\t\t\t\trole: immutableProfile.role,\n\t\t\t\t\tresumeContext: conversation.getResumeContext(),\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (prepared.attempt.status !== \"suspended\") {\n\t\t\t\tthis.cancelAndPublish(lifecycle, prepared.record.laneId, \"worker_conversation_unavailable\");\n\t\t\t}\n\t\t\tthis.safeWarn(`Worker conversation setup failed: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\treturn { started: false, skipReason: \"worker_conversation_unavailable\" };\n\t\t}\n\t\tconst reservation = this.writeReservations.acquire(prepared.record.laneId, prepared.attempt, executionPlan);\n\t\tif (reservation.kind === \"denied\") {\n\t\t\tthis.cancelAndPublish(lifecycle, prepared.record.laneId, reservation.reasonCode);\n\t\t\treturn { started: false, skipReason: reservation.reasonCode };\n\t\t}\n\t\tif (reservation.kind === \"blocked\") {\n\t\t\tthis.scheduler.enqueue(prepared.record, { ...request, profileId: admission.shipment.profile.profileId });\n\t\t\tthis.notifications.statusChanged();\n\t\t\tonStarted?.(prepared.record);\n\t\t\treturn { started: true, record: prepared.record };\n\t\t}\n\t\tlet durableHandle: StartedDelegationAttempt;\n\t\ttry {\n\t\t\tdurableHandle =\n\t\t\t\tregisteredAgent && prepared.attempt.status === \"suspended\"\n\t\t\t\t\t? lifecycle.resumeAgent(\n\t\t\t\t\t\t\tprepared.record.laneId,\n\t\t\t\t\t\t\tregisteredAgent.agentId,\n\t\t\t\t\t\t\timmutableProfile.leaseTtlMs,\n\t\t\t\t\t\t\tthis.agentControl.getProcessOwnerId(),\n\t\t\t\t\t\t)\n\t\t\t\t\t: lifecycle.startAgent(\n\t\t\t\t\t\t\tprepared.record.laneId,\n\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\timmutableProfile.leaseTtlMs,\n\t\t\t\t\t\t\tthis.agentControl.getProcessOwnerId(),\n\t\t\t\t\t\t);\n\t\t} catch (error) {\n\t\t\tthis.writeReservations.release(prepared.record.laneId);\n\t\t\tif (prepared.attempt.status !== \"suspended\")\n\t\t\t\tthis.cancelAndPublish(lifecycle, prepared.record.laneId, \"worker_start_unavailable\");\n\t\t\tthis.safeWarn(`Worker start failed: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\treturn { started: false, skipReason: \"worker_start_unavailable\" };\n\t\t}\n\t\tconst startedRecord = lifecycle.getRecord(prepared.record.laneId);\n\t\tif (!startedRecord) {\n\t\t\tthis.writeReservations.release(prepared.record.laneId);\n\t\t\treturn { started: false, skipReason: \"orchestration_projection_missing\" };\n\t\t}\n\t\tif (\n\t\t\tthis.writeReservations.hasFenceMismatch(\n\t\t\t\tstartedRecord.laneId,\n\t\t\t\tdurableHandle.attemptId,\n\t\t\t\tdurableHandle.fencingToken,\n\t\t\t)\n\t\t) {\n\t\t\tthis.writeReservations.release(startedRecord.laneId);\n\t\t\tconst record = this.cancelAndPublish(lifecycle, startedRecord.laneId, \"write_reservation_fence_mismatch\");\n\t\t\tthis.safeWarn(\"Worker write reservation fence did not match the durable attempt lease.\");\n\t\t\treturn { started: false, skipReason: record?.reasonCode ?? \"write_reservation_fence_mismatch\" };\n\t\t}\n\t\tconst recoveredTerminal =\n\t\t\tprepared.attempt.status === \"suspended\" ? this.recovery.recoveredTerminalCompletion(conversation) : undefined;\n\t\tconst checkpointUsage = lifecycle.getAttemptUsage(startedRecord.laneId);\n\t\tconst initialUsage = this.recovery.initialUsage(conversation, checkpointUsage);\n\t\tonStarted?.(startedRecord);\n\t\tconst maxUsd = grant.budget.maxCostUsd;\n\t\tconst executionPolicy = orchestrationProfile.executionPolicy;\n\t\tconst toolSurface = createLaneToolSurface({\n\t\t\tcwd: this.deps.getCwd(),\n\t\t\treadMemory: executionPlan.readMemory ? (query) => this.deps.readMemoryForLane(query) : undefined,\n\t\t\twriteEnabled: executionPlan.writeEnabled,\n\t\t\twritePaths: executionPlan.writePaths,\n\t\t\t...(executionPlan.processEnabled && executionPolicy ? { executionPolicy } : {}),\n\t\t\tprocessMaxWallClockMs: grant.budget.maxWallClockMs ?? 0,\n\t\t\tgrant,\n\t\t\ttoolManifests: executionPlan.toolManifests,\n\t\t\tinitialUsage,\n\t\t});\n\t\tconst writeGranted =\n\t\t\texecutionPlan.writeEnabled &&\n\t\t\ttoolSurface.gateway !== undefined &&\n\t\t\ttoolSurface.allowedTools.some((name) => name === \"write\" || name === \"edit\");\n\t\tconst workerRequest: WorkerRequest = {\n\t\t\tid: startedRecord.laneId,\n\t\t\tinstructions,\n\t\t\troute: {\n\t\t\t\ttier: \"cheap\",\n\t\t\t\trisk: writeGranted ? \"scoped-write\" : \"read-only\",\n\t\t\t\tconfidence: 1,\n\t\t\t\treasonCode: \"profile_worker\",\n\t\t\t\treasons: [writeGranted ? \"Path-scoped worker delegation\" : \"Read-only worker delegation\"],\n\t\t\t},\n\t\t\tenvelope: {\n\t\t\t\tid: `worker-${this.deps.getSessionId()}-${startedRecord.laneId}`,\n\t\t\t\tprofileId: orchestrationProfile.profileId,\n\t\t\t\t// filesystem.write requires BOTH the opt-in AND an explicit non-empty path scope —\n\t\t\t\t// an unscoped write grant is refused here, not discovered at validation time.\n\t\t\t\tcapabilities: [...grant.capabilities],\n\t\t\t\t...(writeGranted ? { allowedPaths: [...grant.writePaths] } : {}),\n\t\t\t\tdeniedPaths: [...grant.deniedPaths],\n\t\t\t\tallowedTools: [...toolSurface.allowedTools],\n\t\t\t\tdeniedTools: [...toolSurface.deniedTools],\n\t\t\t\t...(maxUsd !== undefined ? { maxEstimatedUsd: maxUsd } : {}),\n\t\t\t\tcreatedAt: new Date().toISOString(),\n\t\t\t},\n\t\t\t...(maxUsd !== undefined ? { maxEstimatedUsd: maxUsd } : {}),\n\t\t\tcreatedAt: new Date().toISOString(),\n\t\t};\n\t\t// Worker delegation START. Routing/scope codes + budget only — never the instructions text.\n\t\tthis.deps.emitAutonomyTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.workerRequest,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tpayload: {\n\t\t\t\tid: workerRequest.id,\n\t\t\t\ttier: workerRequest.route.tier,\n\t\t\t\tcapabilities: [...workerRequest.envelope.capabilities],\n\t\t\t\tmaxEstimatedUsd: workerRequest.maxEstimatedUsd ?? null,\n\t\t\t},\n\t\t});\n\t\tconst usageReportId = `worker:${this.deps.getSessionId()}:${startedRecord.laneId}`;\n\t\tconst laneAbortController = new AbortController();\n\t\tthis.laneAbortControllers.set(startedRecord.laneId, laneAbortController);\n\t\tconst workerSignal = AbortSignal.any([this.workerAbort.signal, laneAbortController.signal]);\n\n\t\t// Registered for the lane's full run so the reload gate waits it out; deregistered in the\n\t\t// finally below no matter how this lane terminates (success, disposal, or a thrown error).\n\t\t// registerInFlightWork is a pure sync map op (cannot throw), so placing it as the last\n\t\t// statement before `try` still guarantees the matching finally always runs.\n\t\tconst deregisterInFlight = registerInFlightWork(\n\t\t\tthis.deps.getAgentDir(),\n\t\t\t\"lane\",\n\t\t\t`worker:${startedRecord.laneId}`,\n\t\t);\n\t\tconst executor = createWorkerAttemptExecutor({\n\t\t\trequest: workerRequest,\n\t\t\tgrant,\n\t\t\texecutionPlan,\n\t\t\ttoolSurface,\n\t\t\tconversation,\n\t\t\tlifecycle,\n\t\t\tlaneId: startedRecord.laneId,\n\t\t\tagentId,\n\t\t\tdurableHandle,\n\t\t\tparentSessionId: this.deps.getSessionId(),\n\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\tcwd: this.deps.getCwd(),\n\t\t\tmodel,\n\t\t\tthinkingLevel: modelBinding.thinkingLevel,\n\t\t\tlaneCapability,\n\t\t\t...(soul ? { soul } : {}),\n\t\t\tworkerResourceSystemPrompt,\n\t\t\tinitialUsage,\n\t\t\thasPersistedUsageCheckpoint: checkpointUsage !== undefined,\n\t\t\tusageReportId,\n\t\t\tprocessCapable: executionPlan.processEnabled,\n\t\t\t...(request.verificationOfTaskId ? { verificationSubjectTaskId: request.verificationOfTaskId } : {}),\n\t\t\t...(recoveredTerminal ? { recoveredTerminal } : {}),\n\t\t\t...(retentionPolicy ? { retentionPolicy } : {}),\n\t\t\tsignal: workerSignal,\n\t\t\trunIsolatedCompletion: (options) => this.deps.runIsolatedCompletion(options),\n\t\t\tagentControl: this.agentControl,\n\t\t\tapplyActions: workerRequest.envelope.capabilities.includes(\"filesystem.write\")\n\t\t\t\t? (actions, actionJournal) =>\n\t\t\t\t\t\tapplyWorkerActions({\n\t\t\t\t\t\t\tactions,\n\t\t\t\t\t\t\tgateway: toolSurface.gateway!,\n\t\t\t\t\t\t\ttoolManifests: executionPlan.toolManifests,\n\t\t\t\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\t\t\t\t...(actionJournal ? { actionJournal } : {}),\n\t\t\t\t\t\t})\n\t\t\t\t: undefined,\n\t\t\twarn: (message) => this.safeWarn(message),\n\t\t});\n\t\ttry {\n\t\t\t// Register before the first execution await: disposal sees the live mutable ledger.\n\t\t\tthis.inFlightLedgers.set(startedRecord.laneId, {\n\t\t\t\tchangedFiles: executor.ledger.changedFiles,\n\t\t\t\tgetUsage: executor.ledger.getUsage,\n\t\t\t\trequest: workerRequest,\n\t\t\t\thandle: durableHandle,\n\t\t\t});\n\t\t\tconst executionResult = await executor.run();\n\t\t\tconst rawOutcome = executionResult.rawOutcome;\n\t\t\tconst verificationRequired =\n\t\t\t\torchestrationProfile.requireIndependentVerification &&\n\t\t\t\torchestrationProfile.role !== \"verifier\" &&\n\t\t\t\trawOutcome.claim.status === \"completed\";\n\t\t\tconst outcome = verificationRequired\n\t\t\t\t? {\n\t\t\t\t\t\t...rawOutcome,\n\t\t\t\t\t\taccepted: false,\n\t\t\t\t\t\treasonCode: \"independent_verification_required\",\n\t\t\t\t\t\tacceptance: {\n\t\t\t\t\t\t\toutcome: \"ask-user\" as const,\n\t\t\t\t\t\t\tgate: \"independent_verification\",\n\t\t\t\t\t\t\treasonCode: \"independent_verification_required\",\n\t\t\t\t\t\t\tmessage: \"The owner-authored profile requires an independent verifier before acceptance.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tclaim: {\n\t\t\t\t\t\t\t...rawOutcome.claim,\n\t\t\t\t\t\t\tparentReviewRequired: true,\n\t\t\t\t\t\t\tblockers: [\n\t\t\t\t\t\t\t\t...(rawOutcome.claim.blockers ?? []),\n\t\t\t\t\t\t\t\t\"independent verification is required before acceptance\",\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: rawOutcome;\n\n\t\t\t// Never persist against a disposed session. When disposal raced this\n\t\t\t// await, `abortInFlightLanes()`'s synchronous cutoff already completed this lane, persisted\n\t\t\t// its durable lane record + bounded WorkerClaim, and consumed (deleted) the ledger —\n\t\t\t// `.complete()` below is then a no-op (the lane is already terminal, so it returns\n\t\t\t// undefined) and no double persistence or duplicate terminal notification can happen here.\n\t\t\tif (this.deps.isDisposed()) {\n\t\t\t\tconst record = lifecycle.getRecord(startedRecord.laneId);\n\t\t\t\treturn { started: true, record, outcome };\n\t\t\t}\n\n\t\t\tconst verificationSubject = request.verificationOfTaskId\n\t\t\t\t? lifecycle.getTask(request.verificationOfTaskId)\n\t\t\t\t: undefined;\n\t\t\tconst finalUsage = executionResult.usage;\n\t\t\tconst reportedUsage = providerUsageFromAttemptUsage(finalUsage);\n\t\t\tlet record = finalizeWorkerClaim(lifecycle, {\n\t\t\t\thandle: durableHandle,\n\t\t\t\tclaim: outcome.claim,\n\t\t\t\taccepted: outcome.accepted,\n\t\t\t\tcostUsd: finalUsage.costUsd,\n\t\t\t\treasonCode: outcome.reasonCode,\n\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\tinputTokens: finalUsage.inputTokens,\n\t\t\t\toutputTokens: finalUsage.outputTokens,\n\t\t\t\ttotalTokens: reportedUsage.totalTokens,\n\t\t\t\twallClockMs: finalUsage.activeWallClockMs,\n\t\t\t\ttoolCalls: finalUsage.toolCalls,\n\t\t\t\tverificationRequired,\n\t\t\t\tverificationCriterionIds: verificationSubject?.task.acceptanceCriterionIds,\n\t\t\t\tnotify: !verificationRequired,\n\t\t\t}).record;\n\t\t\ttry {\n\t\t\t\tthis.deps.saveWorkerClaimSnapshot(outcome.claim, workerRequest);\n\t\t\t} catch (error) {\n\t\t\t\tthis.safeWarn(\n\t\t\t\t\t`Failed to persist worker claim ${startedRecord.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (reportedUsage.cost.total > 0 || reportedUsage.totalTokens > 0) {\n\t\t\t\tthis.deps.addSpawnedUsage(reportedUsage, { label: \"worker-delegation\", reportId: usageReportId });\n\t\t\t}\n\n\t\t\tconst terminalRecords: LaneRecord[] = [record];\n\t\t\tif (request.verificationOfTaskId) {\n\t\t\t\tconst decision = outcome.accepted ? outcome.claim.verification : undefined;\n\t\t\t\tconst subject = lifecycle.reconcileVerification({\n\t\t\t\t\tsubjectTaskId: request.verificationOfTaskId,\n\t\t\t\t\tverifierTaskId: startedRecord.laneId,\n\t\t\t\t\tverifierAttemptId: durableHandle.attemptId,\n\t\t\t\t\tverdict: decision?.verdict ?? \"inconclusive\",\n\t\t\t\t\treasonCode: decision\n\t\t\t\t\t\t? decision.verdict === \"accepted\"\n\t\t\t\t\t\t\t? \"independent_verification_accepted\"\n\t\t\t\t\t\t\t: `independent_verification_rejected:${decision.reasonCodes.join(\",\")}`\n\t\t\t\t\t\t: `independent_verification_inconclusive:${outcome.reasonCode}`,\n\t\t\t\t});\n\t\t\t\tterminalRecords.push(subject);\n\t\t\t} else if (verificationRequired) {\n\t\t\t\tconst verifierStart = verifierShipment\n\t\t\t\t\t? this.startInternal(\n\t\t\t\t\t\t\tthis.buildVerifierRequest({\n\t\t\t\t\t\t\t\tsubjectTaskId: startedRecord.laneId,\n\t\t\t\t\t\t\t\tverifierProfileId: verifierShipment.profile.profileId,\n\t\t\t\t\t\t\t\tsummary: rawOutcome.claim.summary,\n\t\t\t\t\t\t\t\tartifactUris: rawOutcome.claim.changedFiles,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tverifierWorkerExecutionContract(admission.executionContract),\n\t\t\t\t\t\t)\n\t\t\t\t\t: { started: false as const, skipReason: \"independent_verifier_unavailable\" };\n\t\t\t\tif (verifierStart.started) {\n\t\t\t\t\t// The durable verifier dispatch is now the terminal-work owner. The subject remains\n\t\t\t\t\t// blocked and emits no compatibility terminal snapshot until reconciliation.\n\t\t\t\t\tterminalRecords.length = 0;\n\t\t\t\t\tthis.scheduler.drain();\n\t\t\t\t} else {\n\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t`Independent verifier for ${startedRecord.laneId} did not start: ${verifierStart.skipReason}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (outcome.acceptance.outcome === \"ask-user\" && terminalRecords.length > 0) {\n\t\t\t\tthis.deps.queueWorkerHumanInput({\n\t\t\t\t\tworkerRequestId: startedRecord.laneId,\n\t\t\t\t\tmessage: outcome.acceptance.message ?? \"Worker output requires owner review.\",\n\t\t\t\t\tblockers: outcome.claim.blockers ?? [],\n\t\t\t\t});\n\t\t\t}\n\t\t\tfor (const terminalRecord of terminalRecords) {\n\t\t\t\tthis.publishTerminalRecord(terminalRecord);\n\t\t\t}\n\t\t\tif (request.verificationOfTaskId) {\n\t\t\t\trecord = lifecycle.getRecord(startedRecord.laneId) ?? record;\n\t\t\t}\n\t\t\treturn { started: true, record, outcome };\n\t\t} catch (error) {\n\t\t\tconst durableState = lifecycle.ledger.runtime.getSnapshot().attempts[durableHandle.attemptId];\n\t\t\tif (durableState?.status === \"suspended\") {\n\t\t\t\t// Disposal/reload fences agent-bound work before its aborted completion unwinds. Do not\n\t\t\t\t// convert that resumable interruption into a terminal claim or cancellation.\n\t\t\t\treturn { started: true, record: lifecycle.getRecord(startedRecord.laneId) };\n\t\t\t}\n\t\t\tif (durableState?.status === \"cancelled\" && (laneAbortController.signal.aborted || this.deps.isDisposed())) {\n\t\t\t\treturn { started: true, record: lifecycle.getRecord(startedRecord.laneId) };\n\t\t\t}\n\t\t\tif (durableState?.status === \"running\" || durableState?.status === \"leased\") {\n\t\t\t\tconst failureClaim: WorkerClaim = {\n\t\t\t\t\trequestId: startedRecord.laneId,\n\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\tsummary: `Worker delegation failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\tchangedFiles: [],\n\t\t\t\t\tcreatedAt: new Date().toISOString(),\n\t\t\t\t};\n\t\t\t\ttry {\n\t\t\t\t\tconst failureUsage = executor.checkpointUsage(\n\t\t\t\t\t\t\"Persisted cumulative usage while recording worker failure.\",\n\t\t\t\t\t);\n\t\t\t\t\tconst reportedUsage = providerUsageFromAttemptUsage(failureUsage);\n\t\t\t\t\tfinalizeWorkerClaim(lifecycle, {\n\t\t\t\t\t\thandle: durableHandle,\n\t\t\t\t\t\tclaim: failureClaim,\n\t\t\t\t\t\taccepted: false,\n\t\t\t\t\t\tcostUsd: failureUsage.costUsd,\n\t\t\t\t\t\tcwd: this.deps.getCwd(),\n\t\t\t\t\t\tinputTokens: failureUsage.inputTokens,\n\t\t\t\t\t\toutputTokens: failureUsage.outputTokens,\n\t\t\t\t\t\ttotalTokens: reportedUsage.totalTokens,\n\t\t\t\t\t\twallClockMs: failureUsage.activeWallClockMs,\n\t\t\t\t\t\ttoolCalls: failureUsage.toolCalls,\n\t\t\t\t\t\treasonCode: \"worker_delegation_error\",\n\t\t\t\t\t});\n\t\t\t\t} catch (persistError) {\n\t\t\t\t\tthis.safeWarn(\n\t\t\t\t\t\t`Failed to persist durable worker failure ${startedRecord.laneId}: ${persistError instanceof Error ? persistError.message : String(persistError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet record = lifecycle.getRecord(startedRecord.laneId);\n\t\t\tif (record?.status === \"queued\" || record?.status === \"running\") {\n\t\t\t\trecord = this.cancelAndPublish(lifecycle, startedRecord.laneId, \"worker_delegation_error\");\n\t\t\t}\n\t\t\tif (record && !this.deps.isDisposed()) this.publishTerminalRecord(record);\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthis.deps.emit({ type: \"warning\", message: `Worker delegation failed: ${message}` });\n\t\t\treturn { started: true, record };\n\t\t} finally {\n\t\t\tthis.writeReservations.release(startedRecord.laneId, durableHandle.attemptId, durableHandle.fencingToken);\n\t\t\tthis.inFlightLedgers.delete(startedRecord.laneId);\n\t\t\tthis.laneAbortControllers.delete(startedRecord.laneId);\n\t\t\tthis.agentControl.signalStateChanged();\n\t\t\tderegisterInFlight();\n\t\t}\n\t}\n\n\t/** Start every capacity-eligible queued worker at the owner session's foreground-idle boundary. */\n\tdrain(): void {\n\t\tthis.recovery.recover();\n\t\tthis.scheduler.drain();\n\t}\n}\n"]}
@@ -1,3 +1,15 @@
1
+ /** Runtime-owned task correlation retained with a durable worker dispatch. Never model-settable. */
2
+ export interface WorkerDelegationTaskContext {
3
+ requirementIds: readonly string[];
4
+ dependsOnTaskIds: readonly string[];
5
+ acceptanceCriterionIds: readonly string[];
6
+ /**
7
+ * Optional runtime narrowing of the owner-admitted profile resources. An empty list does not
8
+ * suppress owner resources: admission expands it to the immutable profile pointer set and
9
+ * persists that exact selection with the attempt.
10
+ */
11
+ resourcePointerIds: readonly string[];
12
+ }
1
13
  /**
2
14
  * The foreground orchestrator may select an owner-authored profile and provide task context. It
3
15
  * cannot select or override a model, thinking level, budget, tool surface, or concurrency policy.
@@ -7,5 +19,7 @@ export interface WorkerDelegationRequest {
7
19
  profileId?: string;
8
20
  /** Runtime-owned correlation for an automatically dispatched verifier; never model-settable. */
9
21
  verificationOfTaskId?: string;
22
+ /** Runtime-owned durable task correlation; the delegate tool schema intentionally omits this. */
23
+ taskContext?: WorkerDelegationTaskContext;
10
24
  }
11
25
  //# sourceMappingURL=worker-delegation-request.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-delegation-request.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gGAAgG;IAChG,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B","sourcesContent":["/**\n * The foreground orchestrator may select an owner-authored profile and provide task context. It\n * cannot select or override a model, thinking level, budget, tool surface, or concurrency policy.\n */\nexport interface WorkerDelegationRequest {\n\tinstructions: string;\n\tprofileId?: string;\n\t/** Runtime-owned correlation for an automatically dispatched verifier; never model-settable. */\n\tverificationOfTaskId?: string;\n}\n"]}
1
+ {"version":3,"file":"worker-delegation-request.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-request.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,MAAM,WAAW,2BAA2B;IAC3C,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,sBAAsB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C;;;;OAIG;IACH,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gGAAgG;IAChG,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iGAAiG;IACjG,WAAW,CAAC,EAAE,2BAA2B,CAAC;CAC1C","sourcesContent":["/** Runtime-owned task correlation retained with a durable worker dispatch. Never model-settable. */\nexport interface WorkerDelegationTaskContext {\n\trequirementIds: readonly string[];\n\tdependsOnTaskIds: readonly string[];\n\tacceptanceCriterionIds: readonly string[];\n\t/**\n\t * Optional runtime narrowing of the owner-admitted profile resources. An empty list does not\n\t * suppress owner resources: admission expands it to the immutable profile pointer set and\n\t * persists that exact selection with the attempt.\n\t */\n\tresourcePointerIds: readonly string[];\n}\n\n/**\n * The foreground orchestrator may select an owner-authored profile and provide task context. It\n * cannot select or override a model, thinking level, budget, tool surface, or concurrency policy.\n */\nexport interface WorkerDelegationRequest {\n\tinstructions: string;\n\tprofileId?: string;\n\t/** Runtime-owned correlation for an automatically dispatched verifier; never model-settable. */\n\tverificationOfTaskId?: string;\n\t/** Runtime-owned durable task correlation; the delegate tool schema intentionally omits this. */\n\ttaskContext?: WorkerDelegationTaskContext;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"worker-delegation-request.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-request.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The foreground orchestrator may select an owner-authored profile and provide task context. It\n * cannot select or override a model, thinking level, budget, tool surface, or concurrency policy.\n */\nexport interface WorkerDelegationRequest {\n\tinstructions: string;\n\tprofileId?: string;\n\t/** Runtime-owned correlation for an automatically dispatched verifier; never model-settable. */\n\tverificationOfTaskId?: string;\n}\n"]}
1
+ {"version":3,"file":"worker-delegation-request.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-request.ts"],"names":[],"mappings":"","sourcesContent":["/** Runtime-owned task correlation retained with a durable worker dispatch. Never model-settable. */\nexport interface WorkerDelegationTaskContext {\n\trequirementIds: readonly string[];\n\tdependsOnTaskIds: readonly string[];\n\tacceptanceCriterionIds: readonly string[];\n\t/**\n\t * Optional runtime narrowing of the owner-admitted profile resources. An empty list does not\n\t * suppress owner resources: admission expands it to the immutable profile pointer set and\n\t * persists that exact selection with the attempt.\n\t */\n\tresourcePointerIds: readonly string[];\n}\n\n/**\n * The foreground orchestrator may select an owner-authored profile and provide task context. It\n * cannot select or override a model, thinking level, budget, tool surface, or concurrency policy.\n */\nexport interface WorkerDelegationRequest {\n\tinstructions: string;\n\tprofileId?: string;\n\t/** Runtime-owned correlation for an automatically dispatched verifier; never model-settable. */\n\tverificationOfTaskId?: string;\n\t/** Runtime-owned durable task correlation; the delegate tool schema intentionally omits this. */\n\ttaskContext?: WorkerDelegationTaskContext;\n}\n"]}
@@ -1,10 +1,11 @@
1
- import type { WorkerDelegationRunOutcome } from "../agent-session.ts";
1
+ import type { WorkerDelegationRunOutcome } from "../agent-session-contracts.ts";
2
2
  import type { LaneRecord } from "../autonomy/lane-tracker.ts";
3
3
  import type { WorkerDelegationRequest } from "./worker-delegation-request.ts";
4
4
  export type WorkerDispatchAdmission = {
5
5
  action: "start";
6
6
  } | {
7
7
  action: "wait";
8
+ reason?: "capacity" | "write_reservation";
8
9
  } | {
9
10
  action: "cancel";
10
11
  reasonCode: string;
@@ -27,12 +28,13 @@ export declare class WorkerDispatchScheduler {
27
28
  private readonly queued;
28
29
  private readonly queuedDeregisters;
29
30
  private readonly running;
31
+ private readonly reservationBlocked;
30
32
  private draining;
31
33
  constructor(options: WorkerDispatchSchedulerOptions);
32
34
  get queuedCount(): number;
33
35
  enqueue(record: LaneRecord, request: WorkerDelegationRequest, recovered?: boolean, priority?: boolean): void;
34
36
  track(laneId: string, promise: Promise<WorkerDelegationRunOutcome>): void;
35
- drain(): void;
37
+ drain(reservationAvailable?: boolean): void;
36
38
  cancelQueued(): void;
37
39
  dropQueued(laneId: string): boolean;
38
40
  private removeQueued;
@@ -1 +1 @@
1
- {"version":3,"file":"worker-dispatch-scheduler.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-dispatch-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,g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AK,IAAI,IAAI,CAsBZ;IAED,YAAY,IAAI,IAAI,CAInB;IAED,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAIlC;IAED,OAAO,CAAC,YAAY;CAKpB","sourcesContent":["import type { WorkerDelegationRunOutcome } from \"../agent-session.ts\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport { registerInFlightWork } from \"../reload-blockers.ts\";\nimport type { WorkerDelegationRequest } from \"./worker-delegation-request.ts\";\n\nexport type WorkerDispatchAdmission =\n\t| { action: \"start\" }\n\t| { action: \"wait\" }\n\t| { action: \"cancel\"; reasonCode: string };\n\nexport interface WorkerDispatchSchedulerOptions {\n\tagentDir: string;\n\tisDisposed(): boolean;\n\tadmit(request: WorkerDelegationRequest, record: LaneRecord): WorkerDispatchAdmission;\n\tgetRecord(laneId: string): LaneRecord | undefined;\n\trun(request: WorkerDelegationRequest, record: LaneRecord): Promise<WorkerDelegationRunOutcome>;\n\tcancel(laneId: string, reasonCode: string): void;\n\twarn(message: string): void;\n}\n\n/**\n * Single owner of worker queue and promise transitions. Execution policy and durable lifecycle stay\n * outside; this class only decides when a prepared durable attempt moves from queued to running.\n */\nexport class WorkerDispatchScheduler {\n\tprivate readonly options: WorkerDispatchSchedulerOptions;\n\tprivate readonly queued = new Map<string, WorkerDelegationRequest>();\n\tprivate readonly queuedDeregisters = new Map<string, () => void>();\n\tprivate readonly running = new Map<string, Promise<WorkerDelegationRunOutcome>>();\n\tprivate draining = false;\n\n\tconstructor(options: WorkerDispatchSchedulerOptions) {\n\t\tthis.options = options;\n\t}\n\n\tget queuedCount(): number {\n\t\treturn this.queued.size;\n\t}\n\n\tenqueue(record: LaneRecord, request: WorkerDelegationRequest, recovered = false, priority = false): void {\n\t\tif (this.queued.has(record.laneId) || this.running.has(record.laneId)) return;\n\t\tif (priority) {\n\t\t\tconst waiting = [...this.queued];\n\t\t\tthis.queued.clear();\n\t\t\tthis.queued.set(record.laneId, request);\n\t\t\tfor (const [laneId, queuedRequest] of waiting) this.queued.set(laneId, queuedRequest);\n\t\t} else {\n\t\t\tthis.queued.set(record.laneId, request);\n\t\t}\n\t\tthis.queuedDeregisters.set(\n\t\t\trecord.laneId,\n\t\t\tregisterInFlightWork(\n\t\t\t\tthis.options.agentDir,\n\t\t\t\t\"lane\",\n\t\t\t\trecovered ? `worker-recovered:${record.laneId}` : `worker-queued:${record.laneId}`,\n\t\t\t),\n\t\t);\n\t}\n\n\ttrack(laneId: string, promise: Promise<WorkerDelegationRunOutcome>): void {\n\t\tthis.running.set(laneId, promise);\n\t\tvoid promise.then(\n\t\t\t(outcome) => {\n\t\t\t\tif (!outcome.started) this.options.cancel(laneId, outcome.skipReason ?? \"worker_not_started\");\n\t\t\t\tthis.running.delete(laneId);\n\t\t\t\tif (!this.options.isDisposed()) this.drain();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tthis.options.cancel(laneId, \"worker_background_error\");\n\t\t\t\tthis.options.warn(`Worker ${laneId} rejected: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t\tthis.running.delete(laneId);\n\t\t\t\tif (!this.options.isDisposed()) this.drain();\n\t\t\t},\n\t\t);\n\t}\n\n\tdrain(): void {\n\t\tif (this.draining || this.options.isDisposed()) return;\n\t\tthis.draining = true;\n\t\ttry {\n\t\t\tfor (const [laneId, request] of [...this.queued]) {\n\t\t\t\tconst record = this.options.getRecord(laneId);\n\t\t\t\tif (!record) {\n\t\t\t\t\tthis.removeQueued(laneId);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst admission = this.options.admit(request, record);\n\t\t\t\tif (admission.action === \"wait\") continue;\n\t\t\t\tthis.removeQueued(laneId);\n\t\t\t\tif (admission.action === \"cancel\") {\n\t\t\t\t\tthis.options.cancel(laneId, admission.reasonCode);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthis.track(laneId, this.options.run(request, record));\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.draining = false;\n\t\t}\n\t}\n\n\tcancelQueued(): void {\n\t\tfor (const deregister of this.queuedDeregisters.values()) deregister();\n\t\tthis.queuedDeregisters.clear();\n\t\tthis.queued.clear();\n\t}\n\n\tdropQueued(laneId: string): boolean {\n\t\tif (!this.queued.has(laneId)) return false;\n\t\tthis.removeQueued(laneId);\n\t\treturn true;\n\t}\n\n\tprivate removeQueued(laneId: string): void {\n\t\tthis.queued.delete(laneId);\n\t\tthis.queuedDeregisters.get(laneId)?.();\n\t\tthis.queuedDeregisters.delete(laneId);\n\t}\n}\n"]}
1
+ {"version":3,"file":"worker-dispatch-scheduler.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-dispatch-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAE9E,MAAM,MAAM,uBAAuB,GAChC;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GACnB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,UAAU,GAAG,mBAAmB,CAAA;CAAE,GAC7D;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C,MAAM,WAAW,8BAA8B;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,IAAI,OAAO,CAAC;IACtB,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,UAAU,GAAG,uBAAuB,CAAC;IACrF,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;IAClD,GAAG,CAAC,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAC/F,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;;GAGG;AACH,qBAAa,uBAAuB;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8C;IACrE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAiC;IACnE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0D;IAClF,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqB;IACxD,OAAO,CAAC,QAAQ,CAAS;IAEzB,YAAY,OAAO,EAAE,8BAA8B,EAElD;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,uBAAuB,EAAE,SAAS,UAAQ,EAAE,QAAQ,UAAQ,GAAG,IAAI,CAkBvG;IAED,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,0BAA0B,CAAC,GAAG,IAAI,CAexE;IAED,KAAK,CAAC,oBAAoB,UAAQ,GAAG,IAAI,CA2BxC;IAED,YAAY,IAAI,IAAI,CAOnB;IAED,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAIlC;IAED,OAAO,CAAC,YAAY;CAMpB","sourcesContent":["import type { WorkerDelegationRunOutcome } from \"../agent-session-contracts.ts\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport { registerInFlightWork } from \"../reload-blockers.ts\";\nimport type { WorkerDelegationRequest } from \"./worker-delegation-request.ts\";\n\nexport type WorkerDispatchAdmission =\n\t| { action: \"start\" }\n\t| { action: \"wait\"; reason?: \"capacity\" | \"write_reservation\" }\n\t| { action: \"cancel\"; reasonCode: string };\n\nexport interface WorkerDispatchSchedulerOptions {\n\tagentDir: string;\n\tisDisposed(): boolean;\n\tadmit(request: WorkerDelegationRequest, record: LaneRecord): WorkerDispatchAdmission;\n\tgetRecord(laneId: string): LaneRecord | undefined;\n\trun(request: WorkerDelegationRequest, record: LaneRecord): Promise<WorkerDelegationRunOutcome>;\n\tcancel(laneId: string, reasonCode: string): void;\n\twarn(message: string): void;\n}\n\n/**\n * Single owner of worker queue and promise transitions. Execution policy and durable lifecycle stay\n * outside; this class only decides when a prepared durable attempt moves from queued to running.\n */\nexport class WorkerDispatchScheduler {\n\tprivate readonly options: WorkerDispatchSchedulerOptions;\n\tprivate readonly queued = new Map<string, WorkerDelegationRequest>();\n\tprivate readonly queuedDeregisters = new Map<string, () => void>();\n\tprivate readonly running = new Map<string, Promise<WorkerDelegationRunOutcome>>();\n\tprivate readonly reservationBlocked = new Set<string>();\n\tprivate draining = false;\n\n\tconstructor(options: WorkerDispatchSchedulerOptions) {\n\t\tthis.options = options;\n\t}\n\n\tget queuedCount(): number {\n\t\treturn this.queued.size;\n\t}\n\n\tenqueue(record: LaneRecord, request: WorkerDelegationRequest, recovered = false, priority = false): void {\n\t\tif (this.queued.has(record.laneId) || this.running.has(record.laneId)) return;\n\t\tif (priority) {\n\t\t\tconst waiting = [...this.queued];\n\t\t\tthis.queued.clear();\n\t\t\tthis.queued.set(record.laneId, request);\n\t\t\tfor (const [laneId, queuedRequest] of waiting) this.queued.set(laneId, queuedRequest);\n\t\t} else {\n\t\t\tthis.queued.set(record.laneId, request);\n\t\t}\n\t\tthis.queuedDeregisters.set(\n\t\t\trecord.laneId,\n\t\t\tregisterInFlightWork(\n\t\t\t\tthis.options.agentDir,\n\t\t\t\t\"lane\",\n\t\t\t\trecovered ? `worker-recovered:${record.laneId}` : `worker-queued:${record.laneId}`,\n\t\t\t),\n\t\t);\n\t}\n\n\ttrack(laneId: string, promise: Promise<WorkerDelegationRunOutcome>): void {\n\t\tthis.running.set(laneId, promise);\n\t\tvoid promise.then(\n\t\t\t(outcome) => {\n\t\t\t\tif (!outcome.started) this.options.cancel(laneId, outcome.skipReason ?? \"worker_not_started\");\n\t\t\t\tthis.running.delete(laneId);\n\t\t\t\tif (!this.options.isDisposed()) this.drain();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tthis.options.cancel(laneId, \"worker_background_error\");\n\t\t\t\tthis.options.warn(`Worker ${laneId} rejected: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t\tthis.running.delete(laneId);\n\t\t\t\tif (!this.options.isDisposed()) this.drain();\n\t\t\t},\n\t\t);\n\t}\n\n\tdrain(reservationAvailable = false): void {\n\t\tif (this.draining || this.options.isDisposed()) return;\n\t\tthis.draining = true;\n\t\ttry {\n\t\t\tfor (const [laneId, request] of [...this.queued]) {\n\t\t\t\tif (this.reservationBlocked.has(laneId) && !reservationAvailable) continue;\n\t\t\t\tconst record = this.options.getRecord(laneId);\n\t\t\t\tif (!record) {\n\t\t\t\t\tthis.removeQueued(laneId);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst admission = this.options.admit(request, record);\n\t\t\t\tif (admission.action === \"wait\") {\n\t\t\t\t\tif (admission.reason === \"write_reservation\") this.reservationBlocked.add(laneId);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthis.reservationBlocked.delete(laneId);\n\t\t\t\tthis.removeQueued(laneId);\n\t\t\t\tif (admission.action === \"cancel\") {\n\t\t\t\t\tthis.options.cancel(laneId, admission.reasonCode);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthis.track(laneId, this.options.run(request, record));\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.draining = false;\n\t\t}\n\t}\n\n\tcancelQueued(): void {\n\t\tfor (const laneId of [...this.queued.keys()]) {\n\t\t\t// The controller owns durable cancellation and any pre-admission resources (for example a\n\t\t\t// write reservation). Dropping this scheduler-only reference would leak those resources.\n\t\t\tthis.options.cancel(laneId, \"session_disposed\");\n\t\t\tthis.removeQueued(laneId);\n\t\t}\n\t}\n\n\tdropQueued(laneId: string): boolean {\n\t\tif (!this.queued.has(laneId)) return false;\n\t\tthis.removeQueued(laneId);\n\t\treturn true;\n\t}\n\n\tprivate removeQueued(laneId: string): void {\n\t\tthis.queued.delete(laneId);\n\t\tthis.reservationBlocked.delete(laneId);\n\t\tthis.queuedDeregisters.get(laneId)?.();\n\t\tthis.queuedDeregisters.delete(laneId);\n\t}\n}\n"]}
@@ -8,6 +8,7 @@ export class WorkerDispatchScheduler {
8
8
  queued = new Map();
9
9
  queuedDeregisters = new Map();
10
10
  running = new Map();
11
+ reservationBlocked = new Set();
11
12
  draining = false;
12
13
  constructor(options) {
13
14
  this.options = options;
@@ -46,20 +47,26 @@ export class WorkerDispatchScheduler {
46
47
  this.drain();
47
48
  });
48
49
  }
49
- drain() {
50
+ drain(reservationAvailable = false) {
50
51
  if (this.draining || this.options.isDisposed())
51
52
  return;
52
53
  this.draining = true;
53
54
  try {
54
55
  for (const [laneId, request] of [...this.queued]) {
56
+ if (this.reservationBlocked.has(laneId) && !reservationAvailable)
57
+ continue;
55
58
  const record = this.options.getRecord(laneId);
56
59
  if (!record) {
57
60
  this.removeQueued(laneId);
58
61
  continue;
59
62
  }
60
63
  const admission = this.options.admit(request, record);
61
- if (admission.action === "wait")
64
+ if (admission.action === "wait") {
65
+ if (admission.reason === "write_reservation")
66
+ this.reservationBlocked.add(laneId);
62
67
  continue;
68
+ }
69
+ this.reservationBlocked.delete(laneId);
63
70
  this.removeQueued(laneId);
64
71
  if (admission.action === "cancel") {
65
72
  this.options.cancel(laneId, admission.reasonCode);
@@ -73,10 +80,12 @@ export class WorkerDispatchScheduler {
73
80
  }
74
81
  }
75
82
  cancelQueued() {
76
- for (const deregister of this.queuedDeregisters.values())
77
- deregister();
78
- this.queuedDeregisters.clear();
79
- this.queued.clear();
83
+ for (const laneId of [...this.queued.keys()]) {
84
+ // The controller owns durable cancellation and any pre-admission resources (for example a
85
+ // write reservation). Dropping this scheduler-only reference would leak those resources.
86
+ this.options.cancel(laneId, "session_disposed");
87
+ this.removeQueued(laneId);
88
+ }
80
89
  }
81
90
  dropQueued(laneId) {
82
91
  if (!this.queued.has(laneId))
@@ -86,6 +95,7 @@ export class WorkerDispatchScheduler {
86
95
  }
87
96
  removeQueued(laneId) {
88
97
  this.queued.delete(laneId);
98
+ this.reservationBlocked.delete(laneId);
89
99
  this.queuedDeregisters.get(laneId)?.();
90
100
  this.queuedDeregisters.delete(laneId);
91
101
  }