@cohortapp/agent-sdk 2.18.21 → 2.18.23

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.
@@ -228,7 +228,7 @@ export function buildNoticeSystemPrompt(o = {}) {
228
228
  kind === "failure:retrying"
229
229
  ? "You are running it again right now. Say so."
230
230
  : kind === "interrupted"
231
- ? "Your machine restarted under the work; you have picked it back up. Say so."
231
+ ? "The session running the work stopped and a new one took over; you have picked it back up. Say so. Do NOT say your machine restarted — the only thing observed is that the process was replaced."
232
232
  : "You have stopped retrying and flagged it. Offer them the choice: narrow it, hand it to someone else, or leave it.";
233
233
  return [
234
234
  `You are ${who}, writing in a workplace chat. A piece of work someone is waiting on has gone wrong, and you are telling them — now, before they ask.`,
@@ -329,7 +329,21 @@ export function fallbackNotice(o = {}) {
329
329
  const topic = quotableTopic(o.topic);
330
330
  const about = topic ? `The work on "${topic}"` : `The work you asked for`;
331
331
  if (o.kind === "interrupted") {
332
- return `${about} was cut off part-way — my machine restarted under it. I've picked it back up from where it stopped.`;
332
+ // SAYS WHAT WAS OBSERVED, NOT WHAT IT GUESSES. The trigger is narrow:
333
+ // assurance.mjs sweepObligations fires this when the obligation's recorded
334
+ // daemonPid differs from the running process AND that pid is gone — i.e.
335
+ // THE DAEMON PROCESS WAS REPLACED. That is not a machine restart. A daemon
336
+ // is replaced by a crash, a launchd respawn, an upgrade, or a deliberate
337
+ // kickstart — including the one lib/session/revive.mjs performs when a
338
+ // front door goes quiet, so this fix's own sibling would have made the
339
+ // seat announce a reboot that never happened.
340
+ //
341
+ // Naming a cause the layer did not observe is the defect that cost this
342
+ // fleet days: the seat's attention record used to guess "probably waiting
343
+ // on a first-run dialog" when the screen held a subscription-limit prompt,
344
+ // and everyone searched where the guess pointed. A person acts on what a
345
+ // colleague tells them, so a notice may only assert what it saw.
346
+ return `${about} was cut off part-way — the session running it stopped and a new one took over. I've picked it back up from where it stopped.`;
333
347
  }
334
348
  if (o.willRetry || o.kind === "failure:retrying") {
335
349
  return `${about} broke before it finished: ${cause}. I'm running it again now.`;
@@ -349,6 +349,14 @@ export async function fetchHistory(params = {}, o = {}) {
349
349
  channelId: channel,
350
350
  channel,
351
351
  ...(params.since != null ? { since: params.since } : {}),
352
+ // `before` (an id: the oldest row of the page you have) is how a reader
353
+ // pages BACK past the newest window. Without it every page is page 0 and
354
+ // an older human post reads as never having existed — the seat-local
355
+ // 8a109a3 fix, carried here so an upgrade cannot clobber it again.
356
+ ...(params.before != null ? { before: params.before } : {}),
357
+ // A thread reply lives only in its thread: a room-level read never
358
+ // shows it, so a reader (or a readback of its own send) needs the id.
359
+ ...(params.threadId != null ? { threadId: params.threadId } : {}),
352
360
  ...(params.cursor != null ? { cursor: params.cursor } : {}),
353
361
  ...(Number.isFinite(params.limit) ? { limit: params.limit } : {}),
354
362
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohortapp/agent-sdk",
3
- "version": "2.18.21",
3
+ "version": "2.18.23",
4
4
  "description": "Cohort Agent SDK — autonomous AI colleague runtime. Deploy senior AI colleagues on dedicated Mac minis, wired to the Cohort operating surface.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -98,7 +98,7 @@ import {
98
98
  noticeRejection,
99
99
  fallbackNotice,
100
100
  } from "../../lib/assurance/notice-voice.mjs";
101
- import { isRetiredFirstReply, firstReplyShape } from "../../lib/assurance/first-reply.mjs";
101
+ import { isRetiredFirstReply, firstReplyShape, REACTIONS } from "../../lib/assurance/first-reply.mjs";
102
102
  // The unit of acknowledgement is the CONVERSATION, not the message: four
103
103
  // messages in a row earn ONE first response that was written with all four in
104
104
  // front of it. `groupIntoBatches` + `batchVerdict` decide WHEN and WHICH;
@@ -227,12 +227,17 @@ export const INTERRUPT_GRACE_MS = num(process.env.ASSURANCE_INTERRUPT_GRACE_MS,
227
227
  /**
228
228
  * Budget for generating the ONE-LINE contextual acknowledgement. Tight on
229
229
  * purpose: an ack that arrives a minute late has already failed at its job,
230
- * and the fallback is deliberate silence (the sweep retries generation once
231
- * once past ACK_AFTER_MS, then stops). NOTE: this is knowingly aggressive for a
232
- * cold `claude --print` spawn — the CEO chose "occasionally silent" over
233
- * "reliably canned". Operators can widen it via env.
230
+ * and the fallback after ACK_GEN_MAX_FAILURES is a REACTION where the surface
231
+ * has one, and only then silence (the sweep retries generation once past
232
+ * ACK_AFTER_MS, then stops). The CEO chose "occasionally silent" over
233
+ * "reliably canned"; he did not choose "reliably silent". At 5s a cold
234
+ * `claude --print` spawn timed out 13 times on one seat on 2026-09-30 and
235
+ * every one of those asks read, from the room, as the person being ignored —
236
+ * the exact symptom the owner raised at 14:18Z that day. 20s keeps the line
237
+ * contextual (it is still generated from the thread, never canned) and lets a
238
+ * cold spawn finish. Operators can widen or narrow it via env.
234
239
  */
235
- export const ACK_GEN_TIMEOUT_MS = num(process.env.ASSURANCE_ACK_GEN_TIMEOUT_MS, 5_000);
240
+ export const ACK_GEN_TIMEOUT_MS = num(process.env.ASSURANCE_ACK_GEN_TIMEOUT_MS, 20_000);
236
241
 
237
242
  /**
238
243
  * How many failed GENERATIONS (distinct from failed SENDS, which
@@ -1319,7 +1324,13 @@ function isAmbientSurface(rec) {
1319
1324
 
1320
1325
  /** A session interrupted by the daemon itself dying/restarting. */
1321
1326
  export function composeInterrupted() {
1322
- return `Heads up — my session on this was interrupted before it finished (my end restarted). I've picked it back up; I'll come back with the answer.`;
1327
+ // "(my end restarted)" claimed a machine reboot. What the trigger actually
1328
+ // observes (sweepObligations, below) is that the obligation's recorded
1329
+ // daemonPid is gone and a different process is running — the DAEMON was
1330
+ // replaced, which a crash, a launchd respawn, an upgrade or a deliberate
1331
+ // kickstart all do without the machine going anywhere. See the note in
1332
+ // lib/assurance/notice-voice.mjs#fallbackNotice.
1333
+ return `Heads up — my session on this was interrupted before it finished (the session running it was replaced). I've picked it back up; I'll come back with the answer.`;
1323
1334
  }
1324
1335
 
1325
1336
  // ---------------------------------------------------------------------------
@@ -2307,7 +2318,7 @@ async function _sweepObligations(a = {}) {
2307
2318
  const interruptedNotice = await generateFailureNotice(
2308
2319
  rec,
2309
2320
  {
2310
- failure: { human: "my end restarted while it was running" },
2321
+ failure: { human: "the session running it was replaced part-way through" },
2311
2322
  willRetry: false,
2312
2323
  kind: NOTICE.INTERRUPTED,
2313
2324
  mayWrite: claimWrittenVoice(rec, NOTICE.INTERRUPTED, now, a.deps && a.deps.roomNoticeImpl),
@@ -2537,8 +2548,33 @@ async function _sweepObligations(a = {}) {
2537
2548
  if (text == null) {
2538
2549
  rec.ackGenFailures = (rec.ackGenFailures || 0) + 1;
2539
2550
  if (rec.ackGenFailures >= ACK_GEN_MAX_FAILURES) {
2551
+ // A LINE THAT COULD NOT BE GENERATED IS NOT A REASON TO SAY NOTHING.
2552
+ // The directive forbids a CANNED line, not a reaction: "sometimes the
2553
+ // initial response can be an emoji response". A "seen" reaction says
2554
+ // exactly what is true here — the person was seen and the answer is
2555
+ // coming — without composing a sentence nothing generated. Only a
2556
+ // surface with no reactions falls through to silence, and that
2557
+ // silence is now logged with its cause rather than chosen quietly.
2558
+ if (canReactTo(item)) {
2559
+ const reactAfterFailure = (a.deps && a.deps.reactImpl) || deliverReaction;
2560
+ const rres = await reactAfterFailure(item, REACTIONS.seen);
2561
+ if (rres && rres.sent) {
2562
+ budgetOf({ service: rec.service, channel: rec.channel, now, agentRoot: AGENT_REPO_DIR, commit: true });
2563
+ rec.acknowledged = true;
2564
+ rec.ackAt = now;
2565
+ rec.interimSaid = true;
2566
+ rec.interimAt = now;
2567
+ rec.ackShape = "react-after-gen-failure";
2568
+ writeRecord(rec);
2569
+ counters.bump("assurance.interim_reaction_after_gen_failure", { failures: rec.ackGenFailures });
2570
+ console.warn(`[assurance] interim for ${rec.key}: line generation failed ${rec.ackGenFailures}x — acknowledged with a reaction instead of silence`);
2571
+ stats.acked++;
2572
+ continue;
2573
+ }
2574
+ counters.bump("assurance.interim_reaction_failed", { reason: (rres && rres.error) || "unknown", after: "gen-failure" });
2575
+ }
2540
2576
  rec.ackSuppressed = true;
2541
- console.warn(`[assurance] interim for ${rec.key} suppressed after ${rec.ackGenFailures} failed generations — deliberate silence, never a canned line`);
2577
+ console.warn(`[assurance] interim for ${rec.key} suppressed after ${rec.ackGenFailures} failed generations — silent, no reaction surface, never a canned line`);
2542
2578
  }
2543
2579
  writeRecord(rec);
2544
2580
  continue; // nothing to send; one decision per obligation per tick