paseo-follow-up 2.6.0 → 2.6.1

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  What changed in each version of Follow-up, newest first. Follow-up shows "What's new" after an update that brings new release notes: the curated part of each stable release since you last looked (betas install quietly; Settings → General can turn it off), and every version's notes from Home's version line.
4
4
 
5
+ ## 2.6.1 (2026-12-05)
6
+
7
+ One fix for 2.6.0.
8
+
9
+ - **No more "Stop hook error occurred" under your agents' messages.** Follow-up's turn-end reminders now reach the agent quietly, never cut into your next message, and never pause the workspace as if you had stopped the agent.
10
+
11
+ <details><summary>Full changelog since 2.6.0</summary>
12
+
13
+ ### Fixes
14
+
15
+ - Follow-up's turn-end reminders no longer show "Stop hook error occurred" in the chat, cut into your next message, or pause the workspace as if you stopped the agent.
16
+
17
+ </details>
18
+
5
19
  ## 2.6.0 (2026-12-01)
6
20
 
7
21
  A new workspace view, a redesigned sidebar, agents that show you their work, and lots of fixes.
package/index.server.ts CHANGED
@@ -78,7 +78,8 @@ import { Wait, waitStatus, type WaitPaseoConfig } from "./server/wait";
78
78
  import { removeGlobalRegistrations } from "./server/mcp-registrations";
79
79
  import { TrustBypass } from "./server/trust-bypass";
80
80
  import { scopes } from "./server/scopes";
81
- import { TurnEnd } from "./server/turn-end";
81
+ import { TurnEnd, isTurnEndItem, turnEndDelivery, turnEndItemId } from "./server/turn-end";
82
+ import { ourSendCanceled } from "./shared/status";
82
83
  import { updateObligation } from "./server/obligations";
83
84
  import { Inbox, INBOX_WRITE_MS, type GuardPause } from "./server/inbox";
84
85
  import { BriefTimeline } from "./server/brief-timeline";
@@ -448,6 +449,12 @@ export default function contribute(server: PluginServerContext) {
448
449
  if (!rows) return { defer: "Paseo unreachable" };
449
450
  const agent = rows.agents.find(r => r.agent.id === item.ref.agentId)?.agent;
450
451
  if (!agent || agent.archivedAt) return { cancel: "The agent was archived, so the message wasn't sent." };
452
+ // Invariant 247: a turn-end check never interrupts a running turn, and one a newer turn followed is dropped.
453
+ if (isTurnEndItem(item.id)) {
454
+ const startedAt = turnStartedAt.get(item.ref.agentId!);
455
+ const held = turnEndDelivery({ turnId: item.ref.turnId ?? null, latestTurn: startedTurns.get(item.ref.agentId!) ?? null, running: runningTurns.has(item.ref.agentId!) || agent.status === "running", startedSince: startedAt !== undefined && startedAt > Date.parse(item.createdAt) });
456
+ if (held) return held;
457
+ }
451
458
  return { target: { workspaceId: null, recipients: [item.ref.agentId!] } };
452
459
  },
453
460
  // No card of its own: one that didn't go out (Failed, or Queued past MESSAGE_STUCK_MS) shows in its workspace's
@@ -512,7 +519,7 @@ export default function contribute(server: PluginServerContext) {
512
519
  saveReceipt: async (workspaceId, receipt) => { if (/^[\w-]+$/.test(workspaceId)) await writeFile(join(directory, "hook-state", `task-nudges-${workspaceId}.json`), JSON.stringify(receipt), { mode: 0o600 }); },
513
520
  send: async (agentId, workspaceId, text, turnId) => {
514
521
  const messageId = randomUUID();
515
- queue.enqueue({ id: `turn-end:${agentId}:${turnId ?? messageId}`, kind: "message", key: workspaceId, ref: { agentId }, messageId, text, priority: "now", state: "queued" });
522
+ queue.enqueue({ id: turnEndItemId(agentId, turnId, messageId), kind: "message", key: workspaceId, ref: { agentId, ...(turnId ? { turnId } : {}) }, messageId, text, priority: "now", state: "queued" });
516
523
  },
517
524
  print: async agentId => {
518
525
  const w = agentTrackedWorkspace(await store.snapshot(), agentId);
@@ -576,6 +583,10 @@ export default function contribute(server: PluginServerContext) {
576
583
  let stopped = false;
577
584
  /** Each agent's latest started turn, so a turn end can tell it was already replaced (holdOnTurnEnd). */
578
585
  const startedTurns = new Map<string, string>();
586
+ /** Each agent's turn running now, from the turn events (invariant 247: a turn-end check waits for it). */
587
+ const runningTurns = new Map<string, string>();
588
+ /** When each agent's latest turn started (invariant 247: a turn end Paseo reports without a turn id). */
589
+ const turnStartedAt = new Map<string, number>();
579
590
  let timer: ReturnType<typeof setTimeout> | null = null;
580
591
  let hookTimer: ReturnType<typeof setInterval> | null = null;
581
592
  let dueTimer: ReturnType<typeof setInterval> | null = null;
@@ -919,7 +930,8 @@ export default function contribute(server: PluginServerContext) {
919
930
  current.milestones = { ...current.milestones, [agentId]: { ...next, at: new Date().toISOString() } };
920
931
  });
921
932
  await agentHooks.confirm(w.id, agentId, summary);
922
- return { workspaceId: w.id, synced: true as const };
933
+ const due = await agentHooks.dueFor(w, agentId);
934
+ return { workspaceId: w.id, synced: true as const, ...(due ? { due } : {}) };
923
935
  });
924
936
  handle(rpc.workspaceNowRpc, async ({ agentId }, { paseo }) => {
925
937
  await requireReady();
@@ -2315,7 +2327,8 @@ export default function contribute(server: PluginServerContext) {
2315
2327
  await rename(temporary, needsYouPath(agentId));
2316
2328
  // The caller is running, so its Needs-you row is live: an archived (gone) row would hide the brief this turn makes.
2317
2329
  if (!restated && call.kind !== "done") { await inbox.reopen(agentId).catch(() => false); feeds.inbox(); }
2318
- return { ok: true as const, briefId: `brief:${turn?.turnId ?? record.at}`,
2330
+ const due = tracked ? await agentHooks.dueFor(tracked, agentId) : undefined;
2331
+ return { ok: true as const, briefId: `brief:${turn?.turnId ?? record.at}`, ...(due ? { due } : {}),
2319
2332
  ...(restated ? { note: DISMISSED_ASK_NOTE }
2320
2333
  : stillArchived && call.kind !== "done" ? { note: ARCHIVED_NEEDS_YOU_NOTE }
2321
2334
  : dismissed.length ? { note: `The developer dismissed ${dismissed.join(", ")}: ${dismissed.length === 1 ? "it no longer matters, so it was" : "they no longer matter, so they were"} left off the card. Don't raise ${dismissed.length === 1 ? "it" : "them"} again.` } : {}) };
@@ -2477,7 +2490,8 @@ export default function contribute(server: PluginServerContext) {
2477
2490
  // superseded hold lifts, the owned workspace's Done ends, the main agent's archived workspace reopens (invariant
2478
2491
  // 111), and a dormant workspace becomes active again.
2479
2492
  server.on("agent.turn_started", async event => {
2480
- if (event.turnId) startedTurns.set(event.agent.id, event.turnId);
2493
+ turnStartedAt.set(event.agent.id, Date.now());
2494
+ if (event.turnId) { startedTurns.set(event.agent.id, event.turnId); runningTurns.set(event.agent.id, event.turnId); }
2481
2495
  engine.outsideTurnStarted(event.agent.id);
2482
2496
  await ready;
2483
2497
  if (stopped || loadError) return;
@@ -2540,6 +2554,7 @@ export default function contribute(server: PluginServerContext) {
2540
2554
  return withTools({ ...request, env: { ...request.env, FOLLOW_UP_CLI: bridge, FOLLOW_UP_CLIENT_ENTRY: clientEntry(), ...(recovery ? { FOLLOW_UP_RECOVERY: "1" } : {}), ...(main ? { FOLLOW_UP_BRIEF: main } : {}) } }, recovery, main, root && !recovery);
2541
2555
  })),
2542
2556
  server.on("agent.turn_ended", async (event, { paseo, signal }) => {
2557
+ if (!event.turnId || runningTurns.get(event.agent.id) === event.turnId) runningTurns.delete(event.agent.id);
2543
2558
  await ready;
2544
2559
  if (stopped || loadError) return;
2545
2560
  const interruption = event.outcome.kind === "canceled" || event.outcome.kind === "failed" ? { turnId: event.turnId, at: new Date().toISOString(), kind: event.outcome.kind } : null;
@@ -2563,7 +2578,9 @@ export default function contribute(server: PluginServerContext) {
2563
2578
  const newerTurn = !!started && started !== event.turnId;
2564
2579
  // Smart Session's own record of a /compact it just delivered: the canceled turn was that compaction.
2565
2580
  const compaction = event.outcome.kind === "canceled" && await compactionJustDelivered(event.agent.id, Date.parse(interruption!.at)).catch(() => false);
2566
- const nudged = await turnEnded(store, event.agent.id, event.outcome, event.turnId ?? null, items, { interruption, guarded, newerTurn, compaction });
2581
+ // Invariant 247: a cancel right after Follow-up's own send to this agent is that send's, never the developer's Stop.
2582
+ const ourSend = event.outcome.kind === "canceled" && ourSendCanceled(queue.lastSendTo(event.agent.id), Date.parse(interruption!.at));
2583
+ const nudged = await turnEnded(store, event.agent.id, event.outcome, event.turnId ?? null, items, { interruption, guarded, newerTurn, compaction, ourSend });
2567
2584
  if (nudged) void engine.nudge(nudged);
2568
2585
  // An outside run's ask the agent was answered on: re-read its run, and an answer it still shows open comes back once.
2569
2586
  await engine.outsideTurnEnded(event.agent.id).catch(() => undefined);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "paseo-follow-up",
3
3
  "private": false,
4
- "version": "2.6.0",
4
+ "version": "2.6.1",
5
5
  "description": "Every agent, one inbox. Follow-up brings what all your coding agents need from you into one ranked list, and follows their work through merge, deploy and after.",
6
6
  "type": "module",
7
7
  "files": [
@@ -353,7 +353,18 @@ async function main() {
353
353
  // Follow-up. The inbox reports this one as the Finished reason (server/inbox-classifier.ts finishedReply).
354
354
  if (typeof event.last_assistant_message === "string" && event.last_assistant_message.trim()) await save(join(directory, "hook-state", `bookkeeping-${agentId}.json`), { at: Date.now(), reply: event.last_assistant_message.slice(0, 4000) }).catch(() => undefined);
355
355
  const reasons = [detached ? detachedNotice : null, decision.due.length ? dueBlock(decision.due, native) : null, decision.sync ? (inPrompt.has("workspace") ? `${stopReason} ${syncBookkeeping} ${say(syncCall)}` : `${stopReason} ${syncBookkeeping}\n\n` + context()) : null, decision.nudge ? say(nudgeReason) : null].filter(Boolean);
356
- process.stdout.write(JSON.stringify({ decision: "block", reason: reasons.join("\n\n") }) + "\n");
356
+ process.stdout.write(JSON.stringify(stopOutput(env("PROVIDER"), event, reasons.join("\n\n"))) + "\n");
357
+ }
358
+ /**
359
+ * Invariant 246, a-turn-end-reminder-is-never-an-error: how the Stop hook keeps a turn going. Claude Code shows any
360
+ * `decision: "block"` to the user as "Stop hook error occurred", while Stop's `additionalContext` continues the turn
361
+ * with the same words and shows nothing (proven on Claude Code 2.1.323). Codex's Stop hook can only block, and its
362
+ * continuation is a hidden hook prompt Paseo doesn't draw. Codex is told by its provider or by the `turn_id` its Stop
363
+ * input carries (Claude Code's has none), so a Codex-based provider never gets a field it would ignore.
364
+ */
365
+ export function stopOutput(provider, event, text) {
366
+ const codex = provider === "codex" || typeof event?.turn_id === "string";
367
+ return codex ? { decision: "block", reason: text } : { hookSpecificOutput: { hookEventName: "Stop", additionalContext: text } };
357
368
  }
358
369
  // Tests import shouldNudge without running the hook; the worker imports workspaceInstructions the same way.
359
370
  if (env("HOOK_IMPORT") !== "1" && !globalThis.followUpHookLibrary) main().catch(() => {});
@@ -5,6 +5,9 @@ import { homedir, tmpdir } from "node:os";
5
5
  import { randomUUID } from "node:crypto";
6
6
  import { hookSource } from "./hook-source";
7
7
  import { backupOnce, writeTarget, writeThrough } from "./write-through";
8
+ import { dueByAgent, pickNudges, type NudgeReceipt } from "../shared/task-due";
9
+ import { dueBlock } from "../shared/turn-checks.mjs";
10
+ import type { Workspace } from "../shared/model";
8
11
 
9
12
 
10
13
  const events = ["SessionStart", "UserPromptSubmit", "PostToolUse", "Stop"];
@@ -80,6 +83,22 @@ export class AgentHooks {
80
83
  if (!/^[\w-]+$/.test(agentId)) throw new Error("Unsupported agent identity");
81
84
  await atomic(join(this.directory, "hook-state", `sync-${agentId}.json`), { workspaceId, at: Date.now(), summary });
82
85
  }
86
+ /**
87
+ * Invariant 246 (a-turn-end-reminder-is-never-an-error): the caller's due tasks, for its turn-end call's reply
88
+ * (sync_workspace, needs_you), counted in the receipt the Stop hook and the turn-end event read (`pickNudges`), so a
89
+ * turn that made its turn-end calls leaves the hook nothing to say. Undefined when nothing is due or all were said.
90
+ */
91
+ async dueFor(w: Workspace, agentId: string, now = Date.now()): Promise<string | undefined> {
92
+ if (!/^[\w-]+$/.test(w.id)) return undefined;
93
+ const due = dueByAgent(w, now)[agentId];
94
+ if (!due?.length) return undefined;
95
+ const path = join(this.directory, "hook-state", `task-nudges-${w.id}.json`);
96
+ const raw = await readFile(path, "utf8").then(t => JSON.parse(t) as unknown, () => null);
97
+ const picked = pickNudges(due, raw && typeof raw === "object" && !Array.isArray(raw) ? raw as NudgeReceipt : {}, now);
98
+ if (!picked.lines.length) return undefined;
99
+ await atomic(path, picked.receipt);
100
+ return dueBlock(picked.lines, true);
101
+ }
83
102
  async stop(): Promise<void> {
84
103
  await rm(join(this.directory, "hooks-enabled.json"), { force: true });
85
104
  await Promise.all(this.paths.map(path => install(path, null, this.directory)));
@@ -913,7 +913,18 @@ export const hookSource: string = [
913
913
  " // Follow-up. The inbox reports this one as the Finished reason (server/inbox-classifier.ts finishedReply).",
914
914
  " if (typeof event.last_assistant_message === \"string\" && event.last_assistant_message.trim()) await save(join(directory, \"hook-state\", `bookkeeping-${agentId}.json`), { at: Date.now(), reply: event.last_assistant_message.slice(0, 4000) }).catch(() => undefined);",
915
915
  " const reasons = [detached ? detachedNotice : null, decision.due.length ? dueBlock(decision.due, native) : null, decision.sync ? (inPrompt.has(\"workspace\") ? `${stopReason} ${syncBookkeeping} ${say(syncCall)}` : `${stopReason} ${syncBookkeeping}\\n\\n` + context()) : null, decision.nudge ? say(nudgeReason) : null].filter(Boolean);",
916
- " process.stdout.write(JSON.stringify({ decision: \"block\", reason: reasons.join(\"\\n\\n\") }) + \"\\n\");",
916
+ " process.stdout.write(JSON.stringify(stopOutput(env(\"PROVIDER\"), event, reasons.join(\"\\n\\n\"))) + \"\\n\");",
917
+ "}",
918
+ "/**",
919
+ " * Invariant 246, a-turn-end-reminder-is-never-an-error: how the Stop hook keeps a turn going. Claude Code shows any",
920
+ " * `decision: \"block\"` to the user as \"Stop hook error occurred\", while Stop's `additionalContext` continues the turn",
921
+ " * with the same words and shows nothing (proven on Claude Code 2.1.323). Codex's Stop hook can only block, and its",
922
+ " * continuation is a hidden hook prompt Paseo doesn't draw. Codex is told by its provider or by the `turn_id` its Stop",
923
+ " * input carries (Claude Code's has none), so a Codex-based provider never gets a field it would ignore.",
924
+ " */",
925
+ "export function stopOutput(provider, event, text) {",
926
+ " const codex = provider === \"codex\" || typeof event?.turn_id === \"string\";",
927
+ " return codex ? { decision: \"block\", reason: text } : { hookSpecificOutput: { hookEventName: \"Stop\", additionalContext: text } };",
917
928
  "}",
918
929
  "// Tests import shouldNudge without running the hook; the worker imports workspaceInstructions the same way.",
919
930
  "if (env(\"HOOK_IMPORT\") !== \"1\" && !globalThis.followUpHookLibrary) main().catch(() => {});",
@@ -641,7 +641,7 @@ export const mcpSource: string = [
641
641
  "function compact(tool, input, result) {",
642
642
  " if (actionNames.has(tool)) return result;",
643
643
  " if (tool === \"workspace_status\") return currentWork(result);",
644
- " if (tool === \"needs_you\") return { ok: result.ok, briefId: result.briefId };",
644
+ " if (tool === \"needs_you\") return { ok: result.ok, briefId: result.briefId, ...(result.due ? { due: result.due } : {}) };",
645
645
  " if (tool === \"declare_done\") return { workspaceId: result.workspace.id, done: !result.blockers.length, alreadyDone: !!result.alreadyDone, completion: result.workspace.completion, blockers: result.blockers, ...(result.unconfirmed?.length ? { deployNotConfirmed: result.unconfirmed } : {}), next: result.next };",
646
646
  " if (tool === \"ask_question\") return { workspaceId: result.workspaceId, question: { id: result.question.id, title: result.question.title, recommend: result.question.recommend, big: result.question.big }, mode: result.mode, instruction: result.instruction, ...(result.outcome && result.outcome !== \"asked\" ? { outcome: result.outcome, of: result.of } : {}) };",
647
647
  " if (tool === \"record_answer\" || tool === \"withdraw_question\") return { workspaceId: result.workspaceId, question: { id: result.question.id, answer: result.question.answer, closed: result.question.closed } };",
package/server/mcp.mjs CHANGED
@@ -431,7 +431,7 @@ function currentWork(w) {
431
431
  function compact(tool, input, result) {
432
432
  if (actionNames.has(tool)) return result;
433
433
  if (tool === "workspace_status") return currentWork(result);
434
- if (tool === "needs_you") return { ok: result.ok, briefId: result.briefId };
434
+ if (tool === "needs_you") return { ok: result.ok, briefId: result.briefId, ...(result.due ? { due: result.due } : {}) };
435
435
  if (tool === "declare_done") return { workspaceId: result.workspace.id, done: !result.blockers.length, alreadyDone: !!result.alreadyDone, completion: result.workspace.completion, blockers: result.blockers, ...(result.unconfirmed?.length ? { deployNotConfirmed: result.unconfirmed } : {}), next: result.next };
436
436
  if (tool === "ask_question") return { workspaceId: result.workspaceId, question: { id: result.question.id, title: result.question.title, recommend: result.question.recommend, big: result.question.big }, mode: result.mode, instruction: result.instruction, ...(result.outcome && result.outcome !== "asked" ? { outcome: result.outcome, of: result.of } : {}) };
437
437
  if (tool === "record_answer" || tool === "withdraw_question") return { workspaceId: result.workspaceId, question: { id: result.question.id, answer: result.question.answer, closed: result.question.closed } };
@@ -113,6 +113,10 @@ export class MessageQueue {
113
113
  readonly writer: WriteBehind<QueueFile>;
114
114
  /** Sends that went out (tests and the harness count them). */
115
115
  sends = 0;
116
+ /** When a send to each agent last started (invariant 247: a cancel right after it is the send's, never a Stop). */
117
+ private sentAt = new Map<string, number>();
118
+ /** When Follow-up's last send to this agent started, or null (since this worker started). */
119
+ lastSendTo(agentId: string): number | null { return this.sentAt.get(agentId) ?? null; }
116
120
  private images: QueueImages | null;
117
121
  constructor(readonly directory: string, private courier: Courier, o: { health?: WriteHealth; writeMs?: number; images?: QueueImages } = {}) {
118
122
  this.scale = queueTimeScale(directory);
@@ -346,6 +350,7 @@ export class MessageQueue {
346
350
  const images = refs.length && this.images ? await this.images.read(refs) : [];
347
351
  try {
348
352
  this.sends++;
353
+ for (const r of target.recipients) this.sentAt.set(r, this.now());
349
354
  const sent = await withDeadline(this.courier.deliverTo(target, envelopeText(items.map(i => i.text)), messageId, by, ...(images.length ? [images] as const : [])), this.attemptMs * this.scale, "Paseo didn't confirm the message in time", this.timers);
350
355
  // A stopped worker writes nothing: the next one owns queue.json and reads this send back as uncertain.
351
356
  if (this.stopped) return;
@@ -111,6 +111,23 @@ export function turnEndCheck(i: TurnEndInput): { text: string | null; receipt: N
111
111
  return { text: [turnEndMessage(d), i.runLine, told].filter(Boolean).join("\n\n"), receipt: d.receipt };
112
112
  }
113
113
 
114
+ /** The queue id of a turn-end check, so the queue can tell one apart (`turnEndDelivery`). */
115
+ export const turnEndItemId = (agentId: string, turnId: string | null, messageId: string) => `turn-end:${agentId}:${turnId ?? messageId}`;
116
+ export const isTurnEndItem = (id: string) => id.startsWith("turn-end:");
117
+ export const TURN_END_SUPERSEDED = "The agent started a newer turn, whose own end is checked instead.";
118
+ export const TURN_END_WAITS = "Waiting for the agent's running turn to end.";
119
+ /**
120
+ * Invariant 247, a-turn-end-check-never-interrupts: a queued turn-end check is about one turn. Once the agent started a
121
+ * newer turn it is dropped (that turn's own end is checked), and it never goes into a running turn (Paseo delivers by
122
+ * steering, which force-cancels a turn that doesn't settle: the developer's quick next prompt, killed by a reminder).
123
+ * Null: send it.
124
+ */
125
+ export function turnEndDelivery(f: { turnId: string | null; latestTurn: string | null; running: boolean; startedSince?: boolean }): { cancel: string } | { defer: string } | null {
126
+ // A turn end Paseo reports without a turn id (some providers) still knows a newer turn by when it started.
127
+ if (f.startedSince || f.turnId && f.latestTurn && f.latestTurn !== f.turnId) return { cancel: TURN_END_SUPERSEDED };
128
+ if (f.running) return { defer: TURN_END_WAITS };
129
+ return null;
130
+ }
114
131
  export type TurnEndDeps = {
115
132
  input(agentId: string, provider: string, items: readonly unknown[] | null, startedAt: number | null): Promise<Omit<TurnEndInput, "provider" | "items" | "startedAt" | "now"> | null>;
116
133
  saveReceipt(workspaceId: string, receipt: NudgeReceipt): Promise<void>;
@@ -48,7 +48,7 @@ export async function turnStarted(store: Store, agent: { id: string; workspaceId
48
48
  * A turn ended: record the history its tail shows, and a developer's Stop or a failed turn on the main agent holds (or
49
49
  * marks the conversation gone). `items` is the bounded tail read outside the state lock; null when it couldn't be read.
50
50
  */
51
- export async function turnEnded(store: Store, agentId: string, outcome: TurnOutcome, turnId: string | null, items: unknown[] | null, o: { interruption: { turnId: string | null; at: string; kind: string } | null; guarded: boolean; newerTurn?: boolean; compaction?: boolean }): Promise<string | null> {
51
+ export async function turnEnded(store: Store, agentId: string, outcome: TurnOutcome, turnId: string | null, items: unknown[] | null, o: { interruption: { turnId: string | null; at: string; kind: string } | null; guarded: boolean; newerTurn?: boolean; compaction?: boolean; ourSend?: boolean }): Promise<string | null> {
52
52
  const w = agentTrackedWorkspace(await store.snapshot(), agentId);
53
53
  if (!w) return null;
54
54
  if (items) await store.mutateWorkspace(w.id, current => {
@@ -66,7 +66,7 @@ export async function turnEnded(store: Store, agentId: string, outcome: TurnOutc
66
66
  if (!tracksAgent(current, agentId) || current.mainAgentId !== agentId) return;
67
67
  // The provider lost the conversation: every later send fails the same way, so stop sending instead of holding.
68
68
  if (outcome.kind === "failed" && conversationGone(outcome.error.message)) { current.goneAgent = { agentId, at: interruption.at, reason: outcome.error.message }; current.completion = null; current.declaration = null; return; }
69
- holdOnTurnEnd(current, { agentId, turnId: interruption.turnId, at: interruption.at, outcome, prompt, newerTurn: !!o.newerTurn, compaction: !!o.compaction });
69
+ holdOnTurnEnd(current, { agentId, turnId: interruption.turnId, at: interruption.at, outcome, prompt, newerTurn: !!o.newerTurn, compaction: !!o.compaction, ourSend: !!o.ourSend });
70
70
  });
71
71
  }
72
72
  return w.id;
@@ -95,7 +95,7 @@ export const agentCommandsRpc = defineRpc({ name: "follow.agent-commands", input
95
95
  pending: z.boolean().optional() }) });
96
96
  export const syncWorkspaceRpc = defineRpc({ name: "follow.sync", input: z.strictObject({ agentId: idSchema, summary: z.string().trim().min(1).max(1000),
97
97
  /** What the caller is working on toward the goal (shared/now.ts). Omitted keeps the last one; null clears it. */
98
- milestone: milestoneInputSchema.optional() }), output: z.object({ workspaceId: idSchema, synced: z.literal(true) }) });
98
+ milestone: milestoneInputSchema.optional() }), output: z.object({ workspaceId: idSchema, synced: z.literal(true), /** The caller's due tasks, said here so its turn ends with no Stop block (invariant 246). */ due: z.string().optional() }) });
99
99
  const nowLineSchema = z.object({
100
100
  agentId: idSchema, role: z.enum(["main", "contributor"]),
101
101
  work: z.object({ text: z.string(), source: z.enum(NOW_SOURCES), done: z.array(z.string()), next: z.array(z.string()), position: z.object({ at: z.number().int(), of: z.number().int() }).nullable() }).nullable(),
@@ -283,7 +283,7 @@ export const needsYouRpc = defineRpc({ name: "follow.needs-you", input: z.strict
283
283
  questions: z.array(z.string()).optional(),
284
284
  context: z.string().optional(),
285
285
  links: z.array(z.strictObject({ label: z.string(), url: z.string().optional(), path: z.string().optional(), pr: z.string().optional() })).optional(),
286
- }), output: z.object({ ok: z.literal(true), briefId: z.string(), /** Decisions the developer had dismissed: left off the card, and why. */ note: z.string().optional() }) });
286
+ }), output: z.object({ ok: z.literal(true), briefId: z.string(), /** The caller's due tasks (invariant 246). */ due: z.string().optional(), /** Decisions the developer had dismissed: left off the card, and why. */ note: z.string().optional() }) });
287
287
  /** Home's detail pane: the full stored brief for one agent (the list carries only its one-liner). */
288
288
  // The message queue (server/message-queue.ts): what waits to go to agents, and Retry or Cancel on one item.
289
289
  export const queueListRpc = defineRpc({ name: "follow.queue-list", input: z.strictObject({ workspaceId: idSchema.optional(), agentId: idSchema.optional() }), output: z.object({ items: z.array(queueViewSchema), recent: z.array(queueViewSchema) }) });
package/shared/status.ts CHANGED
@@ -34,12 +34,14 @@ export { CANCEL_CAUSES };
34
34
  /** A prompt that asks the agent to compact (`/compact`, with or without instructions): never an answer or Follow-up's work. */
35
35
  export const isCompactCommand = (prompt: string | null | undefined) => /^\/compact\b/.test((prompt ?? "").trimStart());
36
36
  export type CancelCause = typeof CANCEL_CAUSES[number];
37
- export function cancelCause(c: { reason: string | null | undefined; prompt?: string | null; newerTurn?: boolean; compaction?: boolean }): CancelCause {
37
+ export function cancelCause(c: { reason: string | null | undefined; prompt?: string | null; newerTurn?: boolean; compaction?: boolean; ourSend?: boolean }): CancelCause {
38
38
  const reason = (c.reason ?? "").trim().toLowerCase();
39
39
  if (/\breload/.test(reason) || /\brestart/.test(reason)) return "reload";
40
40
  if (/\bclos/.test(reason)) return "closed";
41
41
  if (c.compaction || isCompactCommand(c.prompt)) return "compaction";
42
- if (c.newerTurn) return "replaced";
42
+ // Invariant 247: Follow-up's own queue just sent this agent a message, which Paseo delivers by interrupting a running
43
+ // turn. The newer turn it starts may not be seen yet (a race), so the send itself says the turn was replaced.
44
+ if (c.newerTurn || c.ourSend) return "replaced";
43
45
  return "stop";
44
46
  }
45
47
  /** How long after Smart Session delivers a /compact a canceled turn is still that compaction's. */
@@ -61,6 +63,14 @@ export function compactionDelivered(items: readonly unknown[], agentId: string,
61
63
  return sent - 5_000 <= endedAt && endedAt - sent <= COMPACTION_CANCEL_MS && !(done <= endedAt);
62
64
  });
63
65
  }
66
+ /**
67
+ * How long after Follow-up's queue starts a send to an agent a cancel of that agent's turn is the send's (invariant
68
+ * 247, our-send-is-never-the-developer-s-stop). Paseo steers a message into a running turn and force-cancels it when
69
+ * the turn doesn't settle within 2 s (agent-manager `cancelAgentRun`); the margin covers the send's own round trip.
70
+ */
71
+ export const OUR_SEND_CANCEL_MS = 15_000;
72
+ /** Whether a turn that ended canceled at `endedAt` follows Follow-up's own send to that agent (`sentAt`, the send's start). */
73
+ export const ourSendCanceled = (sentAt: number | null | undefined, endedAt: number) => typeof sentAt === "number" && sentAt - 1_000 <= endedAt && endedAt - sentAt <= OUR_SEND_CANCEL_MS;
64
74
  /** Only the developer's own Stop pauses Follow-up. When unsure it doesn't: a missed pause is cheap, a stuck one silently stops repairs. */
65
75
  export const cancelHolds = (cause: CancelCause) => cause === "stop";
66
76
  export type TurnOutcome = { kind: "completed" } | { kind: "failed"; error: { message: string } } | { kind: "canceled"; reason: string };
@@ -69,9 +79,9 @@ export type TurnOutcome = { kind: "completed" } | { kind: "failed"; error: { mes
69
79
  * cause is the developer's Stop. Another agent's turn, and every other cancel cause, leave the workspace as it was.
70
80
  * `newerTurn`: the agent already started another turn when this one's end is handled.
71
81
  */
72
- export function holdOnTurnEnd(w: Workspace, e: { agentId: string; turnId: string | null; at: string; outcome: TurnOutcome; prompt: string | null; newerTurn: boolean; compaction?: boolean }): boolean {
82
+ export function holdOnTurnEnd(w: Workspace, e: { agentId: string; turnId: string | null; at: string; outcome: TurnOutcome; prompt: string | null; newerTurn: boolean; compaction?: boolean; ourSend?: boolean }): boolean {
73
83
  if (w.mainAgentId !== e.agentId || e.outcome.kind === "completed") return false;
74
- if (e.outcome.kind === "canceled" && !cancelHolds(cancelCause({ reason: e.outcome.reason, prompt: e.prompt, newerTurn: e.newerTurn, compaction: e.compaction }))) return false;
84
+ if (e.outcome.kind === "canceled" && !cancelHolds(cancelCause({ reason: e.outcome.reason, prompt: e.prompt, newerTurn: e.newerTurn, compaction: e.compaction, ourSend: e.ourSend }))) return false;
75
85
  const kind = e.outcome.kind;
76
86
  w.hold = interruptionHold(kind); w.interruption = { turnId: e.turnId, at: e.at, kind, agentId: e.agentId, ...(kind === "canceled" ? { cause: "stop" as const } : {}) }; w.completion = null; w.declaration = null;
77
87
  return true;