pi-amq 0.1.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 (264) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/LICENSE +21 -0
  3. package/README.md +92 -0
  4. package/THIRD_PARTY_NOTICES.md +33 -0
  5. package/dist/extension/guidance.d.ts +25 -0
  6. package/dist/extension/guidance.d.ts.map +1 -0
  7. package/dist/extension/guidance.js +121 -0
  8. package/dist/extension/guidance.js.map +1 -0
  9. package/dist/extension/guide.d.ts +30 -0
  10. package/dist/extension/guide.d.ts.map +1 -0
  11. package/dist/extension/guide.js +128 -0
  12. package/dist/extension/guide.js.map +1 -0
  13. package/dist/extension/index.d.ts +4 -0
  14. package/dist/extension/index.d.ts.map +1 -0
  15. package/dist/extension/index.js +6 -0
  16. package/dist/extension/index.js.map +1 -0
  17. package/dist/extension/runtime.d.ts +48 -0
  18. package/dist/extension/runtime.d.ts.map +1 -0
  19. package/dist/extension/runtime.js +1095 -0
  20. package/dist/extension/runtime.js.map +1 -0
  21. package/dist/extension/tools.d.ts +12 -0
  22. package/dist/extension/tools.d.ts.map +1 -0
  23. package/dist/extension/tools.js +198 -0
  24. package/dist/extension/tools.js.map +1 -0
  25. package/dist/extension/worker-runtime.d.ts +34 -0
  26. package/dist/extension/worker-runtime.d.ts.map +1 -0
  27. package/dist/extension/worker-runtime.js +974 -0
  28. package/dist/extension/worker-runtime.js.map +1 -0
  29. package/dist/extension/worker-tools.d.ts +140 -0
  30. package/dist/extension/worker-tools.d.ts.map +1 -0
  31. package/dist/extension/worker-tools.js +217 -0
  32. package/dist/extension/worker-tools.js.map +1 -0
  33. package/dist/integration/confirmed-bind-onboarding.d.ts +44 -0
  34. package/dist/integration/confirmed-bind-onboarding.d.ts.map +1 -0
  35. package/dist/integration/confirmed-bind-onboarding.js +199 -0
  36. package/dist/integration/confirmed-bind-onboarding.js.map +1 -0
  37. package/dist/integration/fleet-view.d.ts +66 -0
  38. package/dist/integration/fleet-view.d.ts.map +1 -0
  39. package/dist/integration/fleet-view.js +238 -0
  40. package/dist/integration/fleet-view.js.map +1 -0
  41. package/dist/integration/fresh-session-dispatcher.d.ts +66 -0
  42. package/dist/integration/fresh-session-dispatcher.d.ts.map +1 -0
  43. package/dist/integration/fresh-session-dispatcher.js +103 -0
  44. package/dist/integration/fresh-session-dispatcher.js.map +1 -0
  45. package/dist/integration/launch-preview.d.ts +31 -0
  46. package/dist/integration/launch-preview.d.ts.map +1 -0
  47. package/dist/integration/launch-preview.js +325 -0
  48. package/dist/integration/launch-preview.js.map +1 -0
  49. package/dist/integration/transport-port.d.ts +39 -0
  50. package/dist/integration/transport-port.d.ts.map +1 -0
  51. package/dist/integration/transport-port.js +2 -0
  52. package/dist/integration/transport-port.js.map +1 -0
  53. package/dist/integration/worker-completion-notifier.d.ts +22 -0
  54. package/dist/integration/worker-completion-notifier.d.ts.map +1 -0
  55. package/dist/integration/worker-completion-notifier.js +81 -0
  56. package/dist/integration/worker-completion-notifier.js.map +1 -0
  57. package/dist/transport/amq-cli-adapter.d.ts +41 -0
  58. package/dist/transport/amq-cli-adapter.d.ts.map +1 -0
  59. package/dist/transport/amq-cli-adapter.js +291 -0
  60. package/dist/transport/amq-cli-adapter.js.map +1 -0
  61. package/dist/transport/amq-message.d.ts +47 -0
  62. package/dist/transport/amq-message.d.ts.map +1 -0
  63. package/dist/transport/amq-message.js +173 -0
  64. package/dist/transport/amq-message.js.map +1 -0
  65. package/dist/transport/amq-operations.d.ts +105 -0
  66. package/dist/transport/amq-operations.d.ts.map +1 -0
  67. package/dist/transport/amq-operations.js +320 -0
  68. package/dist/transport/amq-operations.js.map +1 -0
  69. package/dist/transport/atomic-json.d.ts +18 -0
  70. package/dist/transport/atomic-json.d.ts.map +1 -0
  71. package/dist/transport/atomic-json.js +90 -0
  72. package/dist/transport/atomic-json.js.map +1 -0
  73. package/dist/transport/binding-resolver.d.ts +46 -0
  74. package/dist/transport/binding-resolver.d.ts.map +1 -0
  75. package/dist/transport/binding-resolver.js +389 -0
  76. package/dist/transport/binding-resolver.js.map +1 -0
  77. package/dist/transport/bridge-journal.d.ts +100 -0
  78. package/dist/transport/bridge-journal.d.ts.map +1 -0
  79. package/dist/transport/bridge-journal.js +459 -0
  80. package/dist/transport/bridge-journal.js.map +1 -0
  81. package/dist/transport/dlq-retry-audit.d.ts +28 -0
  82. package/dist/transport/dlq-retry-audit.d.ts.map +1 -0
  83. package/dist/transport/dlq-retry-audit.js +66 -0
  84. package/dist/transport/dlq-retry-audit.js.map +1 -0
  85. package/dist/transport/inbox-pump.d.ts +81 -0
  86. package/dist/transport/inbox-pump.d.ts.map +1 -0
  87. package/dist/transport/inbox-pump.js +558 -0
  88. package/dist/transport/inbox-pump.js.map +1 -0
  89. package/dist/transport/index.d.ts +12 -0
  90. package/dist/transport/index.d.ts.map +1 -0
  91. package/dist/transport/index.js +12 -0
  92. package/dist/transport/index.js.map +1 -0
  93. package/dist/transport/presence-projector.d.ts +29 -0
  94. package/dist/transport/presence-projector.d.ts.map +1 -0
  95. package/dist/transport/presence-projector.js +73 -0
  96. package/dist/transport/presence-projector.js.map +1 -0
  97. package/dist/transport/priority-delivery-scheduler.d.ts +85 -0
  98. package/dist/transport/priority-delivery-scheduler.d.ts.map +1 -0
  99. package/dist/transport/priority-delivery-scheduler.js +210 -0
  100. package/dist/transport/priority-delivery-scheduler.js.map +1 -0
  101. package/dist/transport/receiver-lease.d.ts +102 -0
  102. package/dist/transport/receiver-lease.d.ts.map +1 -0
  103. package/dist/transport/receiver-lease.js +778 -0
  104. package/dist/transport/receiver-lease.js.map +1 -0
  105. package/dist/transport/runtime-status.d.ts +48 -0
  106. package/dist/transport/runtime-status.d.ts.map +1 -0
  107. package/dist/transport/runtime-status.js +71 -0
  108. package/dist/transport/runtime-status.js.map +1 -0
  109. package/dist/workflow/atomic-storage.d.ts +12 -0
  110. package/dist/workflow/atomic-storage.d.ts.map +1 -0
  111. package/dist/workflow/atomic-storage.js +104 -0
  112. package/dist/workflow/atomic-storage.js.map +1 -0
  113. package/dist/workflow/budget.d.ts +18 -0
  114. package/dist/workflow/budget.d.ts.map +1 -0
  115. package/dist/workflow/budget.js +74 -0
  116. package/dist/workflow/budget.js.map +1 -0
  117. package/dist/workflow/index.d.ts +17 -0
  118. package/dist/workflow/index.d.ts.map +1 -0
  119. package/dist/workflow/index.js +17 -0
  120. package/dist/workflow/index.js.map +1 -0
  121. package/dist/workflow/lifecycle-projection.d.ts +18 -0
  122. package/dist/workflow/lifecycle-projection.d.ts.map +1 -0
  123. package/dist/workflow/lifecycle-projection.js +22 -0
  124. package/dist/workflow/lifecycle-projection.js.map +1 -0
  125. package/dist/workflow/model-fallback.d.ts +2 -0
  126. package/dist/workflow/model-fallback.d.ts.map +1 -0
  127. package/dist/workflow/model-fallback.js +17 -0
  128. package/dist/workflow/model-fallback.js.map +1 -0
  129. package/dist/workflow/pi-session-fork.d.ts +18 -0
  130. package/dist/workflow/pi-session-fork.d.ts.map +1 -0
  131. package/dist/workflow/pi-session-fork.js +80 -0
  132. package/dist/workflow/pi-session-fork.js.map +1 -0
  133. package/dist/workflow/run-artifacts.d.ts +5 -0
  134. package/dist/workflow/run-artifacts.d.ts.map +1 -0
  135. package/dist/workflow/run-artifacts.js +25 -0
  136. package/dist/workflow/run-artifacts.js.map +1 -0
  137. package/dist/workflow/run-cleanup.d.ts +70 -0
  138. package/dist/workflow/run-cleanup.d.ts.map +1 -0
  139. package/dist/workflow/run-cleanup.js +222 -0
  140. package/dist/workflow/run-cleanup.js.map +1 -0
  141. package/dist/workflow/run-gate.d.ts +43 -0
  142. package/dist/workflow/run-gate.d.ts.map +1 -0
  143. package/dist/workflow/run-gate.js +70 -0
  144. package/dist/workflow/run-gate.js.map +1 -0
  145. package/dist/workflow/run-store.d.ts +208 -0
  146. package/dist/workflow/run-store.d.ts.map +1 -0
  147. package/dist/workflow/run-store.js +2965 -0
  148. package/dist/workflow/run-store.js.map +1 -0
  149. package/dist/workflow/spawn-confirmation.d.ts +44 -0
  150. package/dist/workflow/spawn-confirmation.d.ts.map +1 -0
  151. package/dist/workflow/spawn-confirmation.js +228 -0
  152. package/dist/workflow/spawn-confirmation.js.map +1 -0
  153. package/dist/workflow/system-process-inspector.d.ts +9 -0
  154. package/dist/workflow/system-process-inspector.d.ts.map +1 -0
  155. package/dist/workflow/system-process-inspector.js +129 -0
  156. package/dist/workflow/system-process-inspector.js.map +1 -0
  157. package/dist/workflow/worker-child-extension.d.ts +3 -0
  158. package/dist/workflow/worker-child-extension.d.ts.map +1 -0
  159. package/dist/workflow/worker-child-extension.js +182 -0
  160. package/dist/workflow/worker-child-extension.js.map +1 -0
  161. package/dist/workflow/worker-gate.d.ts +74 -0
  162. package/dist/workflow/worker-gate.d.ts.map +1 -0
  163. package/dist/workflow/worker-gate.js +165 -0
  164. package/dist/workflow/worker-gate.js.map +1 -0
  165. package/dist/workflow/worker-launch.d.ts +65 -0
  166. package/dist/workflow/worker-launch.d.ts.map +1 -0
  167. package/dist/workflow/worker-launch.js +338 -0
  168. package/dist/workflow/worker-launch.js.map +1 -0
  169. package/dist/workflow/worker-model-catalog.d.ts +36 -0
  170. package/dist/workflow/worker-model-catalog.d.ts.map +1 -0
  171. package/dist/workflow/worker-model-catalog.js +105 -0
  172. package/dist/workflow/worker-model-catalog.js.map +1 -0
  173. package/dist/workflow/worker-process-supervisor.d.ts +110 -0
  174. package/dist/workflow/worker-process-supervisor.d.ts.map +1 -0
  175. package/dist/workflow/worker-process-supervisor.js +1188 -0
  176. package/dist/workflow/worker-process-supervisor.js.map +1 -0
  177. package/dist/workflow/worker-prompt-capsule.d.ts +32 -0
  178. package/dist/workflow/worker-prompt-capsule.d.ts.map +1 -0
  179. package/dist/workflow/worker-prompt-capsule.js +52 -0
  180. package/dist/workflow/worker-prompt-capsule.js.map +1 -0
  181. package/dist/workflow/worker-role-presets.d.ts +38 -0
  182. package/dist/workflow/worker-role-presets.d.ts.map +1 -0
  183. package/dist/workflow/worker-role-presets.js +201 -0
  184. package/dist/workflow/worker-role-presets.js.map +1 -0
  185. package/dist/workflow/workflow-doctor.d.ts +57 -0
  186. package/dist/workflow/workflow-doctor.d.ts.map +1 -0
  187. package/dist/workflow/workflow-doctor.js +289 -0
  188. package/dist/workflow/workflow-doctor.js.map +1 -0
  189. package/dist/workflow/workflow-lease.d.ts +125 -0
  190. package/dist/workflow/workflow-lease.d.ts.map +1 -0
  191. package/dist/workflow/workflow-lease.js +689 -0
  192. package/dist/workflow/workflow-lease.js.map +1 -0
  193. package/dist/workflow/workflow-types.d.ts +335 -0
  194. package/dist/workflow/workflow-types.d.ts.map +1 -0
  195. package/dist/workflow/workflow-types.js +11 -0
  196. package/dist/workflow/workflow-types.js.map +1 -0
  197. package/dist/workflow/workspace-paths.d.ts +4 -0
  198. package/dist/workflow/workspace-paths.d.ts.map +1 -0
  199. package/dist/workflow/workspace-paths.js +22 -0
  200. package/dist/workflow/workspace-paths.js.map +1 -0
  201. package/docs/conformance.md +116 -0
  202. package/docs/demo-transcript.md +34 -0
  203. package/docs/design.md +1481 -0
  204. package/docs/operator-guide.md +100 -0
  205. package/extension/guidance.ts +162 -0
  206. package/extension/guide.ts +155 -0
  207. package/extension/index.ts +8 -0
  208. package/extension/runtime.ts +1224 -0
  209. package/extension/tools.ts +221 -0
  210. package/extension/worker-runtime.ts +1150 -0
  211. package/extension/worker-tools.ts +276 -0
  212. package/integration/confirmed-bind-onboarding.ts +296 -0
  213. package/integration/fleet-view.ts +286 -0
  214. package/integration/fresh-session-dispatcher.ts +166 -0
  215. package/integration/launch-preview.ts +396 -0
  216. package/integration/transport-port.ts +29 -0
  217. package/integration/worker-completion-notifier.ts +98 -0
  218. package/package.json +55 -0
  219. package/roles/oracle.md +9 -0
  220. package/roles/researcher.md +8 -0
  221. package/roles/reviewer.md +9 -0
  222. package/roles/scout.md +8 -0
  223. package/roles/worker.md +10 -0
  224. package/scripts/demo-two-terminal.sh +59 -0
  225. package/skills/coordination-patterns/SKILL.md +41 -0
  226. package/skills/coordination-patterns/references/supervised-worker-fan-out.md +12 -0
  227. package/skills/coordination-patterns/references/today-mail-team.md +36 -0
  228. package/transport/amq-cli-adapter.ts +381 -0
  229. package/transport/amq-message.ts +218 -0
  230. package/transport/amq-operations.ts +482 -0
  231. package/transport/atomic-json.ts +115 -0
  232. package/transport/binding-resolver.ts +565 -0
  233. package/transport/bridge-journal.ts +588 -0
  234. package/transport/dlq-retry-audit.ts +97 -0
  235. package/transport/inbox-pump.ts +729 -0
  236. package/transport/index.ts +11 -0
  237. package/transport/presence-projector.ts +104 -0
  238. package/transport/priority-delivery-scheduler.ts +328 -0
  239. package/transport/receiver-lease.ts +945 -0
  240. package/transport/runtime-status.ts +112 -0
  241. package/workflow/.gitkeep +1 -0
  242. package/workflow/atomic-storage.ts +120 -0
  243. package/workflow/budget.ts +90 -0
  244. package/workflow/index.ts +16 -0
  245. package/workflow/lifecycle-projection.ts +37 -0
  246. package/workflow/model-fallback.ts +17 -0
  247. package/workflow/pi-session-fork.ts +96 -0
  248. package/workflow/run-artifacts.ts +36 -0
  249. package/workflow/run-cleanup.ts +315 -0
  250. package/workflow/run-gate.ts +122 -0
  251. package/workflow/run-store.ts +3890 -0
  252. package/workflow/spawn-confirmation.ts +305 -0
  253. package/workflow/system-process-inspector.ts +142 -0
  254. package/workflow/worker-child-extension.ts +193 -0
  255. package/workflow/worker-gate.ts +238 -0
  256. package/workflow/worker-launch.ts +485 -0
  257. package/workflow/worker-model-catalog.ts +165 -0
  258. package/workflow/worker-process-supervisor.ts +1504 -0
  259. package/workflow/worker-prompt-capsule.ts +81 -0
  260. package/workflow/worker-role-presets.ts +241 -0
  261. package/workflow/workflow-doctor.ts +400 -0
  262. package/workflow/workflow-lease.ts +905 -0
  263. package/workflow/workflow-types.ts +367 -0
  264. package/workflow/workspace-paths.ts +32 -0
@@ -0,0 +1,289 @@
1
+ import { lstat, readdir } from "node:fs/promises";
2
+ import { basename, isAbsolute, join, normalize } from "node:path";
3
+ export class WorkflowDoctor {
4
+ #namespaceDirectory;
5
+ #runs;
6
+ #leases;
7
+ #inspector;
8
+ #now;
9
+ constructor(options) {
10
+ if (!isAbsolute(options.namespaceDirectory)) {
11
+ throw new TypeError("Workflow doctor namespace must be absolute");
12
+ }
13
+ this.#namespaceDirectory = normalize(options.namespaceDirectory);
14
+ this.#runs = options.runs;
15
+ this.#leases = options.leases;
16
+ this.#inspector = options.inspector;
17
+ this.#now = options.now ?? (() => new Date());
18
+ }
19
+ async inspect() {
20
+ const records = await this.#runs.diagnoseRunRecords();
21
+ const healthy = records.filter((record) => record.kind === "healthy");
22
+ const findings = [];
23
+ const orphanProcessIds = new Set();
24
+ for (const record of records) {
25
+ if (record.kind !== "corrupt")
26
+ continue;
27
+ findings.push({
28
+ severity: "error",
29
+ code: "corrupt-run-record",
30
+ message: record.diagnostic,
31
+ paths: [record.directory],
32
+ commands: [quarantineCommand(this.#namespaceDirectory, "run-record", record.directory)],
33
+ });
34
+ }
35
+ const attempts = healthy.flatMap((record) => attemptsIn(record.projection));
36
+ let workerProcessesChecked = 0;
37
+ for (const reference of attempts) {
38
+ const pid = reference.attempt.pidStartEvidence.pid;
39
+ if (pid === null)
40
+ continue;
41
+ workerProcessesChecked += 1;
42
+ const inspection = await this.#inspector.inspect(pid);
43
+ const matches = inspection.kind === "live"
44
+ && processIdentityMatchesAttempt(inspection.identity, reference.attempt);
45
+ if (matches && reference.attempt.pidStartEvidence.observedExitAt !== null) {
46
+ orphanProcessIds.add(pid);
47
+ findings.push(orphanProcessFinding(pid, reference.attempt.session.path, `Process ${pid} still matches terminal ledger attempt ${reference.attempt.attemptId}`));
48
+ }
49
+ else if (!matches && reference.attempt.pidStartEvidence.observedExitAt === null) {
50
+ findings.push({
51
+ severity: "warning",
52
+ code: "ledger-process-missing",
53
+ message: processMismatchDiagnostic(pid, inspection, reference.attempt),
54
+ paths: [reference.attempt.session.path],
55
+ commands: [inspectProcessCommand(pid)],
56
+ });
57
+ }
58
+ }
59
+ let currentIdentity;
60
+ try {
61
+ currentIdentity = await this.#inspector.current();
62
+ }
63
+ catch {
64
+ // Individual records stay visible as abandoned/unverifiable below.
65
+ }
66
+ const leaseRecords = await this.#leases.diagnoseWorkerSessionLeases();
67
+ for (const record of leaseRecords) {
68
+ if (record.projection.kind === "empty")
69
+ continue;
70
+ if (record.projection.kind === "corrupt") {
71
+ findings.push({
72
+ severity: "error",
73
+ code: "corrupt-session-lease",
74
+ message: record.projection.diagnostic,
75
+ paths: [record.path],
76
+ commands: [quarantineCommand(this.#namespaceDirectory, "session-lease", record.path)],
77
+ });
78
+ continue;
79
+ }
80
+ const owner = record.projection.owner;
81
+ const reference = attempts.find((candidate) => leaseOwnerReferences(owner, candidate));
82
+ const inspection = await inspectLeaseOwner(owner, currentIdentity, this.#inspector);
83
+ const live = inspection.kind === "live" && processIdentityMatchesOwner(inspection.identity, owner);
84
+ if (live && (reference === undefined || !leaseOwnerConsistentWithLedger(owner, reference))) {
85
+ if (!orphanProcessIds.has(owner.pid)) {
86
+ orphanProcessIds.add(owner.pid);
87
+ findings.push(orphanProcessFinding(owner.pid, record.path, reference === undefined
88
+ ? `Live lease process ${owner.pid} has no matching readable ledger attempt`
89
+ : `Live lease process ${owner.pid} conflicts with ledger attempt ${reference.attempt.attemptId}`));
90
+ }
91
+ }
92
+ else if (!live && inspection.kind !== "unknown") {
93
+ findings.push({
94
+ severity: "warning",
95
+ code: "stale-session-lease",
96
+ message: leaseMismatchDiagnostic(owner, inspection),
97
+ paths: [record.path, ...(owner.sessionPath ? [owner.sessionPath] : [])],
98
+ commands: [quarantineCommand(this.#namespaceDirectory, "session-lease", record.path)],
99
+ });
100
+ }
101
+ else if (inspection.kind === "unknown") {
102
+ findings.push({
103
+ severity: "warning",
104
+ code: "abandoned-session-lease",
105
+ message: inspection.diagnostic,
106
+ paths: [record.path, ...(owner.sessionPath ? [owner.sessionPath] : [])],
107
+ commands: [inspectProcessCommand(owner.pid)],
108
+ });
109
+ }
110
+ }
111
+ const referencedSessions = new Set(attempts.map((reference) => normalize(reference.attempt.session.path)));
112
+ for (const path of await sessionDirectories(this.#namespaceDirectory)) {
113
+ if (referencedSessions.has(path))
114
+ continue;
115
+ findings.push({
116
+ severity: "warning",
117
+ code: "dangling-session",
118
+ message: records.some((record) => record.kind === "corrupt")
119
+ ? "Session is not referenced by a readable run; corrupt run records make ownership uncertain"
120
+ : "Session is not referenced by any workflow run",
121
+ paths: [path],
122
+ commands: [quarantineCommand(this.#namespaceDirectory, "session", path)],
123
+ });
124
+ }
125
+ findings.sort((left, right) => left.code.localeCompare(right.code) || left.paths[0].localeCompare(right.paths[0]));
126
+ const byArea = await topLevelDiskUsage(this.#namespaceDirectory);
127
+ return {
128
+ schema: 1,
129
+ checkedAt: this.#now().toISOString(),
130
+ status: findings.length === 0 ? "ok" : "attention",
131
+ summary: {
132
+ healthyRuns: healthy.length,
133
+ corruptRuns: records.length - healthy.length,
134
+ workerProcessesChecked,
135
+ orphanProcesses: orphanProcessIds.size,
136
+ staleOrAbandonedLeases: findings.filter((finding) => finding.code === "stale-session-lease"
137
+ || finding.code === "abandoned-session-lease"
138
+ || finding.code === "corrupt-session-lease").length,
139
+ danglingSessions: findings.filter((finding) => finding.code === "dangling-session").length,
140
+ },
141
+ diskUsage: {
142
+ totalBytes: byArea.reduce((sum, area) => sum + area.bytes, 0),
143
+ byArea,
144
+ },
145
+ findings,
146
+ suggestedCommands: [{
147
+ kind: "pi",
148
+ argv: ["/pi-amq-cleanup", "--older-than", "7d"],
149
+ purpose: "Preview explicit cleanup of old terminal workflow state",
150
+ }],
151
+ };
152
+ }
153
+ }
154
+ function attemptsIn(run) {
155
+ return Object.values(run.workers).flatMap((worker) => worker.attempts.map((attempt) => ({ run, worker, attempt })));
156
+ }
157
+ function leaseOwnerReferences(owner, reference) {
158
+ return owner.runId === reference.run.runId
159
+ && owner.workerId === reference.worker.workerId
160
+ && owner.attemptId === reference.attempt.attemptId
161
+ && owner.workerAttemptGeneration === reference.attempt.workerAttemptGeneration
162
+ && owner.sessionPath === reference.attempt.session.path;
163
+ }
164
+ function leaseOwnerConsistentWithLedger(owner, reference) {
165
+ if (owner.stage === "reserved") {
166
+ return reference.attempt.state === "pending"
167
+ && reference.attempt.pidStartEvidence.pid === null
168
+ && reference.attempt.session.leaseGeneration === null;
169
+ }
170
+ return reference.attempt.pidStartEvidence.observedExitAt === null
171
+ && reference.attempt.session.leaseGeneration === owner.generation
172
+ && processIdentityMatchesAttempt({
173
+ pid: owner.pid,
174
+ processStartIdentity: owner.processStartIdentity,
175
+ bootIdentity: owner.bootIdentity,
176
+ executable: owner.executable,
177
+ hostname: owner.hostname,
178
+ }, reference.attempt);
179
+ }
180
+ async function inspectLeaseOwner(owner, current, inspector) {
181
+ if (!current)
182
+ return { kind: "unknown", diagnostic: "Current process identity is unavailable" };
183
+ if (owner.hostname !== current.hostname) {
184
+ return { kind: "unknown", diagnostic: `Lease belongs to remote host ${owner.hostname}` };
185
+ }
186
+ return inspector.inspect(owner.pid);
187
+ }
188
+ function processIdentityMatchesAttempt(identity, attempt) {
189
+ const recorded = attempt.pidStartEvidence;
190
+ return identity.pid === recorded.pid
191
+ && identity.processStartIdentity === recorded.processStartIdentity
192
+ && identity.bootIdentity === recorded.bootIdentity
193
+ && identity.executable === recorded.executable
194
+ && identity.hostname === recorded.hostname;
195
+ }
196
+ function processIdentityMatchesOwner(identity, owner) {
197
+ return identity.pid === owner.pid
198
+ && identity.processStartIdentity === owner.processStartIdentity
199
+ && identity.bootIdentity === owner.bootIdentity
200
+ && identity.executable === owner.executable
201
+ && identity.hostname === owner.hostname;
202
+ }
203
+ function processMismatchDiagnostic(pid, inspection, attempt) {
204
+ if (inspection.kind === "absent")
205
+ return `Ledger attempt ${attempt.attemptId} has no process ${pid}`;
206
+ if (inspection.kind === "unknown") {
207
+ return `Ledger attempt ${attempt.attemptId} process ${pid} is unverifiable: ${inspection.diagnostic}`;
208
+ }
209
+ return `Ledger attempt ${attempt.attemptId} PID ${pid} now has different process identity`;
210
+ }
211
+ function leaseMismatchDiagnostic(owner, inspection) {
212
+ return inspection.kind === "absent"
213
+ ? `Lease owner process ${owner.pid} is absent`
214
+ : `Lease owner PID ${owner.pid} now has different process identity`;
215
+ }
216
+ function orphanProcessFinding(pid, path, message) {
217
+ return {
218
+ severity: "error",
219
+ code: "orphan-process",
220
+ message,
221
+ paths: [path],
222
+ commands: [inspectProcessCommand(pid)],
223
+ };
224
+ }
225
+ function inspectProcessCommand(pid) {
226
+ return {
227
+ kind: "exec",
228
+ argv: ["ps", "-p", String(pid), "-o", "pid=,lstart=,comm="],
229
+ purpose: "Re-inspect PID identity before any operator action",
230
+ };
231
+ }
232
+ function quarantineCommand(namespaceDirectory, prefix, path) {
233
+ return {
234
+ kind: "exec",
235
+ argv: ["mv", "--", path, join(namespaceDirectory, "quarantine", `doctor-${prefix}-${basename(path)}`)],
236
+ purpose: "Quarantine the record for manual recovery instead of deleting it",
237
+ };
238
+ }
239
+ async function sessionDirectories(namespaceDirectory) {
240
+ const parent = join(namespaceDirectory, "worker-sessions");
241
+ try {
242
+ return (await readdir(parent, { withFileTypes: true }))
243
+ .filter((entry) => !entry.name.startsWith("."))
244
+ .map((entry) => normalize(join(parent, entry.name)))
245
+ .sort();
246
+ }
247
+ catch (error) {
248
+ if (isNodeError(error) && error.code === "ENOENT")
249
+ return [];
250
+ throw error;
251
+ }
252
+ }
253
+ async function topLevelDiskUsage(namespaceDirectory) {
254
+ let entries;
255
+ try {
256
+ entries = await readdir(namespaceDirectory);
257
+ }
258
+ catch (error) {
259
+ if (isNodeError(error) && error.code === "ENOENT")
260
+ return [];
261
+ throw error;
262
+ }
263
+ const areas = await Promise.all(entries.filter((entry) => !entry.startsWith(".")).sort().map(async (name) => {
264
+ const path = join(namespaceDirectory, name);
265
+ return { name, path, bytes: await pathBytes(path) };
266
+ }));
267
+ return areas;
268
+ }
269
+ async function pathBytes(path) {
270
+ let info;
271
+ try {
272
+ info = await lstat(path);
273
+ }
274
+ catch (error) {
275
+ if (isNodeError(error) && error.code === "ENOENT")
276
+ return 0;
277
+ throw error;
278
+ }
279
+ if (!info.isDirectory())
280
+ return info.size;
281
+ let total = info.size;
282
+ for (const entry of await readdir(path))
283
+ total += await pathBytes(join(path, entry));
284
+ return total;
285
+ }
286
+ function isNodeError(error) {
287
+ return error instanceof Error && "code" in error;
288
+ }
289
+ //# sourceMappingURL=workflow-doctor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-doctor.js","sourceRoot":"","sources":["../../workflow/workflow-doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AA2ElE,MAAM,OAAO,cAAc;IAChB,mBAAmB,CAAS;IAC5B,KAAK,CAAuB;IAC5B,OAAO,CAAyB;IAChC,UAAU,CAA2B;IACrC,IAAI,CAAa;IAE1B,YAAY,OAA8B;QACxC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;QACpE,CAAC;QACD,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACjE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAC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;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC;QAC5D,MAAM,KAAK,CAAC;IACd,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC;IAC1C,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;IACtB,KAAK,MAAM,KAAK,IAAI,MAAM,OAAO,CAAC,IAAI,CAAC;QAAE,KAAK,IAAI,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACrF,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AACnD,CAAC"}
@@ -0,0 +1,125 @@
1
+ export interface ProcessIdentity {
2
+ readonly pid: number;
3
+ readonly processStartIdentity: string;
4
+ readonly bootIdentity: string | null;
5
+ readonly executable: string;
6
+ readonly hostname: string;
7
+ }
8
+ export type ProcessInspection = {
9
+ readonly kind: "live";
10
+ readonly identity: ProcessIdentity;
11
+ } | {
12
+ readonly kind: "absent";
13
+ } | {
14
+ readonly kind: "unknown";
15
+ readonly diagnostic: string;
16
+ };
17
+ export interface ProcessIdentityInspector {
18
+ current(): Promise<ProcessIdentity>;
19
+ inspect(pid: number): Promise<ProcessInspection>;
20
+ }
21
+ export interface WorkflowLeaseOwnerV1 {
22
+ readonly schema: 1;
23
+ readonly kind: "supervisor" | "worker-session";
24
+ readonly stage: "active" | "reserved";
25
+ readonly generation: string;
26
+ readonly workspaceId: string;
27
+ readonly resourceId: string;
28
+ readonly runId: string | null;
29
+ readonly workerId: string | null;
30
+ readonly attemptId: string | null;
31
+ readonly workerAttemptGeneration: string | null;
32
+ readonly supervisorGeneration: string | null;
33
+ readonly sessionPath: string | null;
34
+ readonly pid: number;
35
+ readonly processStartIdentity: string;
36
+ readonly bootIdentity: string | null;
37
+ readonly executable: string;
38
+ readonly hostname: string;
39
+ readonly createdAt: string;
40
+ }
41
+ export interface WorkflowLeaseManagerOptions {
42
+ readonly namespaceDirectory: string;
43
+ readonly workspaceId: string;
44
+ readonly inspector: ProcessIdentityInspector;
45
+ readonly randomUUID?: () => string;
46
+ readonly now?: () => Date;
47
+ readonly guardWaitMs?: number;
48
+ }
49
+ export interface AcquireWorkerSessionInput {
50
+ readonly sessionPath: string;
51
+ readonly runId: string;
52
+ readonly workerId: string;
53
+ readonly attemptId: string;
54
+ readonly workerAttemptGeneration: string;
55
+ readonly supervisorGeneration: string;
56
+ readonly processIdentity: ProcessIdentity;
57
+ }
58
+ export type WorkflowLeaseRefusalReason = "remote-owner" | "unverifiable-owner" | "corrupt-owner" | "lifecycle-busy" | "lifecycle-unverifiable";
59
+ export type WorkflowLeaseAcquireResult = {
60
+ readonly kind: "acquired";
61
+ readonly owner: WorkflowLeaseOwnerV1;
62
+ readonly reclaimed?: {
63
+ readonly owner: WorkflowLeaseOwnerV1;
64
+ readonly quarantinePath: string;
65
+ };
66
+ } | {
67
+ readonly kind: "held";
68
+ readonly owner: WorkflowLeaseOwnerV1;
69
+ } | {
70
+ readonly kind: "refused";
71
+ readonly reason: WorkflowLeaseRefusalReason;
72
+ readonly diagnostic: string;
73
+ };
74
+ export type WorkflowLeaseReleaseResult = {
75
+ readonly kind: "released";
76
+ } | {
77
+ readonly kind: "not-owner";
78
+ readonly owner?: WorkflowLeaseOwnerV1;
79
+ } | {
80
+ readonly kind: "refused";
81
+ readonly diagnostic: string;
82
+ };
83
+ export type WorkflowLeaseProjection = {
84
+ readonly kind: "empty";
85
+ } | {
86
+ readonly kind: "owned";
87
+ readonly owner: WorkflowLeaseOwnerV1;
88
+ } | {
89
+ readonly kind: "corrupt";
90
+ readonly diagnostic: string;
91
+ };
92
+ export interface WorkerSessionLeaseDiagnostic {
93
+ readonly resourceId: string;
94
+ readonly path: string;
95
+ readonly projection: WorkflowLeaseProjection;
96
+ }
97
+ export declare class WorkflowLeaseFenceError extends Error {
98
+ constructor(message: string);
99
+ }
100
+ export declare class WorkflowLeaseManager {
101
+ #private;
102
+ constructor(options: WorkflowLeaseManagerOptions);
103
+ acquireSupervisor(): Promise<WorkflowLeaseAcquireResult>;
104
+ releaseSupervisor(generation: string): Promise<WorkflowLeaseReleaseResult>;
105
+ withCurrentSupervisor<T>(generation: string, operation: () => Promise<T>): Promise<T>;
106
+ inspectSupervisor(): Promise<WorkflowLeaseProjection>;
107
+ acquireWorkerSession(input: AcquireWorkerSessionInput): Promise<WorkflowLeaseAcquireResult>;
108
+ reserveWorkerSession(input: Omit<AcquireWorkerSessionInput, "processIdentity">): Promise<WorkflowLeaseAcquireResult>;
109
+ activateWorkerSession(input: {
110
+ readonly sessionPath: string;
111
+ readonly generation: string;
112
+ readonly supervisorGeneration: string;
113
+ readonly workerAttemptGeneration: string;
114
+ readonly processIdentity: ProcessIdentity;
115
+ }): Promise<WorkflowLeaseOwnerV1>;
116
+ releaseWorkerSession(input: {
117
+ readonly sessionPath: string;
118
+ readonly generation: string;
119
+ readonly supervisorGeneration: string;
120
+ }): Promise<WorkflowLeaseReleaseResult>;
121
+ inspectWorkerSession(sessionPath: string): Promise<WorkflowLeaseProjection>;
122
+ diagnoseWorkerSessionLeases(): Promise<readonly WorkerSessionLeaseDiagnostic[]>;
123
+ }
124
+ export declare function parseWorkflowLeaseOwnerV1(value: unknown): WorkflowLeaseOwnerV1;
125
+ //# sourceMappingURL=workflow-lease.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-lease.d.ts","sourceRoot":"","sources":["../../workflow/workflow-lease.ts"],"names":[],"mappings":"AAsDA,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CA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