pi-spine 2.25.0 → 2.27.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 +1 -1
- package/bin/spine-review-step.mjs +8 -1
- package/bin/spine-worker-runner.mjs +14 -1
- package/package.json +3 -3
- package/skills/spine-release-operator/SKILL.md +3 -0
- package/src/batch/abort.mjs +74 -38
- package/src/batch/attached-engine-handoff.mjs +2 -2
- package/src/batch/attached-runner-promote.mjs +1 -1
- package/src/batch/attached-runner-reconcile.mjs +1 -1
- package/src/batch/batch-meta-reconstruct.mjs +9 -1
- package/src/batch/batch-state-lock.mjs +173 -31
- package/src/batch/contract-exec.mjs +48 -47
- package/src/batch/contract-parse.mjs +2 -2
- package/src/batch/contract-prelanded.mjs +2 -2
- package/src/batch/contract-spawn.mjs +225 -0
- package/src/batch/contract-verify.mjs +2 -1
- package/src/batch/detached-wait.mjs +1 -1
- package/src/batch/diagnosis-handoff-packet.mjs +74 -0
- package/src/batch/diagnosis-pending-lane.mjs +34 -1
- package/src/batch/engine-lanes/matrix-run.mjs +6 -6
- package/src/batch/engine-lanes/merge.mjs +135 -34
- package/src/batch/engine-lanes/quota-fallback-run.mjs +153 -0
- package/src/batch/engine-lanes/quota-fallback-state.mjs +202 -0
- package/src/batch/engine-lanes/review-code.mjs +1 -0
- package/src/batch/engine-lanes/review-final.mjs +83 -46
- package/src/batch/engine-lanes/review-plan.mjs +22 -2
- package/src/batch/engine-lanes/review-poll.mjs +47 -1
- package/src/batch/engine-lanes.mjs +17 -16
- package/src/batch/engine.mjs +10 -10
- package/src/batch/journal.mjs +15 -0
- package/src/batch/lifecycle-archive.mjs +76 -1
- package/src/batch/lifecycle-cleanup.mjs +110 -0
- package/src/batch/lifecycle.mjs +100 -72
- package/src/batch/metrics.mjs +13 -1
- package/src/batch/parent-session-monitor.mjs +77 -70
- package/src/batch/pause.mjs +92 -25
- package/src/batch/post-merge-limbo.mjs +35 -5
- package/src/batch/provider-quota.mjs +220 -0
- package/src/batch/quota-fallback.mjs +319 -0
- package/src/batch/reconcile-diagnosis-context.mjs +22 -0
- package/src/batch/resume-gate-reopen.mjs +24 -8
- package/src/batch/resume-multi-queue.mjs +25 -10
- package/src/batch/resume-multi.mjs +1 -1
- package/src/batch/resume.mjs +1 -1
- package/src/batch/review-artifacts.mjs +93 -15
- package/src/batch/review-spawn-retry.mjs +106 -0
- package/src/batch/review-spawn.mjs +48 -2
- package/src/batch/review-step-run.mjs +96 -6
- package/src/batch/reviewer-output.mjs +162 -0
- package/src/batch/sequence-run.mjs +26 -8
- package/src/batch/sequence-wait.mjs +87 -8
- package/src/batch/state-guards.mjs +39 -7
- package/src/batch/state-io.mjs +131 -17
- package/src/batch/state.mjs +1 -0
- package/src/batch/worker-host.mjs +81 -7
- package/src/config/cursor-rules/discover.mjs +2 -2
- package/src/config/cursor-rules/match-globs.mjs +6 -4
- package/src/config/defaults.mjs +15 -1
- package/src/config/env-overrides.mjs +41 -4
- package/src/config/preflight/git-batch.mjs +47 -0
- package/src/config/settings-fields.mjs +6 -0
- package/src/config/spine-config-schema.mjs +91 -1
- package/src/doctor/quota-risk.mjs +45 -0
- package/src/fs/atomic-write.mjs +37 -1
- package/src/planner/file-scope.mjs +6 -6
- package/src/tasks/packet/validate-contract.mjs +3 -3
|
@@ -14,13 +14,18 @@ import { validateSettingValue } from "./settings-fields.mjs";
|
|
|
14
14
|
* @typedef {object} EnvOverrideSpec
|
|
15
15
|
* @property {string} envVar
|
|
16
16
|
* @property {string} configPath Dotted path (e.g. paths.tasksRoot)
|
|
17
|
-
* @property {"tasksRoot" | "maxParallel"} kind
|
|
17
|
+
* @property {"tasksRoot" | "maxParallel" | "agentProfile"} kind
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
/** @type {readonly EnvOverrideSpec[]} */
|
|
21
21
|
export const ENV_OVERRIDE_SPECS = Object.freeze([
|
|
22
22
|
{ envVar: "SPINE_TASKS_ROOT", configPath: "paths.tasksRoot", kind: "tasksRoot" },
|
|
23
23
|
{ envVar: "SPINE_MAX_LANES", configPath: "lanes.maxParallel", kind: "maxParallel" },
|
|
24
|
+
{
|
|
25
|
+
envVar: "SPINE_AGENT_PROFILE_OVERRIDE",
|
|
26
|
+
configPath: "agents.activeProfile",
|
|
27
|
+
kind: "agentProfile",
|
|
28
|
+
},
|
|
24
29
|
]);
|
|
25
30
|
|
|
26
31
|
/**
|
|
@@ -120,6 +125,7 @@ export function resolveTasksRootPath(projectRoot, config) {
|
|
|
120
125
|
* config: object,
|
|
121
126
|
* sources: Record<string, ConfigValueSource>,
|
|
122
127
|
* envVars: Record<string, string>,
|
|
128
|
+
* warnings: Record<string, string>,
|
|
123
129
|
* } | { ok: false, error: { code: string, message: string, suggestedCommand?: string } }}
|
|
124
130
|
*/
|
|
125
131
|
export function applyEnvOverrides(config, projectRoot, env = process.env) {
|
|
@@ -127,6 +133,9 @@ export function applyEnvOverrides(config, projectRoot, env = process.env) {
|
|
|
127
133
|
const sources = {};
|
|
128
134
|
/** @type {Record<string, string>} */
|
|
129
135
|
const envVars = {};
|
|
136
|
+
/** Reasons an env var was ignored (e.g. unknown agent profile), keyed by config path. */
|
|
137
|
+
/** @type {Record<string, string>} */
|
|
138
|
+
const warnings = {};
|
|
130
139
|
|
|
131
140
|
for (const spec of ENV_OVERRIDE_SPECS) {
|
|
132
141
|
sources[spec.configPath] = "file";
|
|
@@ -158,6 +167,28 @@ export function applyEnvOverrides(config, projectRoot, env = process.env) {
|
|
|
158
167
|
continue;
|
|
159
168
|
}
|
|
160
169
|
|
|
170
|
+
if (spec.kind === "agentProfile") {
|
|
171
|
+
// Schema validation ran on the file config before env overrides, so the override must
|
|
172
|
+
// check profile membership itself. Unknown names are ignored (soft-fail) so a stale
|
|
173
|
+
// export from a previous run cannot break config load; the reason is recorded for display.
|
|
174
|
+
const requested = String(raw).trim();
|
|
175
|
+
const profiles = merged?.agents?.profiles;
|
|
176
|
+
if (
|
|
177
|
+
profiles == null ||
|
|
178
|
+
typeof profiles !== "object" ||
|
|
179
|
+
Array.isArray(profiles) ||
|
|
180
|
+
!Object.prototype.hasOwnProperty.call(profiles, requested)
|
|
181
|
+
) {
|
|
182
|
+
warnings[spec.configPath] =
|
|
183
|
+
`${spec.envVar} ignored: unknown profile "${requested}"`;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
setValueAtPath(merged, spec.configPath, requested);
|
|
187
|
+
sources[spec.configPath] = "env";
|
|
188
|
+
envVars[spec.configPath] = spec.envVar;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
|
|
161
192
|
if (spec.kind === "maxParallel") {
|
|
162
193
|
const validated = validateSettingValue("lanes.maxParallel", raw);
|
|
163
194
|
if (!validated.ok) {
|
|
@@ -176,7 +207,7 @@ export function applyEnvOverrides(config, projectRoot, env = process.env) {
|
|
|
176
207
|
}
|
|
177
208
|
}
|
|
178
209
|
|
|
179
|
-
return { ok: true, config: merged, sources, envVars };
|
|
210
|
+
return { ok: true, config: merged, sources, envVars, warnings };
|
|
180
211
|
}
|
|
181
212
|
|
|
182
213
|
/**
|
|
@@ -196,13 +227,19 @@ export function listEnvAwareDisplayFields() {
|
|
|
196
227
|
* @param {Record<string, string> | undefined} envVars
|
|
197
228
|
* @param {string} configPath
|
|
198
229
|
* @param {unknown} value
|
|
230
|
+
* @param {Record<string, string> | undefined} [warnings] Reasons an env override was ignored,
|
|
231
|
+
* keyed by config path (e.g. an unknown SPINE_AGENT_PROFILE_OVERRIDE profile).
|
|
199
232
|
* @returns {string}
|
|
200
233
|
*/
|
|
201
|
-
export function formatConfigSourceDetail(sources, envVars, configPath, value) {
|
|
234
|
+
export function formatConfigSourceDetail(sources, envVars, configPath, value, warnings) {
|
|
202
235
|
const display = value === undefined || value === null ? "(not set)" : String(value);
|
|
203
236
|
const source = sources?.[configPath] ?? "file";
|
|
237
|
+
const warning = warnings?.[configPath];
|
|
204
238
|
if (source === "env" && envVars?.[configPath]) {
|
|
205
|
-
return `${display} (source: env, ${envVars[configPath]})`;
|
|
239
|
+
return `${display} (source: env, ${envVars[configPath]}${warning ? `, ${warning}` : ""})`;
|
|
240
|
+
}
|
|
241
|
+
if (warning) {
|
|
242
|
+
return `${display} (source: ${source}, ${warning})`;
|
|
206
243
|
}
|
|
207
244
|
return `${display} (source: ${source})`;
|
|
208
245
|
}
|
|
@@ -4,6 +4,9 @@ import path from "node:path";
|
|
|
4
4
|
import { execFileSync } from "node:child_process";
|
|
5
5
|
import { loadSpineConfig } from "../spine-config-load.mjs";
|
|
6
6
|
import { runReconciliationCheck } from "../../batch/reconcile.mjs";
|
|
7
|
+
import { isBatchArchived } from "../../batch/state-guards.mjs";
|
|
8
|
+
import { loadGateRecord } from "../../batch/gate-evidence-read.mjs";
|
|
9
|
+
import { readJournalEvents } from "../../batch/journal.mjs";
|
|
7
10
|
import {
|
|
8
11
|
isRulesManifestGeneratedAtOnlyDrift,
|
|
9
12
|
RULES_MANIFEST_REL_PATH,
|
|
@@ -130,6 +133,33 @@ function isHealthyActiveBatch(batchState) {
|
|
|
130
133
|
return false;
|
|
131
134
|
}
|
|
132
135
|
|
|
136
|
+
/**
|
|
137
|
+
* A terminal `completed` batch-state whose archive already exists (a phantom
|
|
138
|
+
* recreated by a late land-loop write, #293) or whose integrate gate was
|
|
139
|
+
* approved / integrate already ran needs `spine batch complete` to archive and
|
|
140
|
+
* clear the file — never a self-referential `spine preflight` suggestion
|
|
141
|
+
* (SP-790 / #293).
|
|
142
|
+
*
|
|
143
|
+
* @param {string} projectRoot
|
|
144
|
+
* @param {object} batchState
|
|
145
|
+
*/
|
|
146
|
+
function completedBatchNeedsBatchComplete(projectRoot, batchState) {
|
|
147
|
+
const phase = String(batchState?.phase ?? batchState?.status ?? "");
|
|
148
|
+
if (phase !== "completed") return false;
|
|
149
|
+
const batchId = String(batchState?.batchId ?? batchState?.id ?? "");
|
|
150
|
+
if (!batchId) return false;
|
|
151
|
+
if (isBatchArchived(projectRoot, batchId)) return true;
|
|
152
|
+
const gate = loadGateRecord(projectRoot, batchId);
|
|
153
|
+
if (gate && String(gate.status ?? "") === "approved") return true;
|
|
154
|
+
try {
|
|
155
|
+
return readJournalEvents(projectRoot, batchId).some(
|
|
156
|
+
(event) => event.type === "integrate.completed",
|
|
157
|
+
);
|
|
158
|
+
} catch {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
133
163
|
/**
|
|
134
164
|
* @param {object} ctx
|
|
135
165
|
* @param {string} ctx.projectRoot
|
|
@@ -297,6 +327,23 @@ export function checkNoActiveBatch(ctx) {
|
|
|
297
327
|
);
|
|
298
328
|
}
|
|
299
329
|
|
|
330
|
+
if (completedBatchNeedsBatchComplete(ctx.projectRoot, batchState)) {
|
|
331
|
+
const batchId = batchState.batchId ?? batchState.id ?? "unknown";
|
|
332
|
+
return makeCheck(
|
|
333
|
+
"no-active-batch",
|
|
334
|
+
false,
|
|
335
|
+
`completed batch ${batchId} awaiting archive`,
|
|
336
|
+
{
|
|
337
|
+
details: {
|
|
338
|
+
batchStatePath: path.relative(ctx.projectRoot, batchStatePath),
|
|
339
|
+
batchId,
|
|
340
|
+
phase: "completed",
|
|
341
|
+
},
|
|
342
|
+
suggestedCommand: "spine batch complete",
|
|
343
|
+
},
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
300
347
|
if (isHealthyActiveBatch(batchState)) {
|
|
301
348
|
const batchId = batchState.batchId ?? batchState.id ?? "unknown";
|
|
302
349
|
const phase = batchState.phase ?? batchState.status ?? "unknown";
|
|
@@ -151,6 +151,12 @@ export const SETTINGS_FIELDS = Object.freeze([
|
|
|
151
151
|
type: "string",
|
|
152
152
|
optional: true,
|
|
153
153
|
},
|
|
154
|
+
{
|
|
155
|
+
path: "agents.quotaFallbackProfile",
|
|
156
|
+
label: "Quota fallback agent model profile",
|
|
157
|
+
type: "string",
|
|
158
|
+
optional: true,
|
|
159
|
+
},
|
|
154
160
|
{
|
|
155
161
|
path: "dashboard.port",
|
|
156
162
|
label: "Dashboard port",
|
|
@@ -12,17 +12,25 @@ export const DEFAULT_SEQUENCE_POLL_MS = 5_000;
|
|
|
12
12
|
/** Default dashboard SSE poll interval (wired in SP-453). */
|
|
13
13
|
export const DEFAULT_DASHBOARD_POLL_MS = 2_000;
|
|
14
14
|
|
|
15
|
+
/** Default hard cap for the sequence batch terminal wait (SP-802 / #307). */
|
|
16
|
+
export const DEFAULT_SEQUENCE_MAX_WAIT_MS = 24 * 60 * 60 * 1000;
|
|
17
|
+
|
|
18
|
+
/** Default no-progress window before the sequence wait exits as stalled (SP-802 / #307). */
|
|
19
|
+
export const DEFAULT_SEQUENCE_STALL_MS = 30 * 60 * 1000;
|
|
20
|
+
|
|
15
21
|
/** Lower bound for orchestrator poll intervals. */
|
|
16
22
|
export const MIN_ORCHESTRATOR_POLL_MS = 100;
|
|
17
23
|
|
|
18
24
|
/** Upper bound for orchestrator poll intervals. */
|
|
19
25
|
export const MAX_ORCHESTRATOR_POLL_MS = 60_000;
|
|
20
26
|
|
|
21
|
-
/** @type {Readonly<{ attachedMilestonePollMs: number; sequencePollMs: number; dashboardPollMs: number }>} */
|
|
27
|
+
/** @type {Readonly<{ attachedMilestonePollMs: number; sequencePollMs: number; dashboardPollMs: number; sequenceMaxWaitMs: number; sequenceStallMs: number }>} */
|
|
22
28
|
export const ORCHESTRATOR_DEFAULTS = Object.freeze({
|
|
23
29
|
attachedMilestonePollMs: DEFAULT_ATTACHED_MILESTONE_POLL_MS,
|
|
24
30
|
sequencePollMs: DEFAULT_SEQUENCE_POLL_MS,
|
|
25
31
|
dashboardPollMs: DEFAULT_DASHBOARD_POLL_MS,
|
|
32
|
+
sequenceMaxWaitMs: DEFAULT_SEQUENCE_MAX_WAIT_MS,
|
|
33
|
+
sequenceStallMs: DEFAULT_SEQUENCE_STALL_MS,
|
|
26
34
|
});
|
|
27
35
|
|
|
28
36
|
/**
|
|
@@ -54,6 +62,30 @@ function validatePositivePollMs(value, fieldLabel) {
|
|
|
54
62
|
return { ok: true, value: parsed };
|
|
55
63
|
}
|
|
56
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Positive-integer validation without the poll-interval range clamp: wait/stall
|
|
67
|
+
* budgets legitimately exceed MAX_ORCHESTRATOR_POLL_MS (SP-802 / #307).
|
|
68
|
+
*
|
|
69
|
+
* @param {unknown} value
|
|
70
|
+
* @param {string} fieldLabel
|
|
71
|
+
* @returns {{ ok: true, value: number } | { ok: false, code: string, message: string, suggestedCommand: string }}
|
|
72
|
+
*/
|
|
73
|
+
function validatePositiveDurationMs(value, fieldLabel) {
|
|
74
|
+
if (value == null) {
|
|
75
|
+
return { ok: true, value: 0 };
|
|
76
|
+
}
|
|
77
|
+
const parsed = Number(value);
|
|
78
|
+
if (!Number.isFinite(parsed) || !Number.isInteger(parsed) || parsed <= 0) {
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
code: "CONFIG_ORCHESTRATOR_INVALID",
|
|
82
|
+
message: `${fieldLabel} must be a positive integer when set`,
|
|
83
|
+
suggestedCommand: "spine init --force",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return { ok: true, value: parsed };
|
|
87
|
+
}
|
|
88
|
+
|
|
57
89
|
/**
|
|
58
90
|
* @param {Record<string, any>} config
|
|
59
91
|
* @returns {null | { code: string; message: string; suggestedCommand: string }}
|
|
@@ -82,6 +114,16 @@ export function validateOrchestratorConfig(config) {
|
|
|
82
114
|
}
|
|
83
115
|
}
|
|
84
116
|
|
|
117
|
+
for (const [key, label] of [
|
|
118
|
+
["sequenceMaxWaitMs", "orchestrator.sequenceMaxWaitMs"],
|
|
119
|
+
["sequenceStallMs", "orchestrator.sequenceStallMs"],
|
|
120
|
+
]) {
|
|
121
|
+
const result = validatePositiveDurationMs(orchestrator[key], label);
|
|
122
|
+
if (!result.ok) {
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
85
127
|
return null;
|
|
86
128
|
}
|
|
87
129
|
|
|
@@ -121,6 +163,30 @@ export function resolveDashboardPollMs({ config = {} } = {}) {
|
|
|
121
163
|
return DEFAULT_DASHBOARD_POLL_MS;
|
|
122
164
|
}
|
|
123
165
|
|
|
166
|
+
/**
|
|
167
|
+
* @param {object} [params]
|
|
168
|
+
* @param {object} [params.config]
|
|
169
|
+
*/
|
|
170
|
+
export function resolveSequenceMaxWaitMs({ config = {} } = {}) {
|
|
171
|
+
const configured = Number(config.orchestrator?.sequenceMaxWaitMs);
|
|
172
|
+
if (Number.isFinite(configured) && configured > 0) {
|
|
173
|
+
return configured;
|
|
174
|
+
}
|
|
175
|
+
return DEFAULT_SEQUENCE_MAX_WAIT_MS;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param {object} [params]
|
|
180
|
+
* @param {object} [params.config]
|
|
181
|
+
*/
|
|
182
|
+
export function resolveSequenceStallMs({ config = {} } = {}) {
|
|
183
|
+
const configured = Number(config.orchestrator?.sequenceStallMs);
|
|
184
|
+
if (Number.isFinite(configured) && configured > 0) {
|
|
185
|
+
return configured;
|
|
186
|
+
}
|
|
187
|
+
return DEFAULT_SEQUENCE_STALL_MS;
|
|
188
|
+
}
|
|
189
|
+
|
|
124
190
|
// --- Named agent model profiles (SP-664 / GitHub #216) ---
|
|
125
191
|
|
|
126
192
|
/**
|
|
@@ -230,6 +296,30 @@ export function validateAgentProfilesConfig(config) {
|
|
|
230
296
|
}
|
|
231
297
|
}
|
|
232
298
|
|
|
299
|
+
// SP-805 / #329: profile used when quota fallback kicks in; same membership rule as activeProfile.
|
|
300
|
+
const quotaFallbackProfile = agents.quotaFallbackProfile;
|
|
301
|
+
if (quotaFallbackProfile != null) {
|
|
302
|
+
if (typeof quotaFallbackProfile !== "string") {
|
|
303
|
+
return {
|
|
304
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
305
|
+
message: "agents.quotaFallbackProfile must be a string when set",
|
|
306
|
+
suggestedCommand: "spine settings set agents.quotaFallbackProfile default",
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
const fallbackTarget = quotaFallbackProfile.trim();
|
|
310
|
+
// An empty string unsets the fallback profile; otherwise it must name a real profile.
|
|
311
|
+
if (
|
|
312
|
+
fallbackTarget !== "" &&
|
|
313
|
+
(!isPlainObject(profiles) || !Object.prototype.hasOwnProperty.call(profiles, fallbackTarget))
|
|
314
|
+
) {
|
|
315
|
+
return {
|
|
316
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
317
|
+
message: `agents.quotaFallbackProfile "${fallbackTarget}" does not match a defined agents.profiles entry`,
|
|
318
|
+
suggestedCommand: "spine settings set agents.quotaFallbackProfile default",
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
233
323
|
const escalatePolicy = agents.escalatePolicy;
|
|
234
324
|
if (escalatePolicy != null) {
|
|
235
325
|
if (!isPlainObject(escalatePolicy)) {
|
|
@@ -71,6 +71,17 @@ export function collectQuotaPinTargets(config = {}) {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
// SP-810: the quota fallback profile worker is a fallback-path pin — when
|
|
75
|
+
// the engine falls back to it, its pool must have headroom too.
|
|
76
|
+
const fallbackProfile =
|
|
77
|
+
typeof agents.quotaFallbackProfile === "string" ? agents.quotaFallbackProfile.trim() : "";
|
|
78
|
+
if (fallbackProfile && agents.profiles?.[fallbackProfile]) {
|
|
79
|
+
candidates.push({
|
|
80
|
+
model: agents.profiles[fallbackProfile]?.worker?.model,
|
|
81
|
+
source: `agents.profiles.${fallbackProfile}.worker.model (quota fallback)`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
74
85
|
/** @type {QuotaPinTarget[]} */
|
|
75
86
|
const targets = [];
|
|
76
87
|
const seen = new Set();
|
|
@@ -88,6 +99,37 @@ export function collectQuotaPinTargets(config = {}) {
|
|
|
88
99
|
return targets;
|
|
89
100
|
}
|
|
90
101
|
|
|
102
|
+
/**
|
|
103
|
+
* SP-810: detect a quota fallback profile pinned to the same provider pool
|
|
104
|
+
* as the active worker. Falling back within one exhausted pool can never
|
|
105
|
+
* help, so surface it as an advisory. Advisory only — never fails preflight.
|
|
106
|
+
*
|
|
107
|
+
* @param {object} [config]
|
|
108
|
+
* @returns {string | null}
|
|
109
|
+
*/
|
|
110
|
+
export function detectSamePoolQuotaFallback(config = {}) {
|
|
111
|
+
const agents = config?.agents;
|
|
112
|
+
if (!agents || typeof agents !== "object") return null;
|
|
113
|
+
|
|
114
|
+
const fallbackProfile =
|
|
115
|
+
typeof agents.quotaFallbackProfile === "string" ? agents.quotaFallbackProfile.trim() : "";
|
|
116
|
+
if (!fallbackProfile || !agents.profiles?.[fallbackProfile]) return null;
|
|
117
|
+
|
|
118
|
+
const fallbackModel = agents.profiles[fallbackProfile]?.worker?.model;
|
|
119
|
+
// The active worker is the active profile's worker pin when set, else the
|
|
120
|
+
// base worker pin — mirroring how the engine resolves the worker model.
|
|
121
|
+
const activeProfile = typeof agents.activeProfile === "string" ? agents.activeProfile.trim() : "";
|
|
122
|
+
const activeModel =
|
|
123
|
+
(activeProfile && agents.profiles?.[activeProfile]?.worker?.model) || agents.worker?.model;
|
|
124
|
+
if (typeof fallbackModel !== "string" || typeof activeModel !== "string") return null;
|
|
125
|
+
|
|
126
|
+
const fallbackPool = resolvePoolId(fallbackModel.trim());
|
|
127
|
+
const activePool = resolvePoolId(activeModel.trim());
|
|
128
|
+
if (fallbackPool === "unknown" || fallbackPool !== activePool) return null;
|
|
129
|
+
|
|
130
|
+
return `agents.quotaFallbackProfile ${fallbackProfile} uses the same quota pool (${fallbackPool}) as the active worker — fallback can never help`;
|
|
131
|
+
}
|
|
132
|
+
|
|
91
133
|
/**
|
|
92
134
|
* Evaluate headroom evidence for one pool from an optional probe result.
|
|
93
135
|
* Degrades closed: absent probes/auth mean "no headroom evidence", never an
|
|
@@ -207,6 +249,9 @@ export function buildQuotaRiskDoctorCheck({ config = {}, probeResults, metricsLi
|
|
|
207
249
|
const signals = detectQuotaRiskSignals(metricsLines, { now });
|
|
208
250
|
risks.push(...signals);
|
|
209
251
|
|
|
252
|
+
const samePoolAdvisory = detectSamePoolQuotaFallback(config);
|
|
253
|
+
if (samePoolAdvisory) risks.push(samePoolAdvisory);
|
|
254
|
+
|
|
210
255
|
if (risks.length === 0) {
|
|
211
256
|
const detail =
|
|
212
257
|
targets.length === 0
|
package/src/fs/atomic-write.mjs
CHANGED
|
@@ -14,6 +14,33 @@ export function makeAtomicTempPath(targetPath) {
|
|
|
14
14
|
return `${targetPath}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
const IGNORABLE_DIR_FSYNC_CODES = new Set(["EISDIR", "EPERM", "EINVAL", "EBADF"]);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Durability requires flushing the parent directory entry after the rename so
|
|
21
|
+
* the rename itself survives a crash. Some platforms (win32, network and
|
|
22
|
+
* exotic filesystems) cannot open or fsync a directory at all, so the four
|
|
23
|
+
* codes that indicate that situation are tolerated; anything else is real I/O
|
|
24
|
+
* trouble and propagates to the caller.
|
|
25
|
+
* @param {string} dir
|
|
26
|
+
*/
|
|
27
|
+
function fsyncDirBestEffort(dir) {
|
|
28
|
+
let dirFd;
|
|
29
|
+
try {
|
|
30
|
+
dirFd = fs.openSync(dir, "r");
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (IGNORABLE_DIR_FSYNC_CODES.has(/** @type {any} */ (err)?.code)) return;
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
fs.fsyncSync(dirFd);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
if (!IGNORABLE_DIR_FSYNC_CODES.has(/** @type {any} */ (err)?.code)) throw err;
|
|
39
|
+
} finally {
|
|
40
|
+
fs.closeSync(dirFd);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
17
44
|
/**
|
|
18
45
|
* @param {string} filePath
|
|
19
46
|
* @param {string} content
|
|
@@ -25,8 +52,17 @@ export function writeTextAtomic(filePath, content) {
|
|
|
25
52
|
const tmpPath = makeAtomicTempPath(filePath);
|
|
26
53
|
|
|
27
54
|
try {
|
|
28
|
-
|
|
55
|
+
// Durable temp write: fsync the file contents before the rename so the
|
|
56
|
+
// data reaches disk before the entry swap makes it authoritative (#302).
|
|
57
|
+
const fd = fs.openSync(tmpPath, "w");
|
|
58
|
+
try {
|
|
59
|
+
fs.writeSync(fd, content, null, "utf-8");
|
|
60
|
+
fs.fsyncSync(fd);
|
|
61
|
+
} finally {
|
|
62
|
+
fs.closeSync(fd);
|
|
63
|
+
}
|
|
29
64
|
fs.renameSync(tmpPath, filePath);
|
|
65
|
+
fsyncDirBestEffort(dir);
|
|
30
66
|
} catch (err) {
|
|
31
67
|
try {
|
|
32
68
|
if (fs.existsSync(tmpPath)) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* parallel lane assignment would risk merge conflicts.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import picomatch from 'picomatch';
|
|
10
10
|
|
|
11
11
|
/** Synthetic basename used when expanding globs into concrete probe paths. */
|
|
12
12
|
const PROBE_BASENAME = '__probe__';
|
|
@@ -36,7 +36,7 @@ const SYNTHETIC_PROBE_EXTENSIONS = Object.freeze([
|
|
|
36
36
|
const MAX_BRACE_EXPANSIONS = 32;
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Expand `{a,b}` brace groups into concrete entry variants (
|
|
39
|
+
* Expand `{a,b}` brace groups into concrete entry variants (picomatch-style).
|
|
40
40
|
* Nested groups are expanded recursively; expansion stops at
|
|
41
41
|
* MAX_BRACE_EXPANSIONS so probe generation stays bounded.
|
|
42
42
|
*
|
|
@@ -264,18 +264,18 @@ export function fileScopePatternsOverlap(leftPattern, rightPattern) {
|
|
|
264
264
|
const matchOpts = { dot: true };
|
|
265
265
|
|
|
266
266
|
for (const probe of leftProbes) {
|
|
267
|
-
if (
|
|
267
|
+
if (picomatch(rightEntry, matchOpts)(probe)) return true;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
for (const probe of rightProbes) {
|
|
271
|
-
if (
|
|
271
|
+
if (picomatch(leftEntry, matchOpts)(probe)) return true;
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
if (!patternHasGlobMeta(leftEntry) &&
|
|
274
|
+
if (!patternHasGlobMeta(leftEntry) && picomatch(rightEntry, matchOpts)(leftEntry)) {
|
|
275
275
|
return true;
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
-
if (!patternHasGlobMeta(rightEntry) &&
|
|
278
|
+
if (!patternHasGlobMeta(rightEntry) && picomatch(leftEntry, matchOpts)(rightEntry)) {
|
|
279
279
|
return true;
|
|
280
280
|
}
|
|
281
281
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Validate-time checks for PROMPT.md `## Contract` tables (handoff §4.4).
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import picomatch from "picomatch";
|
|
7
7
|
|
|
8
8
|
import { matchesContractPattern } from "../../batch/contract-verify.mjs";
|
|
9
9
|
import {
|
|
@@ -235,8 +235,8 @@ function isValidContractGlob(pattern) {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
try {
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
picomatch(trimmed)(GLOB_PROBE);
|
|
239
|
+
picomatch(GLOB_PROBE)(trimmed);
|
|
240
240
|
return true;
|
|
241
241
|
} catch {
|
|
242
242
|
return false;
|