pi-spine 2.7.0 → 2.8.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/package.json +1 -1
- package/src/batch/attached-runner-reconcile.mjs +51 -3
- package/src/batch/attached-runner.mjs +1 -0
- package/src/batch/detached-run.mjs +48 -41
- package/src/batch/detached-start.mjs +1 -0
- package/src/batch/diagnosis-merge-failure.mjs +22 -0
- package/src/batch/diagnosis.mjs +10 -8
- package/src/batch/lane-commit.mjs +42 -4
- package/src/batch/lane-dirty-check-commit.mjs +5 -0
- package/src/batch/lane-dirty-check.mjs +5 -0
- package/src/batch/reconcile-orphan.mjs +114 -11
- package/src/batch/resume.mjs +1 -0
package/package.json
CHANGED
|
@@ -27,6 +27,20 @@ import { laneDoneMarkerReadyForPromote } from "./journal-rebuild.mjs";
|
|
|
27
27
|
import { resolveTasksRoot } from "../config/spine-preflight-lib.mjs";
|
|
28
28
|
import { journalHasTaskCompleted } from "./resume-common.mjs";
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* True when the batch still has in-flight work owned by a live engine.
|
|
32
|
+
* Terminal-success / post-merge limbo batches must remain --force recoverable.
|
|
33
|
+
*
|
|
34
|
+
* @param {object|null|undefined} state
|
|
35
|
+
*/
|
|
36
|
+
function batchHasActiveTaskWork(state) {
|
|
37
|
+
const tasks = state?.tasks ?? [];
|
|
38
|
+
return tasks.some((task) => {
|
|
39
|
+
const status = String(task?.status ?? "");
|
|
40
|
+
return status === "running" || status === "pending";
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
/**
|
|
31
45
|
* @param {string} projectRoot
|
|
32
46
|
* @param {string} batchId
|
|
@@ -122,9 +136,17 @@ export function releaseResumeHandoffLock(projectRoot, batchId) {
|
|
|
122
136
|
}
|
|
123
137
|
}
|
|
124
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Phases where a live recorded enginePid is the single resume/batch owner.
|
|
141
|
+
* Force orphan handoff remains allowed from paused/failed recoveries (SP-434).
|
|
142
|
+
* @type {ReadonlySet<string>}
|
|
143
|
+
*/
|
|
144
|
+
const LIVE_RESUME_OWNER_PHASES = new Set(["running", "gating"]);
|
|
145
|
+
|
|
125
146
|
/**
|
|
126
147
|
* Reject a second attached engine when resilience.enginePid is alive (SP-434, GitHub #89).
|
|
127
148
|
* Serialized forced resume handoff when another resume --force is in flight (SP-533, #167).
|
|
149
|
+
* Fail-fast while a live engine already owns a running batch (SP-660, #207).
|
|
128
150
|
*
|
|
129
151
|
* @param {object} params
|
|
130
152
|
* @param {string} params.projectRoot
|
|
@@ -139,13 +161,41 @@ export function enforceAttachedEngineSingleOwner({ projectRoot, force = false, o
|
|
|
139
161
|
}
|
|
140
162
|
|
|
141
163
|
const batchId = String(state.batchId ?? "");
|
|
164
|
+
const fromPhase = String(state.phase ?? "");
|
|
165
|
+
const enginePid = readBatchEnginePid(state);
|
|
142
166
|
/** @type {(() => void) | undefined} */
|
|
143
167
|
let releaseResumeLock;
|
|
144
168
|
|
|
169
|
+
// Detached resume child already recorded as engine owner — do not re-journal handoff (SP-660).
|
|
170
|
+
if (force && operation === "resume" && enginePid != null && enginePid === process.pid) {
|
|
171
|
+
return { ok: true };
|
|
172
|
+
}
|
|
173
|
+
|
|
145
174
|
if (force && operation === "resume") {
|
|
175
|
+
// Live owner still driving active task work: refuse a second --force (dual engines).
|
|
176
|
+
// Terminal-success / post-merge limbo (no active task work) stays --force recoverable.
|
|
177
|
+
if (
|
|
178
|
+
enginePid != null &&
|
|
179
|
+
enginePid !== process.pid &&
|
|
180
|
+
isProcessAlive(enginePid) &&
|
|
181
|
+
LIVE_RESUME_OWNER_PHASES.has(fromPhase) &&
|
|
182
|
+
batchHasActiveTaskWork(state)
|
|
183
|
+
) {
|
|
184
|
+
const output =
|
|
185
|
+
`Batch resume engine already owns this batch (PID ${enginePid}, batch ${batchId}, phase ${fromPhase}).\n` +
|
|
186
|
+
`Wait for that engine to finish, or stop it before starting another resume --force.\n`;
|
|
187
|
+
return {
|
|
188
|
+
ok: false,
|
|
189
|
+
exitCode: 1,
|
|
190
|
+
error: "concurrent_resume_blocked",
|
|
191
|
+
output,
|
|
192
|
+
batchId,
|
|
193
|
+
enginePid,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
146
197
|
const lock = tryAcquireResumeHandoffLock(projectRoot, batchId);
|
|
147
198
|
if (!lock.ok) {
|
|
148
|
-
const enginePid = readBatchEnginePid(state);
|
|
149
199
|
const holderPid = lock.holderPid ?? null;
|
|
150
200
|
const output =
|
|
151
201
|
`Another batch resume --force is already in progress (batch ${batchId}` +
|
|
@@ -167,12 +217,10 @@ export function enforceAttachedEngineSingleOwner({ projectRoot, force = false, o
|
|
|
167
217
|
});
|
|
168
218
|
}
|
|
169
219
|
|
|
170
|
-
const enginePid = readBatchEnginePid(state);
|
|
171
220
|
if (enginePid == null || enginePid === process.pid || !isProcessAlive(enginePid)) {
|
|
172
221
|
return releaseResumeLock ? { ok: true, releaseResumeLock } : { ok: true };
|
|
173
222
|
}
|
|
174
223
|
|
|
175
|
-
const fromPhase = String(state.phase ?? "");
|
|
176
224
|
if (force) {
|
|
177
225
|
const terminateResult = terminateStaleDetachedEngine({
|
|
178
226
|
projectRoot,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Attached batch foreground runner — public facade (SP-343 / #34, SP-348 / #39).
|
|
4
4
|
* Promote/exit: attached-runner-promote.mjs (SP-586).
|
|
5
5
|
* Pause/resume reconcile: attached-runner-reconcile.mjs (SP-604).
|
|
6
|
+
* Single resume owner / concurrent force fail-fast: enforceAttachedEngineSingleOwner (SP-660 / #207).
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
9
|
export {
|
|
@@ -269,60 +269,67 @@ export async function resumeBatchDetached({
|
|
|
269
269
|
// wave merge (#196); spawn the attached engine argv in detached mode (no --attached).
|
|
270
270
|
const argv = buildAttachedBatchResumeArgv({ force });
|
|
271
271
|
const { enginePid, logPath } = spawnDetachedBatchEngine({ projectRoot, spineBin, argv });
|
|
272
|
-
|
|
272
|
+
// Record the child owner before unlocking so a second resume --force cannot race in (SP-660 / #207).
|
|
273
|
+
persistDetachedEnginePid(projectRoot, enginePid);
|
|
273
274
|
const waitTimeoutMs = resolveDetachedWaitTimeoutMs(waitTerminal);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
275
|
+
try {
|
|
276
|
+
const wait = await waitForDetachedBatchResume({
|
|
277
|
+
projectRoot,
|
|
278
|
+
batchId,
|
|
279
|
+
updatedAtBefore: updatedAt,
|
|
280
|
+
taskId,
|
|
281
|
+
waitTerminal,
|
|
282
|
+
timeoutMs: waitTimeoutMs,
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
if (!wait.ok) {
|
|
286
|
+
/** @type {Record<string, unknown>} */
|
|
287
|
+
const payload = {
|
|
288
|
+
ok: false,
|
|
289
|
+
detached: true,
|
|
290
|
+
operation: "resume",
|
|
291
|
+
batchId,
|
|
292
|
+
taskId,
|
|
293
|
+
enginePid,
|
|
294
|
+
logPath,
|
|
295
|
+
error: wait.error,
|
|
296
|
+
lastError: wait.lastError ?? null,
|
|
297
|
+
output:
|
|
298
|
+
wait.error === "timeout_waiting_for_resume"
|
|
299
|
+
? "Engine may still be running or orphaned — run `spine status --diagnose`."
|
|
300
|
+
: `Batch resume failed (phase=${wait.phase ?? "unknown"}).`,
|
|
301
|
+
suggestedCommand: "spine status --diagnose",
|
|
302
|
+
};
|
|
303
|
+
attachDetachedFailureDiagnostics(payload, { projectRoot, batchId, taskId, logPath });
|
|
304
|
+
return {
|
|
305
|
+
ok: false,
|
|
306
|
+
exitCode: 1,
|
|
307
|
+
output: formatDetachedEngineOutput(payload, json),
|
|
308
|
+
result: payload,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
282
311
|
|
|
283
|
-
if (!wait.ok) {
|
|
284
|
-
/** @type {Record<string, unknown>} */
|
|
285
312
|
const payload = {
|
|
286
|
-
ok:
|
|
313
|
+
ok: true,
|
|
287
314
|
detached: true,
|
|
288
315
|
operation: "resume",
|
|
289
|
-
|
|
316
|
+
status: wait.status ?? "engine_started",
|
|
317
|
+
batchId: wait.batchId,
|
|
290
318
|
taskId,
|
|
319
|
+
phase: wait.phase,
|
|
291
320
|
enginePid,
|
|
292
321
|
logPath,
|
|
293
|
-
error: wait.error,
|
|
294
|
-
lastError: wait.lastError ?? null,
|
|
295
|
-
output:
|
|
296
|
-
wait.error === "timeout_waiting_for_resume"
|
|
297
|
-
? "Engine may still be running or orphaned — run `spine status --diagnose`."
|
|
298
|
-
: `Batch resume failed (phase=${wait.phase ?? "unknown"}).`,
|
|
299
322
|
suggestedCommand: "spine status --diagnose",
|
|
300
323
|
};
|
|
301
|
-
attachDetachedFailureDiagnostics(payload, { projectRoot, batchId, taskId, logPath });
|
|
302
324
|
return {
|
|
303
|
-
ok:
|
|
304
|
-
exitCode:
|
|
325
|
+
ok: true,
|
|
326
|
+
exitCode: 0,
|
|
305
327
|
output: formatDetachedEngineOutput(payload, json),
|
|
306
328
|
result: payload,
|
|
307
329
|
};
|
|
330
|
+
} finally {
|
|
331
|
+
// Hold the handoff lock across spawn+wait so paired attached/detached shells cannot
|
|
332
|
+
// start a second --force while this owner is taking ownership (SP-660 / #207).
|
|
333
|
+
releaseResumeLock?.();
|
|
308
334
|
}
|
|
309
|
-
|
|
310
|
-
const payload = {
|
|
311
|
-
ok: true,
|
|
312
|
-
detached: true,
|
|
313
|
-
operation: "resume",
|
|
314
|
-
status: wait.status ?? "engine_started",
|
|
315
|
-
batchId: wait.batchId,
|
|
316
|
-
taskId,
|
|
317
|
-
phase: wait.phase,
|
|
318
|
-
enginePid,
|
|
319
|
-
logPath,
|
|
320
|
-
suggestedCommand: "spine status --diagnose",
|
|
321
|
-
};
|
|
322
|
-
return {
|
|
323
|
-
ok: true,
|
|
324
|
-
exitCode: 0,
|
|
325
|
-
output: formatDetachedEngineOutput(payload, json),
|
|
326
|
-
result: payload,
|
|
327
|
-
};
|
|
328
335
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Detached batch engine spawn — default for `spine batch start` and `spine batch resume`.
|
|
4
4
|
* Thin re-export shim (SP-598): spawn → detached-spawn, diagnostics → detached-diagnostics,
|
|
5
5
|
* wait/run → detached-wait + detached-run.
|
|
6
|
+
* Resume path holds handoff lock across spawn+wait and persists child enginePid (SP-660 / #207).
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
9
|
export {
|
|
@@ -7,9 +7,31 @@ import {
|
|
|
7
7
|
isGitignoredArtifactPath,
|
|
8
8
|
listGitignoredArtifactRoots,
|
|
9
9
|
} from "./lane-dirty-check.mjs";
|
|
10
|
+
import { isGateReadyHeadlineContext } from "./diagnosis-gate-ready.mjs";
|
|
10
11
|
|
|
11
12
|
const GITIGNORED_MERGE_FAILURE_CLASSES = new Set(["merge_failed_gitignored", "GitignoredDirtyWorktree"]);
|
|
12
13
|
|
|
14
|
+
/** Diagnoses that outrank historical GitignoredDirtyWorktree / merge-gitignored remediation (#205). */
|
|
15
|
+
const PRIMARY_OVER_GITIGNORED_DIAGNOSES = new Set(["worker_orphaned", "engine_orphaned"]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Prefer gate-ready / orphan (latest primary failure) over stale gitignored merge headlines (#195 / #205).
|
|
19
|
+
* Keep mergeGitignoredFailure in diagnose signals; only demote the headline/command preference.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} diagnosis
|
|
22
|
+
* @param {object} [ctx]
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
export function shouldPreferPrimaryOverGitignoredHeadline(diagnosis, ctx = {}) {
|
|
26
|
+
if (isGateReadyHeadlineContext(diagnosis, ctx)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (PRIMARY_OVER_GITIGNORED_DIAGNOSES.has(diagnosis)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
13
35
|
/**
|
|
14
36
|
* @param {object} [ctx]
|
|
15
37
|
* @param {string|null} [ctx.exitReason]
|
package/src/batch/diagnosis.mjs
CHANGED
|
@@ -16,11 +16,13 @@ export { buildAlternatives } from "./diagnosis-alternatives.mjs";
|
|
|
16
16
|
import {
|
|
17
17
|
buildMergeFailureHeadline,
|
|
18
18
|
buildGitignoredMergeRepairCommand,
|
|
19
|
+
shouldPreferPrimaryOverGitignoredHeadline,
|
|
19
20
|
} from "./diagnosis-merge-failure.mjs";
|
|
20
21
|
export {
|
|
21
22
|
buildMergeFailureHeadline,
|
|
22
23
|
buildGitignoredMergeRepairCommand,
|
|
23
24
|
inferMergeGitignoredFailure,
|
|
25
|
+
shouldPreferPrimaryOverGitignoredHeadline,
|
|
24
26
|
summarizeMergeFailures,
|
|
25
27
|
} from "./diagnosis-merge-failure.mjs";
|
|
26
28
|
import { buildRunningTailHeadline, isPostIntegrateEngineLimbo, buildPostIntegrateEngineLimboHeadline } from "./diagnosis-tail-state.mjs";
|
|
@@ -126,14 +128,14 @@ const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
|
|
|
126
128
|
* @param {object[]} [ctx.pendingLaneLandTasks]
|
|
127
129
|
*/
|
|
128
130
|
export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
129
|
-
const
|
|
130
|
-
// Prefer gate-approve /
|
|
131
|
-
if (ctx.mergeGitignoredFailure && !
|
|
131
|
+
const preferPrimaryOverGitignored = shouldPreferPrimaryOverGitignoredHeadline(diagnosis, ctx);
|
|
132
|
+
// Prefer gate-approve / orphan primary over recovered merge/gitignored repair (#195 / #205).
|
|
133
|
+
if (ctx.mergeGitignoredFailure && !preferPrimaryOverGitignored) {
|
|
132
134
|
return buildGitignoredMergeRepairCommand(ctx.taskBranch, ctx.gitignoredPaths);
|
|
133
135
|
}
|
|
134
136
|
if (
|
|
135
137
|
ctx.mergeFailed &&
|
|
136
|
-
!
|
|
138
|
+
!preferPrimaryOverGitignored &&
|
|
137
139
|
(diagnosis === "failed" || diagnosis === "needs_retry")
|
|
138
140
|
) {
|
|
139
141
|
return "spine batch resume --force";
|
|
@@ -291,16 +293,16 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
291
293
|
*/
|
|
292
294
|
export function buildHeadline(diagnosis, ctx = {}) {
|
|
293
295
|
const batchLabel = ctx.batchId ? `Batch ${ctx.batchId}` : "Batch";
|
|
294
|
-
const
|
|
296
|
+
const preferPrimaryOverGitignored = shouldPreferPrimaryOverGitignoredHeadline(diagnosis, ctx);
|
|
295
297
|
|
|
296
|
-
// Historical merge/gitignored signals stay in diagnose signals — not the primary headline (#195).
|
|
297
|
-
if (ctx.mergeGitignoredFailure && !
|
|
298
|
+
// Historical merge/gitignored signals stay in diagnose signals — not the primary headline (#195 / #205).
|
|
299
|
+
if (ctx.mergeGitignoredFailure && !preferPrimaryOverGitignored) {
|
|
298
300
|
return `${batchLabel} merge blocked by gitignored paths on a lane branch — drop cached ignored files, then resume`;
|
|
299
301
|
}
|
|
300
302
|
|
|
301
303
|
if (
|
|
302
304
|
ctx.mergeFailed &&
|
|
303
|
-
!
|
|
305
|
+
!preferPrimaryOverGitignored &&
|
|
304
306
|
(diagnosis === "failed" || diagnosis === "needs_retry")
|
|
305
307
|
) {
|
|
306
308
|
return buildMergeFailureHeadline(batchLabel, ctx);
|
|
@@ -7,7 +7,12 @@ import fs from "node:fs";
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { execFileSync } from "node:child_process";
|
|
9
9
|
import { filterGitignoredPaths, gitAddFilteredPaths } from "./git-helpers.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
classifyGitignoredPaths,
|
|
12
|
+
formatGitignoredRemediationMessage,
|
|
13
|
+
isGitignoredArtifactPath,
|
|
14
|
+
sanitizeGitignoredArtifactsBeforeLaneCommit,
|
|
15
|
+
} from "./lane-dirty-check.mjs";
|
|
11
16
|
import { gitExec } from "./git-exec.mjs";
|
|
12
17
|
import { parseContract } from "../tasks/packet/parse-prompt.mjs";
|
|
13
18
|
import {
|
|
@@ -263,14 +268,43 @@ export function commitLaneWorktree({
|
|
|
263
268
|
worktreePath,
|
|
264
269
|
stageCandidatePaths,
|
|
265
270
|
);
|
|
266
|
-
|
|
271
|
+
let gitignoredPaths = [...new Set([...gitignoredDirtyPaths, ...ignoredUntrackedPaths])];
|
|
267
272
|
if (stageable.length === 0 && gitignoredPaths.length > 0) {
|
|
268
|
-
|
|
273
|
+
let { indexTracked, worktreeOnly } = classifyGitignoredPaths(worktreePath, gitignoredPaths);
|
|
274
|
+
// SP-659 / #206: marked artifacts may regenerate after the pre-commit sanitize.
|
|
275
|
+
// Re-clean once before fail-closed GitignoredDirtyWorktree.
|
|
276
|
+
const worktreeOnlyMarkedArtifacts =
|
|
277
|
+
indexTracked.length === 0 &&
|
|
278
|
+
worktreeOnly.length > 0 &&
|
|
279
|
+
worktreeOnly.every((filePath) => isGitignoredArtifactPath(filePath));
|
|
280
|
+
if (worktreeOnlyMarkedArtifacts) {
|
|
281
|
+
sanitizeGitignoredArtifactsBeforeLaneCommit(worktreePath, {
|
|
282
|
+
projectRoot: identityRoot,
|
|
283
|
+
});
|
|
284
|
+
gitignoredPaths = listIgnoredUntrackedPaths(worktreePath);
|
|
285
|
+
if (gitignoredPaths.length === 0) {
|
|
286
|
+
return {
|
|
287
|
+
ok: true,
|
|
288
|
+
committed: false,
|
|
289
|
+
skippedIgnorePaths,
|
|
290
|
+
skippedGitignoredPaths: [...gitignoredDirtyPaths, ...ignoredUntrackedPaths],
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
({ indexTracked, worktreeOnly } = classifyGitignoredPaths(worktreePath, gitignoredPaths));
|
|
294
|
+
}
|
|
295
|
+
if (indexTracked.length === 0 && worktreeOnly.length === 0) {
|
|
296
|
+
return {
|
|
297
|
+
ok: true,
|
|
298
|
+
committed: false,
|
|
299
|
+
skippedIgnorePaths,
|
|
300
|
+
skippedGitignoredPaths: gitignoredPaths,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
269
303
|
return {
|
|
270
304
|
ok: false,
|
|
271
305
|
error: formatGitignoredRemediationMessage(indexTracked, worktreeOnly),
|
|
272
306
|
failureClass: "GitignoredDirtyWorktree",
|
|
273
|
-
gitignoredPaths,
|
|
307
|
+
gitignoredPaths: [...indexTracked, ...worktreeOnly],
|
|
274
308
|
};
|
|
275
309
|
}
|
|
276
310
|
|
|
@@ -291,6 +325,10 @@ export function commitLaneWorktree({
|
|
|
291
325
|
const message = `feat(${taskId}): batch ${batchId} worker completion`;
|
|
292
326
|
git(worktreePath, ["commit", "-m", message], identityRoot);
|
|
293
327
|
const commitSha = git(worktreePath, ["rev-parse", "HEAD"], identityRoot);
|
|
328
|
+
// SP-659 / #206: post-commit hooks may regenerate marked gitignored artifacts.
|
|
329
|
+
sanitizeGitignoredArtifactsBeforeLaneCommit(worktreePath, {
|
|
330
|
+
projectRoot: identityRoot,
|
|
331
|
+
});
|
|
294
332
|
return {
|
|
295
333
|
ok: true,
|
|
296
334
|
committed: true,
|
|
@@ -35,6 +35,8 @@ export const GITIGNORED_ARTIFACT_MARKERS = [
|
|
|
35
35
|
"graphify-out/",
|
|
36
36
|
"/.review/",
|
|
37
37
|
".review/",
|
|
38
|
+
"/.pi-smart-router/",
|
|
39
|
+
".pi-smart-router/",
|
|
38
40
|
"/.spine/runtime/",
|
|
39
41
|
".spine/runtime/",
|
|
40
42
|
];
|
|
@@ -150,6 +152,9 @@ function gitignoredArtifactRootForPath(filePath) {
|
|
|
150
152
|
if (normalized === ".review" || normalized.startsWith(".review/")) {
|
|
151
153
|
return ".review";
|
|
152
154
|
}
|
|
155
|
+
if (normalized === ".pi-smart-router" || normalized.startsWith(".pi-smart-router/")) {
|
|
156
|
+
return ".pi-smart-router";
|
|
157
|
+
}
|
|
153
158
|
if (normalized === ".spine/runtime" || normalized.startsWith(".spine/runtime/")) {
|
|
154
159
|
return ".spine/runtime";
|
|
155
160
|
}
|
|
@@ -58,6 +58,8 @@ export const GITIGNORED_ARTIFACT_MARKERS = [
|
|
|
58
58
|
"graphify-out/",
|
|
59
59
|
"/.review/",
|
|
60
60
|
".review/",
|
|
61
|
+
"/.pi-smart-router/",
|
|
62
|
+
".pi-smart-router/",
|
|
61
63
|
"/.spine/runtime/",
|
|
62
64
|
".spine/runtime/",
|
|
63
65
|
];
|
|
@@ -273,6 +275,9 @@ function gitignoredArtifactRootForPath(filePath) {
|
|
|
273
275
|
if (normalized === ".review" || normalized.startsWith(".review/")) {
|
|
274
276
|
return ".review";
|
|
275
277
|
}
|
|
278
|
+
if (normalized === ".pi-smart-router" || normalized.startsWith(".pi-smart-router/")) {
|
|
279
|
+
return ".pi-smart-router";
|
|
280
|
+
}
|
|
276
281
|
if (normalized === ".spine/runtime" || normalized.startsWith(".spine/runtime/")) {
|
|
277
282
|
return ".spine/runtime";
|
|
278
283
|
}
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
/** Orphan reconcile helpers (SP-606 / #192). */
|
|
2
|
+
/** Orphan reconcile helpers (SP-606 / #192). Post-DONE heal: SP-657 / #205. */
|
|
3
3
|
|
|
4
|
+
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
5
|
+
import { resolveTasksRoot } from "../config/spine-preflight-lib.mjs";
|
|
6
|
+
import { isProcessAlive } from "../process/liveness.mjs";
|
|
7
|
+
import { classifyTaskDoneSemantics } from "./diagnosis-task-done.mjs";
|
|
4
8
|
import {
|
|
5
9
|
appendJournalEvent,
|
|
6
10
|
readJournalEvents,
|
|
7
11
|
} from "./journal.mjs";
|
|
12
|
+
import { laneDoneMarkerReadyForPromote } from "./journal-rebuild.mjs";
|
|
8
13
|
import {
|
|
9
14
|
detectOrphanRunning,
|
|
10
15
|
journalEventsSinceResume,
|
|
11
16
|
} from "./orphan-detect.mjs";
|
|
12
|
-
import {
|
|
17
|
+
import { reconcileBatch } from "./reconcile-batch.mjs";
|
|
18
|
+
import { journalHasTaskCompleted } from "./resume-common.mjs";
|
|
13
19
|
import {
|
|
14
20
|
clearBatchEnginePid,
|
|
15
21
|
readBatchEnginePid,
|
|
22
|
+
recordTaskSucceeded,
|
|
16
23
|
recomputeTaskCounters,
|
|
17
24
|
saveSpineBatchState,
|
|
18
25
|
updateSegmentForTask,
|
|
19
26
|
} from "./state.mjs";
|
|
20
|
-
import { reconcileBatch } from "./reconcile-batch.mjs";
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* @param {object} ctx
|
|
@@ -71,13 +77,76 @@ function journalHasTaskEvent(journalEvents, taskId, eventType) {
|
|
|
71
77
|
});
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
/**
|
|
81
|
+
* True when lane has committed `.DONE` ready for skip-done / skippedDoneOnDisk promote.
|
|
82
|
+
*
|
|
83
|
+
* @param {object} params
|
|
84
|
+
* @param {string} params.projectRoot
|
|
85
|
+
* @param {string} params.batchId
|
|
86
|
+
* @param {object} params.task
|
|
87
|
+
* @param {unknown[]} params.lanes
|
|
88
|
+
* @param {string|null} params.tasksRoot
|
|
89
|
+
*/
|
|
90
|
+
function orphanTaskReadyForSkipDoneHeal({ projectRoot, batchId, task, lanes, tasksRoot }) {
|
|
91
|
+
const classified = classifyTaskDoneSemantics(task, {
|
|
92
|
+
tasksRoot,
|
|
93
|
+
projectRoot,
|
|
94
|
+
batchId,
|
|
95
|
+
lanes,
|
|
96
|
+
});
|
|
97
|
+
return laneDoneMarkerReadyForPromote({
|
|
98
|
+
projectRoot,
|
|
99
|
+
batchId,
|
|
100
|
+
task,
|
|
101
|
+
lanes,
|
|
102
|
+
classified,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Promote a post-DONE orphaned running task via skippedDoneOnDisk semantics
|
|
108
|
+
* (mirrors attached-runner / resume-multi skip-done journal shape).
|
|
109
|
+
*
|
|
110
|
+
* @param {object} params
|
|
111
|
+
* @param {string} params.projectRoot
|
|
112
|
+
* @param {string} params.batchId
|
|
113
|
+
* @param {object} params.state
|
|
114
|
+
* @param {object} params.task
|
|
115
|
+
* @param {object[]} params.journalEvents
|
|
116
|
+
* @returns {boolean}
|
|
117
|
+
*/
|
|
118
|
+
function healPostDoneOrphanTask({ projectRoot, batchId, state, task, journalEvents }) {
|
|
119
|
+
const taskId = String(task?.taskId ?? "");
|
|
120
|
+
if (!taskId) return false;
|
|
121
|
+
if (String(task.status ?? "") !== "running") return false;
|
|
122
|
+
|
|
123
|
+
if (!recordTaskSucceeded(state, taskId, { doneFileFound: true, exitReason: "done" })) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!journalHasTaskCompleted(journalEvents, taskId)) {
|
|
128
|
+
const lane = findLaneForOrphanReconcile(state.lanes, task.laneNumber);
|
|
129
|
+
appendJournalEvent(projectRoot, batchId, "task.completed", {
|
|
130
|
+
taskId,
|
|
131
|
+
laneNumber: task.laneNumber ?? null,
|
|
132
|
+
laneId: lane?.laneId ?? null,
|
|
133
|
+
reconciled: true,
|
|
134
|
+
skippedDoneOnDisk: true,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
74
141
|
/**
|
|
75
142
|
* Transition orphan running tasks to failed so retry/resume paths succeed (SP-315 / #20).
|
|
143
|
+
* When lane `.DONE` is committed (fail-closed promote gate), heal to succeeded with
|
|
144
|
+
* `skippedDoneOnDisk` instead of failing into merge_blocked (SP-657 / #205).
|
|
76
145
|
*
|
|
77
146
|
* @param {object} params
|
|
78
147
|
* @param {string} params.projectRoot
|
|
79
148
|
* @param {object} params.state
|
|
80
|
-
* @returns {{ reconciled: boolean, taskId?: string|null, kind?: string, exitReason?: string }}
|
|
149
|
+
* @returns {{ reconciled: boolean, taskId?: string|null, kind?: string, exitReason?: string, healedTaskIds?: string[] }}
|
|
81
150
|
*/
|
|
82
151
|
export function reconcileOrphanRunningState({ projectRoot, state }) {
|
|
83
152
|
if (!state || typeof state !== "object") {
|
|
@@ -108,7 +177,7 @@ export function reconcileOrphanRunningState({ projectRoot, state }) {
|
|
|
108
177
|
|
|
109
178
|
const exitReason = orphanRunning.kind === "engine" ? "engine_orphaned" : "worker_orphaned";
|
|
110
179
|
/** @type {string[]} */
|
|
111
|
-
const
|
|
180
|
+
const taskIdsToConsider =
|
|
112
181
|
orphanRunning.kind === "lane" && orphanRunning.taskId
|
|
113
182
|
? [orphanRunning.taskId]
|
|
114
183
|
: classifiedTasks
|
|
@@ -116,22 +185,55 @@ export function reconcileOrphanRunningState({ projectRoot, state }) {
|
|
|
116
185
|
.map((task) => task.taskId)
|
|
117
186
|
.filter(Boolean);
|
|
118
187
|
|
|
119
|
-
if (
|
|
188
|
+
if (taskIdsToConsider.length === 0) {
|
|
120
189
|
return { reconciled: false };
|
|
121
190
|
}
|
|
122
191
|
|
|
192
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
193
|
+
const tasksRoot = resolveTasksRoot(projectRoot, configResult);
|
|
194
|
+
const lanes = state.lanes ?? [];
|
|
195
|
+
|
|
123
196
|
const now = Date.now();
|
|
124
197
|
let changed = false;
|
|
198
|
+
/** @type {string[]} */
|
|
199
|
+
const healedTaskIds = [];
|
|
200
|
+
/** @type {string[]} */
|
|
201
|
+
const taskIdsFailed = [];
|
|
125
202
|
|
|
126
|
-
for (const taskId of
|
|
203
|
+
for (const taskId of taskIdsToConsider) {
|
|
127
204
|
const task = (state.tasks ?? []).find((entry) => entry?.taskId === taskId);
|
|
128
205
|
if (!task || task.status !== "running") continue;
|
|
129
206
|
|
|
207
|
+
if (
|
|
208
|
+
orphanTaskReadyForSkipDoneHeal({
|
|
209
|
+
projectRoot,
|
|
210
|
+
batchId,
|
|
211
|
+
task,
|
|
212
|
+
lanes,
|
|
213
|
+
tasksRoot,
|
|
214
|
+
})
|
|
215
|
+
) {
|
|
216
|
+
if (
|
|
217
|
+
healPostDoneOrphanTask({
|
|
218
|
+
projectRoot,
|
|
219
|
+
batchId,
|
|
220
|
+
state,
|
|
221
|
+
task,
|
|
222
|
+
journalEvents,
|
|
223
|
+
})
|
|
224
|
+
) {
|
|
225
|
+
healedTaskIds.push(taskId);
|
|
226
|
+
changed = true;
|
|
227
|
+
}
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
|
|
130
231
|
task.status = "failed";
|
|
131
232
|
task.endedAt = now;
|
|
132
233
|
task.exitReason = exitReason;
|
|
133
234
|
updateSegmentForTask(state, taskId, "failed");
|
|
134
235
|
changed = true;
|
|
236
|
+
taskIdsFailed.push(taskId);
|
|
135
237
|
|
|
136
238
|
if (!journalHasTaskEvent(scopedJournalEvents, taskId, "task.failed")) {
|
|
137
239
|
const lane = findLaneForOrphanReconcile(state.lanes, task.laneNumber);
|
|
@@ -179,20 +281,21 @@ export function reconcileOrphanRunningState({ projectRoot, state }) {
|
|
|
179
281
|
}
|
|
180
282
|
|
|
181
283
|
recomputeTaskCounters(state);
|
|
182
|
-
if (String(state.phase ?? "") === "running") {
|
|
284
|
+
if (taskIdsFailed.length > 0 && String(state.phase ?? "") === "running") {
|
|
183
285
|
state.phase = "failed";
|
|
184
286
|
state.endedAt = state.endedAt ?? now;
|
|
185
287
|
state.lastError =
|
|
186
|
-
state.lastError ??
|
|
288
|
+
state.lastError ??
|
|
289
|
+
`Orphan reconcile: ${exitReason} (task ${taskIdsFailed.join(", ")})`;
|
|
187
290
|
}
|
|
188
291
|
|
|
189
292
|
saveSpineBatchState(projectRoot, state);
|
|
190
293
|
|
|
191
294
|
return {
|
|
192
295
|
reconciled: true,
|
|
193
|
-
taskId: orphanRunning.taskId ??
|
|
296
|
+
taskId: orphanRunning.taskId ?? healedTaskIds[0] ?? taskIdsFailed[0] ?? null,
|
|
194
297
|
kind: orphanRunning.kind,
|
|
195
298
|
exitReason,
|
|
299
|
+
healedTaskIds,
|
|
196
300
|
};
|
|
197
301
|
}
|
|
198
|
-
|