feat(queue): queue as data A2, migration, render and dispatch (#1508)

Filbert approved round 1 (f167b85e). Manifest 782bcb62, 21 files, plus
the QUEUE.md markers and the TOOLS.md section. Lead decision 35.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-09-26 20:14:09 -05:00
co-authored by Claude Opus 5.5
parent c9539baa0f
commit 6ca116b7ba
32 changed files with 4886 additions and 103 deletions
+15 -4
View File
@@ -129,16 +129,26 @@ export function acquire({ gitDir, io, proc = realProc, op = null, verb, waitMs =
try {
if (lstatOrNull(io, gate) !== null) c = classify(readOrNull(io, gate), proc);
} catch (err) {
const left = release(handle, io);
const left = releaseOrWarn(handle, io);
throw new QueueError(`cannot check the unlock gate ${gate}: ${errno(err)}; ${left ?? "lock released"}`, 1);
}
if (c !== null) {
release(handle, io);
throw new QueueError(`unlock gate ${gate} is present (${describe(c)}); check it with \`scripts/mosaic queue unlock --check-gate\``, 2);
const left = releaseOrWarn(handle, io);
throw new QueueError(`unlock gate ${gate} is present (${describe(c)}); check it with \`scripts/mosaic queue unlock --check-gate\`${left ? `\nwarning: ${left}` : ""}`, 2);
}
return handle;
}
// release() on a path that is already reporting something: a throw becomes
// a message naming the lock that may be left behind (P1).
export function releaseOrWarn(handle, io) {
try {
return release(handle, io);
} catch (err) {
return `cannot release the queue lock (${errno(err)}); ${handle.path} may be left in place`;
}
}
// Unlinks only the lock this process published: same inode, same record.
export function release(handle, io) {
const st = lstatOrNull(io, handle.path);
@@ -185,7 +195,8 @@ export function unlock({ gitDir, io, proc = realProc, hook = () => {} }) {
// Like the lock, a swapped gate is reported on success and on refusal (8.4).
if (msg && failure instanceof Error) failure.message += `\nwarning: ${msg}`;
if (failure) throw failure;
return msg ? `${result}\nwarning: ${msg}` : result;
// Apart, so the caller never splits a lock record's text to find it (P3).
return { result, warning: msg };
}
export function checkGate({ gitDir, io, proc = realProc }) {