pi-spine 2.19.0 → 2.21.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/README.md +7 -5
- package/bin/spine-batch.mjs +15 -5
- package/bin/spine-gate.mjs +18 -3
- package/bin/spine-status.mjs +45 -0
- package/package.json +8 -8
- package/skills/spine-autonomous-operator/references/agent-shell-batch-policy.md +2 -0
- package/skills/spine-orchestrate-waves/SKILL.md +2 -0
- package/skills/spine-release-operator/SKILL.md +26 -10
- package/skills/spine-release-operator/references/issue-intake-checklist.md +46 -0
- package/skills/spine-release-operator/references/release-manifest-template.md +12 -0
- package/skills/spine-release-operator/references/release-profiles.md +6 -2
- package/skills/spine-release-operator/scripts/collect-release-intake.sh +44 -0
- package/src/batch/contract-exec.mjs +19 -18
- package/src/batch/engine-lanes/commit.mjs +6 -0
- package/src/batch/engine-lanes/matrix-run.mjs +238 -22
- package/src/batch/engine-lanes/matrix.mjs +33 -2
- package/src/batch/gate-posture-approve.mjs +16 -2
- package/src/batch/lane-commit.mjs +27 -12
- package/src/batch/readers/spine-state.mjs +4 -0
- package/src/batch/resume-multi-lanes.mjs +31 -0
- package/src/batch/resume.mjs +79 -59
- package/src/batch/retry-row.mjs +328 -0
- package/src/batch/retry.mjs +114 -44
- package/src/batch/state-guards.mjs +4 -5
- package/src/batch/state-io.mjs +2 -2
- package/src/batch/worker-host.mjs +3 -0
- package/src/batch/worker-spawn.mjs +14 -0
- package/src/cli/wait.mjs +163 -1
- package/src/metrics/quota-probes.mjs +44 -0
- package/src/tasks/packet/parse-prompt.mjs +17 -0
- package/src/tasks/packet/validate-contract.mjs +1 -0
|
@@ -11,6 +11,8 @@ import { createHash } from "node:crypto";
|
|
|
11
11
|
import {
|
|
12
12
|
acquireLaneSlot,
|
|
13
13
|
aggregateMatrixOutcomes,
|
|
14
|
+
buildMatrixRowEnv,
|
|
15
|
+
loadMatrixTaskRows,
|
|
14
16
|
provisionMatrixSubLaneWorktree,
|
|
15
17
|
recordMatrixEvent,
|
|
16
18
|
releaseLaneSlot,
|
|
@@ -98,13 +100,38 @@ function restoreMatrixRowPrompt({ worktreePath, taskFolderRel, projectRoot }) {
|
|
|
98
100
|
fs.rmSync(path.join(worktreePath, taskFolderRel, ".DONE"), { force: true });
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Effective per-matrix row concurrency (#229): the Contract's optional
|
|
105
|
+
* `matrixMaxParallel` throttle (Slurm `%N` analog) capped by the global
|
|
106
|
+
* `lanes.maxParallel` — a matrix can narrow its share of the pool but never
|
|
107
|
+
* widen it. Missing/invalid throttles fall back to the global cap.
|
|
108
|
+
*
|
|
109
|
+
* @param {object} params
|
|
110
|
+
* @param {number | null} [params.matrixMaxParallel] Contract `matrixMaxParallel` (positive int).
|
|
111
|
+
* @param {number} [params.maxParallel] Global `lanes.maxParallel`.
|
|
112
|
+
* @returns {number}
|
|
113
|
+
*/
|
|
114
|
+
export function resolveMatrixRowConcurrency({ matrixMaxParallel, maxParallel = 1 }) {
|
|
115
|
+
const globalCap = Math.max(1, Math.floor(Number(maxParallel) || 1));
|
|
116
|
+
if (matrixMaxParallel == null) return globalCap;
|
|
117
|
+
const throttle = Number(matrixMaxParallel);
|
|
118
|
+
if (!Number.isFinite(throttle) || throttle < 1) return globalCap;
|
|
119
|
+
return Math.max(1, Math.min(Math.floor(throttle), globalCap));
|
|
120
|
+
}
|
|
121
|
+
|
|
101
122
|
/**
|
|
102
123
|
* Execute a single matrix row in its own worktree. Substitutes `{matrix.X}`
|
|
103
124
|
* placeholders for execution-only rows; LLM rows delegate to `runWorker` with a
|
|
104
125
|
* row-substituted PROMPT.md served into the row worktree (#232). Commits
|
|
105
126
|
* successful row output to the row branch.
|
|
106
127
|
*
|
|
128
|
+
* Rows also receive matrix index environment variables (#229) when `rowIndex`
|
|
129
|
+
* and `rowCount` are supplied: execute rows via the shell env, LLM rows via the
|
|
130
|
+
* worker child env (`buildMatrixRowEnv`).
|
|
131
|
+
*
|
|
107
132
|
* @param {object} params
|
|
133
|
+
* @param {number} [params.rowIndex] 0-based index of this row in the matrix.
|
|
134
|
+
* @param {number} [params.rowCount] Total matrix row count.
|
|
108
135
|
* @returns {Promise<{ rowId: string, ok: boolean, exitCode: number, output: string, worktreePath?: string, branch?: string, commitSha?: string, servedPrompt?: string }>}
|
|
109
136
|
*/
|
|
110
137
|
export async function runMatrixSubLane({
|
|
@@ -120,9 +147,12 @@ export async function runMatrixSubLane({
|
|
|
120
147
|
taskFolderRel,
|
|
121
148
|
config,
|
|
122
149
|
baseBranch,
|
|
150
|
+
rowIndex,
|
|
151
|
+
rowCount,
|
|
123
152
|
}) {
|
|
124
153
|
const rowId = row.rowId;
|
|
125
154
|
const values = row.values;
|
|
155
|
+
const matrixEnv = buildMatrixRowEnv({ taskId, rowId, rowIndex, rowCount });
|
|
126
156
|
let worktreePath;
|
|
127
157
|
let branch;
|
|
128
158
|
|
|
@@ -210,7 +240,7 @@ export async function runMatrixSubLane({
|
|
|
210
240
|
};
|
|
211
241
|
} else {
|
|
212
242
|
const command = substituteRowCommand(rawCommand, values);
|
|
213
|
-
const run = await runShellInDir(worktreePath, command);
|
|
243
|
+
const run = await runShellInDir(worktreePath, command, matrixEnv);
|
|
214
244
|
if (run.exitCode !== 0) {
|
|
215
245
|
result = {
|
|
216
246
|
rowId,
|
|
@@ -314,6 +344,7 @@ export async function runMatrixSubLane({
|
|
|
314
344
|
laneCorrelationId: `${laneCorrelationId}-matrix-${rowId}`,
|
|
315
345
|
fileScopePaths: [],
|
|
316
346
|
config,
|
|
347
|
+
...(matrixEnv ? { extraEnv: matrixEnv } : {}),
|
|
317
348
|
});
|
|
318
349
|
result = {
|
|
319
350
|
rowId,
|
|
@@ -402,6 +433,88 @@ export async function runMatrixSubLane({
|
|
|
402
433
|
return result;
|
|
403
434
|
}
|
|
404
435
|
|
|
436
|
+
/**
|
|
437
|
+
* Resume-path entry for matrix tasks (SP-752 / #230).
|
|
438
|
+
*
|
|
439
|
+
* The single-task (`resume.mjs`) and multi-task (`resume-multi-lanes.mjs`)
|
|
440
|
+
* resume loops run workers directly and have no matrix fan-out — without this
|
|
441
|
+
* dispatch a retried matrix task falls through to a plain worker run on the
|
|
442
|
+
* unsubstituted parent PROMPT. Detect a matrix packet and delegate to
|
|
443
|
+
* `runMatrixTaskOnLane`, which owns per-row execution, carry-over, lane commit,
|
|
444
|
+
* and success/failure recording for the resumed task.
|
|
445
|
+
*
|
|
446
|
+
* On failure the matrix runner has already failed the task, persisted state,
|
|
447
|
+
* and journaled `task.failed`; this finishes the failed-batch bookkeeping
|
|
448
|
+
* (batch phase/counters — the plain worker failure branch does the same) and
|
|
449
|
+
* returns a ready-to-return `cliResult` envelope for the resume caller.
|
|
450
|
+
*
|
|
451
|
+
* @param {object} params
|
|
452
|
+
* @param {string} params.projectRoot
|
|
453
|
+
* @param {object} params.state Live batch state.
|
|
454
|
+
* @param {string} params.batchId
|
|
455
|
+
* @param {string} params.baseBranch
|
|
456
|
+
* @param {object} params.config
|
|
457
|
+
* @param {object} params.task
|
|
458
|
+
* @param {object} params.lane
|
|
459
|
+
* @param {string} params.taskFolderRel
|
|
460
|
+
* @param {string} params.laneCorrelationId
|
|
461
|
+
* @param {string[]} params.fileScopePaths
|
|
462
|
+
* @returns {Promise<{ isMatrix: false } | { isMatrix: true, ok: boolean, cliResult?: object }>}
|
|
463
|
+
*/
|
|
464
|
+
export async function runMatrixTaskForResume({
|
|
465
|
+
projectRoot,
|
|
466
|
+
state,
|
|
467
|
+
batchId,
|
|
468
|
+
baseBranch,
|
|
469
|
+
config,
|
|
470
|
+
task,
|
|
471
|
+
lane,
|
|
472
|
+
taskFolderRel,
|
|
473
|
+
laneCorrelationId,
|
|
474
|
+
fileScopePaths,
|
|
475
|
+
}) {
|
|
476
|
+
const matrix = loadMatrixTaskRows(path.join(projectRoot, taskFolderRel));
|
|
477
|
+
if (!matrix) return { isMatrix: false };
|
|
478
|
+
const result = await runMatrixTaskOnLane({
|
|
479
|
+
projectRoot,
|
|
480
|
+
state,
|
|
481
|
+
batchId,
|
|
482
|
+
baseBranch,
|
|
483
|
+
config,
|
|
484
|
+
task,
|
|
485
|
+
lane,
|
|
486
|
+
taskFolderRel,
|
|
487
|
+
laneCorrelationId,
|
|
488
|
+
fileScopePaths,
|
|
489
|
+
matrix,
|
|
490
|
+
maxParallel: config?.lanes?.maxParallel ?? 1,
|
|
491
|
+
});
|
|
492
|
+
if (!result.ok) {
|
|
493
|
+
const output = result.workerResult?.output ?? result.output ?? "matrix task failed";
|
|
494
|
+
state.failedTasks = 1;
|
|
495
|
+
state.succeededTasks = 0;
|
|
496
|
+
state.phase = "failed";
|
|
497
|
+
state.endedAt = Date.now();
|
|
498
|
+
state.lastError = String(output).slice(0, 500);
|
|
499
|
+
saveEngineBatchState(projectRoot, state);
|
|
500
|
+
return {
|
|
501
|
+
isMatrix: true,
|
|
502
|
+
ok: false,
|
|
503
|
+
cliResult: {
|
|
504
|
+
ok: false,
|
|
505
|
+
exitCode: result.workerResult?.exitCode ?? 1,
|
|
506
|
+
batchId,
|
|
507
|
+
taskId: task.taskId,
|
|
508
|
+
error: result.workerResult?.classification ?? "worker_failed",
|
|
509
|
+
output,
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
// Success: the matrix runner already lane-committed, recorded task success,
|
|
514
|
+
// and journaled — the caller skips its plain worker postlude.
|
|
515
|
+
return { isMatrix: true, ok: true };
|
|
516
|
+
}
|
|
517
|
+
|
|
405
518
|
/**
|
|
406
519
|
* Run every matrix row of a task as a first-class lane-pool competitor
|
|
407
520
|
* (SP-697 / #228, supersedes the SP-690 nested throttle).
|
|
@@ -415,10 +528,13 @@ export async function runMatrixSubLane({
|
|
|
415
528
|
* `lane-{n}-…` worktrees.
|
|
416
529
|
*
|
|
417
530
|
* Each row runs in its own worktree off the lane task branch. The parent task
|
|
418
|
-
* succeeds only when every row succeeds; any
|
|
419
|
-
* surfaces the failing row id(s).
|
|
420
|
-
*
|
|
421
|
-
*
|
|
531
|
+
* succeeds only when every non-canceled row succeeds; any failed row fails the
|
|
532
|
+
* task and surfaces the failing row id(s). `canceled` rows (row-scoped skip,
|
|
533
|
+
* #230) are operator exclusions and leave the required set. On a failed sweep
|
|
534
|
+
* only the failed rows' worktrees are removed — succeeded rows keep theirs so a
|
|
535
|
+
* row-scoped retry carries them over without re-execution. Successful row
|
|
536
|
+
* branches (fresh and carried-over) are merged back into the lane worktree so
|
|
537
|
+
* the normal lane-commit + wave-merge carry all rows' output.
|
|
422
538
|
*
|
|
423
539
|
* @param {object} params
|
|
424
540
|
* @param {number} params.maxParallel Global `lanes.maxParallel` (pool size).
|
|
@@ -444,16 +560,72 @@ export async function runMatrixTaskOnLane({
|
|
|
444
560
|
const taskFolderInWorktree = path.join(wt, taskFolderRel);
|
|
445
561
|
const parentTaskFolderAbs = path.join(projectRoot, taskFolderRel);
|
|
446
562
|
|
|
563
|
+
// Per-matrix throttle (#229): an optional Contract `matrixMaxParallel`
|
|
564
|
+
// narrows this matrix's share of the global pool. The pool itself stays
|
|
565
|
+
// sized `maxParallel` — global `lanes.maxParallel` semantics never change.
|
|
566
|
+
const parentContract = readParentContract(parentTaskFolderAbs);
|
|
567
|
+
const matrixMaxParallel = parentContract?.matrixMaxParallel ?? null;
|
|
568
|
+
const rowConcurrency = resolveMatrixRowConcurrency({ matrixMaxParallel, maxParallel });
|
|
569
|
+
|
|
447
570
|
task.status = "running";
|
|
448
571
|
task.isMatrix = true;
|
|
449
572
|
task.matrixType = matrix.type;
|
|
450
573
|
if (!task.startedAt) task.startedAt = Date.now();
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
574
|
+
// Seed per-row entries preserving prior-attempt state (#230): `succeeded`
|
|
575
|
+
// rows keep their status + persisted worktree/branch for retry carry-over,
|
|
576
|
+
// `canceled` rows stay excluded, and only failed/pending rows re-enter the
|
|
577
|
+
// sweep. Fresh rows start `pending`.
|
|
578
|
+
task.matrixRows = matrix.rows.map((row) => {
|
|
579
|
+
const existing = Array.isArray(task.matrixRows)
|
|
580
|
+
? task.matrixRows.find((entry) => entry && entry.rowId === row.rowId)
|
|
581
|
+
: null;
|
|
582
|
+
return existing ?? {
|
|
583
|
+
rowId: row.rowId,
|
|
584
|
+
status: "pending",
|
|
585
|
+
exitCode: null,
|
|
586
|
+
commitSha: null,
|
|
587
|
+
};
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
// Partition rows for this sweep (#230): carry-over succeeded rows (kept
|
|
591
|
+
// worktree/branch from a prior attempt — never re-executed), rows to run now
|
|
592
|
+
// (status pending), and rows skipped this sweep (canceled, or still failed
|
|
593
|
+
// because only a subset was retried).
|
|
594
|
+
const carryOverRows = [];
|
|
595
|
+
const runnableRows = [];
|
|
596
|
+
const skippedRowIds = [];
|
|
597
|
+
for (const row of matrix.rows) {
|
|
598
|
+
const entry = task.matrixRows.find((m) => m.rowId === row.rowId);
|
|
599
|
+
if (entry.status === "succeeded") {
|
|
600
|
+
const carryWorktree = typeof entry.worktreePath === "string" ? entry.worktreePath : null;
|
|
601
|
+
const carryBranch = typeof entry.branch === "string" ? entry.branch : null;
|
|
602
|
+
if (carryWorktree && carryBranch && fs.existsSync(carryWorktree)) {
|
|
603
|
+
carryOverRows.push({ row, worktreePath: carryWorktree, branch: carryBranch, commitSha: entry.commitSha });
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
// Carry-over material lost (crash recovery / manual cleanup): fall back
|
|
607
|
+
// to re-execution — never worse than the pre-SP-752 whole-sweep rerun.
|
|
608
|
+
// A stale branch would break `worktree add -b`, so drop it first.
|
|
609
|
+
if (carryBranch) {
|
|
610
|
+
gitExec(projectRoot, ["branch", "-D", carryBranch], { throwOnError: false });
|
|
611
|
+
}
|
|
612
|
+
recordMatrixEvent(projectRoot, batchId, "matrix.row_reexecuted", {
|
|
613
|
+
taskId,
|
|
614
|
+
laneNumber,
|
|
615
|
+
rowId: row.rowId,
|
|
616
|
+
correlationId: laneCorrelationId,
|
|
617
|
+
reason: "carry_over_worktree_missing",
|
|
618
|
+
});
|
|
619
|
+
entry.status = "pending";
|
|
620
|
+
runnableRows.push(row);
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
if (entry.status === "pending") {
|
|
624
|
+
runnableRows.push(row);
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
skippedRowIds.push(row.rowId);
|
|
628
|
+
}
|
|
457
629
|
updateSegmentForTask(state, taskId, "running");
|
|
458
630
|
saveEngineBatchState(projectRoot, state);
|
|
459
631
|
|
|
@@ -472,14 +644,26 @@ export async function runMatrixTaskOnLane({
|
|
|
472
644
|
rowIds: matrix.rows.map((row) => row.rowId),
|
|
473
645
|
matrixType: matrix.type,
|
|
474
646
|
maxParallel,
|
|
647
|
+
matrixMaxParallel,
|
|
648
|
+
rowConcurrency,
|
|
649
|
+
runnableRowIds: runnableRows.map((row) => row.rowId),
|
|
650
|
+
carriedOverRowIds: carryOverRows.map((carry) => carry.row.rowId),
|
|
651
|
+
skippedRowIds,
|
|
475
652
|
});
|
|
476
653
|
|
|
477
|
-
const { results } = await runConcurrent(
|
|
654
|
+
const { results } = await runConcurrent(runnableRows, rowConcurrency, async (row, rowIndex) => {
|
|
478
655
|
// Compete for the global lane pool: block until a slot frees (a sibling
|
|
479
656
|
// lane task or another row releasing), then run on that slot as the
|
|
480
657
|
// row's distinct lane identity. Always release so a crashed row cannot
|
|
481
658
|
// leak a slot and stall the batch.
|
|
482
659
|
const rowLaneNumber = await acquireLaneSlot(state, maxParallel);
|
|
660
|
+
// Per-row live status (#230): flip to `running` only once the row actually
|
|
661
|
+
// holds a slot, and persist so `spine status` sees it from another process.
|
|
662
|
+
const runningEntry = task.matrixRows.find((m) => m.rowId === row.rowId);
|
|
663
|
+
if (runningEntry) {
|
|
664
|
+
runningEntry.status = "running";
|
|
665
|
+
saveEngineBatchState(projectRoot, state);
|
|
666
|
+
}
|
|
483
667
|
try {
|
|
484
668
|
return await runMatrixSubLane({
|
|
485
669
|
projectRoot,
|
|
@@ -494,6 +678,8 @@ export async function runMatrixTaskOnLane({
|
|
|
494
678
|
taskFolderRel,
|
|
495
679
|
config,
|
|
496
680
|
baseBranch,
|
|
681
|
+
rowIndex,
|
|
682
|
+
rowCount: matrix.rows.length,
|
|
497
683
|
});
|
|
498
684
|
} catch (err) {
|
|
499
685
|
// Defensive: a crashed sub-lane must never lose its row identity, or the
|
|
@@ -523,21 +709,36 @@ export async function runMatrixTaskOnLane({
|
|
|
523
709
|
entry.status = rowResult.ok ? "succeeded" : "failed";
|
|
524
710
|
entry.exitCode = rowResult.exitCode ?? null;
|
|
525
711
|
entry.commitSha = rowResult.commitSha ?? null;
|
|
712
|
+
if (rowResult.ok && rowResult.worktreePath && rowResult.branch) {
|
|
713
|
+
// Persist carry-over material (#230): a later row-scoped retry reuses
|
|
714
|
+
// this worktree/branch instead of re-executing the succeeded row.
|
|
715
|
+
entry.worktreePath = rowResult.worktreePath;
|
|
716
|
+
entry.branch = rowResult.branch;
|
|
717
|
+
}
|
|
526
718
|
}
|
|
527
719
|
}
|
|
528
720
|
|
|
721
|
+
// Aggregate from the full per-row state (#230): `canceled` rows are operator
|
|
722
|
+
// exclusions and leave the required set; everything else must be `succeeded`.
|
|
723
|
+
// The default all-rows-must-succeed policy itself is unchanged (#231 out of
|
|
724
|
+
// scope).
|
|
529
725
|
const { ok, failedRowIds } = aggregateMatrixOutcomes(
|
|
530
|
-
|
|
726
|
+
task.matrixRows
|
|
727
|
+
.filter((entry) => entry.status !== "canceled")
|
|
728
|
+
.map((entry) => ({ rowId: entry.rowId, ok: entry.status === "succeeded" })),
|
|
531
729
|
);
|
|
532
730
|
|
|
533
731
|
if (!ok) {
|
|
534
732
|
for (const rowResult of results) {
|
|
535
|
-
if (rowResult.worktreePath)
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
733
|
+
if (!rowResult.worktreePath) continue;
|
|
734
|
+
if (rowResult.ok) continue;
|
|
735
|
+
// Failed rows' worktrees are cleaned up; succeeded rows keep theirs as
|
|
736
|
+
// carry-over material for a row-scoped retry (#230).
|
|
737
|
+
removeMatrixSubLaneWorktree(projectRoot, rowResult.worktreePath, rowResult.branch);
|
|
738
|
+
const failedEntry = task.matrixRows.find((m) => m.rowId === rowResult.rowId);
|
|
739
|
+
if (failedEntry) {
|
|
740
|
+
delete failedEntry.worktreePath;
|
|
741
|
+
delete failedEntry.branch;
|
|
541
742
|
}
|
|
542
743
|
}
|
|
543
744
|
const failedSummary = failedRowIds.join(", ");
|
|
@@ -587,7 +788,22 @@ export async function runMatrixTaskOnLane({
|
|
|
587
788
|
|
|
588
789
|
// All rows succeeded: merge each row branch into the lane worktree so the
|
|
589
790
|
// lane carries every row's output, then run the standard lane commit.
|
|
590
|
-
|
|
791
|
+
// Carry-over rows (#230) merge their kept prior-attempt branches alongside
|
|
792
|
+
// the freshly executed rows — their outputs land exactly once.
|
|
793
|
+
const allRowResults = [
|
|
794
|
+
...carryOverRows.map((carry) => ({
|
|
795
|
+
rowId: carry.row.rowId,
|
|
796
|
+
ok: true,
|
|
797
|
+
exitCode: 0,
|
|
798
|
+
output: "",
|
|
799
|
+
worktreePath: carry.worktreePath,
|
|
800
|
+
branch: carry.branch,
|
|
801
|
+
commitSha: carry.commitSha ?? null,
|
|
802
|
+
carriedOver: true,
|
|
803
|
+
})),
|
|
804
|
+
...results,
|
|
805
|
+
];
|
|
806
|
+
for (const rowResult of allRowResults) {
|
|
591
807
|
if (!rowResult.branch) continue;
|
|
592
808
|
try {
|
|
593
809
|
gitExec(
|
|
@@ -598,7 +814,7 @@ export async function runMatrixTaskOnLane({
|
|
|
598
814
|
} catch (err) {
|
|
599
815
|
const message = err instanceof Error ? err.message : String(err);
|
|
600
816
|
gitExec(wt, ["merge", "--abort"], { throwOnError: false, projectRoot });
|
|
601
|
-
for (const other of
|
|
817
|
+
for (const other of allRowResults) {
|
|
602
818
|
if (other.worktreePath) {
|
|
603
819
|
removeMatrixSubLaneWorktree(projectRoot, other.worktreePath, other.branch);
|
|
604
820
|
}
|
|
@@ -632,7 +848,7 @@ export async function runMatrixTaskOnLane({
|
|
|
632
848
|
laneNumber,
|
|
633
849
|
laneId: lane.laneId,
|
|
634
850
|
correlationId: laneCorrelationId,
|
|
635
|
-
rowIds:
|
|
851
|
+
rowIds: allRowResults.map((rowResult) => rowResult.rowId),
|
|
636
852
|
});
|
|
637
853
|
|
|
638
854
|
const ignorePatterns = resolveWorktreeSetupIgnorePaths(config);
|
|
@@ -255,19 +255,50 @@ export function removeMatrixSubLaneWorktree(projectRoot, worktreePath, branch) {
|
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Matrix row index environment (#229). Gives row scripts Slurm/K8s-style
|
|
260
|
+
* identity without string substitution: `SPINE_MATRIX_JOB_ID` is the parent
|
|
261
|
+
* task id, `SPINE_MATRIX_TASK_ID` the row id, `SPINE_MATRIX_TASK_INDEX` the
|
|
262
|
+
* 0-based row position, `SPINE_MATRIX_TASK_COUNT` the row count, and
|
|
263
|
+
* `JOB_COMPLETION_INDEX` aliases the index for Kubernetes indexed-job scripts.
|
|
264
|
+
*
|
|
265
|
+
* Returns null when `rowIndex`/`rowCount` are absent so callers that do not
|
|
266
|
+
* know a row's position (legacy direct calls) inject nothing at all.
|
|
267
|
+
*
|
|
268
|
+
* @param {object} params
|
|
269
|
+
* @param {string} [params.taskId] Parent matrix task id.
|
|
270
|
+
* @param {string} [params.rowId] Row id (`run_id` or derived).
|
|
271
|
+
* @param {number} [params.rowIndex] 0-based position of the row in the matrix.
|
|
272
|
+
* @param {number} [params.rowCount] Total number of matrix rows.
|
|
273
|
+
* @returns {Record<string, string> | null}
|
|
274
|
+
*/
|
|
275
|
+
export function buildMatrixRowEnv({ taskId, rowId, rowIndex, rowCount }) {
|
|
276
|
+
if (!Number.isInteger(rowIndex) || rowIndex < 0) return null;
|
|
277
|
+
if (!Number.isInteger(rowCount) || rowCount < 0) return null;
|
|
278
|
+
return {
|
|
279
|
+
SPINE_MATRIX_JOB_ID: String(taskId ?? ""),
|
|
280
|
+
SPINE_MATRIX_TASK_ID: String(rowId ?? ""),
|
|
281
|
+
SPINE_MATRIX_TASK_INDEX: String(rowIndex),
|
|
282
|
+
SPINE_MATRIX_TASK_COUNT: String(rowCount),
|
|
283
|
+
JOB_COMPLETION_INDEX: String(rowIndex),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
258
287
|
/**
|
|
259
288
|
* Run a shell command in a directory, resolving with exit code and combined output.
|
|
260
289
|
* Uses async spawn so concurrent rows genuinely overlap (required for maxParallel).
|
|
261
290
|
*
|
|
262
291
|
* @param {string} cwd
|
|
263
292
|
* @param {string} command
|
|
293
|
+
* @param {Record<string, string> | null} [extraEnv] Extra environment variables
|
|
294
|
+
* layered over `process.env` (matrix row identity, #229). Null injects nothing.
|
|
264
295
|
* @returns {Promise<{ exitCode: number, output: string }>}
|
|
265
296
|
*/
|
|
266
|
-
export function runShellInDir(cwd, command) {
|
|
297
|
+
export function runShellInDir(cwd, command, extraEnv = null) {
|
|
267
298
|
return new Promise((resolve) => {
|
|
268
299
|
const child = spawn("/bin/sh", ["-c", command], {
|
|
269
300
|
cwd,
|
|
270
|
-
env: process.env,
|
|
301
|
+
env: extraEnv ? { ...process.env, ...extraEnv } : process.env,
|
|
271
302
|
stdio: ["ignore", "pipe", "pipe"],
|
|
272
303
|
});
|
|
273
304
|
let output = "";
|
|
@@ -123,9 +123,10 @@ function recordRejectStreakReset(projectRoot, gate) {
|
|
|
123
123
|
* @param {string} ctx.batchId
|
|
124
124
|
* @param {"human" | "auto"} [ctx.decidedBy]
|
|
125
125
|
* @param {GatePostureEvaluateResult | null} [ctx.postureEvaluation]
|
|
126
|
+
* @param {string} [ctx.synthesis] Optional operator readback note (SP-747 / #280); omitted stays absent.
|
|
126
127
|
*/
|
|
127
128
|
export function approveIntegrateGate(ctx) {
|
|
128
|
-
const { projectRoot, batchId, decidedBy = "human", postureEvaluation = null } = ctx;
|
|
129
|
+
const { projectRoot, batchId, decidedBy = "human", postureEvaluation = null, synthesis } = ctx;
|
|
129
130
|
const gate = loadGateRecord(projectRoot, batchId);
|
|
130
131
|
|
|
131
132
|
if (!gate) {
|
|
@@ -161,6 +162,11 @@ export function approveIntegrateGate(ctx) {
|
|
|
161
162
|
gate.status = "approved";
|
|
162
163
|
gate.decidedAt = new Date().toISOString();
|
|
163
164
|
gate.decidedBy = actor;
|
|
165
|
+
// SP-747 / #280: persist the operator's synthesis readback when provided.
|
|
166
|
+
// Absent / empty flag leaves the field omitted (non-breaking null default);
|
|
167
|
+
// auto-approve never passes synthesis, so automated records stay without one.
|
|
168
|
+
const synthesisNote = typeof synthesis === "string" && synthesis.trim() !== "" ? synthesis : null;
|
|
169
|
+
if (synthesisNote) gate.synthesis = synthesisNote;
|
|
164
170
|
saveGateRecord(projectRoot, gate);
|
|
165
171
|
recordApprovalStreak(projectRoot, gate);
|
|
166
172
|
|
|
@@ -177,6 +183,9 @@ export function approveIntegrateGate(ctx) {
|
|
|
177
183
|
journalPayload.postureReason = postureEvaluation.reason;
|
|
178
184
|
journalPayload.postureTier = postureEvaluation.tier;
|
|
179
185
|
}
|
|
186
|
+
if (synthesisNote) {
|
|
187
|
+
journalPayload.synthesis = synthesisNote;
|
|
188
|
+
}
|
|
180
189
|
|
|
181
190
|
appendJournalEvent(projectRoot, batchId, "gate.approved", journalPayload);
|
|
182
191
|
|
|
@@ -288,9 +297,10 @@ export function maybeAutoApproveIntegrateGate(ctx) {
|
|
|
288
297
|
* @param {string} ctx.projectRoot
|
|
289
298
|
* @param {string} ctx.batchId
|
|
290
299
|
* @param {string} [ctx.reason]
|
|
300
|
+
* @param {string} [ctx.synthesis] Optional operator readback note (SP-747 / #280).
|
|
291
301
|
*/
|
|
292
302
|
export function rejectIntegrateGate(ctx) {
|
|
293
|
-
const { projectRoot, batchId, reason } = ctx;
|
|
303
|
+
const { projectRoot, batchId, reason, synthesis } = ctx;
|
|
294
304
|
const gate = loadGateRecord(projectRoot, batchId);
|
|
295
305
|
|
|
296
306
|
if (!gate) {
|
|
@@ -322,6 +332,9 @@ export function rejectIntegrateGate(ctx) {
|
|
|
322
332
|
gate.decidedAt = new Date().toISOString();
|
|
323
333
|
gate.decidedBy = "human";
|
|
324
334
|
if (reason) gate.rejectionReason = reason;
|
|
335
|
+
// SP-747 / #280: same optional readback contract as approve — omit when absent.
|
|
336
|
+
const synthesisNote = typeof synthesis === "string" && synthesis.trim() !== "" ? synthesis : null;
|
|
337
|
+
if (synthesisNote) gate.synthesis = synthesisNote;
|
|
325
338
|
saveGateRecord(projectRoot, gate);
|
|
326
339
|
recordRejectStreakReset(projectRoot, gate);
|
|
327
340
|
|
|
@@ -331,6 +344,7 @@ export function rejectIntegrateGate(ctx) {
|
|
|
331
344
|
category: gate.category ?? null,
|
|
332
345
|
status: gate.status,
|
|
333
346
|
reason: reason ?? null,
|
|
347
|
+
...(synthesisNote ? { synthesis: synthesisNote } : {}),
|
|
334
348
|
decidedBy: "human",
|
|
335
349
|
});
|
|
336
350
|
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
sanitizeGitignoredArtifactsBeforeLaneCommit,
|
|
15
15
|
} from "./lane-dirty-check.mjs";
|
|
16
16
|
import { gitExec } from "./git-exec.mjs";
|
|
17
|
+
import { deriveMatrixRowId } from "../planner/matrix.mjs";
|
|
17
18
|
import { parseContract, parsePrompt } from "../tasks/packet/parse-prompt.mjs";
|
|
18
19
|
import { substituteMatrixVariables } from "../planner/matrix.mjs";
|
|
19
20
|
import {
|
|
@@ -229,6 +230,7 @@ function listPorcelainPaths(porcelain) {
|
|
|
229
230
|
* @param {string} [params.baseBranch] Base branch for stub contract diff (default main)
|
|
230
231
|
* @param {string[]} [params.ignorePatterns] Hook paths to skip (default includes `.venv`)
|
|
231
232
|
* @param {string[]} [params.fileScopePaths] Task fileScope — paths here are never skipped
|
|
233
|
+
* @param {string[]} [params.canceledMatrixRowIds] Row ids canceled by the operator (#230) — their expanded fileScope patterns are excluded
|
|
232
234
|
* @returns {{ ok: true, committed: boolean, commitSha?: string, skippedGitignoredPaths?: string[], skippedIgnorePaths?: string[] } | { ok: false, error: string, failureClass: string, gitignoredPaths?: string[] }}
|
|
233
235
|
*/
|
|
234
236
|
export function commitLaneWorktree({
|
|
@@ -241,6 +243,7 @@ export function commitLaneWorktree({
|
|
|
241
243
|
baseBranch = "main",
|
|
242
244
|
ignorePatterns,
|
|
243
245
|
fileScopePaths = [],
|
|
246
|
+
canceledMatrixRowIds = [],
|
|
244
247
|
}) {
|
|
245
248
|
const identityRoot = projectRoot ?? worktreePath;
|
|
246
249
|
const effectiveIgnorePatterns = Array.isArray(ignorePatterns)
|
|
@@ -286,18 +289,30 @@ export function commitLaneWorktree({
|
|
|
286
289
|
// Matrix tasks carry `{matrix.<column>}` placeholders in fileScopeMustChange.
|
|
287
290
|
// Expand them across every matrix row so the stub check matches the
|
|
288
291
|
// concrete per-row output paths the rows actually produced.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
292
|
+
const prompt = promptText ? parsePrompt(promptText) : null;
|
|
293
|
+
const matrixRows = Array.isArray(prompt?.matrix) ? prompt.matrix : [];
|
|
294
|
+
// Canceled rows (#230) are operator exclusions — they never execute and
|
|
295
|
+
// produce no output, so their expanded fileScopeMustChange patterns must
|
|
296
|
+
// not gate the lane commit.
|
|
297
|
+
const canceledRowIds = new Set(
|
|
298
|
+
Array.isArray(canceledMatrixRowIds) ? canceledMatrixRowIds : [],
|
|
299
|
+
);
|
|
300
|
+
const activeMatrixRows =
|
|
301
|
+
canceledRowIds.size === 0
|
|
302
|
+
? matrixRows
|
|
303
|
+
: matrixRows.filter(
|
|
304
|
+
(row) => !canceledRowIds.has(deriveMatrixRowId(row, prompt?.matrixColumns ?? [])),
|
|
305
|
+
);
|
|
306
|
+
const effectiveContract =
|
|
307
|
+
matrixRows.length > 0
|
|
308
|
+
? {
|
|
309
|
+
...parsedContract,
|
|
310
|
+
fileScopeMustChange: expandMatrixFileScopePatterns(
|
|
311
|
+
parsedContract.fileScopeMustChange,
|
|
312
|
+
activeMatrixRows,
|
|
313
|
+
),
|
|
314
|
+
}
|
|
315
|
+
: parsedContract;
|
|
301
316
|
const scopeCheck = verifyStubFileScopeMustChange(
|
|
302
317
|
worktreePath,
|
|
303
318
|
effectiveContract,
|
|
@@ -72,6 +72,9 @@ function normalizeTasks(tasks) {
|
|
|
72
72
|
/** @type {Record<string, unknown>} */
|
|
73
73
|
const task = entry && typeof entry === "object" ? /** @type {Record<string, unknown>} */ (entry) : {};
|
|
74
74
|
const status = String(task.status ?? "pending").toLowerCase();
|
|
75
|
+
// Matrix per-row state (#230): pass the row array through when present so
|
|
76
|
+
// `spine status --json` / diagnose surfaces per-row running/succeeded/failed.
|
|
77
|
+
const matrixRows = Array.isArray(task.matrixRows) ? task.matrixRows : null;
|
|
75
78
|
return {
|
|
76
79
|
taskId: String(task.taskId ?? task.id ?? ""),
|
|
77
80
|
status,
|
|
@@ -81,6 +84,7 @@ function normalizeTasks(tasks) {
|
|
|
81
84
|
startedAt: task.startedAt ?? null,
|
|
82
85
|
endedAt: task.endedAt ?? null,
|
|
83
86
|
classification: classifyStatus(status),
|
|
87
|
+
...(matrixRows ? { matrixRows } : {}),
|
|
84
88
|
};
|
|
85
89
|
});
|
|
86
90
|
}
|
|
@@ -18,6 +18,7 @@ import { saveSpineBatchState, updateSegmentForTask } from "./state.mjs";
|
|
|
18
18
|
import { laneTaskBranch } from "./worktree.mjs";
|
|
19
19
|
import { laneDoneMarkerCommittedOnBranch } from "./journal-rebuild.mjs";
|
|
20
20
|
import { runWorker } from "./worker-host.mjs";
|
|
21
|
+
import { runMatrixTaskForResume } from "./engine-lanes/matrix-run.mjs";
|
|
21
22
|
import { runLaneReviewPhasesBeforeCommit } from "./resume-lane-reviews.mjs";
|
|
22
23
|
|
|
23
24
|
export { executeResumeWave } from "./resume-multi-queue.mjs";
|
|
@@ -252,6 +253,36 @@ export async function runResumedTaskOnLane({
|
|
|
252
253
|
resumed: true,
|
|
253
254
|
});
|
|
254
255
|
|
|
256
|
+
// Matrix tasks resume through runMatrixTaskOnLane (row fan-out, carry-over,
|
|
257
|
+
// lane commit, success recording) instead of a plain worker run (#230).
|
|
258
|
+
const matrixResume = await runMatrixTaskForResume({
|
|
259
|
+
projectRoot,
|
|
260
|
+
state,
|
|
261
|
+
batchId,
|
|
262
|
+
baseBranch: state.baseBranch ?? "main",
|
|
263
|
+
config,
|
|
264
|
+
task,
|
|
265
|
+
lane,
|
|
266
|
+
taskFolderRel,
|
|
267
|
+
laneCorrelationId,
|
|
268
|
+
fileScopePaths,
|
|
269
|
+
});
|
|
270
|
+
if (matrixResume.isMatrix) {
|
|
271
|
+
if (!matrixResume.ok) {
|
|
272
|
+
const classification = matrixResume.cliResult?.error ?? "matrix_failed";
|
|
273
|
+
appendJournalEvent(projectRoot, batchId, "lane.died", {
|
|
274
|
+
laneNumber,
|
|
275
|
+
laneId: lane.laneId,
|
|
276
|
+
taskId,
|
|
277
|
+
correlationId: laneCorrelationId,
|
|
278
|
+
reason: classification,
|
|
279
|
+
});
|
|
280
|
+
return { ok: false, aborted: false, workerResult: matrixResume.cliResult, taskId, laneNumber };
|
|
281
|
+
}
|
|
282
|
+
// The matrix runner already lane-committed, recorded success, and journaled.
|
|
283
|
+
return { ok: true, taskId, laneNumber };
|
|
284
|
+
}
|
|
285
|
+
|
|
255
286
|
const workerResult = await runWorker({
|
|
256
287
|
worktreePath: wt,
|
|
257
288
|
taskFolder: taskFolderInWorktree,
|