abso 690: while a seat holds its news stream, the abso-hooks mod's 30-second news poll stands down. abso news --stream marks the folder (.abso/news-stream.json) for the Monitor's 30 minutes plus the ticket's minute; --follow renews the mark on open and at each 45-second ping. The poll asks again once the mark runs out. Tests: client/test/news-stream.test.ts, client/hooks/register.test.ts (node client/test-mods.ts). Version 270 of shared· box-grants· Oct 15 (2026-10-15 22:01 UTC) · Not checked
Version 269 · Files at version 270
5 files, 58 lines added, 2 removed.
--- a/client/hooks/register.test.ts
+++ b/client/hooks/register.test.ts
@@ -62,6 +62,16 @@
62 62 expect(log.split("\n").filter((l) => l.includes("Announcement from lead"))).toHaveLength(1); 65 + test("while the seat holds its news stream (abso 690), the poll stands down, and asks again once the mark runs out", async ($, on) => { 66 + const w = world(on, true, [[], []]); 67 + w.written.set("/w/p/.abso/news-stream.json", JSON.stringify({ until: 1_000_000 + 95_000 })); 68 + await $.session.start({ cwd: "/w/p" }); 69 + await w.clock.advance(90_000); 70 + expect(w.asked).toEqual([]); 71 + await w.clock.advance(30_000); 72 + expect(w.asked).toEqual(["https://avcs.test/p/p/a/bob/news"]); 65 75 test("outside an abso folder it never asks", async ($, on) => { 66 76 const w = world(on, false, [["should not arrive"]]); 67 77 await $.session.start({ cwd: "/w/p" }); --- a/client/hooks/register.ts
+++ b/client/hooks/register.ts
@@ -217,6 +217,12 @@
217 217 /** Ask for the news waiting for this agent (announcements, collisions) and hand it to the model. */ 218 218 async function pollNews($: Engine, root: string): Promise<void> { 220 + // While this seat holds its news stream (abso news --stream or --follow, abso 690), the stream wakes the chat. 221 + const mark = await readOr($, `${await stateOf($, root)}/news-stream.json`); 222 + if (mark !== undefined) { 223 + const until = Number((JSON.parse(mark) as { until?: unknown }).until); 224 + if (Number.isFinite(until) && until > (await $.clock.now())) return; 220 226 const config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as { --- a/client/src/announce.ts
+++ b/client/src/announce.ts
@@ -2,11 +2,14 @@
2 2 // delivered once as news on each one's next edit (or the mod's next poll), 3 3 // and the news waiting for this agent. 5 + import { writeFileSync } from "node:fs"; 6 + import { join } from "node:path"; 5 7 import { newsLines } from "./api.ts"; 6 8 import { bool, type Parsed, str, UsageError } from "./args.ts"; 7 9 import { type Env, type Output, open, plural } from "./commands.ts"; 8 10 import { logNews } from "./folder.ts"; 9 − import { follow, monitorArgs, type Socket, streamText } from "./news-stream.ts";
11 + import { follow, monitorArgs, type Socket, STREAM_MARK, streamMarkUntil, streamText } from "./news-stream.ts"; 12 + import { stateDir } from "./state-dir.ts"; 10 13 import { newsWithTime } from "./times.ts"; 12 15 export async function runAnnounce(args: Parsed, env: Env): Promise<Output> { @@ -74,12 +77,22 @@
74 77 return { text: lines.join("\n"), json: { ...answer } }; 80 + /** Says this folder's seat holds its news stream until `until`, so the abso-hooks mod's poll stands down. Best effort. */ 81 + function markStream(root: string, until: number): void { 83 + writeFileSync(join(stateDir(root), STREAM_MARK), JSON.stringify({ until })); 85 + // The mod keeps polling; nothing is lost. 77 89 export async function runNews(args: Parsed, env: Env): Promise<Output> { 78 90 const { root, config, api } = open(env); 79 91 if (bool(args, "stream") && bool(args, "follow")) 80 92 throw new UsageError("abso news takes --stream or --follow, not both"); 81 93 if (bool(args, "stream")) { 82 94 const ticket = await api.newsTicket(); 95 + markStream(root, streamMarkUntil(ticket, Date.now())); 84 97 text: streamText(ticket, config.project, config.agent), 85 98 json: { monitor: monitorArgs(ticket, config.project, config.agent), expiresAt: ticket.expiresAt }, @@ -99,6 +112,7 @@
99 112 logNews(root, [line]); 100 113 env.write(`${line.replace(/\r?\n/g, " ")}\n`); 115 + held: (until) => markStream(root, until), 103 117 env.write(`${line} --- a/client/src/news-stream.ts
+++ b/client/src/news-stream.ts
@@ -43,6 +43,14 @@
46 + /** The file that says this folder's seat holds its stream, until when: the abso-hooks mod's news poll skips meanwhile. */ 47 + export const STREAM_MARK = "news-stream.json"; 49 + /** How long --stream's mark holds: the Monitor's 30 minutes, and the minute the ticket waits to be used. */ 50 + export function streamMarkUntil(ticket: NewsTicket, now: number): number { 51 + return Math.max(now, ticket.expiresAt) + MONITOR_TIMEOUT_MS; 46 54 /** The part of a WebSocket --follow uses: the platform's own, or a test's. */ 47 55 export interface Socket { 48 56 onopen: (() => void) | null; @@ -79,6 +87,8 @@
79 87 sleep(ms: number): Promise<void>; 81 89 every(ms: number, fn: () => void): () => void; 90 + /** Called when a socket opens and at each ping: the stream is held until the next ping is due, and a little more. */ 91 + held?(until: number): void; 82 92 /** Set when --follow should stop (Ctrl-C, or a test). */ 83 93 readonly stopped: () => boolean; @@ -111,9 +121,13 @@
111 121 const socket = deps.connect(ticket.url, ticket.protocols); 112 122 let stopPing = () => {}; 113 123 socket.onopen = () => { 124 + deps.held?.(deps.now() + 2 * PING_MS); 114 125 stopPing = deps.every(PING_MS, () => { 115 126 if (deps.stopped()) socket.close(1000); 116 − else socket.send(PING);
129 + deps.held?.(deps.now() + 2 * PING_MS); 119 133 socket.onmessage = (e) => { --- a/client/test/news-stream.test.ts
+++ b/client/test/news-stream.test.ts
@@ -15,6 +15,8 @@
19 21 } from "../src/news-stream.ts"; @@ -127,10 +129,20 @@
128 130 test("--follow keeps an idle socket open with a ping the object answers without waking", async () => { 129 131 const w = world([{ frames: [], close: { code: 1006 } }]); 132 + const held: number[] = []; 133 + w.deps.held = (until) => held.push(until); 130 134 await follow(w.deps); 131 135 assert.deepEqual(w.sent, [PING]); 136 + // The stream mark is renewed on open and at each ping, two pings ahead, so the mod's poll stands down meanwhile. 137 + // The first socket opens and pings; the second opens a second later. 138 + assert.deepEqual(held, [NOW + 2 * PING_MS, NOW + 2 * PING_MS, NOW + 1_000 + 2 * PING_MS]); 141 + test("--stream's mark holds for the Monitor's 30 minutes after the ticket's minute", () => { 142 + assert.equal(streamMarkUntil(ticket(1), NOW), NOW + 60_000 + MONITOR_TIMEOUT_MS); 143 + assert.equal(STREAM_MARK, "news-stream.json"); 134 146 test("a refused ticket or a refusal close ends --follow; a ticket that can't be had is tried again", async () => { 135 147 const refusedClose = world([{ frames: ["one item"], close: { code: 4401, reason: "the key was revoked" } }]); 136 148 assert.deepEqual(await follow(refusedClose.deps), { ended: "refused", reason: "the key was revoked" });