diff --git a/CHANGELOG.md b/CHANGELOG.md index 5299e266..a2fa7ac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to `sessionpipe-gui`. The format follows ## [Unreleased] +### Fixed + +- A message acknowledged as taken stays open past its expiry for the bounded delivery pause, allowing its final acknowledgement to be applied. + ## [0.8.18] - 2026-12-04 ### Fixed diff --git a/server/control/control.test.ts b/server/control/control.test.ts index cf49dc2f..392acba0 100644 --- a/server/control/control.test.ts +++ b/server/control/control.test.ts @@ -32,6 +32,7 @@ import { fileHash } from "./files.js"; import { type Control, createControl } from "./index.js"; import { parseAccounts, parseAcks, parseHello } from "./parse.js"; import { pairUrlFor } from "./routes.js"; +import { TAKEN_PAUSE_MS } from "./state.js"; import { commandStr, signCommand, signWithDevice, TestDayKey, TestDeviceKey, TestPasskey } from "./testkeys.js"; import { readKey, readProof } from "./ui.js"; @@ -709,6 +710,40 @@ describe("the queue", () => { expect(b.control.activity().find((a) => a.id === r.body.id)?.outcome).toBe("expired"); }); + it("a message the machine has taken is not expired at expires_at; its final ack is kept", async () => { + vi.useFakeTimers({ toFake: ["Date"] }); + const m = await enrolled(b, pk, "m_takenexpiry000000001"); + const r = await send(m.machine, await signedPrompt(pk, day, m.machine), { expires_in_s: 60 }); + const id = r.body.id as string; + expect((await poll(m)).body.messages!.map((x) => x.id)).toContain(id); + await ack(m, [{ id, outcome: "taken", mode: "sdk" }]); + vi.setSystemTime(Date.now() + 2 * 60_000); + expect((await poll(m)).status).toBe(204); + expect(b.control.activity().find((a) => a.id === id)).toMatchObject({ outcome: "taken" }); + await ack(m, [{ id, outcome: "delivered", reply: "Done." }]); + expect(b.control.activity().find((a) => a.id === id)).toMatchObject({ outcome: "delivered", reply: "Done." }); + + // Taken, then silence: once the taken pause is over it is closed `unconfirmed`, since the + // machine did take it. + const s = await send(m.machine, await signedPrompt(pk, day, m.machine), { expires_in_s: 60 }); + const sid = s.body.id as string; + await poll(m); + await ack(m, [{ id: sid, outcome: "taken" }]); + vi.setSystemTime(Date.now() + TAKEN_PAUSE_MS + 1000); + expect((await poll(m)).status).toBe(204); + expect(b.control.activity().find((a) => a.id === sid)).toMatchObject({ outcome: "unconfirmed" }); + + // A taken ack stamped by a machine clock far ahead holds the row no longer than the + // pause past expires_at. + const f = await send(m.machine, await signedPrompt(pk, day, m.machine), { expires_in_s: 60 }); + const fid = f.body.id as string; + await poll(m); + await ack(m, [{ id: fid, outcome: "taken", at: new Date(Date.now() + 24 * 3600_000).toISOString() }]); + vi.setSystemTime(Date.now() + 60_000 + TAKEN_PAUSE_MS); + await poll(m); + expect(b.control.activity().find((a) => a.id === fid)).toMatchObject({ outcome: "unconfirmed" }); + }); + it("off removes the machine, its token and its queue; forget does the same locally", async () => { const m = await enrolled(b, pk, "m_off00000000000000001"); await send(m.machine, await signedPrompt(pk, day, m.machine)); diff --git a/server/control/state.ts b/server/control/state.ts index 89fd3a80..406c5885 100644 --- a/server/control/state.ts +++ b/server/control/state.ts @@ -610,9 +610,20 @@ export class ControlState { // spacesheep's to settle (applyRemoteJobs): its day is its own, and it may still // hand the job out after this receiver's clock said the row was over. if (isRemoteRow(row)) continue; - row.outcome = "expired"; - row.ackedAt = new Date(now).toISOString(); - row.detail = "expired before the machine took it"; + // A `taken` row is the machine's to finish: its final ack follows (CONTROL.md ยง10). + // It stays open for the taken pause, and never longer than that past expires_at + // (takenAt is the machine's clock). After that it is `unconfirmed`, as remote.ts + // closes a job taken and never heard of again: the machine did take it. + if (row.takenAt) { + const taken = Date.parse(row.takenAt); + if (now - taken < TAKEN_PAUSE_MS && now - Date.parse(row.expiresAt) < TAKEN_PAUSE_MS) continue; + row.outcome = "unconfirmed"; + row.ackedAt = new Date(now).toISOString(); + } else { + row.outcome = "expired"; + row.ackedAt = new Date(now).toISOString(); + row.detail = "expired before the machine took it"; + } const m = this.machinesById.get(id); if (m && row.kind === "key.add") this.keyAddSettled(m, row); changed = true; diff --git a/server/orchestrate/index.ts b/server/orchestrate/index.ts index 455a231e..435783cf 100644 --- a/server/orchestrate/index.ts +++ b/server/orchestrate/index.ts @@ -81,8 +81,8 @@ export interface Orchestrate { /** The longest input a run takes, like a prompt's text. */ const INPUT_MAX = 20_000; /** How long a step's command stays queued: the queue's longest (a day), not its default - * hour. A step is an agent's whole task; expireQueue expires a `taken` row too, so under - * the default an implement step still running after an hour failed as `expired`. The + * hour. A step is an agent's whole task; expireQueue closes a `taken` row too (35 minutes + * on), so under the default an implement step still running after an hour failed. The * body's own `expires_in_s` is not the signer's to shorten here: the run owns the step. */ export const STEP_EXPIRES_MS = EXPIRES_MAX_MS; diff --git a/web/src/control/usePoolSend.ts b/web/src/control/usePoolSend.ts index c77234ee..fdae022d 100644 --- a/web/src/control/usePoolSend.ts +++ b/web/src/control/usePoolSend.ts @@ -42,7 +42,9 @@ export interface PoolSend { } const isLogin = (a: ControlActivity): boolean => !!a.poolAction?.startsWith("login"); -const onItsWay = (a: ControlActivity, now: number): boolean => !isFinal(a) && Date.parse(a.expiresAt) > now; +// A taken row stays open past expires_at until its final ack (state.ts expireQueue). +const onItsWay = (a: ControlActivity, now: number): boolean => + !isFinal(a) && (a.outcome === "taken" || Date.parse(a.expiresAt) > now); export function usePoolSend(m: MachineSummary): PoolSend { const control = m.control;