pi-spine 2.2.0 → 2.3.0
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.
- package/bin/spine-cli/verify.mjs +2 -19
- package/package.json +1 -1
- package/src/batch/attached-runner-promote.mjs +370 -0
- package/src/batch/attached-runner-reconcile.mjs +291 -0
- package/src/batch/attached-runner.mjs +24 -645
- package/src/batch/batch-guards.mjs +69 -0
- package/src/batch/contract-exec.mjs +483 -0
- package/src/batch/contract-parse.mjs +243 -0
- package/src/batch/contract-verify.mjs +32 -707
- package/src/batch/detached-diagnostics.mjs +255 -0
- package/src/batch/detached-run.mjs +326 -0
- package/src/batch/detached-start.mjs +18 -894
- package/src/batch/detached-wait.mjs +346 -0
- package/src/batch/engine.mjs +8 -67
- package/src/batch/integrate-git.mjs +21 -0
- package/src/batch/integrate.mjs +5 -15
- package/src/batch/journal-rebuild-structural.mjs +352 -0
- package/src/batch/journal-rebuild.mjs +16 -348
- package/src/batch/lane-dirty-check-commit.mjs +361 -0
- package/src/batch/lane-dirty-check-git.mjs +298 -0
- package/src/batch/lane-dirty-check.mjs +31 -297
- package/src/batch/reconcile-batch.mjs +483 -0
- package/src/batch/reconcile-classify.mjs +433 -0
- package/src/batch/reconcile-diagnosis.mjs +459 -0
- package/src/batch/reconcile-light-cache.mjs +61 -0
- package/src/batch/reconcile-orphan.mjs +198 -0
- package/src/batch/reconcile.mjs +19 -1693
- package/src/batch/resume-multi-lanes.mjs +6 -148
- package/src/batch/resume-multi-queue.mjs +159 -0
- package/src/batch/resume-single-validate.mjs +25 -0
- package/src/batch/resume.mjs +3 -20
- package/src/batch/review-artifacts.mjs +419 -0
- package/src/batch/review-step-run.mjs +383 -0
- package/src/batch/review-step.mjs +451 -0
- package/src/batch/review.mjs +32 -1199
- package/src/batch/salvage-batch-list.mjs +291 -0
- package/src/batch/salvage-batch.mjs +10 -284
- package/src/batch/sequence-plan.mjs +234 -0
- package/src/batch/sequence-run.mjs +418 -0
- package/src/batch/sequence-wait.mjs +167 -0
- package/src/batch/sequence.mjs +22 -783
- package/src/batch/state-guards.mjs +284 -0
- package/src/batch/state-io.mjs +135 -0
- package/src/batch/state.mjs +27 -396
- package/src/batch/worker-heartbeat.mjs +375 -0
- package/src/batch/worker-host.mjs +50 -541
- package/src/batch/worker-spawn.mjs +315 -0
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
/**
|
|
3
3
|
* Detached batch engine spawn — default for `spine batch start` and `spine batch resume`.
|
|
4
|
+
* Thin re-export shim (SP-598): spawn → detached-spawn, diagnostics → detached-diagnostics,
|
|
5
|
+
* wait/run → detached-wait + detached-run.
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
|
-
import fs from "node:fs";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
9
|
-
import {
|
|
10
|
-
buildAttachedBatchResumeArgv,
|
|
11
|
-
buildAttachedBatchStartArgv,
|
|
12
|
-
DETACHED_ENGINE_LOG_REL,
|
|
13
|
-
detachedEngineLogPath,
|
|
14
|
-
spawnDetachedBatchEngine,
|
|
15
|
-
} from "./detached-spawn.mjs";
|
|
16
|
-
|
|
17
8
|
export {
|
|
18
9
|
buildAttachedBatchResumeArgv,
|
|
19
10
|
buildAttachedBatchStartArgv,
|
|
@@ -21,888 +12,21 @@ export {
|
|
|
21
12
|
detachedEngineLogPath,
|
|
22
13
|
spawnDetachedBatchEngine,
|
|
23
14
|
} from "./detached-spawn.mjs";
|
|
24
|
-
import { maybeSpawnSupervisorOnDetachedStart } from "./supervisor-spawn.mjs";
|
|
25
|
-
import { runBatchPreflight } from "../config/spine-preflight-lib.mjs";
|
|
26
|
-
import { loadGateRecord } from "./gate.mjs";
|
|
27
|
-
import { reconcileBatch } from "./reconcile.mjs";
|
|
28
|
-
import { validateResumeBatch } from "./resume.mjs";
|
|
29
|
-
import { assessRunningPhaseResumeEligibility } from "./resume-multi-validate.mjs";
|
|
30
|
-
import { readLastTaskFailedEvent } from "./journal.mjs";
|
|
31
|
-
import { prepareOrphanResumeHandoff } from "./resume-engine.mjs";
|
|
32
|
-
import { enforceAttachedEngineSingleOwner, finalizeResumePostMergeLimbo } from "./attached-runner.mjs";
|
|
33
|
-
import {
|
|
34
|
-
ACTIVE_PHASES,
|
|
35
|
-
loadSpineBatchState,
|
|
36
|
-
recordBatchEnginePid,
|
|
37
|
-
saveSpineBatchState,
|
|
38
|
-
TERMINAL_BATCH_PHASES,
|
|
39
|
-
} from "./state.mjs";
|
|
40
|
-
|
|
41
|
-
/** Diagnoses that benefit from blocking until resume engine reaches terminal phase. */
|
|
42
|
-
const RESUME_WAIT_TERMINAL_DIAGNOSES = new Set([
|
|
43
|
-
"engine_orphaned",
|
|
44
|
-
"worker_orphaned",
|
|
45
|
-
"state_drift",
|
|
46
|
-
"needs_integrate",
|
|
47
|
-
]);
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Default detached resume to --wait-terminal after orphan/drift diagnoses.
|
|
51
|
-
*
|
|
52
|
-
* @param {string} projectRoot
|
|
53
|
-
* @param {boolean} explicitWaitTerminal
|
|
54
|
-
* @param {boolean} noWaitTerminal
|
|
55
|
-
*/
|
|
56
|
-
export function resolveDefaultResumeWaitTerminal(
|
|
57
|
-
projectRoot,
|
|
58
|
-
explicitWaitTerminal,
|
|
59
|
-
noWaitTerminal = false,
|
|
60
|
-
) {
|
|
61
|
-
if (explicitWaitTerminal) return true;
|
|
62
|
-
if (noWaitTerminal) return false;
|
|
63
|
-
const reconciliation = reconcileBatch({ projectRoot });
|
|
64
|
-
const diagnosis = reconciliation.diagnosis;
|
|
65
|
-
if (diagnosis && RESUME_WAIT_TERMINAL_DIAGNOSES.has(diagnosis)) {
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** @type {ReadonlySet<string>} */
|
|
72
|
-
const TERMINAL_TASK_STATUSES = new Set(["succeeded", "failed", "skipped", "aborted"]);
|
|
73
|
-
|
|
74
|
-
const FAILURE_LOG_TAIL_LINES = 20;
|
|
75
|
-
|
|
76
|
-
/** Default wait when --wait-terminal blocks on orphan/drift resume (real workers exceed 30s). */
|
|
77
|
-
const DETACHED_WAIT_TERMINAL_TIMEOUT_MS = 2 * 60 * 60 * 1000;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @param {boolean} waitTerminal
|
|
81
|
-
* @param {number} [explicitTimeoutMs]
|
|
82
|
-
*/
|
|
83
|
-
export function resolveDetachedWaitTimeoutMs(waitTerminal, explicitTimeoutMs) {
|
|
84
|
-
if (Number.isFinite(explicitTimeoutMs) && explicitTimeoutMs > 0) {
|
|
85
|
-
return explicitTimeoutMs;
|
|
86
|
-
}
|
|
87
|
-
return waitTerminal ? DETACHED_WAIT_TERMINAL_TIMEOUT_MS : 30_000;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @param {string} filePath
|
|
92
|
-
* @param {number} [lineCount]
|
|
93
|
-
* @returns {string|null}
|
|
94
|
-
*/
|
|
95
|
-
function readLogTailLines(filePath, lineCount = FAILURE_LOG_TAIL_LINES) {
|
|
96
|
-
if (!fs.existsSync(filePath)) return null;
|
|
97
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
98
|
-
const lines = content.split("\n");
|
|
99
|
-
if (lines.at(-1) === "") lines.pop();
|
|
100
|
-
if (lines.length === 0) return null;
|
|
101
|
-
return lines.slice(-lineCount).join("\n");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const DETACHED_ENGINE_LOG_HEADER_RE = /^--- detached batch engine /;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Read tail of detached engine log, scoped to the current (last) batch session.
|
|
108
|
-
* The append-only log contains headers like `--- detached batch engine <ISO> argv=... ---`
|
|
109
|
-
* separating sessions. Without filtering, stale entries from previous batches are shown.
|
|
110
|
-
*
|
|
111
|
-
* @param {string} filePath
|
|
112
|
-
* @param {number} [lineCount]
|
|
113
|
-
* @returns {string|null}
|
|
114
|
-
*/
|
|
115
|
-
export function readCurrentBatchLogTail(filePath, lineCount = FAILURE_LOG_TAIL_LINES) {
|
|
116
|
-
if (!fs.existsSync(filePath)) return null;
|
|
117
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
118
|
-
const lines = content.split("\n");
|
|
119
|
-
if (lines.at(-1) === "") lines.pop();
|
|
120
|
-
if (lines.length === 0) return null;
|
|
121
|
-
|
|
122
|
-
let lastHeaderIdx = -1;
|
|
123
|
-
for (let i = lines.length - 1; i >= 0; i--) {
|
|
124
|
-
if (DETACHED_ENGINE_LOG_HEADER_RE.test(lines[i])) {
|
|
125
|
-
lastHeaderIdx = i;
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const sessionLines = lastHeaderIdx >= 0 ? lines.slice(lastHeaderIdx) : lines;
|
|
131
|
-
if (sessionLines.length === 0) return null;
|
|
132
|
-
return sessionLines.slice(-lineCount).join("\n");
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @param {string} projectRoot
|
|
137
|
-
* @param {string} batchId
|
|
138
|
-
* @param {string|null|undefined} taskId
|
|
139
|
-
* @returns {string|null}
|
|
140
|
-
*/
|
|
141
|
-
function findWorkerOutputLogPath(projectRoot, batchId, taskId) {
|
|
142
|
-
const lanesDir = path.join(projectRoot, ".spine", "runtime", batchId, "lanes");
|
|
143
|
-
if (!fs.existsSync(lanesDir)) return null;
|
|
144
|
-
|
|
145
|
-
/** @type {string|null} */
|
|
146
|
-
let newestPath = null;
|
|
147
|
-
/** @type {number} */
|
|
148
|
-
let newestMtime = 0;
|
|
149
|
-
|
|
150
|
-
for (const laneDir of fs.readdirSync(lanesDir)) {
|
|
151
|
-
if (!laneDir.startsWith("lane-")) continue;
|
|
152
|
-
const lanePath = path.join(lanesDir, laneDir);
|
|
153
|
-
for (const name of fs.readdirSync(lanePath)) {
|
|
154
|
-
if (!name.startsWith("worker-output-") || !name.endsWith(".log")) continue;
|
|
155
|
-
if (taskId && name !== `worker-output-${taskId}.log`) continue;
|
|
156
|
-
const candidate = path.join(lanePath, name);
|
|
157
|
-
const mtime = fs.statSync(candidate).mtimeMs;
|
|
158
|
-
if (mtime >= newestMtime) {
|
|
159
|
-
newestMtime = mtime;
|
|
160
|
-
newestPath = candidate;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return newestPath;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @param {object} event
|
|
170
|
-
*/
|
|
171
|
-
function summarizeTaskFailedEvent(event) {
|
|
172
|
-
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
173
|
-
/** @type {string[]} */
|
|
174
|
-
const parts = [];
|
|
175
|
-
if (event.taskId) parts.push(`task ${event.taskId}`);
|
|
176
|
-
if (payload.classification) parts.push(String(payload.classification));
|
|
177
|
-
if (payload.error) parts.push(String(payload.error).slice(0, 120));
|
|
178
|
-
if (payload.output) parts.push(String(payload.output).slice(0, 120));
|
|
179
|
-
if (payload.reason) parts.push(String(payload.reason));
|
|
180
|
-
return parts.join(" — ") || JSON.stringify(payload).slice(0, 160);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* @param {object} params
|
|
185
|
-
* @param {string} params.projectRoot
|
|
186
|
-
* @param {string|null|undefined} [params.batchId]
|
|
187
|
-
* @param {string|null|undefined} [params.taskId]
|
|
188
|
-
* @param {string|null|undefined} [params.logPath]
|
|
189
|
-
*/
|
|
190
|
-
export function collectDetachedFailureDiagnostics({ projectRoot, batchId, taskId, logPath }) {
|
|
191
|
-
/** @type {Record<string, unknown>} */
|
|
192
|
-
const diagnostics = {};
|
|
193
|
-
|
|
194
|
-
if (batchId) {
|
|
195
|
-
const failedEvent = readLastTaskFailedEvent(projectRoot, batchId);
|
|
196
|
-
if (failedEvent) {
|
|
197
|
-
diagnostics.taskFailedEvent = failedEvent;
|
|
198
|
-
diagnostics.taskFailedSummary = summarizeTaskFailedEvent(failedEvent);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (batchId) {
|
|
203
|
-
const workerLogPath = findWorkerOutputLogPath(projectRoot, batchId, taskId ?? null);
|
|
204
|
-
if (workerLogPath) {
|
|
205
|
-
const tail = readLogTailLines(workerLogPath);
|
|
206
|
-
if (tail) {
|
|
207
|
-
diagnostics.workerLogPath = path.relative(projectRoot, workerLogPath);
|
|
208
|
-
diagnostics.workerLogTail = tail;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const engineLogPath = logPath
|
|
214
|
-
? path.isAbsolute(logPath)
|
|
215
|
-
? logPath
|
|
216
|
-
: path.join(projectRoot, logPath)
|
|
217
|
-
: detachedEngineLogPath(projectRoot);
|
|
218
|
-
const engineTail = readCurrentBatchLogTail(engineLogPath);
|
|
219
|
-
if (engineTail) {
|
|
220
|
-
diagnostics.engineLogPath = path.isAbsolute(logPath ?? "")
|
|
221
|
-
? logPath
|
|
222
|
-
: logPath ?? DETACHED_ENGINE_LOG_REL;
|
|
223
|
-
diagnostics.engineLogTail = engineTail;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return diagnostics;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* @param {Record<string, unknown>} payload
|
|
231
|
-
* @param {object} params
|
|
232
|
-
* @param {string} params.projectRoot
|
|
233
|
-
* @param {string|null|undefined} [params.batchId]
|
|
234
|
-
* @param {string|null|undefined} [params.taskId]
|
|
235
|
-
* @param {string|null|undefined} [params.logPath]
|
|
236
|
-
*/
|
|
237
|
-
function attachDetachedFailureDiagnostics(payload, { projectRoot, batchId, taskId, logPath }) {
|
|
238
|
-
const diagnostics = collectDetachedFailureDiagnostics({ projectRoot, batchId, taskId, logPath });
|
|
239
|
-
if (diagnostics.taskFailedSummary) payload.taskFailedSummary = diagnostics.taskFailedSummary;
|
|
240
|
-
if (diagnostics.workerLogTail) {
|
|
241
|
-
payload.workerLogPath = diagnostics.workerLogPath;
|
|
242
|
-
payload.workerLogTail = diagnostics.workerLogTail;
|
|
243
|
-
}
|
|
244
|
-
if (diagnostics.engineLogTail) {
|
|
245
|
-
payload.engineLogPath = diagnostics.engineLogPath;
|
|
246
|
-
payload.engineLogTail = diagnostics.engineLogTail;
|
|
247
|
-
}
|
|
248
|
-
return payload;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* @param {number} ms
|
|
253
|
-
*/
|
|
254
|
-
function sleep(ms) {
|
|
255
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* @param {object|null|undefined} raw
|
|
260
|
-
* @param {string|null|undefined} taskId
|
|
261
|
-
*/
|
|
262
|
-
function resumedTaskReachedTerminal(raw, taskId) {
|
|
263
|
-
if (!taskId || !raw || !Array.isArray(raw.tasks)) return false;
|
|
264
|
-
const task = raw.tasks.find((entry) => entry?.taskId === taskId);
|
|
265
|
-
return Boolean(task && TERMINAL_TASK_STATUSES.has(String(task.status ?? "")));
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* @param {string} projectRoot
|
|
270
|
-
* @param {object|null|undefined} raw
|
|
271
|
-
*/
|
|
272
|
-
function detachedResumeRequiresIntegrateGate(projectRoot, raw) {
|
|
273
|
-
if (!raw?.batchId || String(raw.phase ?? "") !== "completed") {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
if (!raw.orchBranch) {
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
const config = loadSpineConfig(projectRoot).config ?? {};
|
|
280
|
-
return config.gates?.requireBeforeIntegrate === true;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* @param {string} projectRoot
|
|
285
|
-
* @param {object|null|undefined} raw
|
|
286
|
-
*/
|
|
287
|
-
function detachedResumeIntegrateGateReady(projectRoot, raw) {
|
|
288
|
-
if (!detachedResumeRequiresIntegrateGate(projectRoot, raw)) {
|
|
289
|
-
return true;
|
|
290
|
-
}
|
|
291
|
-
return Boolean(loadGateRecord(projectRoot, String(raw.batchId)));
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* @param {object|null|undefined} raw
|
|
296
|
-
* @param {string|null|undefined} taskId
|
|
297
|
-
* @param {number} updatedAtBefore
|
|
298
|
-
*/
|
|
299
|
-
function evaluateDetachedResumeWait(raw, taskId, updatedAtBefore) {
|
|
300
|
-
if (!raw?.batchId) return null;
|
|
301
|
-
const updatedAt = Number(raw.updatedAt ?? 0);
|
|
302
|
-
if (updatedAt <= updatedAtBefore) return null;
|
|
303
|
-
|
|
304
|
-
if (TERMINAL_BATCH_PHASES.has(String(raw.phase ?? ""))) {
|
|
305
|
-
return {
|
|
306
|
-
ok: true,
|
|
307
|
-
status: "resume_completed",
|
|
308
|
-
batchId: raw.batchId,
|
|
309
|
-
phase: raw.phase,
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (resumedTaskReachedTerminal(raw, taskId)) {
|
|
314
|
-
return {
|
|
315
|
-
ok: true,
|
|
316
|
-
status: "resume_completed",
|
|
317
|
-
batchId: raw.batchId,
|
|
318
|
-
phase: raw.phase,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return null;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* @param {string} projectRoot
|
|
327
|
-
* @param {number|null} enginePid
|
|
328
|
-
*/
|
|
329
|
-
function persistDetachedEnginePid(projectRoot, enginePid) {
|
|
330
|
-
const pid = Number(enginePid);
|
|
331
|
-
if (!Number.isFinite(pid) || pid <= 0) return;
|
|
332
|
-
const { raw } = loadSpineBatchState(projectRoot);
|
|
333
|
-
if (!raw) return;
|
|
334
|
-
recordBatchEnginePid(raw, pid);
|
|
335
|
-
saveSpineBatchState(projectRoot, raw);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Kill a stale detached engine and persist cleared PID before spawning resume engine (SP-254).
|
|
340
|
-
* Resume child records its own PID after terminateStaleDetachedEngine runs in-process.
|
|
341
|
-
* Running-phase orphan resume (SP-296) clears a dead engine PID without requiring pause first.
|
|
342
|
-
*
|
|
343
|
-
* @param {string} projectRoot
|
|
344
|
-
*/
|
|
345
|
-
export function prepareDetachedResumeEngineHandoff(projectRoot) {
|
|
346
|
-
const loaded = loadSpineBatchState(projectRoot);
|
|
347
|
-
if (!loaded.raw) {
|
|
348
|
-
return { ok: false, reason: "no_active_batch" };
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const state = loaded.raw;
|
|
352
|
-
const batchId = String(state.batchId ?? "");
|
|
353
|
-
const fromPhase = String(state.phase ?? "");
|
|
354
|
-
const orphanEligibility =
|
|
355
|
-
fromPhase === "running"
|
|
356
|
-
? assessRunningPhaseResumeEligibility({ projectRoot, state })
|
|
357
|
-
: { engineConfirmedDead: false, allowOrphanResume: false };
|
|
358
|
-
const handoff = prepareOrphanResumeHandoff({
|
|
359
|
-
projectRoot,
|
|
360
|
-
state,
|
|
361
|
-
batchId,
|
|
362
|
-
fromPhase,
|
|
363
|
-
orphanResume: orphanEligibility.allowOrphanResume,
|
|
364
|
-
engineConfirmedDead: orphanEligibility.engineConfirmedDead,
|
|
365
|
-
});
|
|
366
|
-
saveSpineBatchState(projectRoot, state, { bypassWriteGuard: true });
|
|
367
|
-
|
|
368
|
-
return {
|
|
369
|
-
ok: true,
|
|
370
|
-
batchId,
|
|
371
|
-
fromPhase,
|
|
372
|
-
terminateResult: handoff.terminateResult,
|
|
373
|
-
orphanResume: orphanEligibility.allowOrphanResume,
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* @param {object} params
|
|
379
|
-
* @param {string} params.projectRoot
|
|
380
|
-
* @param {string | null} [params.previousBatchId]
|
|
381
|
-
* @param {number} [params.timeoutMs]
|
|
382
|
-
* @param {boolean} [params.waitTerminal]
|
|
383
|
-
*/
|
|
384
|
-
export async function waitForDetachedBatchStart({
|
|
385
|
-
projectRoot,
|
|
386
|
-
previousBatchId = null,
|
|
387
|
-
timeoutMs = 30_000,
|
|
388
|
-
waitTerminal = false,
|
|
389
|
-
}) {
|
|
390
|
-
const deadline = Date.now() + timeoutMs;
|
|
391
|
-
/** @type {string|null} */
|
|
392
|
-
let startedBatchId = null;
|
|
393
|
-
|
|
394
|
-
while (Date.now() < deadline) {
|
|
395
|
-
const { raw } = loadSpineBatchState(projectRoot);
|
|
396
|
-
const batchId = raw?.batchId ?? null;
|
|
397
|
-
if (batchId && batchId !== previousBatchId) {
|
|
398
|
-
if (raw.phase === "failed" || raw.phase === "aborted") {
|
|
399
|
-
return {
|
|
400
|
-
ok: false,
|
|
401
|
-
error: "batch_engine_failed",
|
|
402
|
-
batchId,
|
|
403
|
-
phase: raw.phase,
|
|
404
|
-
lastError: raw.lastError ?? null,
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
if (TERMINAL_BATCH_PHASES.has(String(raw.phase ?? "")) || raw.phase === "paused") {
|
|
409
|
-
return {
|
|
410
|
-
ok: true,
|
|
411
|
-
status: "start_completed",
|
|
412
|
-
batchId,
|
|
413
|
-
phase: raw.phase,
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (ACTIVE_PHASES.has(raw.phase)) {
|
|
418
|
-
startedBatchId = batchId;
|
|
419
|
-
if (!waitTerminal) {
|
|
420
|
-
return {
|
|
421
|
-
ok: true,
|
|
422
|
-
status: "engine_started",
|
|
423
|
-
batchId,
|
|
424
|
-
phase: raw.phase,
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
await sleep(200);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
if (startedBatchId) {
|
|
433
|
-
return {
|
|
434
|
-
ok: false,
|
|
435
|
-
error: "timeout_waiting_for_batch",
|
|
436
|
-
batchId: startedBatchId,
|
|
437
|
-
status: "engine_started",
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
return { ok: false, error: "timeout_waiting_for_batch" };
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* @param {object} params
|
|
446
|
-
* @param {string} params.projectRoot
|
|
447
|
-
* @param {string} params.batchId
|
|
448
|
-
* @param {number} params.updatedAtBefore
|
|
449
|
-
* @param {string|null|undefined} [params.taskId]
|
|
450
|
-
* @param {number} [params.timeoutMs]
|
|
451
|
-
* @param {boolean} [params.waitTerminal]
|
|
452
|
-
*/
|
|
453
|
-
export async function waitForDetachedBatchResume({
|
|
454
|
-
projectRoot,
|
|
455
|
-
batchId,
|
|
456
|
-
updatedAtBefore,
|
|
457
|
-
taskId = null,
|
|
458
|
-
timeoutMs = 30_000,
|
|
459
|
-
waitTerminal = false,
|
|
460
|
-
}) {
|
|
461
|
-
const deadline = Date.now() + timeoutMs;
|
|
462
|
-
/** @type {boolean} */
|
|
463
|
-
let engineStarted = false;
|
|
464
|
-
|
|
465
|
-
while (Date.now() < deadline) {
|
|
466
|
-
const { raw } = loadSpineBatchState(projectRoot);
|
|
467
|
-
if (raw?.batchId !== batchId) {
|
|
468
|
-
await sleep(200);
|
|
469
|
-
continue;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
if (raw.phase === "failed" || raw.phase === "aborted") {
|
|
473
|
-
return {
|
|
474
|
-
ok: false,
|
|
475
|
-
error: "batch_engine_failed",
|
|
476
|
-
batchId,
|
|
477
|
-
phase: raw.phase,
|
|
478
|
-
lastError: raw.lastError ?? null,
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
const updatedAt = Number(raw.updatedAt ?? 0);
|
|
483
|
-
if (raw.phase === "running" && updatedAt > updatedAtBefore) {
|
|
484
|
-
engineStarted = true;
|
|
485
|
-
if (!waitTerminal) {
|
|
486
|
-
return {
|
|
487
|
-
ok: true,
|
|
488
|
-
status: "engine_started",
|
|
489
|
-
batchId,
|
|
490
|
-
phase: raw.phase,
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
const completed = evaluateDetachedResumeWait(raw, taskId, updatedAtBefore);
|
|
496
|
-
if (completed && detachedResumeIntegrateGateReady(projectRoot, raw)) {
|
|
497
|
-
return completed;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
await sleep(200);
|
|
501
|
-
}
|
|
502
15
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* @param {object} params
|
|
513
|
-
* @param {string} params.projectRoot
|
|
514
|
-
* @param {boolean} [params.skipPreflight]
|
|
515
|
-
*/
|
|
516
|
-
export function runDetachedStartPreflight({ projectRoot, skipPreflight = false }) {
|
|
517
|
-
if (skipPreflight) {
|
|
518
|
-
return { ok: true };
|
|
519
|
-
}
|
|
520
|
-
const preflight = runBatchPreflight({ projectRoot, skipDoctor: false });
|
|
521
|
-
if (!preflight.ok) {
|
|
522
|
-
return {
|
|
523
|
-
ok: false,
|
|
524
|
-
exitCode: preflight.exitCode ?? 1,
|
|
525
|
-
error: "preflight_failed",
|
|
526
|
-
output: preflight.output,
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
return { ok: true };
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* @param {object} result
|
|
534
|
-
* @param {boolean} [json]
|
|
535
|
-
*/
|
|
536
|
-
export function formatDetachedEngineOutput(result, json = false) {
|
|
537
|
-
if (json) {
|
|
538
|
-
return `${JSON.stringify(result, null, 2)}\n`;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
const operation = result.operation ?? "start";
|
|
542
|
-
const operationLabel = operation === "resume" ? "resume" : "start";
|
|
543
|
-
|
|
544
|
-
if (!result.ok) {
|
|
545
|
-
const lines = [
|
|
546
|
-
"",
|
|
547
|
-
`Detached batch ${operationLabel} failed`,
|
|
548
|
-
"",
|
|
549
|
-
result.output ?? result.error ?? "Unknown error",
|
|
550
|
-
];
|
|
551
|
-
if (result.taskFailedSummary) {
|
|
552
|
-
lines.push("", " Last task.failed:", ` ${result.taskFailedSummary}`);
|
|
553
|
-
}
|
|
554
|
-
if (result.workerLogTail) {
|
|
555
|
-
lines.push(
|
|
556
|
-
"",
|
|
557
|
-
` Worker log tail${result.workerLogPath ? ` (${result.workerLogPath})` : ""}:`,
|
|
558
|
-
...result.workerLogTail.split("\n").map((line) => ` ${line}`),
|
|
559
|
-
);
|
|
560
|
-
}
|
|
561
|
-
if (result.engineLogTail) {
|
|
562
|
-
lines.push(
|
|
563
|
-
"",
|
|
564
|
-
` Detached engine log tail${result.engineLogPath ? ` (${result.engineLogPath})` : ""}:`,
|
|
565
|
-
...result.engineLogTail.split("\n").map((line) => ` ${line}`),
|
|
566
|
-
);
|
|
567
|
-
}
|
|
568
|
-
if (result.logPath) {
|
|
569
|
-
lines.push("", ` Log: ${result.logPath}`);
|
|
570
|
-
}
|
|
571
|
-
if (result.suggestedCommand) {
|
|
572
|
-
lines.push("", ` → ${result.suggestedCommand}`);
|
|
573
|
-
}
|
|
574
|
-
lines.push("", " Run with --attached for foreground errors.", "");
|
|
575
|
-
return lines.join("\n");
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/** @type {string} */
|
|
579
|
-
let headline;
|
|
580
|
-
if (result.status === "resume_completed" || result.status === "start_completed") {
|
|
581
|
-
headline =
|
|
582
|
-
operationLabel === "resume"
|
|
583
|
-
? "Batch resume completed."
|
|
584
|
-
: "Batch start completed.";
|
|
585
|
-
} else if (result.status === "engine_started") {
|
|
586
|
-
headline =
|
|
587
|
-
operationLabel === "resume"
|
|
588
|
-
? "Batch engine resuming in the background (engine started; resume not yet confirmed)."
|
|
589
|
-
: "Batch engine starting in the background (engine started; batch not yet confirmed).";
|
|
590
|
-
} else {
|
|
591
|
-
headline = `Batch engine ${operationLabel === "resume" ? "resuming" : "starting"} in the background.`;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
const lines = ["", headline, ""];
|
|
595
|
-
if (result.status) lines.push(` Status: ${result.status}`);
|
|
596
|
-
if (result.scope) lines.push(` Scope: ${result.scope}`);
|
|
597
|
-
if (result.batchId) lines.push(` Batch: ${result.batchId}`);
|
|
598
|
-
if (result.taskId) lines.push(` Task: ${result.taskId}`);
|
|
599
|
-
if (result.phase) lines.push(` Phase: ${result.phase}`);
|
|
600
|
-
if (result.enginePid) lines.push(` Engine PID: ${result.enginePid}`);
|
|
601
|
-
if (result.logPath) lines.push(` Log: ${result.logPath}`);
|
|
602
|
-
lines.push("", ` → ${result.suggestedCommand ?? "spine status --diagnose"}`, "");
|
|
603
|
-
return lines.join("\n");
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
/** @deprecated use formatDetachedEngineOutput */
|
|
607
|
-
export function formatDetachedBatchStartOutput(result, json = false) {
|
|
608
|
-
return formatDetachedEngineOutput(result, json);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* @param {object} params
|
|
613
|
-
* @param {string} params.projectRoot
|
|
614
|
-
* @param {string} params.spineBin
|
|
615
|
-
* @param {string} params.scope
|
|
616
|
-
* @param {boolean} [params.skipPreflight]
|
|
617
|
-
* @param {boolean} [params.forceSuperseded]
|
|
618
|
-
* @param {number|null} [params.waveFilter]
|
|
619
|
-
* @param {boolean} [params.waitTerminal]
|
|
620
|
-
* @param {boolean} [params.json]
|
|
621
|
-
*/
|
|
622
|
-
export async function startBatchDetached({
|
|
623
|
-
projectRoot,
|
|
624
|
-
spineBin,
|
|
625
|
-
scope,
|
|
626
|
-
skipPreflight = false,
|
|
627
|
-
forceSuperseded = false,
|
|
628
|
-
waveFilter = null,
|
|
629
|
-
waitTerminal = false,
|
|
630
|
-
json = false,
|
|
631
|
-
}) {
|
|
632
|
-
const preflight = runDetachedStartPreflight({ projectRoot, skipPreflight });
|
|
633
|
-
if (!preflight.ok) {
|
|
634
|
-
const payload = {
|
|
635
|
-
ok: false,
|
|
636
|
-
detached: true,
|
|
637
|
-
operation: "start",
|
|
638
|
-
error: preflight.error,
|
|
639
|
-
output: preflight.output,
|
|
640
|
-
};
|
|
641
|
-
return {
|
|
642
|
-
ok: false,
|
|
643
|
-
exitCode: preflight.exitCode ?? 1,
|
|
644
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
645
|
-
result: payload,
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
const before = loadSpineBatchState(projectRoot);
|
|
650
|
-
const previousBatchId = before.raw?.batchId ?? null;
|
|
651
|
-
const engineLock = enforceAttachedEngineSingleOwner({ projectRoot, force: false, operation: "start" });
|
|
652
|
-
if (!engineLock.ok) {
|
|
653
|
-
const payload = {
|
|
654
|
-
ok: false,
|
|
655
|
-
detached: true,
|
|
656
|
-
operation: "start",
|
|
657
|
-
batchId: engineLock.batchId,
|
|
658
|
-
error: engineLock.error,
|
|
659
|
-
output: engineLock.output,
|
|
660
|
-
enginePid: engineLock.enginePid,
|
|
661
|
-
suggestedCommand: "spine batch resume --attached --force",
|
|
662
|
-
};
|
|
663
|
-
return {
|
|
664
|
-
ok: false,
|
|
665
|
-
exitCode: engineLock.exitCode ?? 1,
|
|
666
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
667
|
-
result: payload,
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
const argv = buildAttachedBatchStartArgv({
|
|
671
|
-
scope,
|
|
672
|
-
skipPreflight: true,
|
|
673
|
-
forceSuperseded,
|
|
674
|
-
waveFilter,
|
|
675
|
-
});
|
|
676
|
-
const { enginePid, logPath } = spawnDetachedBatchEngine({ projectRoot, spineBin, argv });
|
|
677
|
-
persistDetachedEnginePid(projectRoot, enginePid);
|
|
678
|
-
const wait = await waitForDetachedBatchStart({ projectRoot, previousBatchId, waitTerminal });
|
|
679
|
-
|
|
680
|
-
if (!wait.ok) {
|
|
681
|
-
/** @type {Record<string, unknown>} */
|
|
682
|
-
const payload = {
|
|
683
|
-
ok: false,
|
|
684
|
-
detached: true,
|
|
685
|
-
operation: "start",
|
|
686
|
-
scope,
|
|
687
|
-
enginePid,
|
|
688
|
-
logPath,
|
|
689
|
-
error: wait.error,
|
|
690
|
-
batchId: wait.batchId ?? null,
|
|
691
|
-
lastError: wait.lastError ?? null,
|
|
692
|
-
output:
|
|
693
|
-
wait.error === "timeout_waiting_for_batch"
|
|
694
|
-
? "Engine may still be running or orphaned — run `spine status --diagnose`."
|
|
695
|
-
: `Batch engine exited before running (phase=${wait.phase ?? "unknown"}).`,
|
|
696
|
-
suggestedCommand: "spine status --diagnose",
|
|
697
|
-
};
|
|
698
|
-
attachDetachedFailureDiagnostics(payload, {
|
|
699
|
-
projectRoot,
|
|
700
|
-
batchId: wait.batchId ?? null,
|
|
701
|
-
logPath,
|
|
702
|
-
});
|
|
703
|
-
return {
|
|
704
|
-
ok: false,
|
|
705
|
-
exitCode: 1,
|
|
706
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
707
|
-
result: payload,
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
const configResult = loadSpineConfig(projectRoot);
|
|
712
|
-
const supervisorSpawn = maybeSpawnSupervisorOnDetachedStart({
|
|
713
|
-
projectRoot,
|
|
714
|
-
batchId: wait.batchId,
|
|
715
|
-
config: configResult.config ?? {},
|
|
716
|
-
});
|
|
717
|
-
|
|
718
|
-
const payload = {
|
|
719
|
-
ok: true,
|
|
720
|
-
detached: true,
|
|
721
|
-
operation: "start",
|
|
722
|
-
status: wait.status ?? "engine_started",
|
|
723
|
-
batchId: wait.batchId,
|
|
724
|
-
phase: wait.phase,
|
|
725
|
-
scope,
|
|
726
|
-
enginePid,
|
|
727
|
-
logPath,
|
|
728
|
-
suggestedCommand: "spine status --diagnose",
|
|
729
|
-
supervisorSpawned: supervisorSpawn.spawned === true,
|
|
730
|
-
supervisorPid: supervisorSpawn.supervisorPid ?? null,
|
|
731
|
-
};
|
|
732
|
-
return {
|
|
733
|
-
ok: true,
|
|
734
|
-
exitCode: 0,
|
|
735
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
736
|
-
result: payload,
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
/**
|
|
741
|
-
* @param {object} params
|
|
742
|
-
* @param {string} params.projectRoot
|
|
743
|
-
* @param {string} params.spineBin
|
|
744
|
-
* @param {boolean} [params.force]
|
|
745
|
-
* @param {boolean} [params.waitTerminal]
|
|
746
|
-
* @param {boolean} [params.json]
|
|
747
|
-
*/
|
|
748
|
-
export async function resumeBatchDetached({
|
|
749
|
-
projectRoot,
|
|
750
|
-
spineBin,
|
|
751
|
-
force = false,
|
|
752
|
-
waitTerminal = false,
|
|
753
|
-
json = false,
|
|
754
|
-
}) {
|
|
755
|
-
const engineLock = enforceAttachedEngineSingleOwner({ projectRoot, force, operation: "resume" });
|
|
756
|
-
if (!engineLock.ok) {
|
|
757
|
-
const payload = {
|
|
758
|
-
ok: false,
|
|
759
|
-
detached: true,
|
|
760
|
-
operation: "resume",
|
|
761
|
-
batchId: engineLock.batchId,
|
|
762
|
-
error: engineLock.error,
|
|
763
|
-
output: engineLock.output,
|
|
764
|
-
enginePid: engineLock.enginePid,
|
|
765
|
-
suggestedCommand:
|
|
766
|
-
engineLock.error === "concurrent_resume_blocked"
|
|
767
|
-
? "spine status --diagnose"
|
|
768
|
-
: "spine batch resume --attached --force",
|
|
769
|
-
};
|
|
770
|
-
return {
|
|
771
|
-
ok: false,
|
|
772
|
-
exitCode: engineLock.exitCode ?? 1,
|
|
773
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
774
|
-
result: payload,
|
|
775
|
-
};
|
|
776
|
-
}
|
|
777
|
-
const releaseResumeLock = engineLock.releaseResumeLock;
|
|
778
|
-
|
|
779
|
-
const resumeCheck = validateResumeBatch({ projectRoot, force });
|
|
780
|
-
if (!resumeCheck.ok) {
|
|
781
|
-
releaseResumeLock?.();
|
|
782
|
-
const payload = {
|
|
783
|
-
ok: false,
|
|
784
|
-
detached: true,
|
|
785
|
-
operation: "resume",
|
|
786
|
-
error: resumeCheck.error,
|
|
787
|
-
output: resumeCheck.output,
|
|
788
|
-
batchId: resumeCheck.batchId,
|
|
789
|
-
taskId: resumeCheck.taskId,
|
|
790
|
-
};
|
|
791
|
-
return {
|
|
792
|
-
ok: false,
|
|
793
|
-
exitCode: resumeCheck.exitCode ?? 1,
|
|
794
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
795
|
-
result: payload,
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
const { batchId, updatedAt, taskId } = resumeCheck;
|
|
800
|
-
|
|
801
|
-
if (resumeCheck.postMergeLimbo) {
|
|
802
|
-
const loaded = loadSpineBatchState(projectRoot);
|
|
803
|
-
const state = loaded.raw;
|
|
804
|
-
const finalizeResult = finalizeResumePostMergeLimbo({
|
|
805
|
-
projectRoot,
|
|
806
|
-
state,
|
|
807
|
-
batchId,
|
|
808
|
-
orchBranch: state.orchBranch,
|
|
809
|
-
fromPhase: String(state.phase ?? "running"),
|
|
810
|
-
resumeForced: force,
|
|
811
|
-
});
|
|
812
|
-
releaseResumeLock?.();
|
|
813
|
-
if (!finalizeResult?.ok) {
|
|
814
|
-
const payload = {
|
|
815
|
-
ok: false,
|
|
816
|
-
detached: true,
|
|
817
|
-
operation: "resume",
|
|
818
|
-
batchId,
|
|
819
|
-
taskId,
|
|
820
|
-
error: "post_merge_limbo_finalize_failed",
|
|
821
|
-
output: finalizeResult?.output ?? "Failed to finalize post-merge limbo.\n",
|
|
822
|
-
};
|
|
823
|
-
return {
|
|
824
|
-
ok: false,
|
|
825
|
-
exitCode: 1,
|
|
826
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
827
|
-
result: payload,
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
const payload = {
|
|
832
|
-
ok: true,
|
|
833
|
-
detached: true,
|
|
834
|
-
operation: "resume",
|
|
835
|
-
status: "resume_completed",
|
|
836
|
-
batchId,
|
|
837
|
-
taskId,
|
|
838
|
-
phase: "completed",
|
|
839
|
-
output: finalizeResult.output,
|
|
840
|
-
};
|
|
841
|
-
return {
|
|
842
|
-
ok: true,
|
|
843
|
-
exitCode: 0,
|
|
844
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
845
|
-
result: payload,
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
prepareDetachedResumeEngineHandoff(projectRoot);
|
|
850
|
-
const argv = buildAttachedBatchResumeArgv({ force });
|
|
851
|
-
const { enginePid, logPath } = spawnDetachedBatchEngine({ projectRoot, spineBin, argv });
|
|
852
|
-
releaseResumeLock?.();
|
|
853
|
-
const waitTimeoutMs = resolveDetachedWaitTimeoutMs(waitTerminal);
|
|
854
|
-
const wait = await waitForDetachedBatchResume({
|
|
855
|
-
projectRoot,
|
|
856
|
-
batchId,
|
|
857
|
-
updatedAtBefore: updatedAt,
|
|
858
|
-
taskId,
|
|
859
|
-
waitTerminal,
|
|
860
|
-
timeoutMs: waitTimeoutMs,
|
|
861
|
-
});
|
|
862
|
-
|
|
863
|
-
if (!wait.ok) {
|
|
864
|
-
/** @type {Record<string, unknown>} */
|
|
865
|
-
const payload = {
|
|
866
|
-
ok: false,
|
|
867
|
-
detached: true,
|
|
868
|
-
operation: "resume",
|
|
869
|
-
batchId,
|
|
870
|
-
taskId,
|
|
871
|
-
enginePid,
|
|
872
|
-
logPath,
|
|
873
|
-
error: wait.error,
|
|
874
|
-
lastError: wait.lastError ?? null,
|
|
875
|
-
output:
|
|
876
|
-
wait.error === "timeout_waiting_for_resume"
|
|
877
|
-
? "Engine may still be running or orphaned — run `spine status --diagnose`."
|
|
878
|
-
: `Batch resume failed (phase=${wait.phase ?? "unknown"}).`,
|
|
879
|
-
suggestedCommand: "spine status --diagnose",
|
|
880
|
-
};
|
|
881
|
-
attachDetachedFailureDiagnostics(payload, { projectRoot, batchId, taskId, logPath });
|
|
882
|
-
return {
|
|
883
|
-
ok: false,
|
|
884
|
-
exitCode: 1,
|
|
885
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
886
|
-
result: payload,
|
|
887
|
-
};
|
|
888
|
-
}
|
|
16
|
+
export {
|
|
17
|
+
collectDetachedFailureDiagnostics,
|
|
18
|
+
formatDetachedBatchStartOutput,
|
|
19
|
+
formatDetachedEngineOutput,
|
|
20
|
+
readCurrentBatchLogTail,
|
|
21
|
+
} from "./detached-diagnostics.mjs";
|
|
889
22
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
suggestedCommand: "spine status --diagnose",
|
|
901
|
-
};
|
|
902
|
-
return {
|
|
903
|
-
ok: true,
|
|
904
|
-
exitCode: 0,
|
|
905
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
906
|
-
result: payload,
|
|
907
|
-
};
|
|
908
|
-
}
|
|
23
|
+
export {
|
|
24
|
+
prepareDetachedResumeEngineHandoff,
|
|
25
|
+
resolveDefaultResumeWaitTerminal,
|
|
26
|
+
resolveDetachedWaitTimeoutMs,
|
|
27
|
+
runDetachedStartPreflight,
|
|
28
|
+
waitForDetachedBatchResume,
|
|
29
|
+
waitForDetachedBatchStart,
|
|
30
|
+
} from "./detached-wait.mjs";
|
|
31
|
+
|
|
32
|
+
export { resumeBatchDetached, startBatchDetached } from "./detached-run.mjs";
|