@tea-agent/loop-agent 0.41.0 → 0.42.0-next.1

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 +102 -14
  2. package/dist/adapters/context-transfer/optional-pi-handoff.js +31 -0
  3. package/dist/adapters/context-transfer/pi-session.js +61 -0
  4. package/dist/build-stamp.json +3 -3
  5. package/dist/cli/command-definitions.js +12 -0
  6. package/dist/cli/program.js +23 -1
  7. package/dist/commands/dag-artifact.js +284 -0
  8. package/dist/commands/dag-context.js +184 -0
  9. package/dist/commands/dag-rerun.js +206 -1
  10. package/dist/executors/dag-pi-executor.js +39 -12
  11. package/dist/executors/pi-sdk-executor.js +3 -0
  12. package/dist/{worker → infrastructure}/console/app-data.js +4 -0
  13. package/dist/infrastructure/console/artifact-revision-store.js +430 -0
  14. package/dist/infrastructure/console/context-export-store.js +160 -0
  15. package/dist/infrastructure/console/dir-lock.js +132 -0
  16. package/dist/{worker → infrastructure}/console/operation-store.js +28 -0
  17. package/dist/infrastructure/harness/artifact-store.js +10 -1
  18. package/dist/infrastructure/harness/atomic-write.js +12 -2
  19. package/dist/shared/context-transfer/artifact-revision.js +172 -0
  20. package/dist/shared/context-transfer.js +418 -0
  21. package/dist/shared/operator/capabilities.js +14 -0
  22. package/dist/shared/operator/safe-run-summary.js +1 -0
  23. package/dist/shared/path-safety.js +93 -0
  24. package/dist/shared/preview.js +28 -4
  25. package/dist/task/config-types.js +2 -1
  26. package/dist/task/task-demand-routing.js +3 -0
  27. package/dist/worker/console/chat/chat-event-store.js +2 -2
  28. package/dist/worker/console/chat/resource-preferences-store.js +1 -1
  29. package/dist/worker/console/chat/routes.js +1 -1
  30. package/dist/worker/console/chat/session-store.js +1 -1
  31. package/dist/worker/console/chat/user-questions.js +1 -1
  32. package/dist/worker/console/console-update-runtime.js +1 -1
  33. package/dist/worker/console/context-transfer-diagnostics.js +198 -0
  34. package/dist/worker/console/dag-confirmation.js +1 -1
  35. package/dist/worker/console/dag-execution-receipt.js +1 -1
  36. package/dist/worker/console/doctor.js +1 -1
  37. package/dist/worker/console/draft-store.js +1 -1
  38. package/dist/worker/console/human-gate-token.js +1 -1
  39. package/dist/worker/console/index.js +3 -3
  40. package/dist/worker/console/interview/assessment.js +1 -1
  41. package/dist/worker/console/interview/session.js +1 -1
  42. package/dist/worker/console/operation-runner.js +45 -4
  43. package/dist/worker/console/operation-sse.js +1 -1
  44. package/dist/worker/console/operation-wait.js +1 -1
  45. package/dist/worker/console/operator-actions.js +104 -3
  46. package/dist/worker/console/operator-surface-health.js +1 -1
  47. package/dist/worker/console/operator-user-error.js +169 -0
  48. package/dist/worker/console/pi-plugins.js +57 -0
  49. package/dist/worker/console/routes.js +637 -8
  50. package/dist/worker/console/security.js +35 -0
  51. package/dist/worker/console/server.js +6 -3
  52. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-DwVJxUxz.js → abnfDiagram-N423BO3Z-DZZ8m3PO.js} +1 -1
  53. package/dist/worker/console/static/assets/{arc-DqfCcXdu.js → arc-D6PvaVd-.js} +1 -1
  54. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-qMVtggRv.js → architectureDiagram-T3A2C74G-B_OTOiI8.js} +1 -1
  55. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-ECrV38dh.js → blockDiagram-VBNYF7ZC-Bv6rqHBg.js} +1 -1
  56. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-DBaaLqQv.js → c4Diagram-5PPSVZJV-B8eHr0oz.js} +1 -1
  57. package/dist/worker/console/static/assets/channel-BU5gOilw.js +1 -0
  58. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-BvfNHkAz.js → chunk-2GRJ4B5K-DYwR0im2.js} +1 -1
  59. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-C5StiIbc.js → chunk-2Q5K7J3B-D2WPGqXt.js} +1 -1
  60. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-HabGiJkS.js → chunk-5RXB4S5H-CQISJ_I7.js} +1 -1
  61. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-BiTg127i.js → chunk-5VM5RSS4-C0o2Du1e.js} +1 -1
  62. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-CZsXBPuR.js → chunk-6Q2QTUOP-4f8kr-U7.js} +1 -1
  63. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-D-r1MxLK.js → chunk-GF5L2VYU-D_OWvXzX.js} +1 -1
  64. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-DQxb9plr.js → chunk-JWPE2WC7-CasdPz5X.js} +1 -1
  65. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-DMndGvCT.js → chunk-KBJHAD2P-Cj8lRrla.js} +1 -1
  66. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-ByL4BgOJ.js → chunk-RYQCIY6F-CUvD1FSd.js} +1 -1
  67. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-BVe1b1gL.js → chunk-XXDRQBXY-CqLw_eqB.js} +1 -1
  68. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DIzKJGHr.js +1 -0
  69. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DIzKJGHr.js +1 -0
  70. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BAyGzN8j.js → cose-bilkent-JH36ORCC-ku-WqJPx.js} +1 -1
  71. package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-C5yVYU7E.js → cynefin-VYW2F7L2-Bq_PYDhl.js} +1 -1
  72. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-x-MwsEm9.js → cynefinDiagram-MW4NZA55-BiGZV641.js} +1 -1
  73. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-CT5Tle5F.js → dagre-VZM6K2ZE-C4JRlglF.js} +1 -1
  74. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-BARERhlS.js → diagram-7IWD3JNH-B0dNeWYG.js} +1 -1
  75. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-BwfUz0VM.js → diagram-B4RE2ZJO-Cj35YvYM.js} +1 -1
  76. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-Mk4r2WvJ.js → diagram-LBJQPF4R-uzQoJ2-8.js} +1 -1
  77. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-KUrxuBs0.js → diagram-Q27KOJAE-D1a-Buoz.js} +1 -1
  78. package/dist/worker/console/static/assets/{diagram-UB23O5K3-CjZOceZn.js → diagram-UB23O5K3-XjRrLRSs.js} +1 -1
  79. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-rnwUCiEI.js → ebnfDiagram-BXEA7PRR-Da_O24cW.js} +1 -1
  80. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-DM4j23FM.js → erDiagram-JOGREHBK-BLJ8jrYU.js} +1 -1
  81. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-DD5HdDEs.js → flowDiagram-UKHOOZJN-B9GrLjM0.js} +1 -1
  82. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-CIAGSF47.js → ganttDiagram-PKOTCBZU-CeJ0TqiK.js} +1 -1
  83. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-DbwFbVEL.js → gitGraphDiagram-DS77QQ5N-Bm2eNNFX.js} +1 -1
  84. package/dist/worker/console/static/assets/index-H9rFJiGL.css +1 -0
  85. package/dist/worker/console/static/assets/{index-Bih9w9h9.js → index-xwu9GxEc.js} +80 -80
  86. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-B-Pb0T66.js → infoDiagram-6WML65LV-DB26i3d8.js} +1 -1
  87. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-B9Unk-YX.js → ishikawaDiagram-WSZJBQD7-BOGRyeZT.js} +1 -1
  88. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-C2F3JkPt.js → journeyDiagram-NVQOT4AX-CZRoBO_6.js} +1 -1
  89. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-Bl8-Xcoz.js → kanban-definition-27J2QSJJ-qlWhJyoB.js} +1 -1
  90. package/dist/worker/console/static/assets/{linear-yK4uZmC5.js → linear-CfUiDDB3.js} +1 -1
  91. package/dist/worker/console/static/assets/{mermaid.core-Bpa6PmuE.js → mermaid.core-BQe6fpqj.js} +5 -5
  92. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-BfGRoCSe.js → mindmap-definition-FAOFIHXS-zFzWHw64.js} +1 -1
  93. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-Bz6_HtST.js → pegDiagram-VL7TDLO6-DFGUqjZO.js} +1 -1
  94. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-i0Umbsby.js → pieDiagram-7S7Q4E2Y-BB5i0l8Z.js} +1 -1
  95. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-DaVQBobe.js → quadrantDiagram-CIZ2JOQS-obbVZ_X5.js} +1 -1
  96. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-DMTGnSq7.js → railroadDiagram-AXF67PYL-BwdaNzc1.js} +1 -1
  97. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-2ao_DaSq.js → requirementDiagram-LRYGKXZP-CkTJaugh.js} +1 -1
  98. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-2SG1lTB9.js → sankeyDiagram-W5VNT64P-BwJ-hIgq.js} +1 -1
  99. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-BQYOLybR.js → sequenceDiagram-SI44F4Z6-BzSgmm7w.js} +1 -1
  100. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-C8g3yjuI.js → sizeCapture-X5ZJPWSS-Bn3oj5Q1.js} +1 -1
  101. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-q_F8nAQG.js → stateDiagram-OKZ733FA-dxhGtL8K.js} +1 -1
  102. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Cld2qK9v.js +1 -0
  103. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-8LrWpH2s.js → swimlanes-SLNWSIFB-BLpEInya.js} +2 -2
  104. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-TIHpiT7w.js +8 -0
  105. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-BQoY3qzl.js → timeline-definition-Z64GVDOM-ChJGYcXy.js} +1 -1
  106. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-BDu1UjSp.js → vennDiagram-T6HMQDX7-DK-qjRer.js} +1 -1
  107. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-C48M7Y0a.js → wardleyDiagram-T6FBY63Y-3qeaWAg-.js} +1 -1
  108. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-YU6FTl_F.js → xychartDiagram-ELKLHX3M-CootlyP9.js} +1 -1
  109. package/dist/worker/console/static/index.html +7 -2
  110. package/dist/worker/console/static-src/app/useOperatorActions.js +3 -2
  111. package/dist/worker/console/static-src/shell/console-update-reload.js +25 -0
  112. package/dist/worker/console/workspace-context.js +28 -2
  113. package/dist/worker/console/workspace-registry.js +2 -2
  114. package/dist/worker/continuation/worker-continuation.js +278 -0
  115. package/dist/worker/observe/health.js +1 -1
  116. package/dist/worker/observe/node-transparency.js +572 -0
  117. package/dist/worker/observe/routes.js +51 -1
  118. package/dist/worker/observe/static/api.js +69 -5
  119. package/dist/worker/observe/static/dag-context-reason-labels.d.ts +9 -0
  120. package/dist/worker/observe/static/dag-context-reason-labels.js +120 -0
  121. package/dist/worker/observe/static/state.js +3 -1
  122. package/dist/worker/observe/static/styles.css +1037 -126
  123. package/dist/worker/observe/static/views/dag-inspector.js +1215 -58
  124. package/dist/worker/observe/static/views/session-timeline.js +75 -10
  125. package/dist/worker/outcomes/adapters.js +19 -0
  126. package/dist/worker/outcomes/types.js +1 -0
  127. package/dist/worker/pool/attempt-lease.js +97 -66
  128. package/dist/worker/pool/begin-attempt-with-lease.js +1 -0
  129. package/dist/worker/pool/reconcile.js +46 -1
  130. package/dist/worker/pool/run-store.js +2 -0
  131. package/dist/worker/pool/state-projection.js +2 -0
  132. package/dist/worker/task-spec/workflow-routing.js +8 -3
  133. package/dist/workflows/dag/artifact-bindings.js +149 -0
  134. package/dist/workflows/dag/artifact-revision-schema-registry.js +31 -0
  135. package/dist/workflows/dag/budget-enforcement.js +10 -0
  136. package/dist/workflows/dag/context-receipt.js +305 -0
  137. package/dist/workflows/dag/context-transfer/context-bundle.js +423 -0
  138. package/dist/workflows/dag/context-transfer/operator-actions.js +61 -0
  139. package/dist/workflows/dag/context-transfer/renderers.js +93 -0
  140. package/dist/workflows/dag/frontend-writer-rollback.js +32 -0
  141. package/dist/workflows/dag/init-hybrid.js +146 -0
  142. package/dist/workflows/dag/node-execution.js +112 -27
  143. package/dist/workflows/dag/path-safety.js +1 -0
  144. package/dist/workflows/dag/prompt.js +29 -4
  145. package/dist/workflows/dag/rerun-plan.js +555 -1
  146. package/dist/workflows/dag/rerun-run.js +601 -15
  147. package/dist/workflows/dag/runner.js +20 -1
  148. package/dist/workflows/dag/skill-snapshot.js +17 -0
  149. package/dist/workflows/dag/types.js +183 -7
  150. package/docs/architecture/runtime-boundaries.md +6 -6
  151. package/docs/architecture/worker-and-feature.md +1 -1
  152. package/docs/templates/agent-dag.schema.json +32 -0
  153. package/docs/templates/product-line/task.yaml +1 -1
  154. package/package.json +3 -1
  155. package/skills/loop-agent/references/command-reference.md +6 -0
  156. package/dist/worker/console/static/assets/channel-CL1NRAmS.js +0 -1
  157. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-PBGzzjZA.js +0 -1
  158. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-PBGzzjZA.js +0 -1
  159. package/dist/worker/console/static/assets/index-BfleX-qj.css +0 -1
  160. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DrxGBDJu.js +0 -1
  161. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BhpDxzAf.js +0 -8
  162. /package/dist/{worker → infrastructure}/console/repo-fingerprint.js +0 -0
@@ -0,0 +1,278 @@
1
+ import path from "node:path";
2
+ import { deriveWorkerContinuationRunId, workerContinuationAuthorityV1Schema, } from "../../shared/context-transfer.js";
3
+ import { controllerIdentityAnchor } from "../../shared/package-metadata.js";
4
+ import { locateDagRun, readDagRunState, } from "../../workflows/dag/lifecycle.js";
5
+ import { beginWorkerAttemptWithLease } from "../pool/begin-attempt-with-lease.js";
6
+ import { readAttemptLease, releaseAttemptLease, } from "../pool/attempt-lease.js";
7
+ import { readRunOwner } from "../pool/run-owner-store.js";
8
+ import { findRunByWorkerRunId, recordTaskPoolRun, readTaskPoolState, writeTaskPoolState, } from "../pool/run-store.js";
9
+ /**
10
+ * Resolve a Worker parent into an immutable continuation authority. Standalone
11
+ * and missing fixture parents return undefined; a detected Worker parent with
12
+ * incomplete Task Pool ownership fails closed.
13
+ */
14
+ export async function resolveWorkerContinuationAuthority(input) {
15
+ const located = await locateDagRun(input.repoRoot, input.parentDagRunId);
16
+ if (!located)
17
+ return undefined;
18
+ const state = await readDagRunState(located.runDir);
19
+ const association = state.workerAssociation;
20
+ if (!association)
21
+ return undefined;
22
+ if (located.lifecycle !== "completed" || state.status !== "finished") {
23
+ throw new Error(`WORKER_CONTINUATION_AUTHORITY_MISMATCH: parent DAG is not completed: ${input.parentDagRunId}`);
24
+ }
25
+ const expectedChildWorkerRunId = deriveWorkerContinuationRunId(association.workerRunId, input.revisionId);
26
+ const [owner, parentRun, childRun, poolState, activeLease] = await Promise.all([
27
+ readRunOwner(input.repoRoot, association.workerRunId),
28
+ findRunByWorkerRunId(input.repoRoot, association.workerRunId),
29
+ findRunByWorkerRunId(input.repoRoot, expectedChildWorkerRunId),
30
+ readTaskPoolState(input.repoRoot, {
31
+ featureId: association.featureId,
32
+ taskId: association.taskId,
33
+ }),
34
+ readAttemptLease(input.repoRoot, association.featureId, association.taskId),
35
+ ]);
36
+ const parentOutcomeReady = poolState?.status === "Done" &&
37
+ poolState.workerRunId === association.workerRunId;
38
+ const matchingActiveContinuation = input.allowActiveRevision === true &&
39
+ poolState?.status === "Running" &&
40
+ poolState.workerRunId === expectedChildWorkerRunId &&
41
+ poolState.attemptKind === "artifact-continuation" &&
42
+ poolState.continuation?.parentWorkerRunId === association.workerRunId &&
43
+ poolState.continuation.parentDagRunId === input.parentDagRunId &&
44
+ poolState.continuation.revisionId === input.revisionId &&
45
+ activeLease?.workerRunId === expectedChildWorkerRunId &&
46
+ activeLease.revisionId === input.revisionId &&
47
+ activeLease.claimId === poolState.continuation.operationId;
48
+ const matchingTerminalContinuation = input.allowActiveRevision === true &&
49
+ poolState?.status === "Failed" &&
50
+ poolState.workerRunId === expectedChildWorkerRunId &&
51
+ poolState.attemptKind === "artifact-continuation" &&
52
+ poolState.continuation?.parentWorkerRunId === association.workerRunId &&
53
+ poolState.continuation.parentDagRunId === input.parentDagRunId &&
54
+ poolState.continuation.revisionId === input.revisionId &&
55
+ childRun?.status === "failed" &&
56
+ childRun.attemptKind === "artifact-continuation" &&
57
+ childRun.continuation?.operationId ===
58
+ poolState.continuation.operationId &&
59
+ activeLease === undefined;
60
+ if (!owner ||
61
+ !parentRun ||
62
+ owner.workerRunId !== association.workerRunId ||
63
+ owner.featureId !== association.featureId ||
64
+ owner.taskId !== association.taskId ||
65
+ parentRun.featureId !== association.featureId ||
66
+ parentRun.taskId !== association.taskId ||
67
+ parentRun.batchRunId !== owner.batchRunId ||
68
+ parentRun.status !== "succeeded" ||
69
+ (!parentOutcomeReady &&
70
+ !matchingActiveContinuation &&
71
+ !matchingTerminalContinuation)) {
72
+ throw new Error(`WORKER_CONTINUATION_AUTHORITY_MISMATCH: parent Worker ownership is incomplete for ${association.workerRunId}`);
73
+ }
74
+ const authority = workerContinuationAuthorityV1Schema.parse({
75
+ schemaVersion: 1,
76
+ parentWorkerRunId: association.workerRunId,
77
+ childWorkerRunId: expectedChildWorkerRunId,
78
+ featureId: association.featureId,
79
+ taskId: association.taskId,
80
+ batchRunId: owner.batchRunId,
81
+ revisionId: input.revisionId,
82
+ });
83
+ return { authority, parentDagRunId: input.parentDagRunId };
84
+ }
85
+ export async function beginWorkerContinuation(input) {
86
+ const { authority } = input.resolved;
87
+ const priorState = await readTaskPoolState(input.repoRoot, {
88
+ featureId: authority.featureId,
89
+ taskId: authority.taskId,
90
+ });
91
+ const existingLease = await readAttemptLease(input.repoRoot, authority.featureId, authority.taskId);
92
+ const freshParentOutcome = priorState?.status === "Done" &&
93
+ priorState.workerRunId === authority.parentWorkerRunId &&
94
+ priorState.lastContinuation?.revisionId !== authority.revisionId;
95
+ const sameCanonicalRunning = priorState?.status === "Running" &&
96
+ priorState.workerRunId === authority.childWorkerRunId &&
97
+ priorState.continuation?.operationId === input.operationId &&
98
+ existingLease?.workerRunId === authority.childWorkerRunId &&
99
+ existingLease.revisionId === authority.revisionId &&
100
+ existingLease.claimId === input.operationId;
101
+ if (!freshParentOutcome && !sameCanonicalRunning) {
102
+ throw new Error(`state-conflict for ${authority.featureId}/${authority.taskId}: continuation admission is not fresh`);
103
+ }
104
+ if (existingLease) {
105
+ const sameCanonicalOperation = existingLease.workerRunId === authority.childWorkerRunId &&
106
+ existingLease.revisionId === authority.revisionId &&
107
+ existingLease.claimId === input.operationId &&
108
+ priorState?.continuation?.operationId === input.operationId;
109
+ if (!sameCanonicalOperation) {
110
+ throw new Error(`attempt-lease-conflict for ${authority.featureId}/${authority.taskId}: held by ${existingLease.workerRunId}`);
111
+ }
112
+ }
113
+ const identity = input.client.getIdentity?.();
114
+ const lineage = buildLineage(input.resolved, input.operationId);
115
+ try {
116
+ await beginWorkerAttemptWithLease({
117
+ repoRoot: input.repoRoot,
118
+ featureId: authority.featureId,
119
+ taskId: authority.taskId,
120
+ workerRunId: authority.childWorkerRunId,
121
+ batchRunId: authority.batchRunId,
122
+ revisionId: authority.revisionId,
123
+ leaseClaimId: input.operationId,
124
+ ...(identity
125
+ ? {
126
+ controllerAnchor: controllerIdentityAnchor(identity),
127
+ skipProtocolPreflight: true,
128
+ }
129
+ : { skipProtocolPreflight: true }),
130
+ stateExtras: {
131
+ attemptKind: "artifact-continuation",
132
+ continuation: lineage,
133
+ },
134
+ });
135
+ }
136
+ catch (error) {
137
+ if (!existingLease) {
138
+ const lease = await readAttemptLease(input.repoRoot, authority.featureId, authority.taskId);
139
+ const ownsLease = lease?.workerRunId === authority.childWorkerRunId &&
140
+ lease.revisionId === authority.revisionId &&
141
+ lease.claimId === input.operationId;
142
+ if (ownsLease && lease) {
143
+ await releaseAttemptLease({
144
+ repoRoot: input.repoRoot,
145
+ featureId: authority.featureId,
146
+ taskId: authority.taskId,
147
+ token: lease.token,
148
+ workerRunId: authority.childWorkerRunId,
149
+ }).catch(() => undefined);
150
+ }
151
+ const current = await readTaskPoolState(input.repoRoot, {
152
+ featureId: authority.featureId,
153
+ taskId: authority.taskId,
154
+ });
155
+ if (ownsLease &&
156
+ priorState &&
157
+ current?.workerRunId === authority.childWorkerRunId &&
158
+ current.continuation?.operationId === input.operationId) {
159
+ await writeTaskPoolState(input.repoRoot, priorState);
160
+ }
161
+ }
162
+ throw error;
163
+ }
164
+ }
165
+ /**
166
+ * Terminal projection is idempotent. needs-reconcile deliberately retains the
167
+ * Running state and Task lease so recovery cannot be raced by a new attempt.
168
+ */
169
+ export async function settleWorkerContinuation(input) {
170
+ if (input.state === "needs-reconcile")
171
+ return;
172
+ if (input.state !== "succeeded" &&
173
+ input.state !== "failed" &&
174
+ input.state !== "timed-out")
175
+ return;
176
+ const { authority } = input.resolved;
177
+ const lineage = buildLineage(input.resolved, input.operation.operationId);
178
+ const existing = await findRunByWorkerRunId(input.repoRoot, authority.childWorkerRunId);
179
+ let terminalRun = existing;
180
+ if (existing) {
181
+ assertMatchingTerminalRecord(existing, lineage, authority);
182
+ }
183
+ else {
184
+ const located = await locateDagRun(input.repoRoot, authority.childWorkerRunId);
185
+ const succeeded = input.state === "succeeded" && input.info.ok;
186
+ terminalRun = {
187
+ schemaVersion: 1,
188
+ batchRunId: authority.batchRunId,
189
+ workerRunId: authority.childWorkerRunId,
190
+ taskId: authority.taskId,
191
+ featureId: authority.featureId,
192
+ status: succeeded ? "succeeded" : "failed",
193
+ attemptKind: "artifact-continuation",
194
+ continuation: lineage,
195
+ harnessTaskId: authority.childWorkerRunId,
196
+ ...(located
197
+ ? { dagPath: path.relative(input.repoRoot, located.runDir).split(path.sep).join("/") }
198
+ : {}),
199
+ recordedAt: input.operation.finishedAt ?? new Date().toISOString(),
200
+ ...(succeeded
201
+ ? {}
202
+ : {
203
+ error: input.operation.errorMessage ?? input.info.errorCode ?? "artifact continuation failed",
204
+ failure: {
205
+ category: "Unknown",
206
+ recommendedFollowUpKind: "manual-review",
207
+ derivedFollowUpTaskId: `${authority.taskId}-continuation-review`,
208
+ source: "runner-error",
209
+ },
210
+ }),
211
+ };
212
+ await recordTaskPoolRun({
213
+ repoRoot: input.repoRoot,
214
+ run: terminalRun,
215
+ });
216
+ }
217
+ if (terminalRun?.status === "succeeded") {
218
+ const parentRun = await findRunByWorkerRunId(input.repoRoot, authority.parentWorkerRunId);
219
+ if (!parentRun || parentRun.status !== "succeeded") {
220
+ throw new Error(`parent Worker outcome is unavailable after continuation: ${authority.parentWorkerRunId}`);
221
+ }
222
+ await writeTaskPoolState(input.repoRoot, {
223
+ schemaVersion: 2,
224
+ featureId: authority.featureId,
225
+ taskId: authority.taskId,
226
+ status: "Done",
227
+ updatedAt: terminalRun.recordedAt,
228
+ workerRunId: authority.parentWorkerRunId,
229
+ ...(parentRun.runRecordPath
230
+ ? { lastRunRecordPath: parentRun.runRecordPath }
231
+ : {}),
232
+ lastContinuation: {
233
+ ...lineage,
234
+ status: "succeeded",
235
+ recordedAt: terminalRun.recordedAt,
236
+ },
237
+ });
238
+ }
239
+ const lease = await readAttemptLease(input.repoRoot, authority.featureId, authority.taskId);
240
+ if (!lease)
241
+ return;
242
+ if (lease.workerRunId !== authority.childWorkerRunId ||
243
+ lease.revisionId !== authority.revisionId ||
244
+ lease.claimId !== input.operation.operationId) {
245
+ throw new Error(`attempt lease ownership drift for ${authority.featureId}/${authority.taskId}`);
246
+ }
247
+ await releaseAttemptLease({
248
+ repoRoot: input.repoRoot,
249
+ featureId: authority.featureId,
250
+ taskId: authority.taskId,
251
+ token: lease.token,
252
+ workerRunId: authority.childWorkerRunId,
253
+ });
254
+ }
255
+ function buildLineage(resolved, operationId) {
256
+ return {
257
+ schemaVersion: 1,
258
+ kind: "artifact-continuation",
259
+ parentWorkerRunId: resolved.authority.parentWorkerRunId,
260
+ parentDagRunId: resolved.parentDagRunId,
261
+ childWorkerRunId: resolved.authority.childWorkerRunId,
262
+ revisionId: resolved.authority.revisionId,
263
+ operationId,
264
+ };
265
+ }
266
+ function assertMatchingTerminalRecord(run, lineage, authority) {
267
+ if (run.attemptKind !== "artifact-continuation" ||
268
+ run.featureId !== authority.featureId ||
269
+ run.taskId !== authority.taskId ||
270
+ run.batchRunId !== authority.batchRunId ||
271
+ run.continuation?.parentWorkerRunId !== lineage.parentWorkerRunId ||
272
+ run.continuation?.parentDagRunId !== lineage.parentDagRunId ||
273
+ run.continuation?.childWorkerRunId !== lineage.childWorkerRunId ||
274
+ run.continuation?.revisionId !== lineage.revisionId ||
275
+ run.continuation?.operationId !== lineage.operationId) {
276
+ throw new Error(`Worker continuation terminal record conflict: ${authority.childWorkerRunId}`);
277
+ }
278
+ }
@@ -1,7 +1,7 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  import path from "node:path";
3
3
  import { findPackageRoot, readPackageName, readPackageVersion, } from "../../shared/package-metadata.js";
4
- import { repoFingerprintV1 } from "../console/repo-fingerprint.js";
4
+ import { repoFingerprintV1 } from "../../infrastructure/console/repo-fingerprint.js";
5
5
  /** Observe `/api/health` schema version (independent of Console product health). */
6
6
  export const OBSERVE_HEALTH_SCHEMA_VERSION = 1;
7
7
  function routeExists(routes, method, pathname) {