pi-spine 2.12.2 → 2.13.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/skills/spine-release-operator/SKILL.md +1 -0
- package/src/batch/engine-lanes/matrix-run.mjs +23 -30
- package/src/batch/engine-lanes/matrix.mjs +78 -0
- package/src/batch/engine-lanes/review.mjs +507 -1
- package/src/batch/engine-lanes.mjs +77 -21
- package/src/batch/resume-lane-reviews.mjs +6 -1
- package/src/doctor/quota-risk.mjs +229 -0
- package/src/doctor/run-doctor-checks.mjs +18 -0
- package/src/metrics/quota-probes.mjs +171 -9
- package/src/metrics/quota-snapshot.mjs +1 -1
package/package.json
CHANGED
|
@@ -55,6 +55,7 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
|
|
|
55
55
|
- **Do not** execute tasks outside the approved manifest scope
|
|
56
56
|
- **Never** start Phase 4 (execute) without **recorded scope approval** — the release manifest must show `Operator approved scope: yes` from the Phase 2 gate. Refuse the first wave when approval is missing or `no` (F1, [#249](https://github.com/beettlle/pi-spine/issues/249))
|
|
57
57
|
- **Never** mid-release-edit `.spine/spine-config.json` agent pins (`agents.worker.model` / `agents.reviewer.model`) while a batch is running or integrated work is still unpublished. Pin **one worker** per release; escalate models **only** on content/contract failure — never on quota/403 or launch storms, which make releases worse (F7, [#248](https://github.com/beettlle/pi-spine/issues/248)). To override mid-release, first record the reason and date in the release manifest
|
|
58
|
+
- **Heed** the doctor/preflight **quota-risk advisory** ([#251](https://github.com/beettlle/pi-spine/issues/251)): `spine doctor` surfaces `ok: true, warning: true` when escalate/hard worker pins target quota-constrained pools without headroom evidence, or recent run-metrics show launch-storm / quota-abort patterns. It is advisory only — never fails preflight — and does not change the mid-release pin-thrash ban above
|
|
58
59
|
- **Always** push/sync `main` to `origin` after each land loop once the post-integrate regression gate is green — do not let `main` drift far ahead of `origin` during a release (F8, [#249](https://github.com/beettlle/pi-spine/issues/249))
|
|
59
60
|
- **Do not** start a second batch while another batch is **running** on this repo
|
|
60
61
|
- **Never** background `spine batch resume --attached` or `resume --attached --force` ([#163](https://github.com/beettlle/pi-spine/issues/163))
|
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
import fs from "node:fs";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import {
|
|
11
|
+
acquireLaneSlot,
|
|
11
12
|
aggregateMatrixOutcomes,
|
|
12
13
|
provisionMatrixSubLaneWorktree,
|
|
13
14
|
recordMatrixEvent,
|
|
15
|
+
releaseLaneSlot,
|
|
14
16
|
removeMatrixSubLaneWorktree,
|
|
15
17
|
runConcurrent,
|
|
16
18
|
runMatrixSubLaneSetupHook,
|
|
@@ -33,32 +35,6 @@ import { parseContract } from "../../tasks/packet/parse-prompt.mjs";
|
|
|
33
35
|
import { verifyContract } from "../contract-verify.mjs";
|
|
34
36
|
import { gitExec } from "../git-exec.mjs";
|
|
35
37
|
|
|
36
|
-
/**
|
|
37
|
-
* SP-690 / #227 — interim throttle for nested matrix row concurrency.
|
|
38
|
-
*
|
|
39
|
-
* A matrix task runs ON a lane the batch has already counted against
|
|
40
|
-
* `lanes.maxParallel`. While that parent lane is held, the rows it fans out
|
|
41
|
-
* must not reuse the parent's slot — otherwise global in-flight workers
|
|
42
|
-
* (sibling lane workers + matrix rows) can exceed `lanes.maxParallel`.
|
|
43
|
-
*
|
|
44
|
-
* Caps the rows to the remaining free slots: `max(1, globalMaxParallel -
|
|
45
|
-
* occupiedLaneSlots)`, never below 1 so a matrix task always makes forward
|
|
46
|
-
* progress. `occupiedLaneSlots` defaults to 1 (the parent matrix lane).
|
|
47
|
-
*
|
|
48
|
-
* This is an interim invariant. First-class row scheduling (#228) supersedes
|
|
49
|
-
* it by scheduling rows as real lane occupants instead of nested workers,
|
|
50
|
-
* which also closes the concurrent-sibling edge case for `maxParallel > 2`.
|
|
51
|
-
*
|
|
52
|
-
* @param {number} globalMaxParallel Configured `lanes.maxParallel`.
|
|
53
|
-
* @param {number} [occupiedLaneSlots] Lane slots already in use (≥ 1: the parent).
|
|
54
|
-
* @returns {number} Row concurrency limit, at least 1.
|
|
55
|
-
*/
|
|
56
|
-
export function matrixRowConcurrencyLimit(globalMaxParallel, occupiedLaneSlots = 1) {
|
|
57
|
-
const max = Math.max(1, Math.floor(Number(globalMaxParallel) || 1));
|
|
58
|
-
const occupied = Math.max(0, Math.floor(Number(occupiedLaneSlots) || 0));
|
|
59
|
-
return Math.max(1, max - occupied);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
38
|
/**
|
|
63
39
|
* Read the `## Contract` table from a parent task folder (un-substituted).
|
|
64
40
|
*
|
|
@@ -331,15 +307,25 @@ export async function runMatrixSubLane({
|
|
|
331
307
|
}
|
|
332
308
|
|
|
333
309
|
/**
|
|
334
|
-
* Run every matrix row of a task as a
|
|
310
|
+
* Run every matrix row of a task as a first-class lane-pool competitor
|
|
311
|
+
* (SP-697 / #228, supersedes the SP-690 nested throttle).
|
|
312
|
+
*
|
|
313
|
+
* The parent task does NOT hold a lane slot while its rows run: each active
|
|
314
|
+
* row acquires a slot from the global pool sized `lanes.maxParallel` (shared
|
|
315
|
+
* with sibling lane tasks via `acquireLaneSlot`), so rows compete with sibling
|
|
316
|
+
* lanes for the same pool and global in-flight workers never exceed
|
|
317
|
+
* `lanes.maxParallel`. The acquired slot number is the row's lane identity —
|
|
318
|
+
* its worktree/branch use it, so concurrent rows land on distinct
|
|
319
|
+
* `lane-{n}-…` worktrees.
|
|
335
320
|
*
|
|
336
321
|
* Each row runs in its own worktree off the lane task branch. The parent task
|
|
337
322
|
* succeeds only when every row succeeds; any failure fails the task and
|
|
338
323
|
* surfaces the failing row id(s). Successful row branches are merged back into
|
|
339
324
|
* the lane worktree so the normal lane-commit + wave-merge carry all rows'
|
|
340
|
-
* output.
|
|
325
|
+
* output.
|
|
341
326
|
*
|
|
342
327
|
* @param {object} params
|
|
328
|
+
* @param {number} params.maxParallel Global `lanes.maxParallel` (pool size).
|
|
343
329
|
*/
|
|
344
330
|
export async function runMatrixTaskOnLane({
|
|
345
331
|
projectRoot,
|
|
@@ -393,11 +379,16 @@ export async function runMatrixTaskOnLane({
|
|
|
393
379
|
});
|
|
394
380
|
|
|
395
381
|
const { results } = await runConcurrent(matrix.rows, maxParallel, async (row) => {
|
|
382
|
+
// Compete for the global lane pool: block until a slot frees (a sibling
|
|
383
|
+
// lane task or another row releasing), then run on that slot as the
|
|
384
|
+
// row's distinct lane identity. Always release so a crashed row cannot
|
|
385
|
+
// leak a slot and stall the batch.
|
|
386
|
+
const rowLaneNumber = await acquireLaneSlot(state, maxParallel);
|
|
396
387
|
try {
|
|
397
388
|
return await runMatrixSubLane({
|
|
398
389
|
projectRoot,
|
|
399
390
|
batchId,
|
|
400
|
-
laneNumber,
|
|
391
|
+
laneNumber: rowLaneNumber,
|
|
401
392
|
taskId,
|
|
402
393
|
laneBranch,
|
|
403
394
|
laneCorrelationId,
|
|
@@ -414,7 +405,7 @@ export async function runMatrixTaskOnLane({
|
|
|
414
405
|
const message = err instanceof Error ? err.message : String(err);
|
|
415
406
|
recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.failed", {
|
|
416
407
|
taskId,
|
|
417
|
-
laneNumber,
|
|
408
|
+
laneNumber: rowLaneNumber,
|
|
418
409
|
rowId: row.rowId,
|
|
419
410
|
correlationId: laneCorrelationId,
|
|
420
411
|
error: `sub-lane crashed: ${message}`,
|
|
@@ -425,6 +416,8 @@ export async function runMatrixTaskOnLane({
|
|
|
425
416
|
exitCode: 1,
|
|
426
417
|
output: `sub-lane crashed: ${message}`,
|
|
427
418
|
};
|
|
419
|
+
} finally {
|
|
420
|
+
releaseLaneSlot(state, rowLaneNumber);
|
|
428
421
|
}
|
|
429
422
|
});
|
|
430
423
|
|
|
@@ -285,6 +285,84 @@ export function runShellInDir(cwd, command) {
|
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Global lane-slot pool (SP-697 / #228).
|
|
290
|
+
*
|
|
291
|
+
* First-class matrix row scheduling replaces the SP-690 nested throttle: every
|
|
292
|
+
* active worker in a batch — a plain lane task or a matrix row — occupies
|
|
293
|
+
* exactly one slot of a pool sized `lanes.maxParallel`. Non-matrix tasks hold
|
|
294
|
+
* their slot for the whole task; a matrix parent task holds NO slot while its
|
|
295
|
+
* rows run, so the rows compete for the same global pool as sibling lanes and
|
|
296
|
+
* global in-flight workers can never exceed `lanes.maxParallel`.
|
|
297
|
+
*
|
|
298
|
+
* The slot number doubles as the row's scheduling identity: rows provision
|
|
299
|
+
* their worktree/branch with it, so concurrent rows always land on distinct
|
|
300
|
+
* `lane-{n}-…` worktrees with real lane diversity.
|
|
301
|
+
*
|
|
302
|
+
* Pools are keyed by the live batch state object (never serialized — the map
|
|
303
|
+
* is module-level and state-keyed), so a resume with a fresh state object
|
|
304
|
+
* starts with a fresh pool.
|
|
305
|
+
*
|
|
306
|
+
* @type {WeakMap<object, { max: number, inUse: Set<number>, waiters: Array<(slot: number) => void> }>}
|
|
307
|
+
*/
|
|
308
|
+
const laneSlotPools = new WeakMap();
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @param {object} state Live batch state (pool key).
|
|
312
|
+
* @param {number} maxParallel Configured `lanes.maxParallel`.
|
|
313
|
+
* @returns {{ max: number, inUse: Set<number>, waiters: Array<(slot: number) => void> }}
|
|
314
|
+
*/
|
|
315
|
+
function getLaneSlotPool(state, maxParallel) {
|
|
316
|
+
let pool = laneSlotPools.get(state);
|
|
317
|
+
if (!pool) {
|
|
318
|
+
pool = {
|
|
319
|
+
max: Math.max(1, Math.floor(Number(maxParallel) || 1)),
|
|
320
|
+
inUse: new Set(),
|
|
321
|
+
waiters: [],
|
|
322
|
+
};
|
|
323
|
+
laneSlotPools.set(state, pool);
|
|
324
|
+
}
|
|
325
|
+
return pool;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Acquire a lane slot from the global pool, waiting until one frees up.
|
|
330
|
+
* Returns the lowest free slot number in `1..maxParallel`.
|
|
331
|
+
*
|
|
332
|
+
* @param {object} state Live batch state (pool key).
|
|
333
|
+
* @param {number} maxParallel Configured `lanes.maxParallel`.
|
|
334
|
+
* @returns {Promise<number>} Acquired slot number; pass to `releaseLaneSlot`.
|
|
335
|
+
*/
|
|
336
|
+
export function acquireLaneSlot(state, maxParallel) {
|
|
337
|
+
const pool = getLaneSlotPool(state, maxParallel);
|
|
338
|
+
for (let slot = 1; slot <= pool.max; slot++) {
|
|
339
|
+
if (!pool.inUse.has(slot)) {
|
|
340
|
+
pool.inUse.add(slot);
|
|
341
|
+
return Promise.resolve(slot);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return new Promise((resolve) => {
|
|
345
|
+
pool.waiters.push(resolve);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Release a lane slot back to the pool, waking the oldest waiter (FIFO) if any.
|
|
351
|
+
*
|
|
352
|
+
* @param {object} state Live batch state (pool key).
|
|
353
|
+
* @param {number} slot Slot number previously returned by `acquireLaneSlot`.
|
|
354
|
+
*/
|
|
355
|
+
export function releaseLaneSlot(state, slot) {
|
|
356
|
+
const pool = laneSlotPools.get(state);
|
|
357
|
+
if (!pool || !pool.inUse.has(slot)) return;
|
|
358
|
+
pool.inUse.delete(slot);
|
|
359
|
+
const next = pool.waiters.shift();
|
|
360
|
+
if (next) {
|
|
361
|
+
pool.inUse.add(slot);
|
|
362
|
+
next(slot);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
288
366
|
/**
|
|
289
367
|
* Generic concurrency-limited map. Runs `workerFn` over `items` with at most
|
|
290
368
|
* `limit` in flight. Returns per-index results and the peak concurrency observed.
|