pi-spine 2.5.0 → 2.6.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.mjs +22 -0
- package/package.json +1 -1
- package/src/batch/attached-runner-promote.mjs +95 -11
- package/src/batch/diagnosis-alternatives.mjs +18 -0
- package/src/batch/diagnosis-gate-ready.mjs +23 -0
- package/src/batch/diagnosis-pending-lane.mjs +63 -0
- package/src/batch/diagnosis-retry-command.mjs +23 -0
- package/src/batch/diagnosis-tail-state.mjs +68 -0
- package/src/batch/diagnosis.mjs +69 -52
- package/src/batch/engine-lanes/commit.mjs +2 -0
- package/src/batch/engine-lanes.mjs +2 -3
- package/src/batch/evidence-command.mjs +125 -4
- package/src/batch/lane-commit.mjs +77 -8
- package/src/batch/lifecycle-archive.mjs +71 -0
- package/src/batch/lifecycle.mjs +27 -67
- package/src/batch/orphan-detect.mjs +68 -5
- package/src/batch/post-merge-limbo.mjs +137 -22
- package/src/batch/reconcile-batch.mjs +40 -43
- package/src/batch/reconcile-diagnosis-context.mjs +88 -0
- package/src/batch/reconcile-diagnosis.mjs +14 -32
- package/src/batch/resume-multi-validate.mjs +51 -9
- package/src/batch/retry.mjs +18 -2
- package/src/config/pi-spine-root.mjs +22 -0
- package/src/config/spine-config-load.mjs +26 -0
- package/src/doctor/duplicate-install.mjs +100 -0
- package/src/doctor/run-doctor-checks.mjs +10 -1
- package/src/doctor/worktree-health.mjs +4 -0
- package/templates/spine-config.json +3 -2
|
@@ -121,6 +121,105 @@ export function finalizeAttachedPostMergeLimbo({ projectRoot, state, batchId, or
|
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* @param {string} projectRoot
|
|
126
|
+
* @param {string} batchId
|
|
127
|
+
* @param {string} type
|
|
128
|
+
*/
|
|
129
|
+
function journalHasEventType(projectRoot, batchId, type) {
|
|
130
|
+
if (!batchId) return false;
|
|
131
|
+
return readJournalEvents(projectRoot, batchId).some((event) => event.type === type);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Idempotent land-loop close after gate open or host integrate (#198 / SP-636).
|
|
136
|
+
* Clears engine PID and emits `batch.land_loop_finalized` so `spine batch complete`
|
|
137
|
+
* is not blocked while a resume engine is still mid-evidence or lingering.
|
|
138
|
+
*
|
|
139
|
+
* @param {object} params
|
|
140
|
+
* @param {string} params.projectRoot
|
|
141
|
+
* @param {object} params.state
|
|
142
|
+
* @param {string} params.batchId
|
|
143
|
+
* @param {boolean} [params.resumed]
|
|
144
|
+
* @param {boolean} [params.resumeForced]
|
|
145
|
+
* @param {string} [params.source]
|
|
146
|
+
* @returns {{ ok: true, changed: boolean, batchId: string, exitCode: 0, shouldExit: boolean } | null}
|
|
147
|
+
*/
|
|
148
|
+
export function ensureLandLoopFinalizedAfterGateOrIntegrate({
|
|
149
|
+
projectRoot,
|
|
150
|
+
state,
|
|
151
|
+
batchId,
|
|
152
|
+
resumed = false,
|
|
153
|
+
resumeForced = false,
|
|
154
|
+
source = "ensure_after_gate_or_integrate",
|
|
155
|
+
}) {
|
|
156
|
+
if (!state || typeof state !== "object" || !batchId) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const gateRecord = loadGateRecord(projectRoot, batchId);
|
|
161
|
+
const integrateCompleted = journalHasEventType(projectRoot, batchId, "integrate.completed");
|
|
162
|
+
const gateApproved = gateRecord != null && String(gateRecord.status ?? "") === "approved";
|
|
163
|
+
const phaseCompleted = String(state.phase ?? "") === "completed";
|
|
164
|
+
|
|
165
|
+
if (!gateRecord && !integrateCompleted && !phaseCompleted) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let changed = false;
|
|
170
|
+
const taskIds = (state.tasks ?? []).map((task) => task.taskId);
|
|
171
|
+
|
|
172
|
+
if (!phaseCompleted) {
|
|
173
|
+
state.endedAt = state.endedAt ?? Date.now();
|
|
174
|
+
state.phase = "completed";
|
|
175
|
+
changed = true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!journalHasEventType(projectRoot, batchId, "batch.completed")) {
|
|
179
|
+
appendJournalEvent(projectRoot, batchId, "batch.completed", {
|
|
180
|
+
taskIds,
|
|
181
|
+
mergeCommit: state.mergeResults?.at(-1)?.mergeCommit,
|
|
182
|
+
resumed,
|
|
183
|
+
postMergeLimbo: !resumed,
|
|
184
|
+
resumeForced,
|
|
185
|
+
source,
|
|
186
|
+
});
|
|
187
|
+
changed = true;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (state.resilience?.enginePid != null) {
|
|
191
|
+
clearBatchEnginePid(state);
|
|
192
|
+
changed = true;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!journalHasEventType(projectRoot, batchId, "batch.land_loop_finalized")) {
|
|
196
|
+
const finalizeSource = integrateCompleted
|
|
197
|
+
? "host_integrate"
|
|
198
|
+
: gateApproved
|
|
199
|
+
? "host_gate_approved"
|
|
200
|
+
: source;
|
|
201
|
+
appendJournalEvent(projectRoot, batchId, "batch.land_loop_finalized", {
|
|
202
|
+
resumed,
|
|
203
|
+
resumeForced,
|
|
204
|
+
gateId: gateRecord?.gateId ?? null,
|
|
205
|
+
source: finalizeSource,
|
|
206
|
+
});
|
|
207
|
+
changed = true;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (changed) {
|
|
211
|
+
saveSpineBatchState(projectRoot, state, { bypassWriteGuard: true });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
ok: true,
|
|
216
|
+
changed,
|
|
217
|
+
batchId,
|
|
218
|
+
exitCode: 0,
|
|
219
|
+
shouldExit: integrateCompleted || gateApproved,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
124
223
|
/**
|
|
125
224
|
* Open integrate gate or spawn detached resume before attached engine exit (SP-378, GitHub #59).
|
|
126
225
|
*
|
|
@@ -148,10 +247,24 @@ export function finalizeAttachedLandLoopBeforeExit({
|
|
|
148
247
|
const state = loaded.raw;
|
|
149
248
|
const batchId = String(state.batchId ?? "");
|
|
150
249
|
const orchBranch = String(state.orchBranch ?? "");
|
|
250
|
+
const gateExists = loadGateRecord(projectRoot, batchId) != null;
|
|
251
|
+
const integrateCompleted = journalHasEventType(projectRoot, batchId, "integrate.completed");
|
|
151
252
|
|
|
152
|
-
if (String(state.phase ?? "") === "completed" ||
|
|
253
|
+
if (String(state.phase ?? "") === "completed" || gateExists || integrateCompleted) {
|
|
254
|
+
const ensured = ensureLandLoopFinalizedAfterGateOrIntegrate({
|
|
255
|
+
projectRoot,
|
|
256
|
+
state,
|
|
257
|
+
batchId,
|
|
258
|
+
resumed: true,
|
|
259
|
+
source: integrateCompleted ? "host_integrate" : "attached_exit_after_gate",
|
|
260
|
+
});
|
|
153
261
|
attachedExitFinalizeInFlight = false;
|
|
154
|
-
return {
|
|
262
|
+
return {
|
|
263
|
+
handled: true,
|
|
264
|
+
action: ensured?.changed ? "finalized_after_gate_or_integrate" : "already_finalized",
|
|
265
|
+
batchId,
|
|
266
|
+
result: ensured,
|
|
267
|
+
};
|
|
155
268
|
}
|
|
156
269
|
|
|
157
270
|
hydrateMergeResultsFromJournal({ projectRoot, state, batchId });
|
|
@@ -307,6 +420,10 @@ export function tryFinalizePostMergeLimbo({
|
|
|
307
420
|
* Open integrate gate and mark batch completed (idempotent gate open).
|
|
308
421
|
* Shared by engine completion and resume post-merge limbo fast path (SP-204, SP-280).
|
|
309
422
|
*
|
|
423
|
+
* Clear engine PID before gate open so extended evidence (often `npm test`) cannot
|
|
424
|
+
* leave a live PID blocking `batch complete` while the gate record already exists (#198).
|
|
425
|
+
* Journal order keeps `gate.opened` before `batch.completed`.
|
|
426
|
+
*
|
|
310
427
|
* @param {object} params
|
|
311
428
|
*/
|
|
312
429
|
export function finalizeBatchForIntegrate({
|
|
@@ -321,40 +438,37 @@ export function finalizeBatchForIntegrate({
|
|
|
321
438
|
const summaryTask =
|
|
322
439
|
taskIds.length === 1 ? taskIds[0] : `${taskIds.length} tasks (${taskIds.join(", ")})`;
|
|
323
440
|
const alreadyCompleted = String(state.phase ?? "") === "completed";
|
|
441
|
+
const landLoopSource = resumed ? "resume_fast_path" : "engine_land_loop";
|
|
324
442
|
|
|
325
443
|
if (!alreadyCompleted) {
|
|
326
444
|
state.endedAt = Date.now();
|
|
327
445
|
}
|
|
328
446
|
|
|
447
|
+
// Persist PID clear before evidence collection can hang (#198 / SP-636).
|
|
448
|
+
clearBatchEnginePid(state);
|
|
449
|
+
saveSpineBatchState(projectRoot, state, { bypassWriteGuard: true });
|
|
450
|
+
|
|
329
451
|
const gateResult = openIntegrateGateAfterBatchComplete({
|
|
330
452
|
projectRoot,
|
|
331
453
|
batchId,
|
|
332
454
|
batchState: { ...state, phase: "completed" },
|
|
333
455
|
});
|
|
334
456
|
|
|
457
|
+
// Always mark completed in memory before ensure so a prior land-loop journal
|
|
458
|
+
// (e.g. start then pause/resume) still persists phase: completed on disk.
|
|
335
459
|
if (!alreadyCompleted) {
|
|
336
460
|
state.phase = "completed";
|
|
337
|
-
|
|
338
|
-
taskIds,
|
|
339
|
-
mergeCommit: state.mergeResults?.at(-1)?.mergeCommit,
|
|
340
|
-
resumed,
|
|
341
|
-
postMergeLimbo: !resumed,
|
|
342
|
-
resumeForced,
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
clearBatchEnginePid(state);
|
|
347
|
-
|
|
348
|
-
const gateRecord = loadGateRecord(projectRoot, batchId);
|
|
349
|
-
if (gateRecord) {
|
|
350
|
-
appendJournalEvent(projectRoot, batchId, "batch.land_loop_finalized", {
|
|
351
|
-
resumed,
|
|
352
|
-
resumeForced,
|
|
353
|
-
gateId: gateRecord.gateId ?? gateResult?.gate?.gateId ?? null,
|
|
354
|
-
source: resumed ? "resume_fast_path" : "engine_land_loop",
|
|
355
|
-
});
|
|
461
|
+
state.endedAt = state.endedAt ?? Date.now();
|
|
356
462
|
}
|
|
357
|
-
|
|
463
|
+
ensureLandLoopFinalizedAfterGateOrIntegrate({
|
|
464
|
+
projectRoot,
|
|
465
|
+
state,
|
|
466
|
+
batchId,
|
|
467
|
+
resumed,
|
|
468
|
+
resumeForced,
|
|
469
|
+
source: landLoopSource,
|
|
470
|
+
});
|
|
471
|
+
// Ensure may no-op when journal events already exist; always persist phase/PID.
|
|
358
472
|
saveSpineBatchState(projectRoot, state, { bypassWriteGuard: true });
|
|
359
473
|
|
|
360
474
|
const completionLabel = resumed ? "resumed and completed" : "completed";
|
|
@@ -370,6 +484,7 @@ export function finalizeBatchForIntegrate({
|
|
|
370
484
|
taskId: taskIds.length === 1 ? taskIds[0] : undefined,
|
|
371
485
|
orchBranch,
|
|
372
486
|
mergeCommit: state.mergeResults?.at(-1)?.mergeCommit,
|
|
487
|
+
gateResult,
|
|
373
488
|
output:
|
|
374
489
|
`Batch ${batchId} ${completionLabel}: ${summaryTask} succeeded; merged to ${orchBranch}.\n` +
|
|
375
490
|
nextSteps,
|
|
@@ -7,11 +7,8 @@ import { buildStalePathDoctorCheck } from "../doctor/stale-path.mjs";
|
|
|
7
7
|
import { PACKAGE_ROOT } from "../config/spine-init-constants.mjs";
|
|
8
8
|
import { loadGateRecord } from "./gate-evidence-read.mjs";
|
|
9
9
|
import { deriveMacroPhase, macroPhaseLabel } from "./macro-phase.mjs";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
inferMergeGitignoredFailure,
|
|
13
|
-
isGateReadyHeadlineContext,
|
|
14
|
-
} from "./diagnosis.mjs";
|
|
10
|
+
import { buildDiagnosisOutput, inferMergeGitignoredFailure } from "./diagnosis.mjs";
|
|
11
|
+
import { isGateReadyHeadlineContext } from "./diagnosis-gate-ready.mjs";
|
|
15
12
|
import {
|
|
16
13
|
classifyTasks,
|
|
17
14
|
inspectGitState,
|
|
@@ -47,6 +44,7 @@ import {
|
|
|
47
44
|
} from "./batch-state-io.mjs";
|
|
48
45
|
import { readBatchEnginePid } from "./state.mjs";
|
|
49
46
|
import {
|
|
47
|
+
buildReconcileDiagnosisContext,
|
|
50
48
|
deriveDiagnosis,
|
|
51
49
|
enrichLaunchFailureFromWorkerOutput,
|
|
52
50
|
enrichWorkerDoneMissingContext,
|
|
@@ -395,49 +393,48 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
395
393
|
const enginePid = readBatchEnginePid(batch.raw);
|
|
396
394
|
const staleEnginePid =
|
|
397
395
|
enginePid != null && !isProcessAlive(enginePid);
|
|
396
|
+
const engineStillRunning = enginePid != null && !staleEnginePid;
|
|
398
397
|
const engineOrphanCause =
|
|
399
398
|
diagnosis === "engine_orphaned"
|
|
400
399
|
? inferEngineOrphanCause({ journalEvents, staleEnginePid })
|
|
401
400
|
: null;
|
|
402
401
|
|
|
403
|
-
const output = buildDiagnosisOutput(
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
overlapPaths: humanBaseSync?.overlapPaths ?? [],
|
|
440
|
-
});
|
|
402
|
+
const output = buildDiagnosisOutput(
|
|
403
|
+
diagnosis,
|
|
404
|
+
buildReconcileDiagnosisContext({
|
|
405
|
+
batch,
|
|
406
|
+
git,
|
|
407
|
+
signals,
|
|
408
|
+
classifiedTasks,
|
|
409
|
+
diagnosis,
|
|
410
|
+
failedTaskId,
|
|
411
|
+
driftTaskStatus,
|
|
412
|
+
exitReason,
|
|
413
|
+
resolvedLaunchFailureKind,
|
|
414
|
+
pendingTaskCount,
|
|
415
|
+
salvageChangedFileCount,
|
|
416
|
+
salvageRetryCommand,
|
|
417
|
+
ghostRunningCluster,
|
|
418
|
+
integrateGateOpen,
|
|
419
|
+
stalePathSpine,
|
|
420
|
+
planReviewNestedSpawnBlocked,
|
|
421
|
+
mergeGitignoredFailure,
|
|
422
|
+
mergeFailedForHeadline,
|
|
423
|
+
mergeFailureSummary,
|
|
424
|
+
taskBranch,
|
|
425
|
+
gitignoredPaths,
|
|
426
|
+
hasRunningTasks,
|
|
427
|
+
hasPendingTasks,
|
|
428
|
+
macroPhase,
|
|
429
|
+
reviewHonorSignal,
|
|
430
|
+
doneMissingContext,
|
|
431
|
+
engineOrphanCause,
|
|
432
|
+
staleEnginePid,
|
|
433
|
+
enginePid,
|
|
434
|
+
engineStillRunning,
|
|
435
|
+
humanBaseSync,
|
|
436
|
+
}),
|
|
437
|
+
);
|
|
441
438
|
|
|
442
439
|
if (humanBaseSync && (diagnosis === "human_base_diverged" || diagnosis === "integrate_isolated_ok")) {
|
|
443
440
|
output.headline = humanBaseSync.headline;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/** Diagnosis output context after reconcile signal enrichment (#201 / SP-645). */
|
|
3
|
+
|
|
4
|
+
import { findPendingLaneLandTasks } from "./diagnosis-pending-lane.mjs";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {object} params
|
|
8
|
+
*/
|
|
9
|
+
export function buildReconcileDiagnosisContext(params) {
|
|
10
|
+
const {
|
|
11
|
+
batch,
|
|
12
|
+
git,
|
|
13
|
+
signals,
|
|
14
|
+
classifiedTasks,
|
|
15
|
+
diagnosis: _diagnosis,
|
|
16
|
+
failedTaskId,
|
|
17
|
+
driftTaskStatus,
|
|
18
|
+
exitReason,
|
|
19
|
+
resolvedLaunchFailureKind,
|
|
20
|
+
pendingTaskCount,
|
|
21
|
+
salvageChangedFileCount,
|
|
22
|
+
salvageRetryCommand,
|
|
23
|
+
ghostRunningCluster,
|
|
24
|
+
integrateGateOpen,
|
|
25
|
+
stalePathSpine,
|
|
26
|
+
planReviewNestedSpawnBlocked,
|
|
27
|
+
mergeGitignoredFailure,
|
|
28
|
+
mergeFailedForHeadline,
|
|
29
|
+
mergeFailureSummary,
|
|
30
|
+
taskBranch,
|
|
31
|
+
gitignoredPaths,
|
|
32
|
+
hasRunningTasks,
|
|
33
|
+
hasPendingTasks,
|
|
34
|
+
macroPhase,
|
|
35
|
+
reviewHonorSignal,
|
|
36
|
+
doneMissingContext,
|
|
37
|
+
engineOrphanCause,
|
|
38
|
+
staleEnginePid,
|
|
39
|
+
enginePid,
|
|
40
|
+
engineStillRunning,
|
|
41
|
+
humanBaseSync,
|
|
42
|
+
} = params;
|
|
43
|
+
|
|
44
|
+
const pendingLaneLandTasks = findPendingLaneLandTasks(classifiedTasks);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
batchId: batch.batchId,
|
|
48
|
+
baseBranch: batch.baseBranch ?? git.baseBranch ?? "main",
|
|
49
|
+
pendingLaneLandTasks,
|
|
50
|
+
phase: batch.phase,
|
|
51
|
+
failedTasks: signals.failedTasks,
|
|
52
|
+
failedTaskId,
|
|
53
|
+
driftTaskStatus,
|
|
54
|
+
exitReason,
|
|
55
|
+
launchFailureKind: resolvedLaunchFailureKind,
|
|
56
|
+
gitMerged: git.orchMergedToBase,
|
|
57
|
+
pendingTaskCount,
|
|
58
|
+
salvageChangedFileCount,
|
|
59
|
+
salvageRetryCommand,
|
|
60
|
+
ghostRunningCluster,
|
|
61
|
+
postMergeLimbo: signals.postMergeLimbo === true,
|
|
62
|
+
integrateGateOpen,
|
|
63
|
+
stalePathSpine,
|
|
64
|
+
planReviewNestedSpawnBlocked,
|
|
65
|
+
mergeGitignoredFailure,
|
|
66
|
+
mergeFailed: mergeFailedForHeadline,
|
|
67
|
+
failedWaveIndex: mergeFailureSummary.failedWaveIndex,
|
|
68
|
+
failedLane: mergeFailureSummary.failedLane,
|
|
69
|
+
lastError: mergeFailureSummary.lastError,
|
|
70
|
+
succeededTasks: batch.succeededTasks,
|
|
71
|
+
totalTasks: batch.totalTasks,
|
|
72
|
+
taskBranch,
|
|
73
|
+
gitignoredPaths,
|
|
74
|
+
hasRunningTasks,
|
|
75
|
+
hasPendingTasks,
|
|
76
|
+
allTasksTerminalSuccess: signals.allTasksTerminalSuccess,
|
|
77
|
+
tasksRoot: signals.tasksRoot,
|
|
78
|
+
macroPhase,
|
|
79
|
+
reviewHonorSignal,
|
|
80
|
+
...(doneMissingContext ?? {}),
|
|
81
|
+
engineOrphanCause,
|
|
82
|
+
staleEnginePid,
|
|
83
|
+
enginePid,
|
|
84
|
+
engineStillRunning,
|
|
85
|
+
humanBaseSync,
|
|
86
|
+
overlapPaths: humanBaseSync?.overlapPaths ?? [],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
/** Diagnosis derivation (SP-596/SP-606 / #192). */
|
|
3
3
|
|
|
4
4
|
import fs from "node:fs";
|
|
5
|
+
import { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "./diagnosis.mjs";
|
|
5
6
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./diagnosis.mjs";
|
|
7
|
+
findPendingLaneLandTasks,
|
|
8
|
+
shouldDiagnosePendingLaneLand,
|
|
9
|
+
} from "./diagnosis-pending-lane.mjs";
|
|
9
10
|
import { inferWorkerDoneMissingFailure } from "./diagnosis-worker-done-missing.mjs";
|
|
10
11
|
import { inferStubExitReasonForTask } from "./diagnosis-stub.mjs";
|
|
11
12
|
import { workerOutputLogPath, workerOutputLogRef } from "./worker-output.mjs";
|
|
12
|
-
import { journalEventsSinceResume } from "./orphan-detect.mjs";
|
|
13
13
|
import { isPostMergeLimbo } from "./limbo-detect.mjs";
|
|
14
|
-
import { isProcessAlive } from "../process/liveness.mjs";
|
|
15
|
-
import { readBatchEnginePid } from "./state.mjs";
|
|
16
14
|
import {
|
|
17
15
|
LIMBO_PHASES,
|
|
18
16
|
RUNNING_PHASES,
|
|
19
17
|
} from "./reconcile-light-cache.mjs";
|
|
18
|
+
export { buildReconcileDiagnosisContext } from "./reconcile-diagnosis-context.mjs";
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @param {unknown} rawTasks
|
|
@@ -241,22 +240,6 @@ function withFailureContext(diagnosis, failedTaskId, signals, exitReason = null)
|
|
|
241
240
|
};
|
|
242
241
|
}
|
|
243
242
|
|
|
244
|
-
/**
|
|
245
|
-
* @param {object[]} journalEvents
|
|
246
|
-
* @param {Record<string, unknown>|null|undefined} raw
|
|
247
|
-
* @param {string|null} taskId
|
|
248
|
-
*/
|
|
249
|
-
function journalIndicatesResumeRulesStall(journalEvents, raw, taskId) {
|
|
250
|
-
const scoped = journalEventsSinceResume(journalEvents, raw);
|
|
251
|
-
const hasRulesSelected = scoped.some((event) => {
|
|
252
|
-
if (event.type !== "worker.rules_selected") return false;
|
|
253
|
-
const eventTaskId = event.taskId ?? event.payload?.taskId;
|
|
254
|
-
return !taskId || !eventTaskId || eventTaskId === taskId;
|
|
255
|
-
});
|
|
256
|
-
const hasBatchResumed = scoped.some((event) => event.type === "batch.resumed");
|
|
257
|
-
return hasRulesSelected && hasBatchResumed;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
243
|
/**
|
|
261
244
|
* @param {object} signals
|
|
262
245
|
*/
|
|
@@ -300,21 +283,20 @@ export function deriveDiagnosis(signals) {
|
|
|
300
283
|
|
|
301
284
|
if (orphanRunning) {
|
|
302
285
|
if (orphanRunning.kind === "lane" && orphanRunning.taskId) {
|
|
303
|
-
const enginePid = readBatchEnginePid(signals.raw);
|
|
304
|
-
const engineDead = enginePid == null || !isProcessAlive(enginePid);
|
|
305
|
-
const resumeRulesStall = journalIndicatesResumeRulesStall(
|
|
306
|
-
signals.journalEvents ?? [],
|
|
307
|
-
signals.raw,
|
|
308
|
-
orphanRunning.taskId,
|
|
309
|
-
);
|
|
310
|
-
if (engineDead && resumeRulesStall) {
|
|
311
|
-
return withFailureContext("engine_orphaned", orphanRunning.taskId, signals);
|
|
312
|
-
}
|
|
313
286
|
return withFailureContext("worker_orphaned", orphanRunning.taskId, signals);
|
|
314
287
|
}
|
|
315
288
|
return withFailureContext("engine_orphaned", orphanRunning.taskId ?? null, signals);
|
|
316
289
|
}
|
|
317
290
|
|
|
291
|
+
if (shouldDiagnosePendingLaneLand(signals)) {
|
|
292
|
+
const pendingLaneLandTasks = findPendingLaneLandTasks(signals.tasks);
|
|
293
|
+
return withFailureContext(
|
|
294
|
+
"pending_lane_land",
|
|
295
|
+
pendingLaneLandTasks[0]?.taskId ?? null,
|
|
296
|
+
signals,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
318
300
|
if (signals.stateDrift?.drifted) {
|
|
319
301
|
const driftTask = signals.stateDrift.entries.find((entry) => entry.taskId !== "*");
|
|
320
302
|
return withFailureContext("state_drift", driftTask?.taskId ?? null, signals);
|
|
@@ -61,24 +61,66 @@ export function detectPostMergeLimboForResume({ projectRoot, state }) {
|
|
|
61
61
|
export { hasPendingWaveMerge } from "./merge/wave-merge-state.mjs";
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Terminal-success evidence for force-resume eligibility (#196 / #197).
|
|
65
|
+
* Prefer classification / done* markers over raw `status === "succeeded"` only —
|
|
66
|
+
* diagnose and salvage use the same signals when the status cache lags.
|
|
67
|
+
*
|
|
68
|
+
* @param {object|null|undefined} task
|
|
69
|
+
*/
|
|
70
|
+
function isTerminalSuccessForResume(task) {
|
|
71
|
+
const status = String(task?.status ?? "").toLowerCase();
|
|
72
|
+
if (status === "succeeded" || status === "skipped") return true;
|
|
73
|
+
if (task?.doneInLane === true || task?.doneFileFound === true || task?.doneOnMain === true) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return String(task?.classification ?? "").toLowerCase() === "terminal-success";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Whether every task is terminal-success (or skipped) for drift recovery (#196 / #197).
|
|
65
81
|
*
|
|
66
82
|
* @param {object|null|undefined} state
|
|
67
83
|
*/
|
|
68
84
|
function allTasksTerminalSuccessForResume(state) {
|
|
69
85
|
const tasks = state?.tasks ?? [];
|
|
70
86
|
if (tasks.length < 1) return false;
|
|
71
|
-
return tasks.every((task) =>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
return tasks.every((task) => isTerminalSuccessForResume(task));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Pending wave merge for resume eligibility.
|
|
92
|
+
*
|
|
93
|
+
* Status-only `hasPendingWaveMerge` misses #197 when tasks are still `status: running`
|
|
94
|
+
* but classification / doneInLane already show terminal success. In that case treat any
|
|
95
|
+
* wave without a succeeded mergeResults row as pending merge (same intent as
|
|
96
|
+
* findFirstWaveNeedingMerge, without widening wave-merge-state blast radius).
|
|
97
|
+
*
|
|
98
|
+
* @param {object|null|undefined} state
|
|
99
|
+
*/
|
|
100
|
+
function hasPendingWaveMergeForResume(state) {
|
|
101
|
+
if (hasPendingWaveMerge(state)) return true;
|
|
102
|
+
if (!allTasksTerminalSuccessForResume(state)) return false;
|
|
103
|
+
const wavePlan = state?.wavePlan ?? [];
|
|
104
|
+
if (wavePlan.length < 1) return false;
|
|
105
|
+
const mergeResults = state?.mergeResults ?? [];
|
|
106
|
+
const succeeded = new Set(
|
|
107
|
+
mergeResults
|
|
108
|
+
.filter((entry) => String(entry?.status ?? "").toLowerCase() === "succeeded")
|
|
109
|
+
.map((entry) => Number(entry.waveIndex))
|
|
110
|
+
.filter((waveIndex) => Number.isFinite(waveIndex)),
|
|
111
|
+
);
|
|
112
|
+
for (let waveIndex = 0; waveIndex < wavePlan.length; waveIndex++) {
|
|
113
|
+
if (!succeeded.has(waveIndex)) return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
75
116
|
}
|
|
76
117
|
|
|
77
118
|
/**
|
|
78
119
|
* Assess whether a running-phase batch may resume after a dead detached engine (SP-296).
|
|
79
120
|
*
|
|
80
|
-
* Also covers SP-613 / #196: pidless engine + all tasks terminal-success
|
|
81
|
-
*
|
|
121
|
+
* Also covers SP-613 / #196 and SP-635 / #197: pidless engine + all tasks terminal-success
|
|
122
|
+
* (status healed or classification/doneInLane) + pending wave merge must not dead-end on
|
|
123
|
+
* phase=running.
|
|
82
124
|
*
|
|
83
125
|
* @param {object} params
|
|
84
126
|
* @param {string} params.projectRoot
|
|
@@ -101,11 +143,11 @@ export function assessRunningPhaseResumeEligibility({ projectRoot, state }) {
|
|
|
101
143
|
const enginePid = readBatchEnginePid(state);
|
|
102
144
|
const enginePidDead = enginePid != null && !isProcessAlive(enginePid);
|
|
103
145
|
const pidlessEngineOrphan = enginePid == null && orphanRunning?.kind === "engine";
|
|
104
|
-
// Dead/missing engine with work finished but merge not landed — agent-safe detached resume (#196).
|
|
146
|
+
// Dead/missing engine with work finished but merge not landed — agent-safe detached resume (#196 / #197).
|
|
105
147
|
const pidlessTerminalSuccessPendingMerge =
|
|
106
148
|
enginePid == null &&
|
|
107
149
|
allTasksTerminalSuccessForResume(state) &&
|
|
108
|
-
|
|
150
|
+
hasPendingWaveMergeForResume(state);
|
|
109
151
|
const engineConfirmedDead =
|
|
110
152
|
enginePidDead || pidlessEngineOrphan || pidlessTerminalSuccessPendingMerge;
|
|
111
153
|
|
package/src/batch/retry.mjs
CHANGED
|
@@ -18,6 +18,16 @@ import {
|
|
|
18
18
|
const RETRY_ALLOWED_PHASES = new Set(["paused", "failed"]);
|
|
19
19
|
const RETRY_BLOCKED_PHASES = new Set(["running", "planning"]);
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Fail running tasks and clear dead engine/worker PIDs before retry/skip (#203 / SP-647).
|
|
23
|
+
*
|
|
24
|
+
* @param {string} projectRoot
|
|
25
|
+
* @param {object} state
|
|
26
|
+
*/
|
|
27
|
+
function reconcileOrphanBeforeTaskMutation(projectRoot, state) {
|
|
28
|
+
return reconcileOrphanRunningState({ projectRoot, state });
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
/**
|
|
22
32
|
* @param {object} state
|
|
23
33
|
* @param {string} taskId
|
|
@@ -115,7 +125,7 @@ export function retryTask({ projectRoot, taskId }) {
|
|
|
115
125
|
return { ok: false, exitCode: 1, error: "no_active_batch", output: "No active pi-spine batch.\n" };
|
|
116
126
|
}
|
|
117
127
|
|
|
118
|
-
|
|
128
|
+
reconcileOrphanBeforeTaskMutation(projectRoot, loaded.raw);
|
|
119
129
|
|
|
120
130
|
const reloaded = loadSpineBatchState(projectRoot);
|
|
121
131
|
const state = reloaded.raw;
|
|
@@ -255,7 +265,13 @@ export function skipTask({ projectRoot, taskId }) {
|
|
|
255
265
|
return { ok: false, exitCode: 1, error: "no_active_batch", output: "No active pi-spine batch.\n" };
|
|
256
266
|
}
|
|
257
267
|
|
|
258
|
-
|
|
268
|
+
reconcileOrphanBeforeTaskMutation(projectRoot, loaded.raw);
|
|
269
|
+
|
|
270
|
+
const reloaded = loadSpineBatchState(projectRoot);
|
|
271
|
+
const state = reloaded.raw;
|
|
272
|
+
if (!state) {
|
|
273
|
+
return { ok: false, exitCode: 1, error: "no_active_batch", output: "No active pi-spine batch.\n" };
|
|
274
|
+
}
|
|
259
275
|
const phase = String(state.phase ?? "");
|
|
260
276
|
|
|
261
277
|
if (RETRY_BLOCKED_PHASES.has(phase)) {
|
|
@@ -30,6 +30,28 @@ function realpathOrResolve(root) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Default `PI_SPINE_ROOT` to cwd when unset/empty so CLI doctor/preflight
|
|
35
|
+
* do not require a manual export (SP-643 / #203). Does not override an
|
|
36
|
+
* explicit env value. Worker package-root resolution stays in
|
|
37
|
+
* {@link resolvePiSpineRoot}.
|
|
38
|
+
*
|
|
39
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
40
|
+
* @param {string} [cwd]
|
|
41
|
+
* @returns {string} Effective `PI_SPINE_ROOT` after ensure
|
|
42
|
+
*/
|
|
43
|
+
export function ensureDefaultPiSpineRootEnv(
|
|
44
|
+
env = process.env,
|
|
45
|
+
cwd = process.cwd(),
|
|
46
|
+
) {
|
|
47
|
+
const current = env.PI_SPINE_ROOT;
|
|
48
|
+
if (typeof current === "string" && current.trim()) {
|
|
49
|
+
return current.trim();
|
|
50
|
+
}
|
|
51
|
+
env.PI_SPINE_ROOT = cwd;
|
|
52
|
+
return cwd;
|
|
53
|
+
}
|
|
54
|
+
|
|
33
55
|
/**
|
|
34
56
|
* @param {object} [config]
|
|
35
57
|
* @param {string} [projectRoot]
|
|
@@ -14,6 +14,29 @@ import { validateOrchestratorConfig } from "./spine-config-schema.mjs";
|
|
|
14
14
|
|
|
15
15
|
export { resolveGatePostureConfig } from "./gate-posture-config.mjs";
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Default hook paths skipped at lane commit when config omits ignore paths (SP-640 / #200).
|
|
19
|
+
* Worktree setup hooks commonly `ln -s` `.venv` into lane worktrees; do not stage that symlink.
|
|
20
|
+
*/
|
|
21
|
+
export const DEFAULT_WORKTREE_SETUP_IGNORE_PATHS = Object.freeze([".venv"]);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolve effective `worktreeSetupIgnorePaths`, always unioning defaults so hook `.venv`
|
|
25
|
+
* stays ignored. Opt in to committing an ignore path via task `fileScope`, not by clearing config.
|
|
26
|
+
*
|
|
27
|
+
* @param {Record<string, unknown> | null | undefined} config
|
|
28
|
+
* @returns {string[]}
|
|
29
|
+
*/
|
|
30
|
+
export function resolveWorktreeSetupIgnorePaths(config) {
|
|
31
|
+
const raw = config?.worktreeSetupIgnorePaths;
|
|
32
|
+
const configured = Array.isArray(raw)
|
|
33
|
+
? raw
|
|
34
|
+
.filter((/** @type {unknown} */ entry) => typeof entry === "string" && entry.trim())
|
|
35
|
+
.map((/** @type {unknown} */ entry) => /** @type {string} */ (entry).trim())
|
|
36
|
+
: [];
|
|
37
|
+
return [...new Set([...DEFAULT_WORKTREE_SETUP_IGNORE_PATHS, ...configured])];
|
|
38
|
+
}
|
|
39
|
+
|
|
17
40
|
const REQUIRED_TOP_LEVEL = [
|
|
18
41
|
"configVersion",
|
|
19
42
|
"project",
|
|
@@ -91,6 +114,9 @@ export function loadSpineConfig(projectRoot) {
|
|
|
91
114
|
|
|
92
115
|
const config = structuredClone(fileResult.config);
|
|
93
116
|
applyConfigDefaults(config);
|
|
117
|
+
if (config.worktreeSetupIgnorePaths == null) {
|
|
118
|
+
config.worktreeSetupIgnorePaths = [...DEFAULT_WORKTREE_SETUP_IGNORE_PATHS];
|
|
119
|
+
}
|
|
94
120
|
|
|
95
121
|
const contractError = validateContractConfig(config);
|
|
96
122
|
if (contractError) {
|