pi-braid 0.43.26 → 0.43.28
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/CHANGELOG.md +49 -0
- package/build-info.json +4 -4
- package/dist/extensions/orchestrator/index.js +71 -5
- package/dist/lib/orchestrator/workers.d.ts +122 -6
- package/dist/lib/orchestrator/workers.js +246 -4
- package/docs/LOCAL_DEV.md +1 -1
- package/package.json +1 -1
- package/src/extensions/orchestrator/index.ts +87 -4
- package/src/lib/orchestrator/workers.ts +337 -11
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
* session growth, branch commits, result schema) — never from the worker's
|
|
9
9
|
* own claim alone.
|
|
10
10
|
*
|
|
11
|
+
* Each row also carries its queue rank and the worker ids it waits for, so the
|
|
12
|
+
* order workers may run in is read from the registry: `orderWorkerRows`
|
|
13
|
+
* prints it, and a verdict says `blocked` while a dependency has not been
|
|
14
|
+
* delivered. Both facts are the registry's own; no caller has to remember
|
|
15
|
+
* which piece of work lands first.
|
|
16
|
+
*
|
|
11
17
|
* Registry file location: ~/.pi/agent/braid/projects/<sanitized-cwd>/workers.json
|
|
12
18
|
* (per-CWD, beside locks.json, shared across all agents on the same project).
|
|
13
19
|
*
|
|
@@ -106,6 +112,17 @@ export interface WorkerEntry {
|
|
|
106
112
|
outputFile: string | null;
|
|
107
113
|
branch: string | null;
|
|
108
114
|
files: string[];
|
|
115
|
+
/**
|
|
116
|
+
* Queue rank: lower runs sooner. Null is unranked, which sorts after every
|
|
117
|
+
* ranked row. Filled with null on a row admitted before the field existed.
|
|
118
|
+
*/
|
|
119
|
+
priority: number | null;
|
|
120
|
+
/**
|
|
121
|
+
* Worker ids this row waits for, in declared order. Empty means it waits for
|
|
122
|
+
* nothing. Fixed at admission: a dependency gained after the work started is
|
|
123
|
+
* a second unit of work wearing the first one's id.
|
|
124
|
+
*/
|
|
125
|
+
dependsOn: string[];
|
|
109
126
|
spawnedAt: string;
|
|
110
127
|
lastSeenAt: string | null;
|
|
111
128
|
resultAt: string | null;
|
|
@@ -147,6 +164,13 @@ export interface RegisterWorkerInput {
|
|
|
147
164
|
files?: string[];
|
|
148
165
|
branch?: string;
|
|
149
166
|
outputFile?: string;
|
|
167
|
+
/** Queue rank: lower runs sooner; null or absent is unranked. */
|
|
168
|
+
priority?: number | null;
|
|
169
|
+
/**
|
|
170
|
+
* Worker ids this row waits for. Refused when an id is unknown, is this
|
|
171
|
+
* row's own id, or would close a dependency loop.
|
|
172
|
+
*/
|
|
173
|
+
dependsOn?: string[];
|
|
150
174
|
/**
|
|
151
175
|
* Worker handle, when the caller already has it at admission time. Absent
|
|
152
176
|
* stays null: a handle is never invented, and a pane is a place to look, not
|
|
@@ -170,6 +194,10 @@ export interface RegisterWorkerResult {
|
|
|
170
194
|
reason?: string;
|
|
171
195
|
/** True when a live entry already admitted this request and was reused. */
|
|
172
196
|
reused?: boolean;
|
|
197
|
+
/** Machine-readable reason when the admission itself was refused. */
|
|
198
|
+
refusedBy?: DependencyRefusalReason;
|
|
199
|
+
/** The dependency id the refusal names. */
|
|
200
|
+
offendingId?: string;
|
|
173
201
|
}
|
|
174
202
|
|
|
175
203
|
export interface UpdateWorkerPatch {
|
|
@@ -180,6 +208,8 @@ export interface UpdateWorkerPatch {
|
|
|
180
208
|
branch?: string;
|
|
181
209
|
files?: string[];
|
|
182
210
|
status?: WorkerStatus;
|
|
211
|
+
/** Queue rank to set; null clears it back to unranked. */
|
|
212
|
+
priority?: number | null;
|
|
183
213
|
/** Resume point to record; stamped with the write time. */
|
|
184
214
|
checkpoint?: WorkerCheckpointInput;
|
|
185
215
|
}
|
|
@@ -199,11 +229,21 @@ export interface WorkerCheckOptions {
|
|
|
199
229
|
now?: number;
|
|
200
230
|
/** Frozen-session threshold in seconds; defaults to 600. */
|
|
201
231
|
stalledAfterSec?: number;
|
|
232
|
+
/**
|
|
233
|
+
* The registry the entry belongs to, which is what its dependencies are
|
|
234
|
+
* resolved against. checkWorker always supplies it; a caller that omits it
|
|
235
|
+
* leaves dependency satisfaction unread, so no row is reported blocked.
|
|
236
|
+
*/
|
|
237
|
+
registry?: WorkerRegistry;
|
|
202
238
|
}
|
|
203
239
|
|
|
204
240
|
export interface WorkerCheckResult {
|
|
205
241
|
workerId: string;
|
|
206
242
|
status: WorkerVerdictStatus;
|
|
243
|
+
/** The row's own stored status, beside the verdict — never replaced by it. */
|
|
244
|
+
storedStatus: WorkerStatus;
|
|
245
|
+
/** Dependency ids nothing has satisfied yet; empty when the row may run. */
|
|
246
|
+
blockedBy: string[];
|
|
207
247
|
reason: string;
|
|
208
248
|
outputFile: string | null;
|
|
209
249
|
outputExists: boolean;
|
|
@@ -233,12 +273,39 @@ export interface WorkerCheckResult {
|
|
|
233
273
|
}
|
|
234
274
|
|
|
235
275
|
/**
|
|
236
|
-
*
|
|
237
|
-
* the
|
|
238
|
-
* statement about evidence rather than a lifecycle state a caller sets. No
|
|
239
|
-
* stored row carries it, so the on-disk status set is unchanged.
|
|
276
|
+
* Why a dependency edge was refused at admission: the id is not in the registry,
|
|
277
|
+
* the row names itself, or the edge would close a loop.
|
|
240
278
|
*/
|
|
241
|
-
export type
|
|
279
|
+
export type DependencyRefusalReason = "unknown-dependency" | "self-dependency" | "dependency-cycle";
|
|
280
|
+
|
|
281
|
+
/** One refused dependency edge, as the admission reports it. */
|
|
282
|
+
export interface DependencyRefusal {
|
|
283
|
+
reason: DependencyRefusalReason;
|
|
284
|
+
/** The offending id: the unknown one, the row's own, or where a loop starts. */
|
|
285
|
+
id: string;
|
|
286
|
+
/**
|
|
287
|
+
* The loop from the admitted row back to itself, e.g. `[a, b, a]`; empty
|
|
288
|
+
* when the refusal names no loop.
|
|
289
|
+
*/
|
|
290
|
+
path: string[];
|
|
291
|
+
/** The refusal in one sentence, prefixed with its reason token. */
|
|
292
|
+
message: string;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** One listing row: the entry, and the dependency ids still blocking it. */
|
|
296
|
+
export interface WorkerOrderRow {
|
|
297
|
+
entry: WorkerEntry;
|
|
298
|
+
blockedBy: string[];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* A status the registry reports. `resumable` and `blocked` are derived, never
|
|
303
|
+
* stored: `resumable` says the entry is mid-flight with a checkpoint to resume
|
|
304
|
+
* from, `blocked` that a dependency has not been delivered. Both are statements
|
|
305
|
+
* about evidence rather than lifecycle states a caller sets, so no stored row
|
|
306
|
+
* carries either and the on-disk status set is unchanged.
|
|
307
|
+
*/
|
|
308
|
+
export type WorkerVerdictStatus = WorkerStatus | "resumable" | "blocked";
|
|
242
309
|
|
|
243
310
|
// ── Constants ──────────────────────────────────────────────────────────────
|
|
244
311
|
|
|
@@ -270,10 +337,14 @@ export const WORKER_OUTCOMES: readonly WorkerOutcome[] = [
|
|
|
270
337
|
"closed",
|
|
271
338
|
];
|
|
272
339
|
|
|
273
|
-
/**
|
|
340
|
+
/**
|
|
341
|
+
* Statuses check-worker may report: the stored statuses plus the derived ones,
|
|
342
|
+
* `resumable` and `blocked`, which no row ever carries on disk.
|
|
343
|
+
*/
|
|
274
344
|
export const WORKER_VERDICT_STATUSES: readonly WorkerVerdictStatus[] = [
|
|
275
345
|
...WORKER_STATUSES,
|
|
276
346
|
"resumable",
|
|
347
|
+
"blocked",
|
|
277
348
|
];
|
|
278
349
|
|
|
279
350
|
/** Statuses a worker's result schema may self-report. */
|
|
@@ -331,7 +402,7 @@ export const WORKER_STATUS_LAYERS: readonly WorkerStatusLayer[] = [
|
|
|
331
402
|
role: "computed verdict",
|
|
332
403
|
owner: "check-worker",
|
|
333
404
|
values: WORKER_VERDICT_STATUSES,
|
|
334
|
-
states: "what check-worker derives from evidence, resumable never stored",
|
|
405
|
+
states: "what check-worker derives from evidence, resumable and blocked never stored",
|
|
335
406
|
},
|
|
336
407
|
{
|
|
337
408
|
role: "result attestation",
|
|
@@ -393,6 +464,11 @@ function normalizeEntry(raw: WorkerEntry): WorkerEntry {
|
|
|
393
464
|
requestId,
|
|
394
465
|
checkpoint: isCheckpoint(raw.checkpoint) ? raw.checkpoint : null,
|
|
395
466
|
admissionRefusals: Array.isArray(raw.admissionRefusals) ? raw.admissionRefusals : [],
|
|
467
|
+
// A row admitted before the queue facts existed is unranked and waits for
|
|
468
|
+
// nothing, which is exactly what the absent fields mean.
|
|
469
|
+
priority:
|
|
470
|
+
typeof raw.priority === "number" && Number.isFinite(raw.priority) ? raw.priority : null,
|
|
471
|
+
dependsOn: normalizeDependsOn(raw.dependsOn),
|
|
396
472
|
};
|
|
397
473
|
}
|
|
398
474
|
|
|
@@ -526,7 +602,7 @@ function isSameRequest(entry: WorkerEntry, requestId: string): boolean {
|
|
|
526
602
|
/** What a request states about the work, against what the entry recorded. */
|
|
527
603
|
function requestDifferences(
|
|
528
604
|
entry: WorkerEntry,
|
|
529
|
-
request: { spec?: string; files?: string[] },
|
|
605
|
+
request: { spec?: string; files?: string[]; dependsOn?: readonly string[] },
|
|
530
606
|
): string[] {
|
|
531
607
|
const differences: string[] = [];
|
|
532
608
|
if (request.spec !== undefined && request.spec !== entry.spec) {
|
|
@@ -541,6 +617,17 @@ function requestDifferences(
|
|
|
541
617
|
differences.push(`files [${recorded.join(", ")}] vs [${requested.join(", ")}]`);
|
|
542
618
|
}
|
|
543
619
|
}
|
|
620
|
+
// Dependencies are part of what the work is, so a retry that changes them is
|
|
621
|
+
// a different request, not the same one resubmitted.
|
|
622
|
+
if (request.dependsOn !== undefined) {
|
|
623
|
+
const recorded = [...normalizeDependsOn(entry.dependsOn)].sort();
|
|
624
|
+
const requested = [...normalizeDependsOn(request.dependsOn)].sort();
|
|
625
|
+
const same =
|
|
626
|
+
recorded.length === requested.length && recorded.every((id, i) => id === requested[i]);
|
|
627
|
+
if (!same) {
|
|
628
|
+
differences.push(`dependsOn [${recorded.join(", ")}] vs [${requested.join(", ")}]`);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
544
631
|
return differences;
|
|
545
632
|
}
|
|
546
633
|
|
|
@@ -560,7 +647,7 @@ export interface WorkerAdmissionDecision {
|
|
|
560
647
|
export function decideAdmission(
|
|
561
648
|
existing: WorkerEntry | undefined,
|
|
562
649
|
requestId: string,
|
|
563
|
-
request: { spec?: string; files?: string[] },
|
|
650
|
+
request: { spec?: string; files?: string[]; dependsOn?: readonly string[] },
|
|
564
651
|
): WorkerAdmissionDecision {
|
|
565
652
|
if (!existing || existing.closedAt) return { action: "admit" };
|
|
566
653
|
if (!isSameRequest(existing, requestId)) {
|
|
@@ -612,6 +699,181 @@ export function recordAdmissionRefusal(workerId: string, requestId: string, cwd?
|
|
|
612
699
|
return true;
|
|
613
700
|
}
|
|
614
701
|
|
|
702
|
+
// ── Queue facts: priority and dependencies ─────────────────────────────────
|
|
703
|
+
// The registry owns the ids, so it owns what a wait means. A dependency is
|
|
704
|
+
// satisfied by `merged` or `completed` and by nothing else: a worker that
|
|
705
|
+
// failed, stalled or was closed without delivering did not produce the thing
|
|
706
|
+
// the next one waits for. Edges are decided at admission, where an unknown id,
|
|
707
|
+
// a self-edge or a loop is refused before anything is written; satisfaction is
|
|
708
|
+
// read at every check, because the answer changes as the rows it names move.
|
|
709
|
+
|
|
710
|
+
/** Priority values the registry accepts: finite numbers, or null for unranked. */
|
|
711
|
+
export function normalizePriority(raw: unknown): number | null {
|
|
712
|
+
if (raw === undefined || raw === null) return null;
|
|
713
|
+
if (typeof raw !== "number" || !Number.isFinite(raw)) {
|
|
714
|
+
throw new Error(`priority must be a finite number or null, got ${JSON.stringify(raw)}`);
|
|
715
|
+
}
|
|
716
|
+
return raw;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Dependency ids as the registry stores them: strings, trimmed, non-empty,
|
|
721
|
+
* first occurrence kept. A malformed or absent value waits for nothing.
|
|
722
|
+
*/
|
|
723
|
+
export function normalizeDependsOn(raw: unknown): string[] {
|
|
724
|
+
if (!Array.isArray(raw)) return [];
|
|
725
|
+
const ids: string[] = [];
|
|
726
|
+
for (const value of raw) {
|
|
727
|
+
if (typeof value !== "string") continue;
|
|
728
|
+
const id = value.trim();
|
|
729
|
+
if (id.length === 0 || ids.includes(id)) continue;
|
|
730
|
+
ids.push(id);
|
|
731
|
+
}
|
|
732
|
+
return ids;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/** Statuses that satisfy a dependency edge; a failed worker delivered nothing. */
|
|
736
|
+
export const WORKER_SATISFYING_STATUSES: readonly WorkerStatus[] = ["merged", "completed"];
|
|
737
|
+
|
|
738
|
+
/** Look a row up by id, without reading the prototype chain as a registry row. */
|
|
739
|
+
function knownWorker(registry: WorkerRegistry, workerId: string): WorkerEntry | undefined {
|
|
740
|
+
return Object.prototype.hasOwnProperty.call(registry.workers, workerId)
|
|
741
|
+
? registry.workers[workerId]
|
|
742
|
+
: undefined;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/** True when the row that id names delivered the work a dependent waits for. */
|
|
746
|
+
export function isDependencySatisfied(entry: WorkerEntry | undefined): boolean {
|
|
747
|
+
return entry !== undefined && WORKER_SATISFYING_STATUSES.includes(entry.status);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* The dependency ids of one row that nothing has satisfied yet, in declared
|
|
752
|
+
* order. An id with no row at all is unsatisfied: admission refuses unknown ids,
|
|
753
|
+
* so a missing one means the row was hand-edited or removed, and neither is a
|
|
754
|
+
* delivery.
|
|
755
|
+
*/
|
|
756
|
+
export function unsatisfiedDependencies(entry: WorkerEntry, registry: WorkerRegistry): string[] {
|
|
757
|
+
return normalizeDependsOn(entry.dependsOn).filter(
|
|
758
|
+
(id) => !isDependencySatisfied(knownWorker(registry, id)),
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* The loop an admission would close, as ids from the new row back to itself,
|
|
764
|
+
* or null when it closes none. Walks the graph as it would stand after the
|
|
765
|
+
* write: the admitted row contributes only its declared edges (a rolled-over
|
|
766
|
+
* row's old ones die with it), every other row its recorded ones.
|
|
767
|
+
*/
|
|
768
|
+
function dependencyCyclePath(
|
|
769
|
+
workerId: string,
|
|
770
|
+
dependsOn: readonly string[],
|
|
771
|
+
registry: WorkerRegistry,
|
|
772
|
+
): string[] | null {
|
|
773
|
+
const edgesOf = (id: string): string[] =>
|
|
774
|
+
id === workerId
|
|
775
|
+
? [...dependsOn]
|
|
776
|
+
: normalizeDependsOn(knownWorker(registry, id)?.dependsOn ?? []);
|
|
777
|
+
const seen = new Set<string>([workerId]);
|
|
778
|
+
const walk = (from: string, path: string[]): string[] | null => {
|
|
779
|
+
for (const next of edgesOf(from)) {
|
|
780
|
+
if (next === workerId) return [...path, workerId];
|
|
781
|
+
if (seen.has(next)) continue;
|
|
782
|
+
seen.add(next);
|
|
783
|
+
const found = walk(next, [...path, next]);
|
|
784
|
+
if (found) return found;
|
|
785
|
+
}
|
|
786
|
+
return null;
|
|
787
|
+
};
|
|
788
|
+
return walk(workerId, [workerId]);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Decide whether `dependsOn` may be recorded for `workerId`, against the graph
|
|
793
|
+
* the registry holds now. Null means the edges stand. A refused edge writes
|
|
794
|
+
* nothing: the caller reports the reason and the id, and the row is untouched.
|
|
795
|
+
*
|
|
796
|
+
* A row naming itself is refused as a self-dependency before the unknown check,
|
|
797
|
+
* which would otherwise answer `unknown-dependency` for an id that is by
|
|
798
|
+
* construction not admitted yet and hide the actual defect.
|
|
799
|
+
*/
|
|
800
|
+
export function validateDependencies(
|
|
801
|
+
workerId: string,
|
|
802
|
+
dependsOn: readonly string[],
|
|
803
|
+
registry: WorkerRegistry,
|
|
804
|
+
): DependencyRefusal | null {
|
|
805
|
+
const ids = normalizeDependsOn(dependsOn);
|
|
806
|
+
if (ids.includes(workerId)) {
|
|
807
|
+
return {
|
|
808
|
+
reason: "self-dependency",
|
|
809
|
+
id: workerId,
|
|
810
|
+
path: [workerId, workerId],
|
|
811
|
+
message:
|
|
812
|
+
`self-dependency: worker ${workerId} names itself in dependsOn; a worker ` +
|
|
813
|
+
`cannot wait for its own result`,
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
for (const id of ids) {
|
|
817
|
+
if (!knownWorker(registry, id)) {
|
|
818
|
+
return {
|
|
819
|
+
reason: "unknown-dependency",
|
|
820
|
+
id,
|
|
821
|
+
path: [],
|
|
822
|
+
message:
|
|
823
|
+
`unknown-dependency: worker ${workerId} depends on ${id}, which is not in the ` +
|
|
824
|
+
`registry and never was`,
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const path = dependencyCyclePath(workerId, ids, registry);
|
|
829
|
+
if (path) {
|
|
830
|
+
return {
|
|
831
|
+
reason: "dependency-cycle",
|
|
832
|
+
id: path[1] ?? workerId,
|
|
833
|
+
path,
|
|
834
|
+
message:
|
|
835
|
+
`dependency-cycle: worker ${workerId}'s dependsOn would close a loop: ` +
|
|
836
|
+
`${path.join(" -> ")}`,
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Split listing rows into the order they may be acted on: rows whose
|
|
844
|
+
* dependencies are all satisfied first, then blocked rows, each group ranked by
|
|
845
|
+
* priority ascending with unranked rows after every ranked one, ties by
|
|
846
|
+
* admission time and then id so the order is total.
|
|
847
|
+
*
|
|
848
|
+
* Satisfaction is read against the whole registry rather than the rows being
|
|
849
|
+
* printed: a closed row still satisfies its dependents, so it must be read
|
|
850
|
+
* before a listing that hides closed rows is filtered.
|
|
851
|
+
*/
|
|
852
|
+
export function orderWorkerRows(
|
|
853
|
+
entries: readonly WorkerEntry[],
|
|
854
|
+
registry: WorkerRegistry,
|
|
855
|
+
): { ready: WorkerOrderRow[]; blocked: WorkerOrderRow[] } {
|
|
856
|
+
const rows: WorkerOrderRow[] = entries.map((entry) => ({
|
|
857
|
+
entry,
|
|
858
|
+
blockedBy: unsatisfiedDependencies(entry, registry),
|
|
859
|
+
}));
|
|
860
|
+
rows.sort(compareOrderRows);
|
|
861
|
+
return {
|
|
862
|
+
ready: rows.filter((row) => row.blockedBy.length === 0),
|
|
863
|
+
blocked: rows.filter((row) => row.blockedBy.length > 0),
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/** Actionable order inside one group; both priorities null falls through to time. */
|
|
868
|
+
function compareOrderRows(a: WorkerOrderRow, b: WorkerOrderRow): number {
|
|
869
|
+
const pa = a.entry.priority ?? Number.POSITIVE_INFINITY;
|
|
870
|
+
const pb = b.entry.priority ?? Number.POSITIVE_INFINITY;
|
|
871
|
+
if (pa !== pb) return pa - pb;
|
|
872
|
+
const bySpawn = a.entry.spawnedAt.localeCompare(b.entry.spawnedAt);
|
|
873
|
+
if (bySpawn !== 0) return bySpawn;
|
|
874
|
+
return a.entry.workerId.localeCompare(b.entry.workerId);
|
|
875
|
+
}
|
|
876
|
+
|
|
615
877
|
// ── CRUD ───────────────────────────────────────────────────────────────────
|
|
616
878
|
|
|
617
879
|
/**
|
|
@@ -627,7 +889,13 @@ export function registerWorker(input: RegisterWorkerInput, cwd?: string): Regist
|
|
|
627
889
|
const registry = readWorkers(key);
|
|
628
890
|
const existing = registry.workers[input.workerId];
|
|
629
891
|
const requestId = resolveRequestId(input.workerId, input.requestId);
|
|
630
|
-
const
|
|
892
|
+
const priority = normalizePriority(input.priority);
|
|
893
|
+
const dependsOn = normalizeDependsOn(input.dependsOn);
|
|
894
|
+
const decision = decideAdmission(existing, requestId, {
|
|
895
|
+
spec: input.spec,
|
|
896
|
+
files: input.files,
|
|
897
|
+
dependsOn,
|
|
898
|
+
});
|
|
631
899
|
if (decision.action === "reuse") {
|
|
632
900
|
return { ok: true, entry: decision.entry, reused: true };
|
|
633
901
|
}
|
|
@@ -641,6 +909,19 @@ export function registerWorker(input: RegisterWorkerInput, cwd?: string): Regist
|
|
|
641
909
|
return { ok: false, reason: decision.reason, entry: decision.entry };
|
|
642
910
|
}
|
|
643
911
|
|
|
912
|
+
// A dependency that cannot be satisfied refuses the admission before any
|
|
913
|
+
// write: the row, the branch and the locks the caller made for it stand as
|
|
914
|
+
// they were, and the reason names what is wrong with the edge.
|
|
915
|
+
const dependencyRefusal = validateDependencies(input.workerId, dependsOn, registry);
|
|
916
|
+
if (dependencyRefusal) {
|
|
917
|
+
return {
|
|
918
|
+
ok: false,
|
|
919
|
+
reason: dependencyRefusal.message,
|
|
920
|
+
refusedBy: dependencyRefusal.reason,
|
|
921
|
+
offendingId: dependencyRefusal.id,
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
|
|
644
925
|
const nowIso = new Date().toISOString();
|
|
645
926
|
const entry: WorkerEntry = {
|
|
646
927
|
workerId: input.workerId,
|
|
@@ -653,6 +934,8 @@ export function registerWorker(input: RegisterWorkerInput, cwd?: string): Regist
|
|
|
653
934
|
outputFile: input.outputFile ?? null,
|
|
654
935
|
branch: input.branch ?? null,
|
|
655
936
|
files: input.files ?? [],
|
|
937
|
+
priority,
|
|
938
|
+
dependsOn,
|
|
656
939
|
spawnedAt: nowIso,
|
|
657
940
|
lastSeenAt: nowIso,
|
|
658
941
|
resultAt: null,
|
|
@@ -695,6 +978,7 @@ export function updateWorker(
|
|
|
695
978
|
if (patch.branch !== undefined) entry.branch = patch.branch;
|
|
696
979
|
if (patch.files !== undefined) entry.files = patch.files;
|
|
697
980
|
if (patch.status !== undefined) entry.status = parseWorkerStatus(patch.status);
|
|
981
|
+
if (patch.priority !== undefined) entry.priority = normalizePriority(patch.priority);
|
|
698
982
|
if (patch.checkpoint !== undefined) entry.checkpoint = stampCheckpoint(patch.checkpoint);
|
|
699
983
|
entry.lastSeenAt = new Date().toISOString();
|
|
700
984
|
|
|
@@ -1776,6 +2060,19 @@ function normalizeLiveStatus(raw?: string): "working" | "blocked" | "done" | "id
|
|
|
1776
2060
|
return null;
|
|
1777
2061
|
}
|
|
1778
2062
|
|
|
2063
|
+
/**
|
|
2064
|
+
* Say what is holding a row, per blocking id: the status of the row it waits
|
|
2065
|
+
* for, or that no row carries the id at all.
|
|
2066
|
+
*/
|
|
2067
|
+
function describeBlockers(ids: readonly string[], registry: WorkerRegistry | undefined): string {
|
|
2068
|
+
return ids
|
|
2069
|
+
.map((id) => {
|
|
2070
|
+
const dependency = registry ? knownWorker(registry, id) : undefined;
|
|
2071
|
+
return dependency ? `${id} (status ${dependency.status})` : `${id} (no row)`;
|
|
2072
|
+
})
|
|
2073
|
+
.join(", ");
|
|
2074
|
+
}
|
|
2075
|
+
|
|
1779
2076
|
/**
|
|
1780
2077
|
* Compute the verdict for a worker entry. `completed` requires the output
|
|
1781
2078
|
* file to exist and the result schema to parse (impl spec also requires at
|
|
@@ -1807,6 +2104,12 @@ function normalizeLiveStatus(raw?: string): "working" | "blocked" | "done" | "id
|
|
|
1807
2104
|
* recorded gate exited 0. None of the three is the no-effect-evidence flag;
|
|
1808
2105
|
* the flag is a field on the verdict, never a different status, and a row
|
|
1809
2106
|
* that is not a terminal completion carries null.
|
|
2107
|
+
*
|
|
2108
|
+
* A row whose `dependsOn` holds an id that is not `merged` or `completed`
|
|
2109
|
+
* reads as `blocked`, naming each blocking id with the status it carries; the
|
|
2110
|
+
* row's own stored status travels beside the verdict, so a blocked row and a
|
|
2111
|
+
* ready one are never the same answer. The dependencies are read against the
|
|
2112
|
+
* registry the row belongs to, which checkWorker supplies.
|
|
1810
2113
|
*/
|
|
1811
2114
|
export function evaluateWorker(
|
|
1812
2115
|
entry: WorkerEntry,
|
|
@@ -1834,6 +2137,9 @@ export function evaluateWorker(
|
|
|
1834
2137
|
branchAhead,
|
|
1835
2138
|
})
|
|
1836
2139
|
: null;
|
|
2140
|
+
// Dependencies are read off the registry the row belongs to; without it the
|
|
2141
|
+
// answer is not knowable here, so no row is called blocked on a guess.
|
|
2142
|
+
const blockedBy = opts.registry ? unsatisfiedDependencies(entry, opts.registry) : [];
|
|
1837
2143
|
// The stall window is read once: a session written inside it is liveness a
|
|
1838
2144
|
// checkpoint must not outrank, and it is the only case where a checkpoint
|
|
1839
2145
|
// changes the verdict.
|
|
@@ -1843,6 +2149,8 @@ export function evaluateWorker(
|
|
|
1843
2149
|
|
|
1844
2150
|
const base = {
|
|
1845
2151
|
workerId: entry.workerId,
|
|
2152
|
+
storedStatus: entry.status,
|
|
2153
|
+
blockedBy,
|
|
1846
2154
|
outputFile: entry.outputFile,
|
|
1847
2155
|
outputExists,
|
|
1848
2156
|
outputAgeSec,
|
|
@@ -1871,6 +2179,19 @@ export function evaluateWorker(
|
|
|
1871
2179
|
reason: `closed ${entry.closedAt} with outcome ${entry.status}`,
|
|
1872
2180
|
};
|
|
1873
2181
|
}
|
|
2182
|
+
// A row waiting on a dependency nothing delivered is not actionable, whatever
|
|
2183
|
+
// it has recorded itself: the verdict says so and names the ids, and the row's
|
|
2184
|
+
// own status is reported beside it rather than overwritten. A closed row is
|
|
2185
|
+
// exempt above — its outcome is already decided, and its dependents read that.
|
|
2186
|
+
if (blockedBy.length > 0) {
|
|
2187
|
+
return {
|
|
2188
|
+
...base,
|
|
2189
|
+
status: "blocked",
|
|
2190
|
+
reason:
|
|
2191
|
+
`waits on ${describeBlockers(blockedBy, opts.registry)}; ` +
|
|
2192
|
+
`stored status ${entry.status}`,
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
1874
2195
|
if (entry.status === "error") {
|
|
1875
2196
|
return { ...base, status: "error", reason: "registry marked error" };
|
|
1876
2197
|
}
|
|
@@ -2010,7 +2331,12 @@ export function checkWorker(
|
|
|
2010
2331
|
const located = locateWorker(workerId, opts.cwd);
|
|
2011
2332
|
if (!located) return null;
|
|
2012
2333
|
const fallbackBranch = opts.fallbackBranch ?? lockBranchFor(workerId, located.key);
|
|
2013
|
-
|
|
2334
|
+
// The located registry is the one this entry's dependencies are read against.
|
|
2335
|
+
return evaluateWorker(located.registry.workers[workerId], {
|
|
2336
|
+
...opts,
|
|
2337
|
+
fallbackBranch,
|
|
2338
|
+
registry: located.registry,
|
|
2339
|
+
});
|
|
2014
2340
|
}
|
|
2015
2341
|
|
|
2016
2342
|
// ── Fleet statistics ───────────────────────────────────────────────────────
|