@caupulican/pi-adaptative 0.90.2 → 0.90.4

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 (162) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/core/agent-session-contracts.d.ts +2 -0
  3. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  4. package/dist/core/agent-session-contracts.js.map +1 -1
  5. package/dist/core/autonomy/bounded-completion.d.ts +10 -1
  6. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  7. package/dist/core/autonomy/bounded-completion.js +24 -2
  8. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  9. package/dist/core/autonomy/lane-tracker.d.ts +1 -1
  10. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  11. package/dist/core/autonomy/lane-tracker.js +9 -1
  12. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  13. package/dist/core/background-lane-controller.d.ts +1 -3
  14. package/dist/core/background-lane-controller.d.ts.map +1 -1
  15. package/dist/core/background-lane-controller.js.map +1 -1
  16. package/dist/core/compaction-controller.d.ts.map +1 -1
  17. package/dist/core/compaction-controller.js +0 -1
  18. package/dist/core/compaction-controller.js.map +1 -1
  19. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
  20. package/dist/core/delegation/managed-lane-controller.js +5 -1
  21. package/dist/core/delegation/managed-lane-controller.js.map +1 -1
  22. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +8 -1
  23. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
  24. package/dist/core/delegation/worker-agent-control-coordinator.js +94 -36
  25. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
  26. package/dist/core/delegation/worker-agent-control.d.ts +1 -0
  27. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
  28. package/dist/core/delegation/worker-agent-control.js.map +1 -1
  29. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
  30. package/dist/core/delegation/worker-attempt-executor.js +7 -2
  31. package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
  32. package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
  33. package/dist/core/delegation/worker-authority-resolver.js +26 -3
  34. package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
  35. package/dist/core/delegation/worker-delegation-controller.d.ts +7 -4
  36. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  37. package/dist/core/delegation/worker-delegation-controller.js +110 -27
  38. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  39. package/dist/core/delegation/worker-fleet-limits.d.ts +9 -2
  40. package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -1
  41. package/dist/core/delegation/worker-fleet-limits.js +39 -3
  42. package/dist/core/delegation/worker-fleet-limits.js.map +1 -1
  43. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
  44. package/dist/core/delegation/worker-lane-projection.js +4 -0
  45. package/dist/core/delegation/worker-lane-projection.js.map +1 -1
  46. package/dist/core/delegation/worker-lease-heartbeat.d.ts +16 -0
  47. package/dist/core/delegation/worker-lease-heartbeat.d.ts.map +1 -0
  48. package/dist/core/delegation/worker-lease-heartbeat.js +37 -0
  49. package/dist/core/delegation/worker-lease-heartbeat.js.map +1 -0
  50. package/dist/core/delegation/worker-lifecycle.d.ts +1 -0
  51. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  52. package/dist/core/delegation/worker-lifecycle.js +6 -0
  53. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  54. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
  55. package/dist/core/delegation/worker-notification-coordinator.js +2 -1
  56. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
  57. package/dist/core/delegation/worker-runner.js +2 -2
  58. package/dist/core/delegation/worker-runner.js.map +1 -1
  59. package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts +1 -0
  60. package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts.map +1 -1
  61. package/dist/core/delegation/worker-terminal-handoff-coordinator.js +1 -0
  62. package/dist/core/delegation/worker-terminal-handoff-coordinator.js.map +1 -1
  63. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +4 -2
  64. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -1
  65. package/dist/core/delegation/worker-tree-budget-coordinator.js +10 -2
  66. package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -1
  67. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +14 -0
  68. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
  69. package/dist/core/delegation/worker-write-reservation-coordinator.js +121 -33
  70. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
  71. package/dist/core/foreground-terminal-handoff-controller.d.ts +5 -0
  72. package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
  73. package/dist/core/foreground-terminal-handoff-controller.js +28 -12
  74. package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
  75. package/dist/core/orchestration/capability-gateway.d.ts +2 -1
  76. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  77. package/dist/core/orchestration/capability-gateway.js +9 -2
  78. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  79. package/dist/core/orchestration/contracts.d.ts +16 -1
  80. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  81. package/dist/core/orchestration/contracts.js +5 -0
  82. package/dist/core/orchestration/contracts.js.map +1 -1
  83. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  84. package/dist/core/orchestration/profile-registry.js +38 -1
  85. package/dist/core/orchestration/profile-registry.js.map +1 -1
  86. package/dist/core/orchestration/risk-budget.d.ts +10 -0
  87. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  88. package/dist/core/orchestration/risk-budget.js +14 -0
  89. package/dist/core/orchestration/risk-budget.js.map +1 -1
  90. package/dist/core/orchestration/task-runtime-reducer.d.ts +1 -0
  91. package/dist/core/orchestration/task-runtime-reducer.d.ts.map +1 -1
  92. package/dist/core/orchestration/task-runtime-reducer.js +34 -0
  93. package/dist/core/orchestration/task-runtime-reducer.js.map +1 -1
  94. package/dist/core/orchestration/task-runtime.d.ts +1 -0
  95. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  96. package/dist/core/orchestration/task-runtime.js +24 -1
  97. package/dist/core/orchestration/task-runtime.js.map +1 -1
  98. package/dist/core/provider-prompt-contracts.d.ts.map +1 -1
  99. package/dist/core/provider-prompt-contracts.js +2 -1
  100. package/dist/core/provider-prompt-contracts.js.map +1 -1
  101. package/dist/core/reflection-controller.d.ts.map +1 -1
  102. package/dist/core/reflection-controller.js +8 -1
  103. package/dist/core/reflection-controller.js.map +1 -1
  104. package/dist/core/settings-manager.d.ts +2 -2
  105. package/dist/core/settings-manager.d.ts.map +1 -1
  106. package/dist/core/settings-manager.js +2 -2
  107. package/dist/core/settings-manager.js.map +1 -1
  108. package/dist/core/tools/bash.d.ts +3 -0
  109. package/dist/core/tools/bash.d.ts.map +1 -1
  110. package/dist/core/tools/bash.js +13 -2
  111. package/dist/core/tools/bash.js.map +1 -1
  112. package/dist/core/tools/delegate-status.d.ts +1 -0
  113. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  114. package/dist/core/tools/delegate-status.js +19 -1
  115. package/dist/core/tools/delegate-status.js.map +1 -1
  116. package/dist/core/tools/delegate.d.ts +9 -1
  117. package/dist/core/tools/delegate.d.ts.map +1 -1
  118. package/dist/core/tools/delegate.js +198 -64
  119. package/dist/core/tools/delegate.js.map +1 -1
  120. package/dist/core/tools/edit.d.ts.map +1 -1
  121. package/dist/core/tools/edit.js +14 -1
  122. package/dist/core/tools/edit.js.map +1 -1
  123. package/dist/core/tools/file-failure-recovery.d.ts +3 -0
  124. package/dist/core/tools/file-failure-recovery.d.ts.map +1 -1
  125. package/dist/core/tools/file-failure-recovery.js +11 -0
  126. package/dist/core/tools/file-failure-recovery.js.map +1 -1
  127. package/dist/core/tools/orchestration-panel.d.ts +1 -1
  128. package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
  129. package/dist/core/tools/orchestration-panel.js +1 -0
  130. package/dist/core/tools/orchestration-panel.js.map +1 -1
  131. package/dist/core/tools/profile-writer.d.ts.map +1 -1
  132. package/dist/core/tools/profile-writer.js +2 -8
  133. package/dist/core/tools/profile-writer.js.map +1 -1
  134. package/dist/core/tools/search-command-guard.d.ts.map +1 -1
  135. package/dist/core/tools/search-command-guard.js +10 -3
  136. package/dist/core/tools/search-command-guard.js.map +1 -1
  137. package/dist/core/tools/write.d.ts.map +1 -1
  138. package/dist/core/tools/write.js +10 -1
  139. package/dist/core/tools/write.js.map +1 -1
  140. package/dist/modes/interactive/components/activity-lane.d.ts +1 -1
  141. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
  142. package/dist/modes/interactive/components/activity-lane.js +11 -2
  143. package/dist/modes/interactive/components/activity-lane.js.map +1 -1
  144. package/dist/modes/interactive/components/settings-selector.js +1 -1
  145. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  146. package/dist/utils/shell.d.ts +2 -0
  147. package/dist/utils/shell.d.ts.map +1 -1
  148. package/dist/utils/shell.js +3 -1
  149. package/dist/utils/shell.js.map +1 -1
  150. package/docs/harness-architecture.md +6 -3
  151. package/docs/settings.md +8 -6
  152. package/docs/tool-repair.md +1 -1
  153. package/docs/worker-profiles.md +2 -2
  154. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  155. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  156. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  157. package/examples/extensions/sandbox/package-lock.json +2 -2
  158. package/examples/extensions/sandbox/package.json +1 -1
  159. package/examples/extensions/with-deps/package-lock.json +2 -2
  160. package/examples/extensions/with-deps/package.json +1 -1
  161. package/npm-shrinkwrap.json +12 -12
  162. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import { type AgentBindingContract } from "../orchestration/contracts.ts";
1
+ import { type AgentBindingContract, type OrchestrationDelegationLimits } from "../orchestration/contracts.ts";
2
2
  import type { TaskRuntimeProjection } from "../orchestration/task-runtime.ts";
3
3
  /**
4
4
  * Process-independent safety ceilings for one durable session fleet. These limits bound persisted
@@ -8,15 +8,22 @@ export interface WorkerFleetLimits {
8
8
  maxDepth: number;
9
9
  maxAgentsPerSession: number;
10
10
  maxChildrenPerAgent: number;
11
+ maxNestedAgentsPerSession: number;
11
12
  maxQueuedDispatches: number;
12
13
  }
13
14
  export declare const DEFAULT_WORKER_FLEET_LIMITS: Readonly<WorkerFleetLimits>;
15
+ /** Profile-free workers get one useful nested identity without an open-ended recursive fleet. */
16
+ export declare const LEAN_WORKER_DELEGATION_LIMITS: Readonly<OrchestrationDelegationLimits>;
17
+ /** Materialize an optional profile limit inside the process-independent host safety ceiling. */
18
+ export declare function resolveWorkerFleetLimits(delegationLimits?: Readonly<OrchestrationDelegationLimits>): Readonly<WorkerFleetLimits>;
19
+ /** Descendant routing may preserve or narrow an ancestor's recursive authority, never widen it. */
20
+ export declare function intersectWorkerDelegationLimits(requested?: Readonly<OrchestrationDelegationLimits>, boundary?: Readonly<OrchestrationDelegationLimits>): OrchestrationDelegationLimits | undefined;
14
21
  export type NewWorkerAdmission = {
15
22
  ok: true;
16
23
  depth: number;
17
24
  } | {
18
25
  ok: false;
19
- reasonCode: "worker_agent_parent_unknown" | "worker_agent_parent_retired" | "worker_agent_depth_limit_reached" | "worker_agent_child_limit_reached" | "worker_agent_session_limit_reached";
26
+ reasonCode: "worker_agent_parent_unknown" | "worker_agent_parent_retired" | "worker_agent_depth_limit_reached" | "worker_agent_child_limit_reached" | "worker_agent_nested_session_limit_reached" | "worker_agent_session_limit_reached";
20
27
  };
21
28
  export type WorkerIdentityHeadroomAdmission = {
22
29
  ok: true;
@@ -1 +1 @@
1
- {"version":3,"file":"worker-fleet-limits.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-fleet-limits.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,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AAK,EAAE,MAAM,CAAA;CAAE,GAC3B;IACA,EAAE,EAAE,KAAK,CAAC;IACV,UAAU,EACP,6BAA6B,GAC7B,6BAA6B,GAC7B,kCAAkC,GAClC,kCAAkC,GAClC,2CAA2C,GAC3C,oCAAoC,CAAC;CACvC,CAAC;AAEL,MAAM,MAAM,+BAA+B,GACxC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,oCAAoC,CAAA;CAAE,CAAC;AAEnE,+EAA+E;AAC/E,wBAAgB,6BAA6B,CAC5C,QAAQ,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC,GACpE,GAAG,CAAC,MAAM,CAAC,CA0Cb;AAgBD;;;GAGG;AACH,wBAAgB,mCAAmC,CAClD,QAAQ,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC,EACtE,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,QAAQ,CAAC,iBAAiB,CAA+B,GAC/D,+BAA+B,CAKjC;AAED,kGAAkG;AAClG,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,EACtD,aAAa,CAAC,EAAE,MAAM,EACtB,MAAM,GAAE,QAAQ,CAAC,iBAAiB,CAA+B,EACjE,kBAAkB,SAAI,GACpB,kBAAkB,CA2BpB;AAED,+EAA+E;AAC/E,wBAAgB,sBAAsB,CACrC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,EACjB,MAAM,GAAE,QAAQ,CAAC,iBAAiB,CAA+B,GAC/D,OAAO,CAIT"}
@@ -1,11 +1,39 @@
1
1
  import { latestAgentAttemptByDurableOrder } from "../orchestration/attempt-ordering.js";
2
- import { MAX_ORCHESTRATION_AGENT_BINDINGS } from "../orchestration/contracts.js";
2
+ import { MAX_ORCHESTRATION_AGENT_BINDINGS, MAX_ORCHESTRATION_AGENT_DEPTH, MAX_ORCHESTRATION_DIRECT_CHILDREN, } from "../orchestration/contracts.js";
3
3
  export const DEFAULT_WORKER_FLEET_LIMITS = Object.freeze({
4
- maxDepth: 8,
4
+ maxDepth: MAX_ORCHESTRATION_AGENT_DEPTH,
5
5
  maxAgentsPerSession: MAX_ORCHESTRATION_AGENT_BINDINGS,
6
- maxChildrenPerAgent: 64,
6
+ maxChildrenPerAgent: MAX_ORCHESTRATION_DIRECT_CHILDREN,
7
+ maxNestedAgentsPerSession: MAX_ORCHESTRATION_AGENT_BINDINGS,
7
8
  maxQueuedDispatches: 256,
8
9
  });
10
+ /** Profile-free workers get one useful nested identity without an open-ended recursive fleet. */
11
+ export const LEAN_WORKER_DELEGATION_LIMITS = Object.freeze({
12
+ maxDepth: 1,
13
+ maxChildrenPerAgent: 1,
14
+ maxNestedAgentsPerSession: 1,
15
+ });
16
+ /** Materialize an optional profile limit inside the process-independent host safety ceiling. */
17
+ export function resolveWorkerFleetLimits(delegationLimits) {
18
+ return {
19
+ ...DEFAULT_WORKER_FLEET_LIMITS,
20
+ maxDepth: Math.min(delegationLimits?.maxDepth ?? DEFAULT_WORKER_FLEET_LIMITS.maxDepth, MAX_ORCHESTRATION_AGENT_DEPTH),
21
+ maxChildrenPerAgent: Math.min(delegationLimits?.maxChildrenPerAgent ?? DEFAULT_WORKER_FLEET_LIMITS.maxChildrenPerAgent, MAX_ORCHESTRATION_DIRECT_CHILDREN),
22
+ maxNestedAgentsPerSession: Math.min(delegationLimits?.maxNestedAgentsPerSession ?? DEFAULT_WORKER_FLEET_LIMITS.maxNestedAgentsPerSession, MAX_ORCHESTRATION_AGENT_BINDINGS),
23
+ };
24
+ }
25
+ /** Descendant routing may preserve or narrow an ancestor's recursive authority, never widen it. */
26
+ export function intersectWorkerDelegationLimits(requested, boundary) {
27
+ if (!requested && !boundary)
28
+ return undefined;
29
+ const requestedLimits = resolveWorkerFleetLimits(requested);
30
+ const boundaryLimits = resolveWorkerFleetLimits(boundary);
31
+ return {
32
+ maxDepth: Math.min(requestedLimits.maxDepth, boundaryLimits.maxDepth),
33
+ maxChildrenPerAgent: Math.min(requestedLimits.maxChildrenPerAgent, boundaryLimits.maxChildrenPerAgent),
34
+ maxNestedAgentsPerSession: Math.min(requestedLimits.maxNestedAgentsPerSession, boundaryLimits.maxNestedAgentsPerSession),
35
+ };
36
+ }
9
37
  /** Subjects whose admitted verifier identity has not yet been materialized. */
10
38
  export function pendingVerifierSubjectTaskIds(snapshot) {
11
39
  const agents = snapshot.agents ?? {};
@@ -101,6 +129,14 @@ export function evaluateNewWorkerAdmission(agents, parentAgentId, limits = DEFAU
101
129
  if (directChildren >= limits.maxChildrenPerAgent) {
102
130
  return { ok: false, reasonCode: "worker_agent_child_limit_reached" };
103
131
  }
132
+ let nestedAgents = 0;
133
+ for (const agent of Object.values(agents)) {
134
+ if (agent.parentAgentId)
135
+ nestedAgents += 1;
136
+ }
137
+ if (nestedAgents >= limits.maxNestedAgentsPerSession) {
138
+ return { ok: false, reasonCode: "worker_agent_nested_session_limit_reached" };
139
+ }
104
140
  return { ok: true, depth };
105
141
  }
106
142
  /** Keep one queue slot reserved for an already-admitted mandatory verifier. */
@@ -1 +1 @@
1
- {"version":3,"file":"worker-fleet-limits.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-fleet-limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAA6B,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AAc5G,MAAM,CAAC,MAAM,2BAA2B,GAAgC,MAAM,CAAC,MAAM,CAAC;IACrF,QAAQ,EAAE,CAAC;IACX,mBAAmB,EAAE,gCAAgC;IACrD,mBAAmB,EAAE,EAAE;IACvB,mBAAmB,EAAE,GAAG;CACxB,CAAC,CAAC;AAkBH,+EAA+E;AAC/E,MAAM,UAAU,6BAA6B,CAC5C,QAA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ordering.ts\";\nimport { type AgentBindingContract, MAX_ORCHESTRATION_AGENT_BINDINGS } from \"../orchestration/contracts.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\n\n/**\n * Process-independent safety ceilings for one durable session fleet. These limits bound persisted\n * identity growth and scheduler fan-out; model/provider budgets remain separately authoritative.\n */\nexport interface WorkerFleetLimits {\n\tmaxDepth: number;\n\tmaxAgentsPerSession: number;\n\tmaxChildrenPerAgent: number;\n\tmaxQueuedDispatches: number;\n}\n\nexport const DEFAULT_WORKER_FLEET_LIMITS: Readonly<WorkerFleetLimits> = Object.freeze({\n\tmaxDepth: 8,\n\tmaxAgentsPerSession: MAX_ORCHESTRATION_AGENT_BINDINGS,\n\tmaxChildrenPerAgent: 64,\n\tmaxQueuedDispatches: 256,\n});\n\nexport type NewWorkerAdmission =\n\t| { ok: true; depth: number }\n\t| {\n\t\t\tok: false;\n\t\t\treasonCode:\n\t\t\t\t| \"worker_agent_parent_unknown\"\n\t\t\t\t| \"worker_agent_parent_retired\"\n\t\t\t\t| \"worker_agent_depth_limit_reached\"\n\t\t\t\t| \"worker_agent_child_limit_reached\"\n\t\t\t\t| \"worker_agent_session_limit_reached\";\n\t };\n\nexport type WorkerIdentityHeadroomAdmission =\n\t| { ok: true }\n\t| { ok: false; reasonCode: \"worker_agent_session_limit_reached\" };\n\n/** Subjects whose admitted verifier identity has not yet been materialized. */\nexport function pendingVerifierSubjectTaskIds(\n\tsnapshot: Pick<TaskRuntimeProjection, \"agents\" | \"tasks\" | \"attempts\">,\n): Set<string> {\n\tconst agents = snapshot.agents ?? {};\n\tconst tasks = snapshot.tasks ?? {};\n\tconst attempts = snapshot.attempts ?? {};\n\tconst pending = new Set<string>();\n\tfor (const taskId in tasks) {\n\t\tif (!Object.hasOwn(tasks, taskId)) continue;\n\t\tconst subject = tasks[taskId];\n\t\tif (!subject || subject.verification) continue;\n\t\tlet attempt: AttemptRuntimeState | undefined;\n\t\tfor (let index = subject.attemptIds.length - 1; index >= 0; index -= 1) {\n\t\t\tattempt = attempts[subject.attemptIds[index]!];\n\t\t\tif (attempt) break;\n\t\t}\n\t\tif (!attempt?.dispatch.executionContract?.verifier) continue;\n\t\tif (\n\t\t\tattempt.status === \"queued\" ||\n\t\t\tattempt.status === \"leased\" ||\n\t\t\tattempt.status === \"running\" ||\n\t\t\tattempt.status === \"suspended\" ||\n\t\t\tattempt.result?.nextAction === \"independent_verification_required\"\n\t\t) {\n\t\t\tpending.add(subject.task.taskId);\n\t\t}\n\t}\n\tif (pending.size === 0) return pending;\n\tfor (const taskId in tasks) {\n\t\tif (!Object.hasOwn(tasks, taskId)) continue;\n\t\tconst verifierTask = tasks[taskId];\n\t\tconst verificationOfTaskId = verifierTask?.task.verificationOfTaskId;\n\t\tif (!verifierTask || !verificationOfTaskId || !pending.has(verificationOfTaskId)) continue;\n\t\tlet verifierAttempt: AttemptRuntimeState | undefined;\n\t\tfor (let index = verifierTask.attemptIds.length - 1; index >= 0; index -= 1) {\n\t\t\tverifierAttempt = attempts[verifierTask.attemptIds[index]!];\n\t\t\tif (verifierAttempt) break;\n\t\t}\n\t\tconst verifierAgentId =\n\t\t\tverifierAttempt?.agentId ?? verifierAttempt?.dispatch.logicalLaneId ?? verifierTask.task.taskId;\n\t\tif (agents[verifierAgentId]) pending.delete(verificationOfTaskId);\n\t\tif (pending.size === 0) break;\n\t}\n\treturn pending;\n}\n\n/** Reserve durable identity slots without applying parent depth or direct-child limits. */\nfunction evaluateWorkerIdentityHeadroom(\n\tagents: Readonly<Record<string, AgentBindingContract>>,\n\trequiredAgentSlots: number,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n): WorkerIdentityHeadroomAdmission {\n\tif (!Number.isSafeInteger(requiredAgentSlots) || requiredAgentSlots < 0) {\n\t\tthrow new TypeError(\"requiredAgentSlots must be a non-negative safe integer.\");\n\t}\n\treturn requiredAgentSlots > limits.maxAgentsPerSession - Object.keys(agents).length\n\t\t? { ok: false, reasonCode: \"worker_agent_session_limit_reached\" }\n\t\t: { ok: true };\n}\n\n/**\n * A persistent-agent turn consumes no implementation identity, but its retained immutable contract\n * can still require a fresh verifier. Protect both that verifier and every earlier reservation.\n */\nexport function evaluateReusableWorkerTaskAdmission(\n\tsnapshot: Pick<TaskRuntimeProjection, \"agents\" | \"tasks\" | \"attempts\">,\n\tagentId: string,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n): WorkerIdentityHeadroomAdmission {\n\tconst latestAttempt = latestAgentAttemptByDurableOrder(snapshot, agentId);\n\tconst requiredAgentSlots =\n\t\tpendingVerifierSubjectTaskIds(snapshot).size + (latestAttempt?.dispatch.executionContract?.verifier ? 1 : 0);\n\treturn evaluateWorkerIdentityHeadroom(snapshot.agents, requiredAgentSlots, limits);\n}\n\n/** Evaluate a new durable identity before a task, conversation, or scheduler entry is created. */\nexport function evaluateNewWorkerAdmission(\n\tagents: Readonly<Record<string, AgentBindingContract>>,\n\tparentAgentId?: string,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n\trequiredAgentSlots = 1,\n): NewWorkerAdmission {\n\tif (!Number.isSafeInteger(requiredAgentSlots) || requiredAgentSlots < 1) {\n\t\tthrow new TypeError(\"requiredAgentSlots must be a positive safe integer.\");\n\t}\n\tconst headroom = evaluateWorkerIdentityHeadroom(agents, requiredAgentSlots, limits);\n\tif (!headroom.ok) return headroom;\n\tif (!parentAgentId) return { ok: true, depth: 0 };\n\tconst parent = agents[parentAgentId];\n\tif (!parent) return { ok: false, reasonCode: \"worker_agent_parent_unknown\" };\n\tif (parent.status === \"retired\") return { ok: false, reasonCode: \"worker_agent_parent_retired\" };\n\tconst depth = parent.depth + 1;\n\tif (depth > limits.maxDepth) return { ok: false, reasonCode: \"worker_agent_depth_limit_reached\" };\n\tlet directChildren = 0;\n\tfor (const agent of Object.values(agents)) {\n\t\tif (agent.parentAgentId === parent.agentId) directChildren += 1;\n\t}\n\tif (directChildren >= limits.maxChildrenPerAgent) {\n\t\treturn { ok: false, reasonCode: \"worker_agent_child_limit_reached\" };\n\t}\n\treturn { ok: true, depth };\n}\n\n/** Keep one queue slot reserved for an already-admitted mandatory verifier. */\nexport function workerQueueHasCapacity(\n\tqueuedCount: number,\n\tpriority: boolean,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n): boolean {\n\tif (!Number.isSafeInteger(queuedCount) || queuedCount < 0) return false;\n\tconst ceiling = priority ? limits.maxQueuedDispatches : limits.maxQueuedDispatches - 1;\n\treturn queuedCount < ceiling;\n}\n"]}
1
+ {"version":3,"file":"worker-fleet-limits.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-fleet-limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAEN,gCAAgC,EAChC,6BAA6B,EAC7B,iCAAiC,GAEjC,MAAM,+BAA+B,CAAC;AAevC,MAAM,CAAC,MAAM,2BAA2B,GAAgC,MAAM,CAAC,MAAM,CAAC;IACrF,QAAQ,EAAE,6BAA6B;IACvC,mBAAmB,EAAE,gCAAgC;IACrD,mBAAmB,EAAE,iCAAiC;IACtD,yBAAyB,EAAE,gCAAgC;IAC3D,mBAAmB,EAAE,GAAG;CACxB,CAAC,CAAC;AAEH,iGAAiG;AACjG,MAAM,CAAC,MAAM,6BAA6B,GAA4C,MAAM,CAAC,MAAM,CAAC;IACnG,QAAQ,EAAE,CAAC;IACX,mBAAmB,EAAE,CAAC;IACtB,yBAAyB,EAAE,CAAC;CAC5B,CAAC,CAAC;AAEH,gGAAgG;AAChG,MAAM,UAAU,wBAAwB,CACvC,gBAA0D;IAE1D,OAAO;QACN,GAAG,2BAA2B;QAC9B,QAAQ,EAAE,IAAI,CAAC,GAAG,CACjB,gBAAgB,EAAE,QAAQ,IAAI,2BAA2B,CAAC,QAAQ,EACl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ordering.ts\";\nimport {\n\ttype AgentBindingContract,\n\tMAX_ORCHESTRATION_AGENT_BINDINGS,\n\tMAX_ORCHESTRATION_AGENT_DEPTH,\n\tMAX_ORCHESTRATION_DIRECT_CHILDREN,\n\ttype OrchestrationDelegationLimits,\n} from \"../orchestration/contracts.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\n\n/**\n * Process-independent safety ceilings for one durable session fleet. These limits bound persisted\n * identity growth and scheduler fan-out; model/provider budgets remain separately authoritative.\n */\nexport interface WorkerFleetLimits {\n\tmaxDepth: number;\n\tmaxAgentsPerSession: number;\n\tmaxChildrenPerAgent: number;\n\tmaxNestedAgentsPerSession: number;\n\tmaxQueuedDispatches: number;\n}\n\nexport const DEFAULT_WORKER_FLEET_LIMITS: Readonly<WorkerFleetLimits> = Object.freeze({\n\tmaxDepth: MAX_ORCHESTRATION_AGENT_DEPTH,\n\tmaxAgentsPerSession: MAX_ORCHESTRATION_AGENT_BINDINGS,\n\tmaxChildrenPerAgent: MAX_ORCHESTRATION_DIRECT_CHILDREN,\n\tmaxNestedAgentsPerSession: MAX_ORCHESTRATION_AGENT_BINDINGS,\n\tmaxQueuedDispatches: 256,\n});\n\n/** Profile-free workers get one useful nested identity without an open-ended recursive fleet. */\nexport const LEAN_WORKER_DELEGATION_LIMITS: Readonly<OrchestrationDelegationLimits> = Object.freeze({\n\tmaxDepth: 1,\n\tmaxChildrenPerAgent: 1,\n\tmaxNestedAgentsPerSession: 1,\n});\n\n/** Materialize an optional profile limit inside the process-independent host safety ceiling. */\nexport function resolveWorkerFleetLimits(\n\tdelegationLimits?: Readonly<OrchestrationDelegationLimits>,\n): Readonly<WorkerFleetLimits> {\n\treturn {\n\t\t...DEFAULT_WORKER_FLEET_LIMITS,\n\t\tmaxDepth: Math.min(\n\t\t\tdelegationLimits?.maxDepth ?? DEFAULT_WORKER_FLEET_LIMITS.maxDepth,\n\t\t\tMAX_ORCHESTRATION_AGENT_DEPTH,\n\t\t),\n\t\tmaxChildrenPerAgent: Math.min(\n\t\t\tdelegationLimits?.maxChildrenPerAgent ?? DEFAULT_WORKER_FLEET_LIMITS.maxChildrenPerAgent,\n\t\t\tMAX_ORCHESTRATION_DIRECT_CHILDREN,\n\t\t),\n\t\tmaxNestedAgentsPerSession: Math.min(\n\t\t\tdelegationLimits?.maxNestedAgentsPerSession ?? DEFAULT_WORKER_FLEET_LIMITS.maxNestedAgentsPerSession,\n\t\t\tMAX_ORCHESTRATION_AGENT_BINDINGS,\n\t\t),\n\t};\n}\n\n/** Descendant routing may preserve or narrow an ancestor's recursive authority, never widen it. */\nexport function intersectWorkerDelegationLimits(\n\trequested?: Readonly<OrchestrationDelegationLimits>,\n\tboundary?: Readonly<OrchestrationDelegationLimits>,\n): OrchestrationDelegationLimits | undefined {\n\tif (!requested && !boundary) return undefined;\n\tconst requestedLimits = resolveWorkerFleetLimits(requested);\n\tconst boundaryLimits = resolveWorkerFleetLimits(boundary);\n\treturn {\n\t\tmaxDepth: Math.min(requestedLimits.maxDepth, boundaryLimits.maxDepth),\n\t\tmaxChildrenPerAgent: Math.min(requestedLimits.maxChildrenPerAgent, boundaryLimits.maxChildrenPerAgent),\n\t\tmaxNestedAgentsPerSession: Math.min(\n\t\t\trequestedLimits.maxNestedAgentsPerSession,\n\t\t\tboundaryLimits.maxNestedAgentsPerSession,\n\t\t),\n\t};\n}\n\nexport type NewWorkerAdmission =\n\t| { ok: true; depth: number }\n\t| {\n\t\t\tok: false;\n\t\t\treasonCode:\n\t\t\t\t| \"worker_agent_parent_unknown\"\n\t\t\t\t| \"worker_agent_parent_retired\"\n\t\t\t\t| \"worker_agent_depth_limit_reached\"\n\t\t\t\t| \"worker_agent_child_limit_reached\"\n\t\t\t\t| \"worker_agent_nested_session_limit_reached\"\n\t\t\t\t| \"worker_agent_session_limit_reached\";\n\t };\n\nexport type WorkerIdentityHeadroomAdmission =\n\t| { ok: true }\n\t| { ok: false; reasonCode: \"worker_agent_session_limit_reached\" };\n\n/** Subjects whose admitted verifier identity has not yet been materialized. */\nexport function pendingVerifierSubjectTaskIds(\n\tsnapshot: Pick<TaskRuntimeProjection, \"agents\" | \"tasks\" | \"attempts\">,\n): Set<string> {\n\tconst agents = snapshot.agents ?? {};\n\tconst tasks = snapshot.tasks ?? {};\n\tconst attempts = snapshot.attempts ?? {};\n\tconst pending = new Set<string>();\n\tfor (const taskId in tasks) {\n\t\tif (!Object.hasOwn(tasks, taskId)) continue;\n\t\tconst subject = tasks[taskId];\n\t\tif (!subject || subject.verification) continue;\n\t\tlet attempt: AttemptRuntimeState | undefined;\n\t\tfor (let index = subject.attemptIds.length - 1; index >= 0; index -= 1) {\n\t\t\tattempt = attempts[subject.attemptIds[index]!];\n\t\t\tif (attempt) break;\n\t\t}\n\t\tif (!attempt?.dispatch.executionContract?.verifier) continue;\n\t\tif (\n\t\t\tattempt.status === \"queued\" ||\n\t\t\tattempt.status === \"leased\" ||\n\t\t\tattempt.status === \"running\" ||\n\t\t\tattempt.status === \"suspended\" ||\n\t\t\tattempt.result?.nextAction === \"independent_verification_required\"\n\t\t) {\n\t\t\tpending.add(subject.task.taskId);\n\t\t}\n\t}\n\tif (pending.size === 0) return pending;\n\tfor (const taskId in tasks) {\n\t\tif (!Object.hasOwn(tasks, taskId)) continue;\n\t\tconst verifierTask = tasks[taskId];\n\t\tconst verificationOfTaskId = verifierTask?.task.verificationOfTaskId;\n\t\tif (!verifierTask || !verificationOfTaskId || !pending.has(verificationOfTaskId)) continue;\n\t\tlet verifierAttempt: AttemptRuntimeState | undefined;\n\t\tfor (let index = verifierTask.attemptIds.length - 1; index >= 0; index -= 1) {\n\t\t\tverifierAttempt = attempts[verifierTask.attemptIds[index]!];\n\t\t\tif (verifierAttempt) break;\n\t\t}\n\t\tconst verifierAgentId =\n\t\t\tverifierAttempt?.agentId ?? verifierAttempt?.dispatch.logicalLaneId ?? verifierTask.task.taskId;\n\t\tif (agents[verifierAgentId]) pending.delete(verificationOfTaskId);\n\t\tif (pending.size === 0) break;\n\t}\n\treturn pending;\n}\n\n/** Reserve durable identity slots without applying parent depth or direct-child limits. */\nfunction evaluateWorkerIdentityHeadroom(\n\tagents: Readonly<Record<string, AgentBindingContract>>,\n\trequiredAgentSlots: number,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n): WorkerIdentityHeadroomAdmission {\n\tif (!Number.isSafeInteger(requiredAgentSlots) || requiredAgentSlots < 0) {\n\t\tthrow new TypeError(\"requiredAgentSlots must be a non-negative safe integer.\");\n\t}\n\treturn requiredAgentSlots > limits.maxAgentsPerSession - Object.keys(agents).length\n\t\t? { ok: false, reasonCode: \"worker_agent_session_limit_reached\" }\n\t\t: { ok: true };\n}\n\n/**\n * A persistent-agent turn consumes no implementation identity, but its retained immutable contract\n * can still require a fresh verifier. Protect both that verifier and every earlier reservation.\n */\nexport function evaluateReusableWorkerTaskAdmission(\n\tsnapshot: Pick<TaskRuntimeProjection, \"agents\" | \"tasks\" | \"attempts\">,\n\tagentId: string,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n): WorkerIdentityHeadroomAdmission {\n\tconst latestAttempt = latestAgentAttemptByDurableOrder(snapshot, agentId);\n\tconst requiredAgentSlots =\n\t\tpendingVerifierSubjectTaskIds(snapshot).size + (latestAttempt?.dispatch.executionContract?.verifier ? 1 : 0);\n\treturn evaluateWorkerIdentityHeadroom(snapshot.agents, requiredAgentSlots, limits);\n}\n\n/** Evaluate a new durable identity before a task, conversation, or scheduler entry is created. */\nexport function evaluateNewWorkerAdmission(\n\tagents: Readonly<Record<string, AgentBindingContract>>,\n\tparentAgentId?: string,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n\trequiredAgentSlots = 1,\n): NewWorkerAdmission {\n\tif (!Number.isSafeInteger(requiredAgentSlots) || requiredAgentSlots < 1) {\n\t\tthrow new TypeError(\"requiredAgentSlots must be a positive safe integer.\");\n\t}\n\tconst headroom = evaluateWorkerIdentityHeadroom(agents, requiredAgentSlots, limits);\n\tif (!headroom.ok) return headroom;\n\tif (!parentAgentId) return { ok: true, depth: 0 };\n\tconst parent = agents[parentAgentId];\n\tif (!parent) return { ok: false, reasonCode: \"worker_agent_parent_unknown\" };\n\tif (parent.status === \"retired\") return { ok: false, reasonCode: \"worker_agent_parent_retired\" };\n\tconst depth = parent.depth + 1;\n\tif (depth > limits.maxDepth) return { ok: false, reasonCode: \"worker_agent_depth_limit_reached\" };\n\tlet directChildren = 0;\n\tfor (const agent of Object.values(agents)) {\n\t\tif (agent.parentAgentId === parent.agentId) directChildren += 1;\n\t}\n\tif (directChildren >= limits.maxChildrenPerAgent) {\n\t\treturn { ok: false, reasonCode: \"worker_agent_child_limit_reached\" };\n\t}\n\tlet nestedAgents = 0;\n\tfor (const agent of Object.values(agents)) {\n\t\tif (agent.parentAgentId) nestedAgents += 1;\n\t}\n\tif (nestedAgents >= limits.maxNestedAgentsPerSession) {\n\t\treturn { ok: false, reasonCode: \"worker_agent_nested_session_limit_reached\" };\n\t}\n\treturn { ok: true, depth };\n}\n\n/** Keep one queue slot reserved for an already-admitted mandatory verifier. */\nexport function workerQueueHasCapacity(\n\tqueuedCount: number,\n\tpriority: boolean,\n\tlimits: Readonly<WorkerFleetLimits> = DEFAULT_WORKER_FLEET_LIMITS,\n): boolean {\n\tif (!Number.isSafeInteger(queuedCount) || queuedCount < 0) return false;\n\tconst ceiling = priority ? limits.maxQueuedDispatches : limits.maxQueuedDispatches - 1;\n\treturn queuedCount < ceiling;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"worker-lane-projection.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGnG,e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MAAM,GAAG,UAAU,GAAG,SAAS,CA2C/G;AAED,oEAAoE;AACpE,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,qBAAqB,GAAG,UAAU,EAAE,CAkB7F;AAED,wBAAgB,4BAA4B,CAC3C,QAAQ,EAAE,qBAAqB,EAC/B,aAAa,EAAE,MAAM,GACnB,mBAAmB,GAAG,SAAS,CAQjC"}
@@ -12,6 +12,10 @@ function terminalStatus(attempt) {
12
12
  return "succeeded";
13
13
  if (attempt.status === "cancelled")
14
14
  return "canceled";
15
+ if (attempt.result?.status === "partial")
16
+ return "partial";
17
+ if (attempt.result?.status === "blocked")
18
+ return "blocked";
15
19
  const reasonCode = attempt.result?.reasonCode ?? attempt.reasonCode ?? "";
16
20
  if (reasonCode.includes("budget"))
17
21
  return "budget_exhausted";
@@ -1 +1 @@
1
- {"version":3,"file":"worker-lane-projection.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,CAAC,MAAM,8BAA8B,GAAwB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAC5G,MAAM,CAAC,MAAM,mCAAmC,GAAwB,IAAI,GAAG,CAAC;IAC/E,GAAG,8BAA8B;IACjC,WAAW;CACX,CAAC,CAAC;AAEH,MAAM,UAAU,sBAAsB,CAAC,OAA4B;IAClE,OAAO,OAAO,CAAC,QAAQ,CAAC,aAAa,KAAK,iBAAiB,CAAC;AAC7D,CAAC;AAED,SAAS,cAAc,CAAC,OAA4B;IACnD,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW;QAAE,OAAO,WAAW,CAAC;IACvD,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC;IACtD,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,UAAU,IAAI,OAAO,CAAC,U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C,IAAI,EAAE,KAAK,EAAE,EAAE;QACrB,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;QAChG,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAClF,CAAC,CAAC;SACD,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACV,CAAC","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\nimport { deriveWorkerTaskLabel } from \"./worker-task-label.ts\";\n\nexport const ACTIVE_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\"queued\", \"leased\", \"running\"]);\nexport const NONTERMINAL_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\n\t...ACTIVE_WORKER_ATTEMPT_STATUSES,\n\t\"suspended\",\n]);\n\nexport function isManagedWorkerAttempt(attempt: AttemptRuntimeState): boolean {\n\treturn attempt.dispatch.executionKind === \"managed-process\";\n}\n\nfunction terminalStatus(attempt: AttemptRuntimeState): LaneTerminalStatus {\n\tif (attempt.status === \"completed\") return \"succeeded\";\n\tif (attempt.status === \"cancelled\") return \"canceled\";\n\tconst reasonCode = attempt.result?.reasonCode ?? attempt.reasonCode ?? \"\";\n\tif (reasonCode.includes(\"budget\")) return \"budget_exhausted\";\n\tif (reasonCode.includes(\"timeout\")) return \"timeout\";\n\treturn \"failed\";\n}\n\nexport function selectedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\ttaskId: string,\n): AttemptRuntimeState | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tif (!task) return undefined;\n\tconst attempts = task.attemptIds.map((attemptId) => snapshot.attempts[attemptId]).filter(Boolean);\n\treturn (\n\t\t[...attempts].reverse().find((attempt) => attempt && NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(attempt.status)) ??\n\t\tattempts.at(-1)\n\t);\n}\n\n/**\n * One-way compatibility projection from durable orchestration state. A LaneRecord is never read\n * back to decide lifecycle, retry, verification, or notification transitions.\n */\nexport function projectWorkerLaneRecord(snapshot: TaskRuntimeProjection, taskId: string): LaneRecord | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\tif (!task || !attempt) return undefined;\n\tconst managed = isManagedWorkerAttempt(attempt);\n\tconst objective = snapshot.objectives[task.task.objectiveId];\n\tconst awaitingVerification =\n\t\tattempt.result?.nextAction === \"independent_verification_required\" && task.verification === undefined;\n\tconst status = awaitingVerification\n\t\t? \"running\"\n\t\t: task.verification\n\t\t\t? task.verification.verdict === \"accepted\"\n\t\t\t\t? \"succeeded\"\n\t\t\t\t: \"failed\"\n\t\t\t: attempt.status === \"queued\"\n\t\t\t\t? \"queued\"\n\t\t\t\t: attempt.status === \"leased\" || attempt.status === \"running\" || attempt.status === \"suspended\"\n\t\t\t\t\t? \"running\"\n\t\t\t\t\t: terminalStatus(attempt);\n\tconst reasonCode = task.verification?.reasonCode ?? attempt.result?.reasonCode ?? attempt.reasonCode;\n\tconst genericTitle = `Delegated ${task.task.role} work`;\n\tconst label = deriveWorkerTaskLabel(\n\t\ttask.task.title === genericTitle ? task.task.description : task.task.title,\n\t\tgenericTitle,\n\t);\n\tconst goalId = objective?.objective.objectiveId.startsWith(\"goal:\")\n\t\t? objective.objective.objectiveId.slice(\"goal:\".length)\n\t\t: undefined;\n\treturn {\n\t\tlaneId: managed ? (attempt.dispatch.logicalLaneId ?? taskId) : taskId,\n\t\ttype: managed ? \"tmux-worker\" : \"worker\",\n\t\tstatus,\n\t\tlabel,\n\t\tprofileId: attempt.dispatch.profileId,\n\t\t...(reasonCode ? { reasonCode } : {}),\n\t\t...(attempt.status !== \"queued\" ? { startedAt: attempt.createdAt } : {}),\n\t\t...(status === \"queued\" || status === \"running\"\n\t\t\t? {}\n\t\t\t: { completedAt: task.verification?.completedAt ?? attempt.updatedAt }),\n\t\t...(attempt.result?.usage.costUsd !== undefined ? { costUsd: attempt.result.usage.costUsd } : {}),\n\t\t...(goalId ? { goalId } : {}),\n\t\t...(attempt.dispatch.worktreeLaneKey ? { worktreeLaneKey: attempt.dispatch.worktreeLaneKey } : {}),\n\t};\n}\n\n/** Latest durable turn for each externally managed logical lane. */\nexport function projectManagedWorkerLaneRecords(snapshot: TaskRuntimeProjection): LaneRecord[] {\n\tconst latest = new Map<string, { sequence: number; createdAt: string; record: LaneRecord }>();\n\tfor (const taskId of Object.keys(snapshot.tasks)) {\n\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\tif (!attempt || !isManagedWorkerAttempt(attempt)) continue;\n\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\tif (!record) continue;\n\t\tconst sequence = attempt.dispatch.dispatchSequence ?? 1;\n\t\tconst current = latest.get(record.laneId);\n\t\tif (\n\t\t\t!current ||\n\t\t\tsequence > current.sequence ||\n\t\t\t(sequence === current.sequence && attempt.createdAt.localeCompare(current.createdAt) > 0)\n\t\t) {\n\t\t\tlatest.set(record.laneId, { sequence, createdAt: attempt.createdAt, record });\n\t\t}\n\t}\n\treturn [...latest.values()].map((entry) => entry.record);\n}\n\nexport function selectedManagedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\tlogicalLaneId: string,\n): AttemptRuntimeState | undefined {\n\treturn Object.values(snapshot.attempts)\n\t\t.filter((attempt) => isManagedWorkerAttempt(attempt) && attempt.dispatch.logicalLaneId === logicalLaneId)\n\t\t.sort((left, right) => {\n\t\t\tconst sequence = (left.dispatch.dispatchSequence ?? 1) - (right.dispatch.dispatchSequence ?? 1);\n\t\t\treturn sequence !== 0 ? sequence : left.createdAt.localeCompare(right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CAAC,CAAC;IAClF,CAAC,CAAC;SACD,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACV,CAAC","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\nimport { deriveWorkerTaskLabel } from \"./worker-task-label.ts\";\n\nexport const ACTIVE_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\"queued\", \"leased\", \"running\"]);\nexport const NONTERMINAL_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\n\t...ACTIVE_WORKER_ATTEMPT_STATUSES,\n\t\"suspended\",\n]);\n\nexport function isManagedWorkerAttempt(attempt: AttemptRuntimeState): boolean {\n\treturn attempt.dispatch.executionKind === \"managed-process\";\n}\n\nfunction terminalStatus(attempt: AttemptRuntimeState): LaneTerminalStatus {\n\tif (attempt.status === \"completed\") return \"succeeded\";\n\tif (attempt.status === \"cancelled\") return \"canceled\";\n\tif (attempt.result?.status === \"partial\") return \"partial\";\n\tif (attempt.result?.status === \"blocked\") return \"blocked\";\n\tconst reasonCode = attempt.result?.reasonCode ?? attempt.reasonCode ?? \"\";\n\tif (reasonCode.includes(\"budget\")) return \"budget_exhausted\";\n\tif (reasonCode.includes(\"timeout\")) return \"timeout\";\n\treturn \"failed\";\n}\n\nexport function selectedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\ttaskId: string,\n): AttemptRuntimeState | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tif (!task) return undefined;\n\tconst attempts = task.attemptIds.map((attemptId) => snapshot.attempts[attemptId]).filter(Boolean);\n\treturn (\n\t\t[...attempts].reverse().find((attempt) => attempt && NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(attempt.status)) ??\n\t\tattempts.at(-1)\n\t);\n}\n\n/**\n * One-way compatibility projection from durable orchestration state. A LaneRecord is never read\n * back to decide lifecycle, retry, verification, or notification transitions.\n */\nexport function projectWorkerLaneRecord(snapshot: TaskRuntimeProjection, taskId: string): LaneRecord | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\tif (!task || !attempt) return undefined;\n\tconst managed = isManagedWorkerAttempt(attempt);\n\tconst objective = snapshot.objectives[task.task.objectiveId];\n\tconst awaitingVerification =\n\t\tattempt.result?.nextAction === \"independent_verification_required\" && task.verification === undefined;\n\tconst status = awaitingVerification\n\t\t? \"running\"\n\t\t: task.verification\n\t\t\t? task.verification.verdict === \"accepted\"\n\t\t\t\t? \"succeeded\"\n\t\t\t\t: \"failed\"\n\t\t\t: attempt.status === \"queued\"\n\t\t\t\t? \"queued\"\n\t\t\t\t: attempt.status === \"leased\" || attempt.status === \"running\" || attempt.status === \"suspended\"\n\t\t\t\t\t? \"running\"\n\t\t\t\t\t: terminalStatus(attempt);\n\tconst reasonCode = task.verification?.reasonCode ?? attempt.result?.reasonCode ?? attempt.reasonCode;\n\tconst genericTitle = `Delegated ${task.task.role} work`;\n\tconst label = deriveWorkerTaskLabel(\n\t\ttask.task.title === genericTitle ? task.task.description : task.task.title,\n\t\tgenericTitle,\n\t);\n\tconst goalId = objective?.objective.objectiveId.startsWith(\"goal:\")\n\t\t? objective.objective.objectiveId.slice(\"goal:\".length)\n\t\t: undefined;\n\treturn {\n\t\tlaneId: managed ? (attempt.dispatch.logicalLaneId ?? taskId) : taskId,\n\t\ttype: managed ? \"tmux-worker\" : \"worker\",\n\t\tstatus,\n\t\tlabel,\n\t\tprofileId: attempt.dispatch.profileId,\n\t\t...(reasonCode ? { reasonCode } : {}),\n\t\t...(attempt.status !== \"queued\" ? { startedAt: attempt.createdAt } : {}),\n\t\t...(status === \"queued\" || status === \"running\"\n\t\t\t? {}\n\t\t\t: { completedAt: task.verification?.completedAt ?? attempt.updatedAt }),\n\t\t...(attempt.result?.usage.costUsd !== undefined ? { costUsd: attempt.result.usage.costUsd } : {}),\n\t\t...(goalId ? { goalId } : {}),\n\t\t...(attempt.dispatch.worktreeLaneKey ? { worktreeLaneKey: attempt.dispatch.worktreeLaneKey } : {}),\n\t};\n}\n\n/** Latest durable turn for each externally managed logical lane. */\nexport function projectManagedWorkerLaneRecords(snapshot: TaskRuntimeProjection): LaneRecord[] {\n\tconst latest = new Map<string, { sequence: number; createdAt: string; record: LaneRecord }>();\n\tfor (const taskId of Object.keys(snapshot.tasks)) {\n\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\tif (!attempt || !isManagedWorkerAttempt(attempt)) continue;\n\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\tif (!record) continue;\n\t\tconst sequence = attempt.dispatch.dispatchSequence ?? 1;\n\t\tconst current = latest.get(record.laneId);\n\t\tif (\n\t\t\t!current ||\n\t\t\tsequence > current.sequence ||\n\t\t\t(sequence === current.sequence && attempt.createdAt.localeCompare(current.createdAt) > 0)\n\t\t) {\n\t\t\tlatest.set(record.laneId, { sequence, createdAt: attempt.createdAt, record });\n\t\t}\n\t}\n\treturn [...latest.values()].map((entry) => entry.record);\n}\n\nexport function selectedManagedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\tlogicalLaneId: string,\n): AttemptRuntimeState | undefined {\n\treturn Object.values(snapshot.attempts)\n\t\t.filter((attempt) => isManagedWorkerAttempt(attempt) && attempt.dispatch.logicalLaneId === logicalLaneId)\n\t\t.sort((left, right) => {\n\t\t\tconst sequence = (left.dispatch.dispatchSequence ?? 1) - (right.dispatch.dispatchSequence ?? 1);\n\t\t\treturn sequence !== 0 ? sequence : left.createdAt.localeCompare(right.createdAt);\n\t\t})\n\t\t.at(-1);\n}\n"]}
@@ -0,0 +1,16 @@
1
+ export interface WorkerLeaseHeartbeatOptions {
2
+ leaseTtlMs: number;
3
+ renew(): void;
4
+ onFailure(error: Error): void;
5
+ }
6
+ /** Keeps one live in-process worker fence valid while provider or tool work is suspended. */
7
+ export declare class WorkerLeaseHeartbeat {
8
+ private readonly options;
9
+ private timer;
10
+ private failure;
11
+ constructor(options: WorkerLeaseHeartbeatOptions);
12
+ start(): void;
13
+ stop(): void;
14
+ assertHealthy(): void;
15
+ }
16
+ //# sourceMappingURL=worker-lease-heartbeat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-lease-heartbeat.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lease-heartbeat.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,2BAA2B;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,IAAI,IAAI,CAAC;IACd,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CAC9B;AAID,6FAA6F;AAC7F,qBAAa,oBAAoB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,KAAK,CAA6C;IAC1D,OAAO,CAAC,OAAO,CAAoB;IAEnC,YAAY,OAAO,EAAE,2BAA2B,EAK/C;IAED,KAAK,IAAI,IAAI,CAaZ;IAED,IAAI,IAAI,IAAI,CAIX;IAED,aAAa,IAAI,IAAI,CAEpB;CACD"}
@@ -0,0 +1,37 @@
1
+ const MAX_HOST_TIMER_DELAY_MS = 2_147_483_647;
2
+ /** Keeps one live in-process worker fence valid while provider or tool work is suspended. */
3
+ export class WorkerLeaseHeartbeat {
4
+ constructor(options) {
5
+ if (!Number.isSafeInteger(options.leaseTtlMs) || options.leaseTtlMs <= 0) {
6
+ throw new Error("Worker lease heartbeat TTL must be a positive safe integer.");
7
+ }
8
+ this.options = options;
9
+ }
10
+ start() {
11
+ if (this.timer || this.failure)
12
+ return;
13
+ const intervalMs = Math.min(MAX_HOST_TIMER_DELAY_MS, Math.max(1, Math.floor(this.options.leaseTtlMs / 3)));
14
+ this.timer = setInterval(() => {
15
+ try {
16
+ this.options.renew();
17
+ }
18
+ catch (error) {
19
+ this.failure = error instanceof Error ? error : new Error(String(error));
20
+ this.stop();
21
+ this.options.onFailure(this.failure);
22
+ }
23
+ }, intervalMs);
24
+ this.timer.unref();
25
+ }
26
+ stop() {
27
+ if (!this.timer)
28
+ return;
29
+ clearInterval(this.timer);
30
+ this.timer = undefined;
31
+ }
32
+ assertHealthy() {
33
+ if (this.failure)
34
+ throw this.failure;
35
+ }
36
+ }
37
+ //# sourceMappingURL=worker-lease-heartbeat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-lease-heartbeat.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-lease-heartbeat.ts"],"names":[],"mappings":"AAMA,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAE9C,6FAA6F;AAC7F,MAAM,OAAO,oBAAoB;IAKhC,YAAY,OAAoC;QAC/C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,EAAE,CAAC;YAC1E,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,KAAK;QACJ,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACvC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3G,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC7B,IAAI,CAAC;gBACJ,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACtB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,CAAC,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBACzE,IAAI,CAAC,IAAI,EAAE,CAAC;gBACZ,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtC,CAAC;QACF,CAAC,EAAE,UAAU,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,IAAI;QACH,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO;QACxB,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACxB,CAAC;IAED,aAAa;QACZ,IAAI,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,CAAC,OAAO,CAAC;IACtC,CAAC;CACD","sourcesContent":["export interface WorkerLeaseHeartbeatOptions {\n\tleaseTtlMs: number;\n\trenew(): void;\n\tonFailure(error: Error): void;\n}\n\nconst MAX_HOST_TIMER_DELAY_MS = 2_147_483_647;\n\n/** Keeps one live in-process worker fence valid while provider or tool work is suspended. */\nexport class WorkerLeaseHeartbeat {\n\tprivate readonly options: WorkerLeaseHeartbeatOptions;\n\tprivate timer: ReturnType<typeof setInterval> | undefined;\n\tprivate failure: Error | undefined;\n\n\tconstructor(options: WorkerLeaseHeartbeatOptions) {\n\t\tif (!Number.isSafeInteger(options.leaseTtlMs) || options.leaseTtlMs <= 0) {\n\t\t\tthrow new Error(\"Worker lease heartbeat TTL must be a positive safe integer.\");\n\t\t}\n\t\tthis.options = options;\n\t}\n\n\tstart(): void {\n\t\tif (this.timer || this.failure) return;\n\t\tconst intervalMs = Math.min(MAX_HOST_TIMER_DELAY_MS, Math.max(1, Math.floor(this.options.leaseTtlMs / 3)));\n\t\tthis.timer = setInterval(() => {\n\t\t\ttry {\n\t\t\t\tthis.options.renew();\n\t\t\t} catch (error) {\n\t\t\t\tthis.failure = error instanceof Error ? error : new Error(String(error));\n\t\t\t\tthis.stop();\n\t\t\t\tthis.options.onFailure(this.failure);\n\t\t\t}\n\t\t}, intervalMs);\n\t\tthis.timer.unref();\n\t}\n\n\tstop(): void {\n\t\tif (!this.timer) return;\n\t\tclearInterval(this.timer);\n\t\tthis.timer = undefined;\n\t}\n\n\tassertHealthy(): void {\n\t\tif (this.failure) throw this.failure;\n\t}\n}\n"]}
@@ -72,6 +72,7 @@ export declare class WorkerLifecycle {
72
72
  synchronizeGoalState(goal: GoalState): LaneRecord[];
73
73
  start(laneId: string, leaseTtlMs: number): StartedDelegationAttempt;
74
74
  startAgent(laneId: string, agentId: string, leaseTtlMs: number, ownerId?: string): StartedDelegationAttempt;
75
+ renewLease(laneId: string, leaseTtlMs: number): import("../orchestration/contracts.ts").AttemptLease;
75
76
  checkpoint(laneId: string, input: {
76
77
  summary: string;
77
78
  artifactIds?: readonly string[];
@@ -1 +1 @@
1
- {"version":3,"file":"worker-lifecycle.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGxD,OAAO,KAAK,EACX,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,oBAAoB,EACpB,UAAU,EACV,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,6BAA6B,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAClC,KAAK,wBAAwB,EAC7B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EACX,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,MAAM,kCAAkC,CAAC;AAa1C,MAAM,MAAM,2BAA2B,GACpC;IACA,MAAM,EAAE,UAAU,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,EAAE,MAAM,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE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QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,GAAG,WAAW,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,GAAG,SAAS,CAS7F;IAED,0BAA0B,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAEnE;IAED,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,2BAA2B;IAenC,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,2BAA2B;CAmBnC"}
1
+ {"version":3,"file":"worker-lifecycle.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGxD,OAAO,KAAK,EACX,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,oBAAoB,EACpB,UAAU,EACV,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,6BAA6B,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAClC,KAAK,wBAAwB,EAC7B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EACX,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,MAAM,kCAAkC,CAAC;AAa1C,MAAM,MAAM,2BAA2B,GACpC;IACA,MAAM,EAAE,UAAU,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,EAAE,MAAM,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,yBAAyB,CAAC,EAAE,uBAAuB,CAAC;CACnD,GACD;IACA,MAAM,EAAE,WAAW,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAA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UAAU,CAAA;KAAE,GAAG,SAAS,CAS7F;IAED,0BAA0B,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAEnE;IAED,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,2BAA2B;IAenC,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,2BAA2B;CAmBnC"}
@@ -128,6 +128,12 @@ export class WorkerLifecycle {
128
128
  const attempt = this.requireActiveAttempt(laneId);
129
129
  return this.ledger.start(attempt.attemptId, leaseTtlMs, ownerId, agentId);
130
130
  }
131
+ renewLease(laneId, leaseTtlMs) {
132
+ const attempt = this.requireActiveAttempt(laneId);
133
+ if (!attempt.lease)
134
+ throw new Error(`Durable worker '${laneId}' has no live lease.`);
135
+ return this.ledger.runtime.renewAttemptLease(attempt.attemptId, attempt.lease.leaseId, attempt.lease.fencingToken, leaseTtlMs);
136
+ }
131
137
  checkpoint(laneId, input) {
132
138
  const attempt = this.requireActiveAttempt(laneId);
133
139
  if (!attempt.lease)
@@ -1 +1 @@
1
- {"version":3,"file":"worker-lifecycle.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-lifecycle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AAWxF,OAAO,EACN,6BAA6B,GAI7B,MAAM,uCAAuC,CAAC;AAM/C,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC;AAChG,OAAO,EACN,8BAA8B,EAC9B,sBAAsB,EACtB,mCAAmC,EACnC,+BAA+B,EAC/B,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,mCAAmC,EAAE,MAAM,2BAA2B,CAAC;AAoBrG;;;GAGG;AACH,MAAM,OAAO,eAAe;IAK3B,YAA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AM,CAAC,KAAK,CACvB,OAAO,CAAC,SAAS,EACjB,UAAU,EACV,WAAW,OAAO,CAAC,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAC7D,CAAC;IACH,CAAC;CACD","sourcesContent":["import type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { GoalState } from \"../goals/goal-state.ts\";\nimport { sameAgentResumeIdentity } from \"../orchestration/agent-resume.ts\";\nimport { latestAgentAttemptByDurableOrder } from \"../orchestration/attempt-ordering.ts\";\nimport type {\n\tAgentBindingContract,\n\tAgentResumeContext,\n\tAttemptRetryState,\n\tAttemptUsageSnapshot,\n\tExecutionGrant,\n\tWorkerExecutionContract,\n\tWorkerResultContract,\n\tWorkerRole,\n} from \"../orchestration/contracts.ts\";\nimport {\n\tDelegationOrchestrationLedger,\n\ttype PrepareDelegationInput,\n\ttype PrepareManagedDelegationInput,\n\ttype StartedDelegationAttempt,\n} from \"../orchestration/delegation-ledger.ts\";\nimport type {\n\tAttemptDispatchReadiness,\n\tAttemptRuntimeState,\n\tTaskRuntimeProjection,\n} from \"../orchestration/task-runtime.ts\";\nimport { verifierWorkerExecutionContract } from \"../orchestration/worker-execution-contract.ts\";\nimport {\n\tACTIVE_WORKER_ATTEMPT_STATUSES,\n\tisManagedWorkerAttempt,\n\tNONTERMINAL_WORKER_ATTEMPT_STATUSES,\n\tprojectManagedWorkerLaneRecords,\n\tprojectWorkerLaneRecord,\n\tselectedManagedWorkerAttempt,\n\tselectedWorkerAttempt,\n} from \"./worker-lane-projection.ts\";\nimport { isLocalProcessAlive, isLocalWorkerProcessOwnerProvenDead } from \"./worker-process-owner.ts\";\n\nexport type PendingVerificationRecovery =\n\t| {\n\t\t\taction: \"dispatch\";\n\t\t\tsubjectTaskId: string;\n\t\t\timplementationProfileId: string;\n\t\t\tsummary: string;\n\t\t\tartifactUris: readonly string[];\n\t\t\tverifierExecutionContract?: WorkerExecutionContract;\n\t }\n\t| {\n\t\t\taction: \"reconcile\";\n\t\t\tsubjectTaskId: string;\n\t\t\tverifierTaskId: string;\n\t\t\tverifierAttemptId: string;\n\t\t\tverdict: \"accepted\" | \"rejected\" | \"inconclusive\";\n\t\t\treasonCode: string;\n\t };\n\n/**\n * Sole owner of in-process worker lifecycle state. LaneRecord is a compatibility/UI projection;\n * all transitions are committed through DurableTaskRuntime before the projection is returned.\n */\nexport class WorkerLifecycle {\n\treadonly ledger: DelegationOrchestrationLedger;\n\tprivate nextLaneNumber: number;\n\tprivate readonly isProcessAlive: (pid: number) => boolean;\n\n\tconstructor(options: {\n\t\tagentDir: string;\n\t\tsessionId: string;\n\t\tisProcessAlive?: (pid: number) => boolean;\n\t\tnow?: () => number;\n\t}) {\n\t\tthis.ledger = new DelegationOrchestrationLedger(options);\n\t\tthis.isProcessAlive = options.isProcessAlive ?? isLocalProcessAlive;\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tconst highest = Object.keys(snapshot.tasks).reduce((current, taskId) => {\n\t\t\tconst suffix = /^worker-(\\d+)$/.exec(taskId)?.[1];\n\t\t\treturn suffix ? Math.max(current, Number(suffix)) : current;\n\t\t}, 0);\n\t\tthis.nextLaneNumber = highest + 1;\n\t}\n\n\tprepare(\n\t\tinput: Omit<PrepareDelegationInput, \"laneId\">,\n\t\tlaneId?: string,\n\t): {\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t} {\n\t\tlet selectedLaneId = laneId;\n\t\tconst generatedLaneId = !selectedLaneId;\n\t\tif (!selectedLaneId) {\n\t\t\tselectedLaneId = this.getNextAvailableLaneIdCandidate();\n\t\t}\n\t\tconst attempt = this.ledger.prepare({ ...input, laneId: selectedLaneId });\n\t\tif (generatedLaneId) this.nextLaneNumber = Number(selectedLaneId.slice(\"worker-\".length)) + 1;\n\t\tconst record = this.getRecord(selectedLaneId);\n\t\tif (!record) throw new Error(`Durable worker '${selectedLaneId}' was not projected after enqueue.`);\n\t\treturn { record, attempt };\n\t}\n\n\t/** Return the next generated lane id without reserving it or changing lifecycle state. */\n\tgetNextAvailableLaneIdCandidate(): string {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tlet candidateNumber = this.nextLaneNumber;\n\t\twhile (snapshot.tasks[`worker-${candidateNumber}`]) candidateNumber += 1;\n\t\treturn `worker-${candidateNumber}`;\n\t}\n\n\t/** Queue the next distinct task/attempt for an idle logical agent. */\n\tprepareAgentTurn(input: {\n\t\tagentId: string;\n\t\tinstructions: string;\n\t\tcontrolMessageId?: string;\n\t\tdependsOnTaskIds?: readonly string[];\n\t}): {\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t} {\n\t\tconst attempt = this.ledger.prepareAgentTurn(input);\n\t\tconst record = this.getRecord(attempt.taskId);\n\t\tif (!record) throw new Error(`Logical worker '${input.agentId}' turn was not projected after enqueue.`);\n\t\treturn { record, attempt };\n\t}\n\n\tensureAgent(input: {\n\t\tagentId: string;\n\t\tparentAgentId?: string;\n\t\trole: WorkerRole;\n\t\tresumeContext: AgentResumeContext;\n\t}): AgentBindingContract {\n\t\tconst agentId = input.agentId.trim();\n\t\tconst existing = this.ledger.runtime.getSnapshot().agents[agentId];\n\t\tif (!existing) return this.ledger.runtime.registerAgent(input);\n\t\tif (\n\t\t\texisting.role !== input.role ||\n\t\t\texisting.parentAgentId !== input.parentAgentId ||\n\t\t\t!sameAgentResumeIdentity(existing.resumeContext, input.resumeContext)\n\t\t) {\n\t\t\tthrow new Error(`Agent '${agentId}' was re-registered with conflicting identity.`);\n\t\t}\n\t\treturn existing;\n\t}\n\n\t/** Retire one idle logical worker while retaining its durable binding and transcript identity. */\n\tretireAgent(agentId: string): AgentBindingContract {\n\t\treturn this.ledger.runtime.retireAgent(agentId);\n\t}\n\n\tprepareManaged(\n\t\tinput: PrepareManagedDelegationInput & {\n\t\t\tleaseTtlMs: number;\n\t\t\tcompileGrant(target: { objectiveId: string; taskId: string; attemptId: string }): ExecutionGrant;\n\t\t},\n\t): {\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t\thandle: StartedDelegationAttempt;\n\t\tcreated: boolean;\n\t} {\n\t\tconst before = selectedManagedWorkerAttempt(this.ledger.runtime.getSnapshot(), input.laneId);\n\t\tif (before?.dispatch.dispatchSequence === input.dispatchSequence) {\n\t\t\tif (\n\t\t\t\tbefore.dispatch.provider !== \"legacy\" &&\n\t\t\t\t(before.dispatch.instructions !== input.instructions ||\n\t\t\t\t\tbefore.dispatch.profileId !== input.profileId ||\n\t\t\t\t\tbefore.dispatch.provider !== input.provider ||\n\t\t\t\t\tbefore.dispatch.worktreeLaneKey !== input.worktreeLaneKey ||\n\t\t\t\t\tbefore.dispatch.authorizationId !== input.authorizationId)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Managed worker '${input.laneId}' turn ${input.dispatchSequence} was re-reported with conflicting dispatch data.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (before.status === \"queued\") {\n\t\t\t\tconst handle = this.startPreparedManagedAttempt(before, input.leaseTtlMs, input.compileGrant);\n\t\t\t\tconst record = this.getManagedRecord(input.laneId);\n\t\t\t\tif (!record) throw new Error(`Managed worker '${input.laneId}' was not projected.`);\n\t\t\t\treturn {\n\t\t\t\t\trecord,\n\t\t\t\t\tattempt: this.ledger.runtime.getSnapshot().attempts[before.attemptId]!,\n\t\t\t\t\thandle,\n\t\t\t\t\tcreated: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst record = this.getManagedRecord(input.laneId);\n\t\t\tif (!record) throw new Error(`Managed worker '${input.laneId}' was not projected.`);\n\t\t\tif (!before.lease) throw new Error(`Managed worker '${input.laneId}' has no durable lease.`);\n\t\t\treturn {\n\t\t\t\trecord,\n\t\t\t\tattempt: before,\n\t\t\t\thandle: this.startedHandle(before),\n\t\t\t\tcreated: false,\n\t\t\t};\n\t\t}\n\t\tif (before && ACTIVE_WORKER_ATTEMPT_STATUSES.has(before.status)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Managed worker '${input.laneId}' cannot dispatch turn ${input.dispatchSequence} while turn ${before.dispatch.dispatchSequence ?? 1} is active.`,\n\t\t\t);\n\t\t}\n\t\tconst attempt = this.ledger.prepareManaged(input);\n\t\tconst handle = this.startPreparedManagedAttempt(attempt, input.leaseTtlMs, input.compileGrant);\n\t\tconst record = this.getManagedRecord(input.laneId);\n\t\tif (!record) throw new Error(`Managed worker '${input.laneId}' was not projected after dispatch.`);\n\t\treturn { record, attempt: this.ledger.runtime.getSnapshot().attempts[attempt.attemptId]!, handle, created: true };\n\t}\n\n\tsynchronizeGoalState(goal: GoalState): LaneRecord[] {\n\t\tconst before = new Map(this.getRecords().map((record) => [record.laneId, record.status]));\n\t\tthis.ledger.synchronizeGoalState(goal);\n\t\treturn this.getRecords().filter((record) => {\n\t\t\tconst previous = before.get(record.laneId);\n\t\t\treturn (\n\t\t\t\t(previous === \"queued\" || previous === \"running\") &&\n\t\t\t\trecord.status !== \"queued\" &&\n\t\t\t\trecord.status !== \"running\"\n\t\t\t);\n\t\t});\n\t}\n\n\tstart(laneId: string, leaseTtlMs: number): StartedDelegationAttempt {\n\t\tconst attempt = this.requireActiveAttempt(laneId);\n\t\treturn this.ledger.start(attempt.attemptId, leaseTtlMs);\n\t}\n\n\tstartAgent(laneId: string, agentId: string, leaseTtlMs: number, ownerId = agentId): StartedDelegationAttempt {\n\t\tconst attempt = this.requireActiveAttempt(laneId);\n\t\treturn this.ledger.start(attempt.attemptId, leaseTtlMs, ownerId, agentId);\n\t}\n\n\tcheckpoint(\n\t\tlaneId: string,\n\t\tinput: {\n\t\t\tsummary: string;\n\t\t\tartifactIds?: readonly string[];\n\t\t\tevidenceIds?: readonly string[];\n\t\t\tusage?: AttemptUsageSnapshot;\n\t\t},\n\t) {\n\t\tconst attempt = this.requireActiveAttempt(laneId);\n\t\tif (!attempt.lease) throw new Error(`Durable worker '${laneId}' has no live lease.`);\n\t\treturn this.ledger.runtime.checkpointAttempt({\n\t\t\tattemptId: attempt.attemptId,\n\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\tsummary: input.summary,\n\t\t\t...(input.artifactIds ? { artifactIds: input.artifactIds } : {}),\n\t\t\t...(input.evidenceIds ? { evidenceIds: input.evidenceIds } : {}),\n\t\t\t...(input.usage ? { usage: input.usage } : {}),\n\t\t});\n\t}\n\n\t/**\n\t * Suspend only attempts whose exact controller owner is known (explicit shutdown) or whose\n\t * recorded local owner PID is proven gone (recovery). A live/unknown owner is never stolen.\n\t */\n\tsuspendBoundInProcessAttemptsForRestart(ownerId?: string): string[] {\n\t\tconst suspended: string[] = [];\n\t\tfor (const attempt of Object.values(this.ledger.runtime.getSnapshot().attempts)) {\n\t\t\tif (\n\t\t\t\t(attempt.status !== \"leased\" && attempt.status !== \"running\") ||\n\t\t\t\t!attempt.agentId ||\n\t\t\t\tattempt.dispatch.executionKind === \"managed-process\" ||\n\t\t\t\t!attempt.lease\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst ownsAttempt =\n\t\t\t\townerId !== undefined\n\t\t\t\t\t? attempt.lease.ownerId === ownerId\n\t\t\t\t\t: isLocalWorkerProcessOwnerProvenDead(attempt.lease.ownerId, this.isProcessAlive);\n\t\t\tif (!ownsAttempt) continue;\n\t\t\tthis.suspendBoundAttempt({\n\t\t\t\tlaneId: attempt.taskId,\n\t\t\t\townerId: attempt.lease.ownerId,\n\t\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\t\treasonCode:\n\t\t\t\t\townerId === undefined ? \"agent_process_recovered_after_owner_exit\" : \"agent_process_interrupted\",\n\t\t\t});\n\t\t\tsuspended.push(attempt.attemptId);\n\t\t}\n\t\treturn suspended;\n\t}\n\n\t/**\n\t * Applies an explicitly authorized restart suspension. The caller must identify both the logical\n\t * lane and the current lease fence; process liveness policy is intentionally kept by this class.\n\t */\n\tsuspendBoundAttempt(args: {\n\t\tlaneId: string;\n\t\townerId: string;\n\t\tleaseId: string;\n\t\tfencingToken: number;\n\t\treasonCode: string;\n\t\tretry?: AttemptRetryState;\n\t}): void {\n\t\tconst attempt = this.getActiveAttempt(args.laneId);\n\t\tif (!attempt || !attempt.agentId || !attempt.lease) {\n\t\t\tthrow new Error(`Durable worker '${args.laneId}' has no live agent-bound attempt for suspension.`);\n\t\t}\n\t\tthis.ledger.runtime.suspendBoundAttempt({\n\t\t\tattemptId: attempt.attemptId,\n\t\t\townerId: args.ownerId,\n\t\t\tleaseId: args.leaseId,\n\t\t\tfencingToken: args.fencingToken,\n\t\t\treasonCode: args.reasonCode,\n\t\t\t...(args.retry ? { retry: args.retry } : {}),\n\t\t});\n\t}\n\n\tresumeAgent(laneId: string, agentId: string, leaseTtlMs: number, ownerId = agentId): StartedDelegationAttempt {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt) throw new Error(`Durable worker '${laneId}' has no resumable attempt.`);\n\t\tthis.ledger.runtime.assertAttemptReadyForResume(attempt.attemptId);\n\t\tthis.ledger.runtime.requestAgentResume(agentId, attempt.attemptId);\n\t\tconst lease = this.ledger.runtime.resumeAttempt(attempt.attemptId, agentId, leaseTtlMs, ownerId);\n\t\treturn this.startedHandle(this.ledger.runtime.startAttempt(attempt.attemptId, lease.leaseId, lease.fencingToken));\n\t}\n\n\tsuspendAgent(\n\t\tlaneId: string,\n\t\tagentId: string,\n\t\townerId: string,\n\t\treasonCode = \"agent_interrupted\",\n\t\tretry?: AttemptRetryState,\n\t): void {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt || attempt.agentId !== agentId || !attempt.lease) {\n\t\t\tthrow new Error(`Logical worker '${agentId}' has no live attempt for interruption.`);\n\t\t}\n\t\tthis.suspendBoundAttempt({\n\t\t\tlaneId,\n\t\t\townerId,\n\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\treasonCode,\n\t\t\t...(retry ? { retry } : {}),\n\t\t});\n\t}\n\n\tscheduleAgentRetry(args: {\n\t\tlaneId: string;\n\t\tagentId: string;\n\t\townerId: string;\n\t\treasonCode: string;\n\t\tretry: AttemptRetryState;\n\t}): AttemptRuntimeState {\n\t\tthis.suspendAgent(args.laneId, args.agentId, args.ownerId, args.reasonCode, args.retry);\n\t\tconst attempt = this.getActiveAttempt(args.laneId);\n\t\tif (!attempt) throw new Error(`Durable worker '${args.laneId}' disappeared after retry suspension.`);\n\t\treturn attempt;\n\t}\n\n\tbindGrant(attemptId: string, grant: ExecutionGrant): void {\n\t\tthis.ledger.runtime.bindAttemptGrant(attemptId, grant);\n\t}\n\n\tfinish(result: WorkerResultContract, options: { notify?: boolean } = {}): LaneRecord {\n\t\tthis.ledger.runtime.finishAttempt(result);\n\t\tconst record = this.getRecord(result.taskId);\n\t\tif (!record) throw new Error(`Durable worker '${result.taskId}' was not projected after completion.`);\n\t\tif (options.notify !== false) this.enqueueTerminalNotification(record);\n\t\treturn record;\n\t}\n\n\treconcileVerification(args: {\n\t\tsubjectTaskId: string;\n\t\tverifierTaskId: string;\n\t\tverifierAttemptId: string;\n\t\tverdict: \"accepted\" | \"rejected\" | \"inconclusive\";\n\t\treasonCode: string;\n\t}): LaneRecord {\n\t\tthis.ledger.runtime.finishVerification({\n\t\t\ttaskId: args.subjectTaskId,\n\t\t\tverifierTaskId: args.verifierTaskId,\n\t\t\tverifierAttemptId: args.verifierAttemptId,\n\t\t\tverdict: args.verdict,\n\t\t\treasonCode: args.reasonCode,\n\t\t});\n\t\tconst subject = this.getRecord(args.subjectTaskId);\n\t\tif (!subject) throw new Error(`Verified worker '${args.subjectTaskId}' was not projected.`);\n\t\tthis.enqueueTerminalNotification(subject);\n\t\treturn subject;\n\t}\n\n\tcancel(laneId: string, reasonCode: string): LaneRecord | undefined {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt) return this.getRecord(laneId);\n\t\tthis.ledger.cancel(attempt.attemptId, reasonCode);\n\t\tconst record = this.getRecord(laneId);\n\t\tif (record) this.enqueueTerminalNotification(record);\n\t\treturn record;\n\t}\n\n\trecoverQueued(): Array<{\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t\tverificationOfTaskId?: string;\n\t}> {\n\t\treturn this.ledger.recoverQueuedDispatches().flatMap((attempt) => {\n\t\t\tif (isManagedWorkerAttempt(attempt)) return [];\n\t\t\tconst record = this.getRecord(attempt.taskId);\n\t\t\tconst task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId]?.task;\n\t\t\treturn record\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trecord,\n\t\t\t\t\t\t\tattempt,\n\t\t\t\t\t\t\t...(task?.verificationOfTaskId ? { verificationOfTaskId: task.verificationOfTaskId } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [];\n\t\t});\n\t}\n\n\t/** Close crash windows between implementation completion, verifier dispatch, and reconciliation. */\n\tgetPendingVerificationRecoveries(): PendingVerificationRecovery[] {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.values(snapshot.tasks).flatMap<PendingVerificationRecovery>((subject) => {\n\t\t\tif (subject.verification) return [];\n\t\t\tconst implementationAttempt = selectedWorkerAttempt(snapshot, subject.task.taskId);\n\t\t\tif (implementationAttempt?.result?.nextAction !== \"independent_verification_required\") return [];\n\t\t\tconst verifier = Object.values(snapshot.tasks)\n\t\t\t\t.filter((candidate) => candidate.task.verificationOfTaskId === subject.task.taskId)\n\t\t\t\t.at(-1);\n\t\t\tif (!verifier) {\n\t\t\t\tconst verifierExecutionContract = implementationAttempt.dispatch.executionContract\n\t\t\t\t\t? verifierWorkerExecutionContract(implementationAttempt.dispatch.executionContract)\n\t\t\t\t\t: undefined;\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\taction: \"dispatch\" as const,\n\t\t\t\t\t\tsubjectTaskId: subject.task.taskId,\n\t\t\t\t\t\timplementationProfileId: implementationAttempt.dispatch.profileId,\n\t\t\t\t\t\tsummary: implementationAttempt.result.summary,\n\t\t\t\t\t\tartifactUris: implementationAttempt.result.artifacts.map((artifact) => artifact.uri),\n\t\t\t\t\t\t...(verifierExecutionContract ? { verifierExecutionContract } : {}),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\tconst verifierAttempt = selectedWorkerAttempt(snapshot, verifier.task.taskId);\n\t\t\tif (!verifierAttempt || NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(verifierAttempt.status)) return [];\n\t\t\tconst review = verifierAttempt.result?.evidence.find(\n\t\t\t\t(evidence) =>\n\t\t\t\t\tevidence.trusted &&\n\t\t\t\t\tevidence.kind === \"review\" &&\n\t\t\t\t\tevidence.metadata?.subjectTaskId === subject.task.taskId &&\n\t\t\t\t\t(evidence.metadata.verdict === \"accepted\" || evidence.metadata.verdict === \"rejected\"),\n\t\t\t);\n\t\t\tconst verdictValue = review?.metadata?.verdict;\n\t\t\tconst verdict = verdictValue === \"accepted\" || verdictValue === \"rejected\" ? verdictValue : \"inconclusive\";\n\t\t\tconst reasonCodesValue = review?.metadata?.reasonCodes;\n\t\t\tconst reasonCodes = Array.isArray(reasonCodesValue)\n\t\t\t\t? reasonCodesValue.filter((reasonCode): reasonCode is string => typeof reasonCode === \"string\")\n\t\t\t\t: [];\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\taction: \"reconcile\" as const,\n\t\t\t\t\tsubjectTaskId: subject.task.taskId,\n\t\t\t\t\tverifierTaskId: verifier.task.taskId,\n\t\t\t\t\tverifierAttemptId: verifierAttempt.attemptId,\n\t\t\t\t\tverdict,\n\t\t\t\t\treasonCode:\n\t\t\t\t\t\tverdict === \"accepted\"\n\t\t\t\t\t\t\t? \"independent_verification_accepted\"\n\t\t\t\t\t\t\t: verdict === \"rejected\"\n\t\t\t\t\t\t\t\t? `independent_verification_rejected:${reasonCodes.join(\",\") || \"unspecified\"}`\n\t\t\t\t\t\t\t\t: `independent_verification_inconclusive:${verifierAttempt.reasonCode ?? verifierAttempt.result?.reasonCode ?? \"interrupted\"}`,\n\t\t\t\t},\n\t\t\t];\n\t\t});\n\t}\n\n\tgetTask(taskId: string): TaskRuntimeProjection[\"tasks\"][string] | undefined {\n\t\treturn this.ledger.runtime.getSnapshot().tasks[taskId];\n\t}\n\n\tgetAgent(agentId: string): AgentBindingContract | undefined {\n\t\treturn this.ledger.runtime.getSnapshot().agents[agentId];\n\t}\n\n\tgetLatestAgentAttempt(agentId: string): AttemptRuntimeState | undefined {\n\t\treturn latestAgentAttemptByDurableOrder(this.ledger.runtime.getSnapshot(), agentId);\n\t}\n\n\tgetTaskRuntimeSnapshot(): TaskRuntimeProjection {\n\t\treturn this.ledger.runtime.getSnapshot();\n\t}\n\n\t/** Read-only dispatch gate for an already persisted queued worker attempt. */\n\tgetAttemptDispatchReadiness(attemptId: string): AttemptDispatchReadiness {\n\t\treturn this.ledger.runtime.getAttemptDispatchReadiness(attemptId);\n\t}\n\n\tgetRecords(): LaneRecord[] {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.keys(snapshot.tasks).flatMap((taskId) => {\n\t\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\t\tif (!attempt || isManagedWorkerAttempt(attempt)) return [];\n\t\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\t\treturn record ? [record] : [];\n\t\t});\n\t}\n\n\tgetManagedRecords(): LaneRecord[] {\n\t\treturn projectManagedWorkerLaneRecords(this.ledger.runtime.getSnapshot());\n\t}\n\n\tgetAllRecords(): LaneRecord[] {\n\t\treturn [...this.getRecords(), ...this.getManagedRecords()];\n\t}\n\n\tgetRecord(laneId: string): LaneRecord | undefined {\n\t\treturn projectWorkerLaneRecord(this.ledger.runtime.getSnapshot(), laneId);\n\t}\n\n\tgetManagedRecord(laneId: string): LaneRecord | undefined {\n\t\treturn this.getManagedRecords().find((record) => record.laneId === laneId);\n\t}\n\n\tgetManagedAttempt(laneId: string): AttemptRuntimeState | undefined {\n\t\treturn selectedManagedWorkerAttempt(this.ledger.runtime.getSnapshot(), laneId);\n\t}\n\n\tgetManagedHandle(laneId: string): StartedDelegationAttempt | undefined {\n\t\tconst attempt = this.getManagedAttempt(laneId);\n\t\treturn attempt?.lease ? this.startedHandle(attempt) : undefined;\n\t}\n\n\tgetActiveAttempt(laneId: string): AttemptRuntimeState | undefined {\n\t\treturn selectedWorkerAttempt(this.ledger.runtime.getSnapshot(), laneId);\n\t}\n\n\tgetAttemptUsage(laneId: string): AttemptUsageSnapshot | undefined {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\treturn attempt ? this.ledger.getAttemptUsage(attempt.attemptId) : undefined;\n\t}\n\n\tgetRunningCount(profileId?: string): number {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.keys(snapshot.tasks).filter((taskId) => {\n\t\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\t\treturn (\n\t\t\t\tattempt?.status === \"running\" &&\n\t\t\t\t!isManagedWorkerAttempt(attempt) &&\n\t\t\t\t(!profileId || attempt.dispatch.profileId === profileId)\n\t\t\t);\n\t\t}).length;\n\t}\n\n\tgetPendingTerminalNotifications(): Array<{ notificationId: string; record: LaneRecord }> {\n\t\tthis.ensureTerminalNotifications();\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.values(snapshot.notifications).flatMap((notification) => {\n\t\t\tif (notification.status !== \"pending\" || !notification.attemptId) return [];\n\t\t\tconst attempt = snapshot.attempts[notification.attemptId];\n\t\t\tif (!attempt) return [];\n\t\t\tconst record = projectWorkerLaneRecord(snapshot, attempt.taskId);\n\t\t\tif (!record || record.status === \"queued\" || record.status === \"running\") return [];\n\t\t\treturn [{ notificationId: notification.notificationId, record }];\n\t\t});\n\t}\n\n\tgetTerminalNotification(\n\t\tlaneId: string,\n\t): { notificationId: string; status: \"pending\" | \"delivered\"; record: LaneRecord } | undefined {\n\t\tconst record = this.getRecord(laneId) ?? this.getManagedRecord(laneId);\n\t\tif (!record || record.status === \"queued\" || record.status === \"running\") return undefined;\n\t\tthis.enqueueTerminalNotification(record);\n\t\tconst attempt = this.getActiveAttempt(laneId) ?? this.getManagedAttempt(laneId);\n\t\tif (!attempt) return undefined;\n\t\tconst notificationId = `worker-terminal:${attempt.attemptId}`;\n\t\tconst notification = this.ledger.runtime.getSnapshot().notifications[notificationId];\n\t\treturn notification ? { notificationId, status: notification.status, record } : undefined;\n\t}\n\n\tmarkNotificationsDelivered(notificationIds: readonly string[]): void {\n\t\tfor (const notificationId of notificationIds) this.ledger.runtime.markNotificationDelivered(notificationId);\n\t}\n\n\tprivate ensureTerminalNotifications(): void {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tfor (const taskId of Object.keys(snapshot.tasks)) {\n\t\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\t\tif (record && record.status !== \"queued\" && record.status !== \"running\") {\n\t\t\t\tthis.enqueueTerminalNotification(record);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate enqueueTerminalNotification(record: LaneRecord): void {\n\t\tconst attempt = this.getActiveAttempt(record.laneId) ?? this.getManagedAttempt(record.laneId);\n\t\tif (!attempt || NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(attempt.status)) return;\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tconst task = snapshot.tasks[attempt.taskId];\n\t\tif (!task) return;\n\t\tif (attempt.result?.nextAction === \"independent_verification_required\" && !task.verification) return;\n\t\tthis.ledger.runtime.enqueueNotification({\n\t\t\tnotificationId: `worker-terminal:${attempt.attemptId}`,\n\t\t\tobjectiveId: task.task.objectiveId,\n\t\t\tattemptId: attempt.attemptId,\n\t\t\tmessage: `Worker ${record.laneId} reached ${record.status}.`,\n\t\t});\n\t}\n\n\tprivate requireActiveAttempt(laneId: string): AttemptRuntimeState {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt || !ACTIVE_WORKER_ATTEMPT_STATUSES.has(attempt.status)) {\n\t\t\tthrow new Error(`Durable worker '${laneId}' has no active attempt.`);\n\t\t}\n\t\treturn attempt;\n\t}\n\n\tprivate startedHandle(attempt: AttemptRuntimeState): StartedDelegationAttempt {\n\t\tconst task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId];\n\t\tif (!task || !attempt.lease) throw new Error(`Attempt '${attempt.attemptId}' has no started handle.`);\n\t\treturn {\n\t\t\tobjectiveId: task.task.objectiveId,\n\t\t\ttaskId: task.task.taskId,\n\t\t\tattemptId: attempt.attemptId,\n\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\texpiresAt: attempt.lease.expiresAt,\n\t\t};\n\t}\n\n\tprivate startPreparedManagedAttempt(\n\t\tattempt: AttemptRuntimeState,\n\t\tleaseTtlMs: number,\n\t\tcompileGrant: (target: { objectiveId: string; taskId: string; attemptId: string }) => ExecutionGrant,\n\t): StartedDelegationAttempt {\n\t\tconst task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId];\n\t\tif (!task) throw new Error(`Managed attempt '${attempt.attemptId}' has no durable task.`);\n\t\tconst grant = compileGrant({\n\t\t\tobjectiveId: task.task.objectiveId,\n\t\t\ttaskId: task.task.taskId,\n\t\t\tattemptId: attempt.attemptId,\n\t\t});\n\t\tthis.bindGrant(attempt.attemptId, grant);\n\t\treturn this.ledger.start(\n\t\t\tattempt.attemptId,\n\t\t\tleaseTtlMs,\n\t\t\t`managed:${attempt.dispatch.logicalLaneId ?? attempt.taskId}`,\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"worker-lifecycle.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-lifecycle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AAWxF,OAAO,EACN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CAAC,SAAS;YAC5B,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;YAC9B,YAAY,EAAE,OAAO,CAAC,KAAK,CAAC,YAAY;YACxC,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,SAAS;SAClC,CAAC;IACH,CAAC;IAEO,2BAA2B,CAClC,OAA4B,EAC5B,UAAkB,EAClB,YAAoG;QAEpG,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,OAAO,CAAC,SAAS,wBAAwB,CAAC,CAAC;QAC1F,MAAM,KAAK,GAAG,YAAY,CAAC;YAC1B,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW;YAClC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;YACxB,SAAS,EAAE,OAAO,CAAC,SAAS;SAC5B,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CACvB,OAAO,CAAC,SAAS,EACjB,UAAU,EACV,WAAW,OAAO,CAAC,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAC7D,CAAC;IACH,CAAC;CACD","sourcesContent":["import type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { GoalState } from \"../goals/goal-state.ts\";\nimport { sameAgentResumeIdentity } from \"../orchestration/agent-resume.ts\";\nimport { latestAgentAttemptByDurableOrder } from \"../orchestration/attempt-ordering.ts\";\nimport type {\n\tAgentBindingContract,\n\tAgentResumeContext,\n\tAttemptRetryState,\n\tAttemptUsageSnapshot,\n\tExecutionGrant,\n\tWorkerExecutionContract,\n\tWorkerResultContract,\n\tWorkerRole,\n} from \"../orchestration/contracts.ts\";\nimport {\n\tDelegationOrchestrationLedger,\n\ttype PrepareDelegationInput,\n\ttype PrepareManagedDelegationInput,\n\ttype StartedDelegationAttempt,\n} from \"../orchestration/delegation-ledger.ts\";\nimport type {\n\tAttemptDispatchReadiness,\n\tAttemptRuntimeState,\n\tTaskRuntimeProjection,\n} from \"../orchestration/task-runtime.ts\";\nimport { verifierWorkerExecutionContract } from \"../orchestration/worker-execution-contract.ts\";\nimport {\n\tACTIVE_WORKER_ATTEMPT_STATUSES,\n\tisManagedWorkerAttempt,\n\tNONTERMINAL_WORKER_ATTEMPT_STATUSES,\n\tprojectManagedWorkerLaneRecords,\n\tprojectWorkerLaneRecord,\n\tselectedManagedWorkerAttempt,\n\tselectedWorkerAttempt,\n} from \"./worker-lane-projection.ts\";\nimport { isLocalProcessAlive, isLocalWorkerProcessOwnerProvenDead } from \"./worker-process-owner.ts\";\n\nexport type PendingVerificationRecovery =\n\t| {\n\t\t\taction: \"dispatch\";\n\t\t\tsubjectTaskId: string;\n\t\t\timplementationProfileId: string;\n\t\t\tsummary: string;\n\t\t\tartifactUris: readonly string[];\n\t\t\tverifierExecutionContract?: WorkerExecutionContract;\n\t }\n\t| {\n\t\t\taction: \"reconcile\";\n\t\t\tsubjectTaskId: string;\n\t\t\tverifierTaskId: string;\n\t\t\tverifierAttemptId: string;\n\t\t\tverdict: \"accepted\" | \"rejected\" | \"inconclusive\";\n\t\t\treasonCode: string;\n\t };\n\n/**\n * Sole owner of in-process worker lifecycle state. LaneRecord is a compatibility/UI projection;\n * all transitions are committed through DurableTaskRuntime before the projection is returned.\n */\nexport class WorkerLifecycle {\n\treadonly ledger: DelegationOrchestrationLedger;\n\tprivate nextLaneNumber: number;\n\tprivate readonly isProcessAlive: (pid: number) => boolean;\n\n\tconstructor(options: {\n\t\tagentDir: string;\n\t\tsessionId: string;\n\t\tisProcessAlive?: (pid: number) => boolean;\n\t\tnow?: () => number;\n\t}) {\n\t\tthis.ledger = new DelegationOrchestrationLedger(options);\n\t\tthis.isProcessAlive = options.isProcessAlive ?? isLocalProcessAlive;\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tconst highest = Object.keys(snapshot.tasks).reduce((current, taskId) => {\n\t\t\tconst suffix = /^worker-(\\d+)$/.exec(taskId)?.[1];\n\t\t\treturn suffix ? Math.max(current, Number(suffix)) : current;\n\t\t}, 0);\n\t\tthis.nextLaneNumber = highest + 1;\n\t}\n\n\tprepare(\n\t\tinput: Omit<PrepareDelegationInput, \"laneId\">,\n\t\tlaneId?: string,\n\t): {\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t} {\n\t\tlet selectedLaneId = laneId;\n\t\tconst generatedLaneId = !selectedLaneId;\n\t\tif (!selectedLaneId) {\n\t\t\tselectedLaneId = this.getNextAvailableLaneIdCandidate();\n\t\t}\n\t\tconst attempt = this.ledger.prepare({ ...input, laneId: selectedLaneId });\n\t\tif (generatedLaneId) this.nextLaneNumber = Number(selectedLaneId.slice(\"worker-\".length)) + 1;\n\t\tconst record = this.getRecord(selectedLaneId);\n\t\tif (!record) throw new Error(`Durable worker '${selectedLaneId}' was not projected after enqueue.`);\n\t\treturn { record, attempt };\n\t}\n\n\t/** Return the next generated lane id without reserving it or changing lifecycle state. */\n\tgetNextAvailableLaneIdCandidate(): string {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tlet candidateNumber = this.nextLaneNumber;\n\t\twhile (snapshot.tasks[`worker-${candidateNumber}`]) candidateNumber += 1;\n\t\treturn `worker-${candidateNumber}`;\n\t}\n\n\t/** Queue the next distinct task/attempt for an idle logical agent. */\n\tprepareAgentTurn(input: {\n\t\tagentId: string;\n\t\tinstructions: string;\n\t\tcontrolMessageId?: string;\n\t\tdependsOnTaskIds?: readonly string[];\n\t}): {\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t} {\n\t\tconst attempt = this.ledger.prepareAgentTurn(input);\n\t\tconst record = this.getRecord(attempt.taskId);\n\t\tif (!record) throw new Error(`Logical worker '${input.agentId}' turn was not projected after enqueue.`);\n\t\treturn { record, attempt };\n\t}\n\n\tensureAgent(input: {\n\t\tagentId: string;\n\t\tparentAgentId?: string;\n\t\trole: WorkerRole;\n\t\tresumeContext: AgentResumeContext;\n\t}): AgentBindingContract {\n\t\tconst agentId = input.agentId.trim();\n\t\tconst existing = this.ledger.runtime.getSnapshot().agents[agentId];\n\t\tif (!existing) return this.ledger.runtime.registerAgent(input);\n\t\tif (\n\t\t\texisting.role !== input.role ||\n\t\t\texisting.parentAgentId !== input.parentAgentId ||\n\t\t\t!sameAgentResumeIdentity(existing.resumeContext, input.resumeContext)\n\t\t) {\n\t\t\tthrow new Error(`Agent '${agentId}' was re-registered with conflicting identity.`);\n\t\t}\n\t\treturn existing;\n\t}\n\n\t/** Retire one idle logical worker while retaining its durable binding and transcript identity. */\n\tretireAgent(agentId: string): AgentBindingContract {\n\t\treturn this.ledger.runtime.retireAgent(agentId);\n\t}\n\n\tprepareManaged(\n\t\tinput: PrepareManagedDelegationInput & {\n\t\t\tleaseTtlMs: number;\n\t\t\tcompileGrant(target: { objectiveId: string; taskId: string; attemptId: string }): ExecutionGrant;\n\t\t},\n\t): {\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t\thandle: StartedDelegationAttempt;\n\t\tcreated: boolean;\n\t} {\n\t\tconst before = selectedManagedWorkerAttempt(this.ledger.runtime.getSnapshot(), input.laneId);\n\t\tif (before?.dispatch.dispatchSequence === input.dispatchSequence) {\n\t\t\tif (\n\t\t\t\tbefore.dispatch.provider !== \"legacy\" &&\n\t\t\t\t(before.dispatch.instructions !== input.instructions ||\n\t\t\t\t\tbefore.dispatch.profileId !== input.profileId ||\n\t\t\t\t\tbefore.dispatch.provider !== input.provider ||\n\t\t\t\t\tbefore.dispatch.worktreeLaneKey !== input.worktreeLaneKey ||\n\t\t\t\t\tbefore.dispatch.authorizationId !== input.authorizationId)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Managed worker '${input.laneId}' turn ${input.dispatchSequence} was re-reported with conflicting dispatch data.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (before.status === \"queued\") {\n\t\t\t\tconst handle = this.startPreparedManagedAttempt(before, input.leaseTtlMs, input.compileGrant);\n\t\t\t\tconst record = this.getManagedRecord(input.laneId);\n\t\t\t\tif (!record) throw new Error(`Managed worker '${input.laneId}' was not projected.`);\n\t\t\t\treturn {\n\t\t\t\t\trecord,\n\t\t\t\t\tattempt: this.ledger.runtime.getSnapshot().attempts[before.attemptId]!,\n\t\t\t\t\thandle,\n\t\t\t\t\tcreated: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst record = this.getManagedRecord(input.laneId);\n\t\t\tif (!record) throw new Error(`Managed worker '${input.laneId}' was not projected.`);\n\t\t\tif (!before.lease) throw new Error(`Managed worker '${input.laneId}' has no durable lease.`);\n\t\t\treturn {\n\t\t\t\trecord,\n\t\t\t\tattempt: before,\n\t\t\t\thandle: this.startedHandle(before),\n\t\t\t\tcreated: false,\n\t\t\t};\n\t\t}\n\t\tif (before && ACTIVE_WORKER_ATTEMPT_STATUSES.has(before.status)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Managed worker '${input.laneId}' cannot dispatch turn ${input.dispatchSequence} while turn ${before.dispatch.dispatchSequence ?? 1} is active.`,\n\t\t\t);\n\t\t}\n\t\tconst attempt = this.ledger.prepareManaged(input);\n\t\tconst handle = this.startPreparedManagedAttempt(attempt, input.leaseTtlMs, input.compileGrant);\n\t\tconst record = this.getManagedRecord(input.laneId);\n\t\tif (!record) throw new Error(`Managed worker '${input.laneId}' was not projected after dispatch.`);\n\t\treturn { record, attempt: this.ledger.runtime.getSnapshot().attempts[attempt.attemptId]!, handle, created: true };\n\t}\n\n\tsynchronizeGoalState(goal: GoalState): LaneRecord[] {\n\t\tconst before = new Map(this.getRecords().map((record) => [record.laneId, record.status]));\n\t\tthis.ledger.synchronizeGoalState(goal);\n\t\treturn this.getRecords().filter((record) => {\n\t\t\tconst previous = before.get(record.laneId);\n\t\t\treturn (\n\t\t\t\t(previous === \"queued\" || previous === \"running\") &&\n\t\t\t\trecord.status !== \"queued\" &&\n\t\t\t\trecord.status !== \"running\"\n\t\t\t);\n\t\t});\n\t}\n\n\tstart(laneId: string, leaseTtlMs: number): StartedDelegationAttempt {\n\t\tconst attempt = this.requireActiveAttempt(laneId);\n\t\treturn this.ledger.start(attempt.attemptId, leaseTtlMs);\n\t}\n\n\tstartAgent(laneId: string, agentId: string, leaseTtlMs: number, ownerId = agentId): StartedDelegationAttempt {\n\t\tconst attempt = this.requireActiveAttempt(laneId);\n\t\treturn this.ledger.start(attempt.attemptId, leaseTtlMs, ownerId, agentId);\n\t}\n\n\trenewLease(laneId: string, leaseTtlMs: number) {\n\t\tconst attempt = this.requireActiveAttempt(laneId);\n\t\tif (!attempt.lease) throw new Error(`Durable worker '${laneId}' has no live lease.`);\n\t\treturn this.ledger.runtime.renewAttemptLease(\n\t\t\tattempt.attemptId,\n\t\t\tattempt.lease.leaseId,\n\t\t\tattempt.lease.fencingToken,\n\t\t\tleaseTtlMs,\n\t\t);\n\t}\n\n\tcheckpoint(\n\t\tlaneId: string,\n\t\tinput: {\n\t\t\tsummary: string;\n\t\t\tartifactIds?: readonly string[];\n\t\t\tevidenceIds?: readonly string[];\n\t\t\tusage?: AttemptUsageSnapshot;\n\t\t},\n\t) {\n\t\tconst attempt = this.requireActiveAttempt(laneId);\n\t\tif (!attempt.lease) throw new Error(`Durable worker '${laneId}' has no live lease.`);\n\t\treturn this.ledger.runtime.checkpointAttempt({\n\t\t\tattemptId: attempt.attemptId,\n\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\tsummary: input.summary,\n\t\t\t...(input.artifactIds ? { artifactIds: input.artifactIds } : {}),\n\t\t\t...(input.evidenceIds ? { evidenceIds: input.evidenceIds } : {}),\n\t\t\t...(input.usage ? { usage: input.usage } : {}),\n\t\t});\n\t}\n\n\t/**\n\t * Suspend only attempts whose exact controller owner is known (explicit shutdown) or whose\n\t * recorded local owner PID is proven gone (recovery). A live/unknown owner is never stolen.\n\t */\n\tsuspendBoundInProcessAttemptsForRestart(ownerId?: string): string[] {\n\t\tconst suspended: string[] = [];\n\t\tfor (const attempt of Object.values(this.ledger.runtime.getSnapshot().attempts)) {\n\t\t\tif (\n\t\t\t\t(attempt.status !== \"leased\" && attempt.status !== \"running\") ||\n\t\t\t\t!attempt.agentId ||\n\t\t\t\tattempt.dispatch.executionKind === \"managed-process\" ||\n\t\t\t\t!attempt.lease\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst ownsAttempt =\n\t\t\t\townerId !== undefined\n\t\t\t\t\t? attempt.lease.ownerId === ownerId\n\t\t\t\t\t: isLocalWorkerProcessOwnerProvenDead(attempt.lease.ownerId, this.isProcessAlive);\n\t\t\tif (!ownsAttempt) continue;\n\t\t\tthis.suspendBoundAttempt({\n\t\t\t\tlaneId: attempt.taskId,\n\t\t\t\townerId: attempt.lease.ownerId,\n\t\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\t\treasonCode:\n\t\t\t\t\townerId === undefined ? \"agent_process_recovered_after_owner_exit\" : \"agent_process_interrupted\",\n\t\t\t});\n\t\t\tsuspended.push(attempt.attemptId);\n\t\t}\n\t\treturn suspended;\n\t}\n\n\t/**\n\t * Applies an explicitly authorized restart suspension. The caller must identify both the logical\n\t * lane and the current lease fence; process liveness policy is intentionally kept by this class.\n\t */\n\tsuspendBoundAttempt(args: {\n\t\tlaneId: string;\n\t\townerId: string;\n\t\tleaseId: string;\n\t\tfencingToken: number;\n\t\treasonCode: string;\n\t\tretry?: AttemptRetryState;\n\t}): void {\n\t\tconst attempt = this.getActiveAttempt(args.laneId);\n\t\tif (!attempt || !attempt.agentId || !attempt.lease) {\n\t\t\tthrow new Error(`Durable worker '${args.laneId}' has no live agent-bound attempt for suspension.`);\n\t\t}\n\t\tthis.ledger.runtime.suspendBoundAttempt({\n\t\t\tattemptId: attempt.attemptId,\n\t\t\townerId: args.ownerId,\n\t\t\tleaseId: args.leaseId,\n\t\t\tfencingToken: args.fencingToken,\n\t\t\treasonCode: args.reasonCode,\n\t\t\t...(args.retry ? { retry: args.retry } : {}),\n\t\t});\n\t}\n\n\tresumeAgent(laneId: string, agentId: string, leaseTtlMs: number, ownerId = agentId): StartedDelegationAttempt {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt) throw new Error(`Durable worker '${laneId}' has no resumable attempt.`);\n\t\tthis.ledger.runtime.assertAttemptReadyForResume(attempt.attemptId);\n\t\tthis.ledger.runtime.requestAgentResume(agentId, attempt.attemptId);\n\t\tconst lease = this.ledger.runtime.resumeAttempt(attempt.attemptId, agentId, leaseTtlMs, ownerId);\n\t\treturn this.startedHandle(this.ledger.runtime.startAttempt(attempt.attemptId, lease.leaseId, lease.fencingToken));\n\t}\n\n\tsuspendAgent(\n\t\tlaneId: string,\n\t\tagentId: string,\n\t\townerId: string,\n\t\treasonCode = \"agent_interrupted\",\n\t\tretry?: AttemptRetryState,\n\t): void {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt || attempt.agentId !== agentId || !attempt.lease) {\n\t\t\tthrow new Error(`Logical worker '${agentId}' has no live attempt for interruption.`);\n\t\t}\n\t\tthis.suspendBoundAttempt({\n\t\t\tlaneId,\n\t\t\townerId,\n\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\treasonCode,\n\t\t\t...(retry ? { retry } : {}),\n\t\t});\n\t}\n\n\tscheduleAgentRetry(args: {\n\t\tlaneId: string;\n\t\tagentId: string;\n\t\townerId: string;\n\t\treasonCode: string;\n\t\tretry: AttemptRetryState;\n\t}): AttemptRuntimeState {\n\t\tthis.suspendAgent(args.laneId, args.agentId, args.ownerId, args.reasonCode, args.retry);\n\t\tconst attempt = this.getActiveAttempt(args.laneId);\n\t\tif (!attempt) throw new Error(`Durable worker '${args.laneId}' disappeared after retry suspension.`);\n\t\treturn attempt;\n\t}\n\n\tbindGrant(attemptId: string, grant: ExecutionGrant): void {\n\t\tthis.ledger.runtime.bindAttemptGrant(attemptId, grant);\n\t}\n\n\tfinish(result: WorkerResultContract, options: { notify?: boolean } = {}): LaneRecord {\n\t\tthis.ledger.runtime.finishAttempt(result);\n\t\tconst record = this.getRecord(result.taskId);\n\t\tif (!record) throw new Error(`Durable worker '${result.taskId}' was not projected after completion.`);\n\t\tif (options.notify !== false) this.enqueueTerminalNotification(record);\n\t\treturn record;\n\t}\n\n\treconcileVerification(args: {\n\t\tsubjectTaskId: string;\n\t\tverifierTaskId: string;\n\t\tverifierAttemptId: string;\n\t\tverdict: \"accepted\" | \"rejected\" | \"inconclusive\";\n\t\treasonCode: string;\n\t}): LaneRecord {\n\t\tthis.ledger.runtime.finishVerification({\n\t\t\ttaskId: args.subjectTaskId,\n\t\t\tverifierTaskId: args.verifierTaskId,\n\t\t\tverifierAttemptId: args.verifierAttemptId,\n\t\t\tverdict: args.verdict,\n\t\t\treasonCode: args.reasonCode,\n\t\t});\n\t\tconst subject = this.getRecord(args.subjectTaskId);\n\t\tif (!subject) throw new Error(`Verified worker '${args.subjectTaskId}' was not projected.`);\n\t\tthis.enqueueTerminalNotification(subject);\n\t\treturn subject;\n\t}\n\n\tcancel(laneId: string, reasonCode: string): LaneRecord | undefined {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt) return this.getRecord(laneId);\n\t\tthis.ledger.cancel(attempt.attemptId, reasonCode);\n\t\tconst record = this.getRecord(laneId);\n\t\tif (record) this.enqueueTerminalNotification(record);\n\t\treturn record;\n\t}\n\n\trecoverQueued(): Array<{\n\t\trecord: LaneRecord;\n\t\tattempt: AttemptRuntimeState;\n\t\tverificationOfTaskId?: string;\n\t}> {\n\t\treturn this.ledger.recoverQueuedDispatches().flatMap((attempt) => {\n\t\t\tif (isManagedWorkerAttempt(attempt)) return [];\n\t\t\tconst record = this.getRecord(attempt.taskId);\n\t\t\tconst task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId]?.task;\n\t\t\treturn record\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trecord,\n\t\t\t\t\t\t\tattempt,\n\t\t\t\t\t\t\t...(task?.verificationOfTaskId ? { verificationOfTaskId: task.verificationOfTaskId } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [];\n\t\t});\n\t}\n\n\t/** Close crash windows between implementation completion, verifier dispatch, and reconciliation. */\n\tgetPendingVerificationRecoveries(): PendingVerificationRecovery[] {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.values(snapshot.tasks).flatMap<PendingVerificationRecovery>((subject) => {\n\t\t\tif (subject.verification) return [];\n\t\t\tconst implementationAttempt = selectedWorkerAttempt(snapshot, subject.task.taskId);\n\t\t\tif (implementationAttempt?.result?.nextAction !== \"independent_verification_required\") return [];\n\t\t\tconst verifier = Object.values(snapshot.tasks)\n\t\t\t\t.filter((candidate) => candidate.task.verificationOfTaskId === subject.task.taskId)\n\t\t\t\t.at(-1);\n\t\t\tif (!verifier) {\n\t\t\t\tconst verifierExecutionContract = implementationAttempt.dispatch.executionContract\n\t\t\t\t\t? verifierWorkerExecutionContract(implementationAttempt.dispatch.executionContract)\n\t\t\t\t\t: undefined;\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\taction: \"dispatch\" as const,\n\t\t\t\t\t\tsubjectTaskId: subject.task.taskId,\n\t\t\t\t\t\timplementationProfileId: implementationAttempt.dispatch.profileId,\n\t\t\t\t\t\tsummary: implementationAttempt.result.summary,\n\t\t\t\t\t\tartifactUris: implementationAttempt.result.artifacts.map((artifact) => artifact.uri),\n\t\t\t\t\t\t...(verifierExecutionContract ? { verifierExecutionContract } : {}),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\tconst verifierAttempt = selectedWorkerAttempt(snapshot, verifier.task.taskId);\n\t\t\tif (!verifierAttempt || NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(verifierAttempt.status)) return [];\n\t\t\tconst review = verifierAttempt.result?.evidence.find(\n\t\t\t\t(evidence) =>\n\t\t\t\t\tevidence.trusted &&\n\t\t\t\t\tevidence.kind === \"review\" &&\n\t\t\t\t\tevidence.metadata?.subjectTaskId === subject.task.taskId &&\n\t\t\t\t\t(evidence.metadata.verdict === \"accepted\" || evidence.metadata.verdict === \"rejected\"),\n\t\t\t);\n\t\t\tconst verdictValue = review?.metadata?.verdict;\n\t\t\tconst verdict = verdictValue === \"accepted\" || verdictValue === \"rejected\" ? verdictValue : \"inconclusive\";\n\t\t\tconst reasonCodesValue = review?.metadata?.reasonCodes;\n\t\t\tconst reasonCodes = Array.isArray(reasonCodesValue)\n\t\t\t\t? reasonCodesValue.filter((reasonCode): reasonCode is string => typeof reasonCode === \"string\")\n\t\t\t\t: [];\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\taction: \"reconcile\" as const,\n\t\t\t\t\tsubjectTaskId: subject.task.taskId,\n\t\t\t\t\tverifierTaskId: verifier.task.taskId,\n\t\t\t\t\tverifierAttemptId: verifierAttempt.attemptId,\n\t\t\t\t\tverdict,\n\t\t\t\t\treasonCode:\n\t\t\t\t\t\tverdict === \"accepted\"\n\t\t\t\t\t\t\t? \"independent_verification_accepted\"\n\t\t\t\t\t\t\t: verdict === \"rejected\"\n\t\t\t\t\t\t\t\t? `independent_verification_rejected:${reasonCodes.join(\",\") || \"unspecified\"}`\n\t\t\t\t\t\t\t\t: `independent_verification_inconclusive:${verifierAttempt.reasonCode ?? verifierAttempt.result?.reasonCode ?? \"interrupted\"}`,\n\t\t\t\t},\n\t\t\t];\n\t\t});\n\t}\n\n\tgetTask(taskId: string): TaskRuntimeProjection[\"tasks\"][string] | undefined {\n\t\treturn this.ledger.runtime.getSnapshot().tasks[taskId];\n\t}\n\n\tgetAgent(agentId: string): AgentBindingContract | undefined {\n\t\treturn this.ledger.runtime.getSnapshot().agents[agentId];\n\t}\n\n\tgetLatestAgentAttempt(agentId: string): AttemptRuntimeState | undefined {\n\t\treturn latestAgentAttemptByDurableOrder(this.ledger.runtime.getSnapshot(), agentId);\n\t}\n\n\tgetTaskRuntimeSnapshot(): TaskRuntimeProjection {\n\t\treturn this.ledger.runtime.getSnapshot();\n\t}\n\n\t/** Read-only dispatch gate for an already persisted queued worker attempt. */\n\tgetAttemptDispatchReadiness(attemptId: string): AttemptDispatchReadiness {\n\t\treturn this.ledger.runtime.getAttemptDispatchReadiness(attemptId);\n\t}\n\n\tgetRecords(): LaneRecord[] {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.keys(snapshot.tasks).flatMap((taskId) => {\n\t\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\t\tif (!attempt || isManagedWorkerAttempt(attempt)) return [];\n\t\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\t\treturn record ? [record] : [];\n\t\t});\n\t}\n\n\tgetManagedRecords(): LaneRecord[] {\n\t\treturn projectManagedWorkerLaneRecords(this.ledger.runtime.getSnapshot());\n\t}\n\n\tgetAllRecords(): LaneRecord[] {\n\t\treturn [...this.getRecords(), ...this.getManagedRecords()];\n\t}\n\n\tgetRecord(laneId: string): LaneRecord | undefined {\n\t\treturn projectWorkerLaneRecord(this.ledger.runtime.getSnapshot(), laneId);\n\t}\n\n\tgetManagedRecord(laneId: string): LaneRecord | undefined {\n\t\treturn this.getManagedRecords().find((record) => record.laneId === laneId);\n\t}\n\n\tgetManagedAttempt(laneId: string): AttemptRuntimeState | undefined {\n\t\treturn selectedManagedWorkerAttempt(this.ledger.runtime.getSnapshot(), laneId);\n\t}\n\n\tgetManagedHandle(laneId: string): StartedDelegationAttempt | undefined {\n\t\tconst attempt = this.getManagedAttempt(laneId);\n\t\treturn attempt?.lease ? this.startedHandle(attempt) : undefined;\n\t}\n\n\tgetActiveAttempt(laneId: string): AttemptRuntimeState | undefined {\n\t\treturn selectedWorkerAttempt(this.ledger.runtime.getSnapshot(), laneId);\n\t}\n\n\tgetAttemptUsage(laneId: string): AttemptUsageSnapshot | undefined {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\treturn attempt ? this.ledger.getAttemptUsage(attempt.attemptId) : undefined;\n\t}\n\n\tgetRunningCount(profileId?: string): number {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.keys(snapshot.tasks).filter((taskId) => {\n\t\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\t\treturn (\n\t\t\t\tattempt?.status === \"running\" &&\n\t\t\t\t!isManagedWorkerAttempt(attempt) &&\n\t\t\t\t(!profileId || attempt.dispatch.profileId === profileId)\n\t\t\t);\n\t\t}).length;\n\t}\n\n\tgetPendingTerminalNotifications(): Array<{ notificationId: string; record: LaneRecord }> {\n\t\tthis.ensureTerminalNotifications();\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\treturn Object.values(snapshot.notifications).flatMap((notification) => {\n\t\t\tif (notification.status !== \"pending\" || !notification.attemptId) return [];\n\t\t\tconst attempt = snapshot.attempts[notification.attemptId];\n\t\t\tif (!attempt) return [];\n\t\t\tconst record = projectWorkerLaneRecord(snapshot, attempt.taskId);\n\t\t\tif (!record || record.status === \"queued\" || record.status === \"running\") return [];\n\t\t\treturn [{ notificationId: notification.notificationId, record }];\n\t\t});\n\t}\n\n\tgetTerminalNotification(\n\t\tlaneId: string,\n\t): { notificationId: string; status: \"pending\" | \"delivered\"; record: LaneRecord } | undefined {\n\t\tconst record = this.getRecord(laneId) ?? this.getManagedRecord(laneId);\n\t\tif (!record || record.status === \"queued\" || record.status === \"running\") return undefined;\n\t\tthis.enqueueTerminalNotification(record);\n\t\tconst attempt = this.getActiveAttempt(laneId) ?? this.getManagedAttempt(laneId);\n\t\tif (!attempt) return undefined;\n\t\tconst notificationId = `worker-terminal:${attempt.attemptId}`;\n\t\tconst notification = this.ledger.runtime.getSnapshot().notifications[notificationId];\n\t\treturn notification ? { notificationId, status: notification.status, record } : undefined;\n\t}\n\n\tmarkNotificationsDelivered(notificationIds: readonly string[]): void {\n\t\tfor (const notificationId of notificationIds) this.ledger.runtime.markNotificationDelivered(notificationId);\n\t}\n\n\tprivate ensureTerminalNotifications(): void {\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tfor (const taskId of Object.keys(snapshot.tasks)) {\n\t\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\t\tif (record && record.status !== \"queued\" && record.status !== \"running\") {\n\t\t\t\tthis.enqueueTerminalNotification(record);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate enqueueTerminalNotification(record: LaneRecord): void {\n\t\tconst attempt = this.getActiveAttempt(record.laneId) ?? this.getManagedAttempt(record.laneId);\n\t\tif (!attempt || NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(attempt.status)) return;\n\t\tconst snapshot = this.ledger.runtime.getSnapshot();\n\t\tconst task = snapshot.tasks[attempt.taskId];\n\t\tif (!task) return;\n\t\tif (attempt.result?.nextAction === \"independent_verification_required\" && !task.verification) return;\n\t\tthis.ledger.runtime.enqueueNotification({\n\t\t\tnotificationId: `worker-terminal:${attempt.attemptId}`,\n\t\t\tobjectiveId: task.task.objectiveId,\n\t\t\tattemptId: attempt.attemptId,\n\t\t\tmessage: `Worker ${record.laneId} reached ${record.status}.`,\n\t\t});\n\t}\n\n\tprivate requireActiveAttempt(laneId: string): AttemptRuntimeState {\n\t\tconst attempt = this.getActiveAttempt(laneId);\n\t\tif (!attempt || !ACTIVE_WORKER_ATTEMPT_STATUSES.has(attempt.status)) {\n\t\t\tthrow new Error(`Durable worker '${laneId}' has no active attempt.`);\n\t\t}\n\t\treturn attempt;\n\t}\n\n\tprivate startedHandle(attempt: AttemptRuntimeState): StartedDelegationAttempt {\n\t\tconst task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId];\n\t\tif (!task || !attempt.lease) throw new Error(`Attempt '${attempt.attemptId}' has no started handle.`);\n\t\treturn {\n\t\t\tobjectiveId: task.task.objectiveId,\n\t\t\ttaskId: task.task.taskId,\n\t\t\tattemptId: attempt.attemptId,\n\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\texpiresAt: attempt.lease.expiresAt,\n\t\t};\n\t}\n\n\tprivate startPreparedManagedAttempt(\n\t\tattempt: AttemptRuntimeState,\n\t\tleaseTtlMs: number,\n\t\tcompileGrant: (target: { objectiveId: string; taskId: string; attemptId: string }) => ExecutionGrant,\n\t): StartedDelegationAttempt {\n\t\tconst task = this.ledger.runtime.getSnapshot().tasks[attempt.taskId];\n\t\tif (!task) throw new Error(`Managed attempt '${attempt.attemptId}' has no durable task.`);\n\t\tconst grant = compileGrant({\n\t\t\tobjectiveId: task.task.objectiveId,\n\t\t\ttaskId: task.task.taskId,\n\t\t\tattemptId: attempt.attemptId,\n\t\t});\n\t\tthis.bindGrant(attempt.attemptId, grant);\n\t\treturn this.ledger.start(\n\t\t\tattempt.attemptId,\n\t\t\tleaseTtlMs,\n\t\t\t`managed:${attempt.dispatch.logicalLaneId ?? attempt.taskId}`,\n\t\t);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"worker-notification-coordinator.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-notification-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAIlF,MAAM,WAAW,2BAA2B;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,kBAAkB,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,SAAS,2BAA2B,EAAE,CAAC;CAC3D;AAQD,MAAM,WAAW,oCAAoC;IACpD,gBAAgB,IAAI,SAAS,UAAU,EAAE,CAAC;IAC1C,UAAU,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CAAC;IACnD,MAAM,CAAC,OAAO,EAAE,SAAS,2BAA2B,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,oBAAoB,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;CAC/D;AAED,sGAAsG;AACtG,qBAAa,6BAA6B;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgD;IACxE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,UAAU,CAA4C;IAC9D,OAAO,CAAC,UAAU,CAAK;IAEvB,YAAY,OAAO,EAAE,oCAAoC,EAExD;IAED,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI,CAavE;IAED,aAAa,IAAI,IAAI,CAEpB;IAED,OAAO,IAAI,IAAI,CAMd;IAED,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,KAAK;CA+Db"}
1
+ {"version":3,"file":"worker-notification-coordinator.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-notification-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAKlF,MAAM,WAAW,2BAA2B;IAC3C,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