pi-spine 2.12.0 → 2.12.2
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 +1 -1
- package/package.json +2 -2
- package/skills/spine-release-operator/SKILL.md +29 -1
- package/skills/spine-release-operator/references/release-manifest-template.md +5 -1
- package/src/batch/engine-lanes/matrix-run.mjs +62 -0
- package/src/batch/engine-lanes/matrix.mjs +87 -1
- package/src/batch/engine-lanes.mjs +13 -3
- package/src/metrics/quota-cli.mjs +21 -3
- package/src/planner/lanes.mjs +10 -141
package/bin/spine.mjs
CHANGED
|
@@ -216,7 +216,7 @@ async function cmdMetrics(args) {
|
|
|
216
216
|
|
|
217
217
|
if (sub === "quota") {
|
|
218
218
|
const { runQuotaReport } = await import("../src/metrics/quota-cli.mjs");
|
|
219
|
-
const result = runQuotaReport({ projectRoot: process.cwd(), args: args.slice(1) });
|
|
219
|
+
const result = await runQuotaReport({ projectRoot: process.cwd(), args: args.slice(1) });
|
|
220
220
|
process.stdout.write(result.output);
|
|
221
221
|
if (result.exitCode !== 0) process.exit(result.exitCode);
|
|
222
222
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-spine",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.2",
|
|
4
4
|
"description": "Orchestration spine for long-running pi development",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typecheck": "tsc --project tsconfig.json --noEmit && tsc --project tsconfig.batch.json --noEmit",
|
|
35
35
|
"verify:reconcile-fixtures": "node scripts/verify-reconcile-test-fixtures.mjs",
|
|
36
36
|
"pretest": "npm run verify:reconcile-fixtures",
|
|
37
|
-
"test": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/batch/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/init/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs",
|
|
37
|
+
"test": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/batch/*.test.mjs tests/metrics/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/init/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs",
|
|
38
38
|
"test:batch": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/batch/*.test.mjs",
|
|
39
39
|
"test:core": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs",
|
|
40
40
|
"test:coverage": "node scripts/run-coverage.mjs --report-only",
|
|
@@ -53,6 +53,9 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
|
|
|
53
53
|
- **Never** use `| tail` or `| head` alone to judge `release:check` pass/fail — verify exit code (`$?` or `${PIPESTATUS[0]}`)
|
|
54
54
|
- **Never** `git push origin main` during a release until post-integrate `release:check` exits 0 on current `HEAD`
|
|
55
55
|
- **Do not** execute tasks outside the approved manifest scope
|
|
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
|
+
- **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
|
+
- **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))
|
|
56
59
|
- **Do not** start a second batch while another batch is **running** on this repo
|
|
57
60
|
- **Never** background `spine batch resume --attached` or `resume --attached --force` ([#163](https://github.com/beettlle/pi-spine/issues/163))
|
|
58
61
|
- **Release and agent batches:** use **detached** `spine batch start|resume` (omit `--attached`); monitor with MonitorCreate, `spine wait`, or `spine status --diagnose` ([#163](https://github.com/beettlle/pi-spine/issues/163), [#185](https://github.com/beettlle/pi-spine/issues/185)) — see [agent-shell-batch-policy.md](../spine-autonomous-operator/references/agent-shell-batch-policy.md)
|
|
@@ -245,6 +248,12 @@ git commit -m "chore(spine): release v{TARGET} task packets"
|
|
|
245
248
|
|
|
246
249
|
## Phase 4 — Execute release scope
|
|
247
250
|
|
|
251
|
+
### Scope-approval gate (HARD STOP — blocking)
|
|
252
|
+
|
|
253
|
+
Before the first wave, confirm the release manifest records **`Operator approved scope: yes`** (Phase 2 gate). **HARD STOP:** do not start any wave when approval is missing or `no`. This closes F1 from the [v2.12.1 post-mortem](../../docs/release/post-mortem-v2.12.1.md) ([#249](https://github.com/beettlle/pi-spine/issues/249)).
|
|
254
|
+
|
|
255
|
+
**Model pin:** one worker pin for the release — do not mid-release-edit `.spine/spine-config.json` agent pins. Escalate models only on content/contract failure, never quota/403 or launch storms (F7, [#248](https://github.com/beettlle/pi-spine/issues/248)). A doctor/preflight quota-risk escalate signal is intentionally **out of scope** for this release — deferred to a later release ([#248](https://github.com/beettlle/pi-spine/issues/248) optional AC).
|
|
256
|
+
|
|
248
257
|
**Detached-first:** See [agent-shell-batch-policy.md](../spine-autonomous-operator/references/agent-shell-batch-policy.md). Omit `--attached` for release waves unless the operator shell is a persistent interactive terminal that blocks until batch completion.
|
|
249
258
|
|
|
250
259
|
**Scope:** manifest tasks only — build a comma-separated release scope ID list.
|
|
@@ -329,6 +338,16 @@ Full reference: [post-integrate-regression-gate.md](references/post-integrate-re
|
|
|
329
338
|
|
|
330
339
|
**Do not** judge pass/fail from `tail` output — `tail` exits 0 even when `release:check` failed.
|
|
331
340
|
|
|
341
|
+
### 4.3b Push/sync `main` to `origin` (F8)
|
|
342
|
+
|
|
343
|
+
When **remote publish** is the goal, push `main` after each land loop once §4.3a is green:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
git push origin main
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Do not let `main` drift far ahead of `origin` between waves — v2.12.1 ran **24 commits ahead** of `origin` at Phase 5 (F8, [#249](https://github.com/beettlle/pi-spine/issues/249)). Local-only releases may defer this push; record the deferral in the manifest publish checklist.
|
|
350
|
+
|
|
332
351
|
### 4.4 Recovery
|
|
333
352
|
|
|
334
353
|
Always: `spine status --diagnose`
|
|
@@ -439,7 +458,13 @@ gh run list --workflow release.yml --limit 3
|
|
|
439
458
|
|
|
440
459
|
**pi async:** `MonitorCreate` with `gh run watch --exit-status <run-id>`, `timeout: 1800000`, `onDone` to report conclusion and run smoke tests if green.
|
|
441
460
|
|
|
442
|
-
Post-publish smoke per `docs/release/npm-publish.md
|
|
461
|
+
Post-publish smoke per `docs/release/npm-publish.md` — **retry on registry lag (F9, [#247](https://github.com/beettlle/pi-spine/issues/247)):** the first `npm install -g` right after a successful `release.yml` run can fail with `ETARGET` / "No matching version found" while the registry propagates, even when `npm view` already lists the version. Prefer the bounded wrapper:
|
|
462
|
+
|
|
463
|
+
```bash
|
|
464
|
+
scripts/post-publish-smoke.sh <version>
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
Manual equivalent (bounded retries on `ETARGET`/404-class errors only — 5s/10s/20s backoff capped at 60s, max 6 attempts; non-lag install errors fail immediately and exhausted retries fail closed, never masked as lag):
|
|
443
468
|
|
|
444
469
|
```bash
|
|
445
470
|
npm install -g pi-spine@<version>
|
|
@@ -447,6 +472,8 @@ spine version
|
|
|
447
472
|
spine doctor
|
|
448
473
|
```
|
|
449
474
|
|
|
475
|
+
If retries exhaust, **STOP** — treat it as a real missing-version failure and investigate the publish; do not keep waiting silently.
|
|
476
|
+
|
|
450
477
|
Update `spine-tasks/CONTEXT.md` release note (version + date).
|
|
451
478
|
|
|
452
479
|
Close GitHub issues where tasks had `Closes: #NNN` and work shipped.
|
|
@@ -486,6 +513,7 @@ spine status --diagnose (do not collide with running batch) →
|
|
|
486
513
|
preflight → for each wave: MonitorCreate batch start (or foreground) → onDone diagnose →
|
|
487
514
|
gate approve → integrate → npm install → batch complete →
|
|
488
515
|
post-integrate release:check (exit 0 required; no tail-only verification) →
|
|
516
|
+
git push origin main when remote publish is the goal (F8) →
|
|
489
517
|
MonitorCreate release:check → HARD STOP if non-zero (fix on main, re-run) → only if exit 0: verify ci.yml green on HEAD (gh run list/watch) → HARD STOP if not green → only then: STOP for publish approval.
|
|
490
518
|
resume --attached --force stays foreground. Post final report with composition table.
|
|
491
519
|
```
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
**Bump type:** patch | minor | major
|
|
7
7
|
**Profile:** patch | minor | major
|
|
8
8
|
**Operator approved scope:** no | yes ({date})
|
|
9
|
+
**Worker model pin:** {provider/id, set once} — do not change mid-release ([#248](https://github.com/beettlle/pi-spine/issues/248))
|
|
10
|
+
**Agent pin override:** none | yes ({date}, {reason}) — record before any mid-release pin change
|
|
9
11
|
|
|
10
12
|
---
|
|
11
13
|
|
|
@@ -62,10 +64,12 @@ Do **not** use `| tail` alone for pass/fail — verify exit code.
|
|
|
62
64
|
|
|
63
65
|
**Operator gates** (human only — sequence does not auto-approve without explicit flags):
|
|
64
66
|
|
|
65
|
-
1. Approve this manifest (operator sign-off on scope)
|
|
67
|
+
1. **Approve this manifest** (operator sign-off on scope) — set `Operator approved scope: yes` above. **Phase 4 HARD STOP** without it (F1, [#249](https://github.com/beettlle/pi-spine/issues/249))
|
|
66
68
|
2. `spine gate approve` per integrate wave
|
|
67
69
|
3. Publish approval before `npm version <bump>`
|
|
68
70
|
|
|
71
|
+
**Model pin policy ([#248](https://github.com/beettlle/pi-spine/issues/248)):** one worker pin for the release. Do not mid-release-edit `.spine/spine-config.json` agent pins; escalate models only on content/contract failure, never quota/403 or launch storms. Any in-release override must be recorded in `Agent pin override` above **before** applying. See [post-mortem F7](../../../docs/release/post-mortem-v2.12.1.md).
|
|
72
|
+
|
|
69
73
|
**Proof gate:** optional pre-publish dry-run (e.g. patch scope with operator touching only gate approve + publish approval; no `npm publish` during proof).
|
|
70
74
|
|
|
71
75
|
Filled example: [`docs/release/manifest-v1.10.0-example.md`](../../../docs/release/manifest-v1.10.0-example.md)
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
recordMatrixEvent,
|
|
14
14
|
removeMatrixSubLaneWorktree,
|
|
15
15
|
runConcurrent,
|
|
16
|
+
runMatrixSubLaneSetupHook,
|
|
16
17
|
runShellInDir,
|
|
17
18
|
substituteRowCommand,
|
|
18
19
|
} from "./matrix.mjs";
|
|
@@ -32,6 +33,32 @@ import { parseContract } from "../../tasks/packet/parse-prompt.mjs";
|
|
|
32
33
|
import { verifyContract } from "../contract-verify.mjs";
|
|
33
34
|
import { gitExec } from "../git-exec.mjs";
|
|
34
35
|
|
|
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
|
+
|
|
35
62
|
/**
|
|
36
63
|
* Read the `## Contract` table from a parent task folder (un-substituted).
|
|
37
64
|
*
|
|
@@ -103,6 +130,41 @@ export async function runMatrixSubLane({
|
|
|
103
130
|
worktreePath,
|
|
104
131
|
});
|
|
105
132
|
|
|
133
|
+
// Mirror the parent-lane provision→hook sequence: the row worktree is freshly
|
|
134
|
+
// provisioned off the lane branch, so gitignored toolchains/assets (e.g.
|
|
135
|
+
// `.venv`) that the row's runCommand depends on are absent until the hook
|
|
136
|
+
// links them in. Fail closed on hook failure so the row reports the missing
|
|
137
|
+
// setup rather than masking it as a runCommand failure (#224).
|
|
138
|
+
try {
|
|
139
|
+
runMatrixSubLaneSetupHook({
|
|
140
|
+
projectRoot,
|
|
141
|
+
worktreePath,
|
|
142
|
+
batchId,
|
|
143
|
+
laneNumber,
|
|
144
|
+
taskId,
|
|
145
|
+
rowId,
|
|
146
|
+
correlationId: laneCorrelationId,
|
|
147
|
+
config,
|
|
148
|
+
});
|
|
149
|
+
} catch (err) {
|
|
150
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
151
|
+
recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.failed", {
|
|
152
|
+
taskId,
|
|
153
|
+
laneNumber,
|
|
154
|
+
rowId,
|
|
155
|
+
correlationId: laneCorrelationId,
|
|
156
|
+
error: `setup hook failed: ${message}`,
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
rowId,
|
|
160
|
+
ok: false,
|
|
161
|
+
exitCode: 1,
|
|
162
|
+
output: `worktree setup hook failed: ${message}`,
|
|
163
|
+
worktreePath,
|
|
164
|
+
branch,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
106
168
|
/** @type {{ rowId: string, ok: boolean, exitCode: number, output: string, worktreePath?: string, branch?: string }} */
|
|
107
169
|
let result;
|
|
108
170
|
|
|
@@ -23,7 +23,11 @@ import {
|
|
|
23
23
|
substituteMatrixVariables,
|
|
24
24
|
} from "../../planner/matrix.mjs";
|
|
25
25
|
import { gitExec } from "../git-exec.mjs";
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
normalizeLaneWorktreeGitPaths,
|
|
28
|
+
runWorktreeSetupHook,
|
|
29
|
+
} from "../worktree.mjs";
|
|
30
|
+
import { resolveWorktreeSetupHook } from "../../config/worktree-setup-hook.mjs";
|
|
27
31
|
import { appendJournalEvent } from "../journal.mjs";
|
|
28
32
|
|
|
29
33
|
/**
|
|
@@ -147,6 +151,88 @@ export function provisionMatrixSubLaneWorktree({
|
|
|
147
151
|
return { worktreePath, branch };
|
|
148
152
|
}
|
|
149
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Run the configured `worktreeSetupHook` for a matrix sub-lane worktree, mirroring
|
|
156
|
+
* the parent-lane provision→hook sequence (SP-688 / #224).
|
|
157
|
+
*
|
|
158
|
+
* Each matrix row runs in its own freshly-provisioned worktree, so gitignored
|
|
159
|
+
* toolchains (e.g. `.venv`) and symlinked assets that live on the main checkout
|
|
160
|
+
* would be absent there — the hook links them in before the row's runCommand /
|
|
161
|
+
* worker executes. Without this, rows that depend on those assets fail in ways
|
|
162
|
+
* that never reproduce on a parent lane, masking the missing setup.
|
|
163
|
+
*
|
|
164
|
+
* Journals `matrix.sub_lane.setup_hook.*` lifecycle events. When a hook is
|
|
165
|
+
* configured it runs with the same env (SPINE_PROJECT_ROOT / SPINE_WORKTREE /
|
|
166
|
+
* SPINE_BATCH_ID / SPINE_LANE_NUMBER) and JSON-stdout contract as parent lanes.
|
|
167
|
+
* On hook failure it rethrows so the caller surfaces the failure on the matrix
|
|
168
|
+
* row (fail closed — never silently continue into runCommand). When no hook is
|
|
169
|
+
* configured it is a no-op (skipped).
|
|
170
|
+
*
|
|
171
|
+
* @param {object} params
|
|
172
|
+
* @param {string} params.projectRoot
|
|
173
|
+
* @param {string} params.worktreePath
|
|
174
|
+
* @param {string} params.batchId
|
|
175
|
+
* @param {number} params.laneNumber
|
|
176
|
+
* @param {string} params.taskId
|
|
177
|
+
* @param {string} params.rowId
|
|
178
|
+
* @param {string} [params.correlationId]
|
|
179
|
+
* @param {object} [params.config]
|
|
180
|
+
* @returns {{ ok: boolean, skipped?: boolean, durationMs?: number }}
|
|
181
|
+
*/
|
|
182
|
+
export function runMatrixSubLaneSetupHook({
|
|
183
|
+
projectRoot,
|
|
184
|
+
worktreePath,
|
|
185
|
+
batchId,
|
|
186
|
+
laneNumber,
|
|
187
|
+
taskId,
|
|
188
|
+
rowId,
|
|
189
|
+
correlationId,
|
|
190
|
+
config = {},
|
|
191
|
+
}) {
|
|
192
|
+
const hookPath = resolveWorktreeSetupHook(projectRoot, config);
|
|
193
|
+
if (!hookPath) {
|
|
194
|
+
return { ok: true, skipped: true };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.setup_hook.started", {
|
|
198
|
+
taskId,
|
|
199
|
+
laneNumber,
|
|
200
|
+
rowId,
|
|
201
|
+
correlationId,
|
|
202
|
+
worktreePath,
|
|
203
|
+
hookPath,
|
|
204
|
+
});
|
|
205
|
+
try {
|
|
206
|
+
const hookResult = runWorktreeSetupHook({
|
|
207
|
+
projectRoot,
|
|
208
|
+
worktreePath,
|
|
209
|
+
batchId,
|
|
210
|
+
laneNumber,
|
|
211
|
+
config,
|
|
212
|
+
});
|
|
213
|
+
recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.setup_hook.completed", {
|
|
214
|
+
taskId,
|
|
215
|
+
laneNumber,
|
|
216
|
+
rowId,
|
|
217
|
+
correlationId,
|
|
218
|
+
worktreePath,
|
|
219
|
+
durationMs: hookResult.durationMs,
|
|
220
|
+
});
|
|
221
|
+
return { ok: true, durationMs: hookResult.durationMs };
|
|
222
|
+
} catch (err) {
|
|
223
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
224
|
+
recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.setup_hook.failed", {
|
|
225
|
+
taskId,
|
|
226
|
+
laneNumber,
|
|
227
|
+
rowId,
|
|
228
|
+
correlationId,
|
|
229
|
+
worktreePath,
|
|
230
|
+
error: message,
|
|
231
|
+
});
|
|
232
|
+
throw err;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
150
236
|
/**
|
|
151
237
|
* Remove a matrix sub-lane worktree and its branch. Idempotent.
|
|
152
238
|
*
|
|
@@ -25,7 +25,7 @@ import { runCodeReviewPhase, runFinalReviewPhase } from "./engine-lanes/review.m
|
|
|
25
25
|
import { ensureLaneSyncedForSharedScopeDeps } from "./engine-lanes/orch-sync.mjs";
|
|
26
26
|
import { resolveWorktreeSetupIgnorePaths } from "../config/spine-config-load.mjs";
|
|
27
27
|
import { loadMatrixTaskRows } from "./engine-lanes/matrix.mjs";
|
|
28
|
-
import { runMatrixTaskOnLane } from "./engine-lanes/matrix-run.mjs";
|
|
28
|
+
import { runMatrixTaskOnLane, matrixRowConcurrencyLimit } from "./engine-lanes/matrix-run.mjs";
|
|
29
29
|
|
|
30
30
|
export {
|
|
31
31
|
buildTasksAndLanesFromPlan,
|
|
@@ -67,10 +67,11 @@ export {
|
|
|
67
67
|
removeAllMatrixSubLaneWorktrees,
|
|
68
68
|
removeMatrixSubLaneWorktree,
|
|
69
69
|
runConcurrent,
|
|
70
|
+
runMatrixSubLaneSetupHook,
|
|
70
71
|
runShellInDir,
|
|
71
72
|
} from "./engine-lanes/matrix.mjs";
|
|
72
73
|
|
|
73
|
-
export { runMatrixTaskOnLane, runMatrixSubLane } from "./engine-lanes/matrix-run.mjs";
|
|
74
|
+
export { runMatrixTaskOnLane, runMatrixSubLane, matrixRowConcurrencyLimit } from "./engine-lanes/matrix-run.mjs";
|
|
74
75
|
|
|
75
76
|
/**
|
|
76
77
|
* @param {string} fromPhase
|
|
@@ -146,6 +147,15 @@ export async function runTaskOnLane({
|
|
|
146
147
|
// Non-matrix tasks fall through to the single-worker path below.
|
|
147
148
|
const matrixRows = loadMatrixTaskRows(path.join(projectRoot, taskFolderRel));
|
|
148
149
|
if (matrixRows) {
|
|
150
|
+
// SP-690 / #227: the parent matrix task already occupies this lane, so its
|
|
151
|
+
// nested rows must not reuse the parent's slot. Cap rows to the remaining
|
|
152
|
+
// free slots so global in-flight workers (siblings + rows) stay within
|
|
153
|
+
// `lanes.maxParallel`. Interim invariant — #228 first-class row scheduling
|
|
154
|
+
// supersedes it.
|
|
155
|
+
const matrixMaxParallel = matrixRowConcurrencyLimit(
|
|
156
|
+
config?.lanes?.maxParallel ?? 1,
|
|
157
|
+
1,
|
|
158
|
+
);
|
|
149
159
|
return runMatrixTaskOnLane({
|
|
150
160
|
projectRoot,
|
|
151
161
|
state,
|
|
@@ -158,7 +168,7 @@ export async function runTaskOnLane({
|
|
|
158
168
|
laneCorrelationId,
|
|
159
169
|
fileScopePaths,
|
|
160
170
|
matrix: matrixRows,
|
|
161
|
-
maxParallel:
|
|
171
|
+
maxParallel: matrixMaxParallel,
|
|
162
172
|
});
|
|
163
173
|
}
|
|
164
174
|
|
|
@@ -15,6 +15,7 @@ import fs from "node:fs";
|
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
|
|
17
17
|
import { buildQuotaSnapshot } from "./quota-snapshot.mjs";
|
|
18
|
+
import { runQuotaProbes } from "./quota-probes.mjs";
|
|
18
19
|
import { renderQuotaHtml, writeHtmlBesideJson } from "./quota-html.mjs";
|
|
19
20
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
20
21
|
|
|
@@ -71,14 +72,23 @@ function formatHumanSummary(snapshot, reportPath) {
|
|
|
71
72
|
/**
|
|
72
73
|
* Run the `spine metrics quota` command.
|
|
73
74
|
*
|
|
75
|
+
* Optional provider probes are run before the snapshot is built so live usage
|
|
76
|
+
* can enrich a pool when credentials and the probe succeed. Probes fail closed
|
|
77
|
+
* to `absent` on missing credentials, network errors, or non-ok responses, so
|
|
78
|
+
* the snapshot degrades to estimate/absent rather than inventing limits or
|
|
79
|
+
* keys. The `authPath`/`fetch` params exist primarily for tests, which point
|
|
80
|
+
* `authPath` at a fixture and inject a mocked `fetch` instead of the network.
|
|
81
|
+
*
|
|
74
82
|
* @param {object} params
|
|
75
83
|
* @param {string} params.projectRoot
|
|
76
84
|
* @param {object} [params.config]
|
|
77
85
|
* @param {string[]} [params.args]
|
|
78
86
|
* @param {number | string | Date} [params.now]
|
|
79
|
-
* @
|
|
87
|
+
* @param {string} [params.authPath] Forwarded to `runQuotaProbes`.
|
|
88
|
+
* @param {typeof globalThis.fetch} [params.fetch] Forwarded to `runQuotaProbes`.
|
|
89
|
+
* @returns {Promise<{ output: string, exitCode: number, reportPath: string | null }>}
|
|
80
90
|
*/
|
|
81
|
-
export function runQuotaReport({ projectRoot, config, args = [], now = Date.now(), metricsLines }) {
|
|
91
|
+
export async function runQuotaReport({ projectRoot, config, args = [], now = Date.now(), metricsLines, authPath, fetch } = {}) {
|
|
82
92
|
const json = args.includes("--json");
|
|
83
93
|
const open = args.includes("--open");
|
|
84
94
|
|
|
@@ -95,7 +105,15 @@ export function runQuotaReport({ projectRoot, config, args = [], now = Date.now(
|
|
|
95
105
|
resolvedConfig = configResult.config;
|
|
96
106
|
}
|
|
97
107
|
|
|
98
|
-
|
|
108
|
+
// Production path: invoke provider probes so live usage can enrich pools.
|
|
109
|
+
// Adapters fail closed to "absent", so a missing/invalid auth file or network
|
|
110
|
+
// error leaves the snapshot at estimate/absent without inventing limits.
|
|
111
|
+
const probeOptions = {};
|
|
112
|
+
if (authPath !== undefined) probeOptions.authPath = authPath;
|
|
113
|
+
if (fetch !== undefined) probeOptions.fetch = fetch;
|
|
114
|
+
const probeResults = await runQuotaProbes(probeOptions);
|
|
115
|
+
|
|
116
|
+
const snapshot = buildQuotaSnapshot({ projectRoot, config: resolvedConfig, metricsLines, probeResults, now });
|
|
99
117
|
|
|
100
118
|
if (json) {
|
|
101
119
|
return {
|
package/src/planner/lanes.mjs
CHANGED
|
@@ -1,145 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* FR-SCHED-03/04: greedy lane assignment subject to file-scope disjointness.
|
|
3
|
+
*
|
|
4
|
+
* NOTE (SP-689 / issue #226): This module previously held a divergent copy of
|
|
5
|
+
* `assignLanesToWaves` whose overlap detection was directory-prefix only
|
|
6
|
+
* (normalizeFileScopePath + pathsOverlap). The production planner calls
|
|
7
|
+
* `planWaves` from `waves.mjs`, whose `assignLanesToWaves` uses the glob-aware
|
|
8
|
+
* `fileScopesOverlap` from `file-scope.mjs` — a strict superset of the logic
|
|
9
|
+
* that lived here. This module was imported only by tests, so the duplicate has
|
|
10
|
+
* been collapsed into a thin re-export of the canonical implementation to keep a
|
|
11
|
+
* single source of truth. Packing semantics are unchanged.
|
|
3
12
|
*/
|
|
4
13
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function normalizeFileScopePath(p) {
|
|
8
|
-
let s = String(p ?? '').trim();
|
|
9
|
-
if (!s) return null;
|
|
10
|
-
|
|
11
|
-
s = s.replace(/\\/g, '/');
|
|
12
|
-
if (s.startsWith('./')) s = s.slice(2);
|
|
13
|
-
s = s.replace(/\/+$/g, '');
|
|
14
|
-
|
|
15
|
-
// Common "globs" used in scopes are treated as directory prefixes.
|
|
16
|
-
if (s.endsWith('/*')) s = s.slice(0, -2);
|
|
17
|
-
if (s.endsWith('/**')) s = s.slice(0, -3);
|
|
18
|
-
|
|
19
|
-
return s || null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function pathsOverlap(a, b) {
|
|
23
|
-
if (a === b) return true;
|
|
24
|
-
// Only treat directory-prefix matches; a file prefix without a slash should not match.
|
|
25
|
-
return a.startsWith(b + '/') || b.startsWith(a + '/');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function taskOverlapsLane(taskPaths, lanePaths) {
|
|
29
|
-
for (const a of taskPaths) {
|
|
30
|
-
for (const b of lanePaths) {
|
|
31
|
-
if (pathsOverlap(a, b)) return true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {{ waves: string[][], tasksById: Record<string, { fileScope?: string[] }>, maxParallel: number, queueExcess?: boolean }} args
|
|
39
|
-
* @returns {Array<{ index: number, taskIds: string[], virtualLaneCount: number, ticks: Array<{ index: number, lanes: string[][] }>, laneAssignments: Record<string, { virtualLane: number, tick: number, laneInTick: number }> }>
|
|
40
|
-
*/
|
|
41
|
-
export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess = true }) {
|
|
42
|
-
const planned = [];
|
|
43
|
-
|
|
44
|
-
for (let waveIndex = 0; waveIndex < waves.length; waveIndex++) {
|
|
45
|
-
const rawWaveTaskIds = waves[waveIndex];
|
|
46
|
-
const waveTaskIds = [];
|
|
47
|
-
|
|
48
|
-
// Expand matrix tasks
|
|
49
|
-
for (const taskId of rawWaveTaskIds) {
|
|
50
|
-
const task = tasksById[taskId];
|
|
51
|
-
if (!task) {
|
|
52
|
-
throw new Error(`Missing task packet for ${taskId} during lane assignment`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (task.matrix && Array.isArray(task.matrix) && task.matrix.length > 0) {
|
|
56
|
-
for (const row of task.matrix) {
|
|
57
|
-
const rowId = deriveMatrixRowId(row, task.matrixColumns || []);
|
|
58
|
-
const subTaskId = `${taskId}[${rowId}]`;
|
|
59
|
-
waveTaskIds.push(subTaskId);
|
|
60
|
-
if (!tasksById[subTaskId]) {
|
|
61
|
-
tasksById[subTaskId] = {
|
|
62
|
-
...task,
|
|
63
|
-
taskId: subTaskId,
|
|
64
|
-
matrixRow: row,
|
|
65
|
-
parentTaskId: taskId
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
waveTaskIds.push(taskId);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** @type {{ lanePaths: string[], taskIds: string[] }} */
|
|
75
|
-
const virtualLanes = [];
|
|
76
|
-
|
|
77
|
-
/** @type {Record<string, { virtualLane: number, tick: number, laneInTick: number }>} */
|
|
78
|
-
const laneAssignments = {};
|
|
79
|
-
|
|
80
|
-
const virtualLaneForTask = {};
|
|
81
|
-
|
|
82
|
-
// Greedy packing into virtual lanes.
|
|
83
|
-
for (const taskId of waveTaskIds) {
|
|
84
|
-
const task = tasksById[taskId];
|
|
85
|
-
|
|
86
|
-
const taskPaths = (task.fileScope ?? [])
|
|
87
|
-
.map(normalizeFileScopePath)
|
|
88
|
-
.filter(Boolean);
|
|
89
|
-
|
|
90
|
-
let placed = false;
|
|
91
|
-
for (let i = 0; i < virtualLanes.length; i++) {
|
|
92
|
-
const lane = virtualLanes[i];
|
|
93
|
-
|
|
94
|
-
// Matrix sub-tasks of the same parent task do not conflict with each other
|
|
95
|
-
const hasSameParent = lane.taskIds.some(id => {
|
|
96
|
-
const other = tasksById[id];
|
|
97
|
-
return other && other.parentTaskId && other.parentTaskId === task.parentTaskId;
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
if (!hasSameParent && taskOverlapsLane(taskPaths, lane.lanePaths)) {
|
|
101
|
-
virtualLaneForTask[taskId] = i;
|
|
102
|
-
// Append to lane paths so future tasks are checked against everything already assigned.
|
|
103
|
-
lane.lanePaths.push(...taskPaths);
|
|
104
|
-
lane.taskIds.push(taskId);
|
|
105
|
-
placed = true;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!placed) {
|
|
111
|
-
const i = virtualLanes.length;
|
|
112
|
-
virtualLanes.push({ lanePaths: [...taskPaths], taskIds: [taskId] });
|
|
113
|
-
virtualLaneForTask[taskId] = i;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const virtualLaneCount = virtualLanes.length;
|
|
118
|
-
const tickCount = queueExcess ? Math.ceil(virtualLaneCount / maxParallel) : 1;
|
|
119
|
-
|
|
120
|
-
const ticks = Array.from({ length: tickCount }, (_, t) => {
|
|
121
|
-
return {
|
|
122
|
-
index: t,
|
|
123
|
-
lanes: Array.from({ length: maxParallel }, () => []),
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
for (const taskId of waveTaskIds) {
|
|
128
|
-
const virtualLane = virtualLaneForTask[taskId];
|
|
129
|
-
const tick = queueExcess ? Math.floor(virtualLane / maxParallel) : 0;
|
|
130
|
-
const laneInTick = virtualLane % maxParallel;
|
|
131
|
-
laneAssignments[taskId] = { virtualLane, tick, laneInTick };
|
|
132
|
-
ticks[tick].lanes[laneInTick].push(taskId);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
planned.push({
|
|
136
|
-
index: waveIndex,
|
|
137
|
-
taskIds: waveTaskIds,
|
|
138
|
-
virtualLaneCount,
|
|
139
|
-
ticks,
|
|
140
|
-
laneAssignments,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return planned;
|
|
145
|
-
}
|
|
14
|
+
export { assignLanesToWaves } from './waves.mjs';
|