From c7141ce1452d2ccae261f7287d953b86c650b098 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Fri, 27 Nov 2026 20:04:43 +0000 Subject: [PATCH 1/3] ci: let the prerelease smoke start the local host, and harden two flaky tests The prerelease workflow never got the polkit rule Verify PR and publish use, so the binary smoke could not start the local host in its own systemd scope and every prerelease since the pi port failed. stopHost now names what still answers and stops a second host, so one stuck host no longer fails three later tests. The outbox pool test accepts a retryable 5xx past SQLite's busy timeout on slow runners. --- .github/workflows/prerelease.yml | 6 ++++++ lib/hosts/local-daemon-start.test.mjs | 17 ++++++++++++++--- lib/message-outbox-review.test.mjs | 5 ++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index a0df3a36..1dee3a3c 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -56,6 +56,12 @@ jobs: env: TAU_RELEASE_TAG: ${{ env.RELEASE_TAG }} run: sh scripts/build-release-binaries.sh + # Hosted Linux runs in a service cgroup: the server starts the local host in its own systemd scope. + - name: Allow the local host's scope + run: | + rule="polkit.addRule(function(action, subject) { if (action.id === 'org.freedesktop.systemd1.manage-units' && subject.user === '$(id -un)' && /\\.scope$/.test(action.lookup('unit') || '')) { return polkit.Result.YES; } });" + printf '%s\n' "$rule" | sudo tee /etc/polkit-1/rules.d/49-tau-fixture-scopes.rules >/dev/null + systemd-run --scope --quiet --collect --no-ask-password true - run: npm run smoke -- --binary release/tau-linux-x64/tau - name: Publish the prerelease diff --git a/lib/hosts/local-daemon-start.test.mjs b/lib/hosts/local-daemon-start.test.mjs index 26a2e842..fbdcb88b 100644 --- a/lib/hosts/local-daemon-start.test.mjs +++ b/lib/hosts/local-daemon-start.test.mjs @@ -89,14 +89,25 @@ async function startFromServer(name) { /** Kills a host and waits until its endpoint stops answering, so the next start sees no daemon. */ async function stopHost(pid) { kill(pid); - for (let attempt = 0; attempt < 50; attempt++) { - try { await requestHostControl("status"); } + const deadline = Date.now() + 15_000; + let last; + while (Date.now() < deadline) { + let answering; + try { answering = (await requestHostControl("status")).pid; } catch (error) { if (["ENOENT", "ECONNREFUSED"].includes(error.code)) return; + last = `${error.code ?? "error"}: ${error.message}`; } + if (answering !== undefined && answering !== pid) { + // Another host took the endpoint: stop it too so later tests start clean, then fail this one. + launched.add(answering); + await stopHost(answering); + throw new Error(`a second host ${answering} answered after host ${pid} was killed`); + } + if (answering !== undefined) last = `host ${pid} answered`; await sleep(100); } - throw new Error(`host ${pid} still answers after SIGKILL`); + throw new Error(`host ${pid} still answers after SIGKILL (last: ${last})`); } test("with no daemon, the server prepares the link, then starts the host it launched", { timeout: 30_000 }, async () => { diff --git a/lib/message-outbox-review.test.mjs b/lib/message-outbox-review.test.mjs index 5fb37991..607df372 100644 --- a/lib/message-outbox-review.test.mjs +++ b/lib/message-outbox-review.test.mjs @@ -1402,7 +1402,10 @@ test("concurrent processes share the 1000-row active pool across arbitrary UUIDs outbox.outboxScope(); const results = await parallelAdds(6, 180, 1, 29_000); assert.equal(results.filter(([status]) => status === 200).length, 1000); - assert.equal(results.filter(([status, code]) => status === 429 && code === "outbox_full").length, 80); + // The rest are refused as full, or, on a slow runner, past the 5 s SQLite busy timeout as a 5xx the browser retries. + const refused = results.filter(([status]) => status !== 200); + assert.deepEqual(refused.filter(([status, code]) => !(status === 429 && code === "outbox_full") && status < 500), []); + assert.equal(refused.length, 80); const database = globalThis.__tauOutboxStore.db; assert.equal(database.prepare("SELECT COUNT(*) AS count FROM entries WHERE state != 'delivered'").get().count, 1000); const known = database.prepare("SELECT id, session_id FROM entries LIMIT 1").get(); From 2190a4c5085568c25d6e1797663a0a31e15adcc9 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Fri, 27 Nov 2026 20:11:40 +0000 Subject: [PATCH 2/3] test: keep the outbox pool test guarding the per-add lock fix; one stopHost deadline --- .github/workflows/prerelease.yml | 2 +- lib/hosts/local-daemon-start.test.mjs | 29 ++++++++++++++++----------- lib/message-outbox-review.test.mjs | 11 +++++----- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 1dee3a3c..35170851 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -57,7 +57,7 @@ jobs: TAU_RELEASE_TAG: ${{ env.RELEASE_TAG }} run: sh scripts/build-release-binaries.sh # Hosted Linux runs in a service cgroup: the server starts the local host in its own systemd scope. - - name: Allow the local host's scope + - name: Allow isolated native fixture scopes run: | rule="polkit.addRule(function(action, subject) { if (action.id === 'org.freedesktop.systemd1.manage-units' && subject.user === '$(id -un)' && /\\.scope$/.test(action.lookup('unit') || '')) { return polkit.Result.YES; } });" printf '%s\n' "$rule" | sudo tee /etc/polkit-1/rules.d/49-tau-fixture-scopes.rules >/dev/null diff --git a/lib/hosts/local-daemon-start.test.mjs b/lib/hosts/local-daemon-start.test.mjs index fbdcb88b..ed84babf 100644 --- a/lib/hosts/local-daemon-start.test.mjs +++ b/lib/hosts/local-daemon-start.test.mjs @@ -89,22 +89,27 @@ async function startFromServer(name) { /** Kills a host and waits until its endpoint stops answering, so the next start sees no daemon. */ async function stopHost(pid) { kill(pid); - const deadline = Date.now() + 15_000; + // Shorter than every caller's test timeout, so an abandoned loop cannot kill the next test's host. + const deadline = Date.now() + 8_000; let last; + let intruder; while (Date.now() < deadline) { - let answering; - try { answering = (await requestHostControl("status")).pid; } - catch (error) { - if (["ENOENT", "ECONNREFUSED"].includes(error.code)) return; - last = `${error.code ?? "error"}: ${error.message}`; - } - if (answering !== undefined && answering !== pid) { + try { + const answering = (await requestHostControl("status")).pid; + last = `host ${answering} answered`; // Another host took the endpoint: stop it too so later tests start clean, then fail this one. - launched.add(answering); - await stopHost(answering); - throw new Error(`a second host ${answering} answered after host ${pid} was killed`); + if (answering !== pid && answering !== process.pid) { + intruder = answering; + launched.add(answering); + kill(answering); + } + } catch (error) { + if (["ENOENT", "ECONNREFUSED"].includes(error.code)) { + if (intruder) throw new Error(`a second host ${intruder} answered after host ${pid} was killed`); + return; + } + last = `${error.code ?? "error"}: ${error.message}`; } - if (answering !== undefined) last = `host ${pid} answered`; await sleep(100); } throw new Error(`host ${pid} still answers after SIGKILL (last: ${last})`); diff --git a/lib/message-outbox-review.test.mjs b/lib/message-outbox-review.test.mjs index 607df372..332150fa 100644 --- a/lib/message-outbox-review.test.mjs +++ b/lib/message-outbox-review.test.mjs @@ -1374,7 +1374,7 @@ async function parallelAdds(workers, perWorker, bytes, timeoutMs) { const sid = '11111111-2222-4333-8444-' + number.toString(16).padStart(12, '0'); const response = await o.runOutboxCommand(sid, {type:'outbox_add', scope, id:'quota-'+number, mode:'prompt', message:'x'.repeat(${bytes})}, 'owner'); const body = await response.json(); - statuses.push([response.status, body.code]); + statuses.push([response.status, body.code, body.error]); } await new Promise(resolve => setTimeout(resolve, 50)); o.closeOutboxStore(); @@ -1402,10 +1402,11 @@ test("concurrent processes share the 1000-row active pool across arbitrary UUIDs outbox.outboxScope(); const results = await parallelAdds(6, 180, 1, 29_000); assert.equal(results.filter(([status]) => status === 200).length, 1000); - // The rest are refused as full, or, on a slow runner, past the 5 s SQLite busy timeout as a 5xx the browser retries. - const refused = results.filter(([status]) => status !== 200); - assert.deepEqual(refused.filter(([status, code]) => !(status === 429 && code === "outbox_full") && status < 500), []); - assert.equal(refused.length, 80); + // The rest are refused as full. A slow runner may exceed SQLite's 5 s busy timeout once or twice (a 500 the + // browser retries); more than that is the per-add lock contention ompweb#535 fixed. + const busy = results.filter(([status, , error]) => status === 500 && /database is locked|SQLITE_BUSY/.test(error ?? "")); + assert.ok(busy.length <= 2, `${busy.length} adds hit the busy timeout`); + assert.equal(results.filter(([status, code]) => status === 429 && code === "outbox_full").length, 80 - busy.length); const database = globalThis.__tauOutboxStore.db; assert.equal(database.prepare("SELECT COUNT(*) AS count FROM entries WHERE state != 'delivered'").get().count, 1000); const known = database.prepare("SELECT id, session_id FROM entries LIMIT 1").get(); From f97fd2851bde609c25886185b067b62dc7752214 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Fri, 27 Nov 2026 20:17:22 +0000 Subject: [PATCH 3/3] test: never kill a second host after stopHost's deadline; give its callers room for the cleanup --- lib/hosts/local-daemon-start.test.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/hosts/local-daemon-start.test.mjs b/lib/hosts/local-daemon-start.test.mjs index ed84babf..d7c57863 100644 --- a/lib/hosts/local-daemon-start.test.mjs +++ b/lib/hosts/local-daemon-start.test.mjs @@ -89,7 +89,7 @@ async function startFromServer(name) { /** Kills a host and waits until its endpoint stops answering, so the next start sees no daemon. */ async function stopHost(pid) { kill(pid); - // Shorter than every caller's test timeout, so an abandoned loop cannot kill the next test's host. + // Each caller's timeout covers its own work plus this deadline and one 3 s status request; nothing is killed after it. const deadline = Date.now() + 8_000; let last; let intruder; @@ -98,7 +98,7 @@ async function stopHost(pid) { const answering = (await requestHostControl("status")).pid; last = `host ${answering} answered`; // Another host took the endpoint: stop it too so later tests start clean, then fail this one. - if (answering !== pid && answering !== process.pid) { + if (answering !== pid && answering !== process.pid && Date.now() < deadline) { intruder = answering; launched.add(answering); kill(answering); @@ -130,7 +130,7 @@ test("an existing daemon, current or drained, is reused and nothing is launched" assert.deepEqual(await ensureLocalHostDaemon({ env: prodEnv(), launch: missingLaunch }), { started: false, pid: process.pid }); }); -test("a registered native supervisor owns startup beyond the old grace without a foreground fallback", { timeout: 15_000 }, async () => { +test("a registered native supervisor owns startup beyond the old grace without a foreground fallback", { timeout: 30_000 }, async () => { let supervised; const result = await ensureLocalHostDaemon({ env: prodEnv(), @@ -221,7 +221,7 @@ test("an active leased server update is not replaced by autostart, even if its c } }); -test("an expired server update does not block autostart", { timeout: 20_000 }, async (t) => { +test("an expired server update does not block autostart", { timeout: 40_000 }, async (t) => { const state = await import("../self-update-state.ts"); const root = state.resolveSelfUpdateTempRoot(); mkdirSync(root, { recursive: true, mode: 0o700 });