Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit b882acd9fdf13cd80d3a32910abe07bbbbcffd4e
parent 7124bdeb5ce697fd6c3ff1c3fe73aa5feacf5db2
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  2 Nov 2026 02:47:08 -0500

umtool: the inserters read the link policy's webpage_url inside the write's lock (structural's `prepare`), so a write's place in the lock's queue is where it was called

A stale-token write that read the record first entered the lock after the writes started after it, and their refusals went unhandled (clipEditor.test.mjs "a stale token is refused by every operation"). The read now runs in the lock, after the token is checked; the e2e spec cites via its own site.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/lib/report/manifest.mjs | 30+++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -1054,8 +1054,7 @@ export async function mergeClips(dir, clipId, { token = null, quote, now = null * @param {{ token?: string | null, now?: string | null }} [opts] */ export async function addClip(dir, spec, { token = null, now = null } = {}) { - const webpageUrl = await policyWebpage(dir, spec); - return prepAfter(dir, (r) => [r.id], structural(dir, "add", token, (m) => { + return prepAfter(dir, (r) => [r.id], structural(dir, "add", token, (m, webpageUrl) => { if (!isObj(spec)) throw new Error("a clip to add is { video, cutStart, cutEnd }"); if (typeof spec.video !== "string" || !/^[\w.-]+$/.test(spec.video)) throw new Error("a clip needs its video id"); const num = (k, v) => { @@ -1096,7 +1095,7 @@ export async function addClip(dir, spec, { token = null, now = null } = {}) { } m.timeline.splice(at, 0, entry); return { id: entry.id, at, entry }; - })); + }, { prepare: (m) => policyWebpage(dir, m, spec) })); } @@ -2045,13 +2044,16 @@ export function reanchorAfterRemove(m, removed, i) { * One structural write: token, read, `mutate` (which throws to refuse), the * build's checks, the auto snapshot of the file as it still is, then the write. */ -async function structural(dir, op, token, mutate, { snapshotEvery = undefined } = {}) { +async function structural(dir, op, token, mutate, { snapshotEvery = undefined, prepare = null } = {}) { return withManifestLock(async () => { const current = await manifestToken(dir); if (token !== null && current !== token) throw new StaleToken(token, current); const manifest = JSON.parse(await readFile(manifestFile(dir), "utf8")); const timelineBefore = Array.isArray(manifest.timeline) ? [...manifest.timeline] : []; - const result = applyStructural(manifest, mutate); + // What a write must read before it mutates (an inserter's link policy: + // the record's webpage_url), inside the lock, after the token is checked. + const prepared = prepare ? await prepare(manifest) : undefined; + const result = applyStructural(manifest, (m) => mutate(m, prepared)); const snapshot = await autoSnapshot(dir, op, snapshotEvery === undefined ? {} : { every: snapshotEvery }); const nextToken = await writeManifestAtomic(dir, manifest); // The project's take patches follow a removal as the manifest's markers @@ -2244,33 +2246,27 @@ function clipEntry(timeline, e) { * @param {{ token?: string | null, at?: number | null }} [opts] `at` is afterId's index */ export async function insertEntry(dir, afterId, spec, { token = null, at = null } = {}) { - const webpageUrl = await policyWebpage(dir, typeof spec === "string" ? parseClipSpec(spec) : spec); - return prepAfter(dir, clipIdOf, structural(dir, "insert", token, (m) => { + return prepAfter(dir, clipIdOf, structural(dir, "insert", token, (m, webpageUrl) => { const i = afterId ? entryIndex(m.timeline, afterId, at) + 1 : 0; const entry = entryFromSpec(m.timeline, spec); // A clip's QR is the project's link policy's (linkPolicy.mjs), not a copied link that breaks it. if (entry.type === "clip") applyPolicyLink(m, entry, webpageUrl); m.timeline.splice(i, 0, entry); return { id: entry.id, at: i, entry }; - })); + }, { prepare: (m) => policyWebpage(dir, m, typeof spec === "string" ? parseClipSpec(spec) : spec) })); } // ---- the link policy (UI notes 2026-10-30, #10; linkPolicy.mjs) ----------- /** * The record's webpage_url when the project's link policy links `spec`'s - * channel direct, else null: read BEFORE the write's lock (a file read), so - * the inserters can write the platform link in the same write. + * channel direct, else null: read inside the write's lock (structural's + * `prepare`), so the inserters write the platform link in the same write. * @param {string} dir + * @param {Record<string, any>} m the manifest as the write read it * @param {{ channel?: string, video?: string } | null | undefined} spec */ -async function policyWebpage(dir, spec) { - let m; - try { - m = JSON.parse(await readFile(manifestFile(dir), "utf8")); - } catch { - return null; - } +async function policyWebpage(dir, m, spec) { const policy = linkPolicyOf(m); if (!policy?.direct.length || !spec || typeof spec !== "object") return null; const chan = typeof spec.channel === "string" && spec.channel ? spec.channel : m.provenance?.channelSlug;