Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions server/control/control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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));
Expand Down
17 changes: 14 additions & 3 deletions server/control/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions server/orchestrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion web/src/control/usePoolSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down