pi-straw-boss 0.80.8 → 0.80.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24547,14 +24547,15 @@ var failure = (cause) => {
24547
24547
  return { status: error instanceof Refused || unreadable ? 409 : 400, body: { error: error instanceof Refused ? "refused" : unreadable ? "unreadable" : "bad_request", reason: error.message } };
24548
24548
  };
24549
24549
  var held = /* @__PURE__ */ new Map();
24550
- var HELD_MS2 = 5 * 6e4;
24550
+ var HELD_MS2 = 25 * 6e4;
24551
24551
  async function lateNotice(d, workspace, json3, via = "pi") {
24552
24552
  const key2 = `${workspace}
24553
24553
  ${String(json3.id)}`, hold = held.get(key2);
24554
24554
  if (via !== "ask") return { status: 409, body: { error: "refused", reason: "no notice is held for that session" } };
24555
- if (json3.clear === true) return held.delete(key2), { status: 200, body: { cleared: hold !== void 0 } };
24556
24555
  const raiser = updateMemory(d.slot, workspace, d.now(), () => void 0).memory.entries.find((e) => e.id === json3.id)?.card?.from?.id;
24557
- if (!hold || !raiser || json3.asker !== raiser || d.now() - hold.at > HELD_MS2) return held.delete(key2), { status: 409, body: { error: "refused", reason: "no notice is held for that session" } };
24556
+ const mine = hold !== void 0 && raiser !== void 0 && json3.asker === raiser;
24557
+ if (json3.clear === true) return mine && (hold.cleared = true), { status: 200, body: { cleared: mine } };
24558
+ if (!hold || !mine || hold.cleared && json3.recover !== true || d.now() - hold.at > HELD_MS2) return !hold || d.now() - hold.at > HELD_MS2 ? held.delete(key2) : false, { status: 409, body: { error: "refused", reason: "no notice is held for that session" } };
24558
24559
  held.delete(key2);
24559
24560
  let timer;
24560
24561
  const cutOff = new Promise((resolve10) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-straw-boss",
3
- "version": "0.80.8",
3
+ "version": "0.80.9",
4
4
  "description": "Straw Boss coordination for pi in Herdr: sessions join a tab's net by choice, the first joiner is its main agent, a workspace tower opens on demand with a live monitoring dashboard, and boss_broadcast reaches the rest",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -142,18 +142,19 @@ const failure = (cause: unknown): { status: number; body: Record<string, unknown
142
142
  };
143
143
 
144
144
  /** The notice of a press whose raiser asked it itself (`asked`), kept in memory for `lateNotice`: the tool's result is that notice, unless its turn was stopped and the result never came (R-F006). A restart forgets them. */
145
- const held = new Map<string, { text: string; at: number; act: string; pressAt: string | undefined }>();
146
- /** A held notice older than this is dropped: the stopped turn's raiser is not sent a decision that old. */
147
- export const HELD_MS = 5 * 60_000;
145
+ const held = new Map<string, { text: string; at: number; act: string; pressAt: string | undefined; cleared?: boolean }>();
146
+ /** A held notice older than this is dropped: the stopped turn's raiser is not sent a decision that old. It outlasts a full round of 4 cards (`CAP_MS` 5 min each in waitask.ts) with a margin. */
147
+ export const HELD_MS = 25 * 60_000;
148
148
 
149
149
  /** `{ op: "wait-notice", id, asker }` at the `ask` door: the asker's turn was stopped after its press, so the raiser (the asker) is sent the notice the result would have been. Once, and only to the session that asked. */
150
150
  export async function lateNotice(d: PressDeps, workspace: string, json: Record<string, unknown>, via: PressDoor = "pi"): Promise<{ status: number; body: Record<string, unknown> }> {
151
151
  const key = `${workspace}\n${String(json.id)}`, hold = held.get(key);
152
152
  if (via !== "ask") return { status: 409, body: { error: "refused", reason: "no notice is held for that session" } };
153
- // `clear`: the tool's own result came back, so the held notice is not needed.
154
- if (json.clear === true) return (held.delete(key), { status: 200, body: { cleared: hold !== undefined } });
155
153
  const raiser = updateMemory(d.slot, workspace, d.now(), () => undefined).memory.entries.find((e) => e.id === json.id)?.card?.from?.id;
156
- if (!hold || !raiser || json.asker !== raiser || d.now() - hold.at > HELD_MS) return (held.delete(key), { status: 409, body: { error: "refused", reason: "no notice is held for that session" } });
154
+ const mine = hold !== undefined && raiser !== undefined && json.asker === raiser;
155
+ // `clear`: the tool's own result came back, so the held notice is not needed. Only the raiser's own call clears it, and the hold stays (marked) until it expires, so a stop that lands during the request can `recover` it.
156
+ if (json.clear === true) return (mine && (hold.cleared = true), { status: 200, body: { cleared: mine } });
157
+ if (!hold || !mine || (hold.cleared && json.recover !== true) || d.now() - hold.at > HELD_MS) return (!hold || d.now() - hold.at > HELD_MS ? held.delete(key) : false, { status: 409, body: { error: "refused", reason: "no notice is held for that session" } });
157
158
  held.delete(key);
158
159
  let timer: ReturnType<typeof setTimeout> | undefined;
159
160
  const cutOff = new Promise<{ status?: string }>((resolve) => { timer = setTimeout(() => resolve({ status: "failed" }), d.waitMs ?? NOTICE_WAIT_MS); timer.unref?.(); });
package/src/waitask.ts CHANGED
@@ -85,6 +85,15 @@ export function createWaitAsk(d: WaitAskDeps) {
85
85
  const r = await d.ask({ cmd: "tower-memory", workspace, json: { ...json, ...(asker ? { asker } : {}) }, via: "ask" });
86
86
  return { ok: r.ok, ...(typeof r.error === "string" ? { error: r.error } : {}), ...(typeof r.status === "number" ? { status: r.status } : {}), ...(typeof r.body === "object" && r.body !== null ? { body: Object.fromEntries(Object.entries(r.body)) } : {}) };
87
87
  };
88
+ let late = false;
89
+ // The round's end settles each held notice (the server holds one longer than a full round of cards). A stop is read after the clear is decided: then the held notice is recovered and sent.
90
+ const settle = async (workspace: string, id: string) => {
91
+ const call = (extra: Record<string, unknown>) => memory(workspace, { op: "wait-notice", id, ...extra }).catch(() => undefined);
92
+ if (signal?.aborted) return void ((await call({}))?.ok === true && (late = true));
93
+ await call({ clear: true });
94
+ cleared.push({ workspace, id });
95
+ };
96
+ const cleared: { workspace: string; id: string }[] = [];
88
97
  /** One card's dialog, with the look at the list beside it: how it ended as the result's line, and why the round ends there, if it does. */
89
98
  const show = async (row: Row, more: boolean): Promise<{ line: string; stop?: string }> => {
90
99
  const ac = new AbortController(), id = name(row), key = keyOf(row);
@@ -135,8 +144,11 @@ export function createWaitAsk(d: WaitAskDeps) {
135
144
  }
136
145
  }));
137
146
  // The raiser that asked is told by this result alone: the server sends it no `wait_card` for its own ask. A turn stopped after the press never gets the result: sb sends the notice then, and drops what it held once the result does come.
138
- let late = false;
139
- if (asker) for (const p of pressedAt) late = ((await memory(p.workspace, { op: "wait-notice", id: p.id, ...(signal?.aborted ? {} : { clear: true }) }).catch(() => undefined))?.ok === true && signal?.aborted === true) || late;
147
+ if (asker) {
148
+ for (const p of pressedAt) await settle(p.workspace, p.id);
149
+ // A stop landing during any settle: each card already cleared this round gets its held notice recovered, once.
150
+ if (signal?.aborted) for (const c of cleared) (await memory(c.workspace, { op: "wait-notice", id: c.id, recover: true }).catch(() => undefined))?.ok === true && (late = true);
151
+ }
140
152
  return { text: [...lines, ...(asker && pressed && !late ? ["This is the boss's answer: no wait_card message follows."] : [])].join("\n"), details: { asked: queue.length } };
141
153
  };
142
154
  }