From 7d60093c6aa8c334a7089f66a7bf296c07a8d9da Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Sun, 22 Nov 2026 21:16:49 +0000 Subject: [PATCH 1/3] fix: read peer prompt outcomes by type and isolate the daemon test's home The daemon sends a peer server's prompt outcome as the frame it received, keyed by `type`, but the wrapper still read the runner's `t` field, so another server's failed prompt never notified. The test fed the old shape and hid it. daemon-runtime.test.mjs set HOME at runtime, which Bun's os.homedir() ignores, so the daemon applied cluster configuration into the real ~/.agents and failed where that is a symlink. The test now mocks homedir. Also drops hub.ts's dead check for the runner's hello/session frames. Closes #6 --- lib/hosts/daemon-runtime.test.mjs | 9 +++++++-- lib/hosts/hub.ts | 2 +- lib/rpc-manager.test.mjs | 4 ++-- lib/rpc-manager.ts | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/hosts/daemon-runtime.test.mjs b/lib/hosts/daemon-runtime.test.mjs index e0fcee51..bbfd73b2 100644 --- a/lib/hosts/daemon-runtime.test.mjs +++ b/lib/hosts/daemon-runtime.test.mjs @@ -1,16 +1,21 @@ import assert from "node:assert/strict"; import test from "node:test"; +import { mock } from "bun:test"; import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { join } from "node:path"; -import { tmpdir } from "node:os"; +import * as os from "node:os"; import { encodeBlobFrame, encodeLine, LINK_LIMITS, LINK_PROTOCOL_VERSION, PartJoiner } from "./link-protocol.ts"; -const scratch = mkdtempSync(join(tmpdir(), "daemon-multi-runtime-")); +const scratch = mkdtempSync(join(os.tmpdir(), "daemon-multi-runtime-")); const old = { agent: process.env.PI_CODING_AGENT_DIR, bin: process.env.TAU_PI_BIN, home: process.env.HOME, profile: process.env.USERPROFILE }; process.env.PI_CODING_AGENT_DIR = join(scratch, "agent"); // A member applies the master's configuration under its home directory too (`~/.agents/skills`). process.env.HOME = process.env.USERPROFILE = join(scratch, "home"); mkdirSync(process.env.HOME, { recursive: true }); +// Bun's os.homedir() keeps the HOME it started with, so the daemon would apply into the real ~/.agents. +// This file runs in its own process (`bun test --parallel`), so the mock needs no restore. +const fakeHome = process.env.HOME; +mock.module("node:os", () => ({ ...os, default: { ...os.default, homedir: () => fakeHome }, homedir: () => fakeHome })); const fakePi = join(scratch, process.platform === "win32" ? "omp.cmd" : "omp"); const spawns = join(scratch, "spawns"); const envs = join(scratch, "envs"); diff --git a/lib/hosts/hub.ts b/lib/hosts/hub.ts index 697e636d..6a5ccc89 100644 --- a/lib/hosts/hub.ts +++ b/lib/hosts/hub.ts @@ -1388,7 +1388,7 @@ export class RemoteRpcTransport implements RpcTransport { if (!isRecord(frame)) return; const sessionId = frame.type === "response" && frame.command === "get_state" && frame.success === true && isRecord(frame.data) ? frame.data.sessionId - : (frame.type === "session" || frame.t === "hello" || frame.t === "session") ? frame.sessionId : undefined; + : frame.type === "session" ? frame.sessionId : undefined; if (typeof sessionId === "string" && isValidSessionId(sessionId)) { this.session = sessionId; } diff --git a/lib/rpc-manager.test.mjs b/lib/rpc-manager.test.mjs index cd2ad152..03cbd8fc 100644 --- a/lib/rpc-manager.test.mjs +++ b/lib/rpc-manager.test.mjs @@ -924,9 +924,9 @@ test("a peer server's failed prompt suppresses completion and notifies its failu const { feed, delivered } = await notifyingSession(t); feed({ type: "agent_start" }); feed({ type: "agent_end", isTerminal: true, messages: [] }); - feed({ type: "peer_prompt_outcome", outcome: { t: "prompt_result", agentInvoked: true, status: "error", error: { message: "boom" } } }); + feed({ type: "peer_prompt_outcome", outcome: { type: "prompt_result", agentInvoked: true, status: "error", error: { message: "boom" } } }); feed({ type: "session_settled" }); - feed({ type: "peer_prompt_outcome", outcome: { t: "prompt_error", command: "prompt", error: "No API key" } }); + feed({ type: "peer_prompt_outcome", outcome: { type: "prompt_error", command: "prompt", error: "No API key" } }); assert.deepEqual(delivered, [["error", "boom"], ["error", "No API key"]]); }); diff --git a/lib/rpc-manager.ts b/lib/rpc-manager.ts index a83d4c1d..c30d9bed 100644 --- a/lib/rpc-manager.ts +++ b/lib/rpc-manager.ts @@ -913,7 +913,7 @@ export class AgentSessionWrapper { } if (event.type === PEER_PROMPT_OUTCOME_FRAME) { // Another server's prompt ended: only the notification detector reads it (that server owns the prompt's state). - const { t: type, ...outcome } = isRecord(event.outcome) ? event.outcome : {}; + const { type, ...outcome } = isRecord(event.outcome) ? event.outcome : {}; if (type === "prompt_result") this.publishNotifications({ ...outcome, type }); else if (type === "prompt_error") this.publishNotifications({ ...outcome, type, errorMessage: typeof outcome.error === "string" ? outcome.error : "Prompt failed" }); return; From 50621b1b2b0a17dcf24431f25328f5617f9a18ea Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Sun, 22 Nov 2026 21:26:57 +0000 Subject: [PATCH 2/3] fix: send a peer's refused prompt from pi's response pi never prints prompt_result or prompt_error: it refuses a message command only in that command's response. The daemon now forgets every command at its response and, when pi refuses a message command, tells the other members as a prompt_error peer outcome, so the elected notifier reports the failure. The daemon's routing of child prompt_result/prompt_error frames, which nothing produces, is gone, and with it the message-command entries it kept for them for the channel's life. Also drops hub.ts's remaining runner `"t"` prefilter and the stale `{t, outcome}` doc. --- lib/hosts/daemon-channels.test.mjs | 17 ++++++++--------- lib/hosts/daemon-channels.ts | 20 ++++++++++---------- lib/hosts/daemon-runtime.test.mjs | 8 ++++---- lib/hosts/hub.ts | 2 +- lib/hosts/link-protocol.ts | 4 ++-- lib/rpc-manager.test.mjs | 5 ++--- lib/rpc-manager.ts | 5 ++--- 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/lib/hosts/daemon-channels.test.mjs b/lib/hosts/daemon-channels.test.mjs index 24cfa372..2e843fc7 100644 --- a/lib/hosts/daemon-channels.test.mjs +++ b/lib/hosts/daemon-channels.test.mjs @@ -223,16 +223,15 @@ test("a companion-extension command is no user message: no peer marker, no edit await h.table.stop(); }); -test("a prompt_result returns under the sending link's own id, to that link only", async () => { +test("a prompt's response returns under the sending link's own id, to that link only", async () => { const h = harness(), a = await h.table.open(h.a, { sessionId: SAVED, launch }); await h.table.open(h.b, { sessionId: SAVED, launch }); h.table.release(h.a, a.ch); h.table.release(h.b, a.ch); h.table.stdin(h.a, a.ch, cmd(1000, "prompt", { message: "hi" })); const [sent] = own(h.children[0]); assert.notEqual(sent.id, 1000); h.children[0].emit(res(sent.id, { agentInvoked: true })); - h.children[0].emit({ type: "prompt_result", id: sent.id, text: "done" }); - const results = h.output.filter(item => item.body.type === "stdout" && ["response", "prompt_result"].includes(JSON.parse(item.body.line).type)); - assert.deepEqual(results.map(item => [item.id, JSON.parse(item.body.line).type, JSON.parse(item.body.line).id]), [["l1", "response", 1000], ["l1", "prompt_result", 1000]]); + const results = h.output.filter(item => item.body.type === "stdout" && JSON.parse(item.body.line).type === "response"); + assert.deepEqual(results.map(item => [item.id, JSON.parse(item.body.line).id]), [["l1", 1000]]); await h.table.stop(); }); @@ -241,12 +240,12 @@ test("a prompt's outcome reaches the other members uncorrelated, so the elected await h.table.open(h.b, { sessionId: SAVED, launch }); h.table.release(h.a, a.ch); h.table.release(h.b, a.ch); h.table.stdin(h.a, a.ch, cmd(1000, "prompt", { message: "hi" })); h.table.stdin(h.a, a.ch, cmd(1001, "prompt", { message: "again" })); const [first, second] = own(h.children[0]); - h.children[0].emit({ type: "prompt_result", id: first.id, agentInvoked: true, status: "error", error: { message: "boom" } }); - h.children[0].emit({ type: "prompt_error", id: second.id, command: "prompt", error: "No API key" }); - const outcomes = frames => frames.filter(frame => ["prompt_result", "prompt_error", "peer_prompt_outcome"].includes(frame.type)); - assert.deepEqual(outcomes(stdoutFrames(h, "l1")).map(frame => [frame.type, frame.id]), [["prompt_result", 1000], ["prompt_error", 1001]]); + // pi answers a message command with a response only: an accepted one tells the peers nothing, a refused one is their prompt_error. + h.children[0].emit({ type: "response", id: first.id, command: "prompt", success: true, data: {} }); + h.children[0].emit({ type: "response", id: second.id, command: "prompt", success: false, error: "No API key" }); + const outcomes = frames => frames.filter(frame => ["response", "peer_prompt_outcome"].includes(frame.type)); + assert.deepEqual(outcomes(stdoutFrames(h, "l1")).map(frame => [frame.type, frame.id, frame.success]), [["response", 1000, true], ["response", 1001, false]]); assert.deepEqual(outcomes(stdoutFrames(h, "l2")), [ - { type: "peer_prompt_outcome", outcome: { type: "prompt_result", agentInvoked: true, status: "error", error: { message: "boom" } } }, { type: "peer_prompt_outcome", outcome: { type: "prompt_error", command: "prompt", error: "No API key" } }, ]); await h.table.stop(); diff --git a/lib/hosts/daemon-channels.ts b/lib/hosts/daemon-channels.ts index 72d06d29..73aa0c90 100644 --- a/lib/hosts/daemon-channels.ts +++ b/lib/hosts/daemon-channels.ts @@ -356,25 +356,25 @@ export class ChannelTable { } const owner = channel.commands.get(fid); if (owner) { - if (!MESSAGE_COMMANDS.has(owner.op)) channel.commands.delete(fid); + channel.commands.delete(fid); const member = owner.link && channel.members.get(owner.link.id); if (member) this.deliver(channel, member, { type: "stdout", ch: channel.ch, line: JSON.stringify({ ...frame, id: owner.id }) }, true); + // pi refuses a message command only in its response: the other members hear it as a prompt_error, so the + // elected notifier reports the failure whichever server prompted. + if (MESSAGE_COMMANDS.has(owner.op) && frame.success === false) { + const outcome = { type: "prompt_error", command: frame.command, error: typeof frame.error === "string" ? frame.error : "Prompt failed" }; + const peer = JSON.stringify({ type: PEER_PROMPT_OUTCOME_FRAME, outcome }); + for (const other of channel.members.values()) if (other !== member) this.deliver(channel, other, { type: "stdout", ch: channel.ch, line: peer }); + } return; } return; } - if ((frame.type === "prompt_result" || frame.type === "prompt_error" || frame.type === "bash_output" || frame.type === "bash_execution_update") && (typeof frame.id === "string" || typeof frame.id === "number")) { - const fid = String(frame.id); - const owner = channel.commands.get(fid); + if ((frame.type === "bash_output" || frame.type === "bash_execution_update") && (typeof frame.id === "string" || typeof frame.id === "number")) { + const owner = channel.commands.get(String(frame.id)); if (owner) { - if (frame.type === "prompt_result" || frame.type === "prompt_error") channel.commands.delete(fid); const member = owner.link && channel.members.get(owner.link.id); if (member) this.deliver(channel, member, { type: "stdout", ch: channel.ch, line: JSON.stringify({ ...frame, id: owner.id }) }); - if (frame.type === "prompt_result" || frame.type === "prompt_error") { - const outcome: WireFrame = { ...frame }; delete outcome.id; - const peer = JSON.stringify({ type: PEER_PROMPT_OUTCOME_FRAME, outcome }); - for (const other of channel.members.values()) if (other !== member) this.deliver(channel, other, { type: "stdout", ch: channel.ch, line: peer }); - } return; } } diff --git a/lib/hosts/daemon-runtime.test.mjs b/lib/hosts/daemon-runtime.test.mjs index bbfd73b2..bb4df092 100644 --- a/lib/hosts/daemon-runtime.test.mjs +++ b/lib/hosts/daemon-runtime.test.mjs @@ -10,12 +10,12 @@ const scratch = mkdtempSync(join(os.tmpdir(), "daemon-multi-runtime-")); const old = { agent: process.env.PI_CODING_AGENT_DIR, bin: process.env.TAU_PI_BIN, home: process.env.HOME, profile: process.env.USERPROFILE }; process.env.PI_CODING_AGENT_DIR = join(scratch, "agent"); // A member applies the master's configuration under its home directory too (`~/.agents/skills`). -process.env.HOME = process.env.USERPROFILE = join(scratch, "home"); -mkdirSync(process.env.HOME, { recursive: true }); +const home = join(scratch, "home"); +process.env.HOME = process.env.USERPROFILE = home; +mkdirSync(home, { recursive: true }); // Bun's os.homedir() keeps the HOME it started with, so the daemon would apply into the real ~/.agents. // This file runs in its own process (`bun test --parallel`), so the mock needs no restore. -const fakeHome = process.env.HOME; -mock.module("node:os", () => ({ ...os, default: { ...os.default, homedir: () => fakeHome }, homedir: () => fakeHome })); +mock.module("node:os", () => ({ ...os, default: { ...os.default, homedir: () => home }, homedir: () => home })); const fakePi = join(scratch, process.platform === "win32" ? "omp.cmd" : "omp"); const spawns = join(scratch, "spawns"); const envs = join(scratch, "envs"); diff --git a/lib/hosts/hub.ts b/lib/hosts/hub.ts index 6a5ccc89..5d9c864b 100644 --- a/lib/hosts/hub.ts +++ b/lib/hosts/hub.ts @@ -1347,7 +1347,7 @@ export class RemoteRpcTransport implements RpcTransport { deliverLine(line: string): void { if (this.closed) return; - if (line.includes('"command":"get_state"') || line.includes('"type":"session"') || line.includes('"t":"hello"') || line.includes('"t":"session"')) this.noteSession(line); + if (line.includes('"command":"get_state"') || line.includes('"type":"session"')) this.noteSession(line); if (this.lineListeners.length > 0) return notify(this.lineListeners, line); const bytes = this.holdable(line); if (bytes === null) return; diff --git a/lib/hosts/link-protocol.ts b/lib/hosts/link-protocol.ts index fae547bc..dc34367e 100644 --- a/lib/hosts/link-protocol.ts +++ b/lib/hosts/link-protocol.ts @@ -66,8 +66,8 @@ export const HISTORY_MUTATING_COMMANDS = new Set([ export const MESSAGE_COMMANDS = new Set(["prompt", "steer", "follow_up", "followUp"]); /** Shared-channel marker a daemon puts in the other members' output when one link writes a message command. */ export const PEER_MESSAGE_FRAME = "peer_message_command"; -/** Shared-channel frame `{t, outcome}` a daemon puts in the other members' output for one link's `prompt_result` or - * `prompt_error` (its command id dropped): the elected notifier must hear a run failed whichever server prompted it. */ +/** Shared-channel frame `{type, outcome}` a daemon puts in the other members' output when pi refuses one link's + * message command (`outcome`: `{type: "prompt_error", command, error}`): the elected notifier must hear a run failed whichever server prompted it. */ export const PEER_PROMPT_OUTCOME_FRAME = "peer_prompt_outcome"; /** Named `req.args` keys for each session op, in parameter order. Named, not diff --git a/lib/rpc-manager.test.mjs b/lib/rpc-manager.test.mjs index 03cbd8fc..245cd02c 100644 --- a/lib/rpc-manager.test.mjs +++ b/lib/rpc-manager.test.mjs @@ -924,10 +924,9 @@ test("a peer server's failed prompt suppresses completion and notifies its failu const { feed, delivered } = await notifyingSession(t); feed({ type: "agent_start" }); feed({ type: "agent_end", isTerminal: true, messages: [] }); - feed({ type: "peer_prompt_outcome", outcome: { type: "prompt_result", agentInvoked: true, status: "error", error: { message: "boom" } } }); - feed({ type: "session_settled" }); feed({ type: "peer_prompt_outcome", outcome: { type: "prompt_error", command: "prompt", error: "No API key" } }); - assert.deepEqual(delivered, [["error", "boom"], ["error", "No API key"]]); + feed({ type: "session_settled" }); + assert.deepEqual(delivered, [["error", "No API key"]]); }); test("a crash of an idle session does not notify", async (t) => { diff --git a/lib/rpc-manager.ts b/lib/rpc-manager.ts index c30d9bed..c5d3a34d 100644 --- a/lib/rpc-manager.ts +++ b/lib/rpc-manager.ts @@ -913,9 +913,8 @@ export class AgentSessionWrapper { } if (event.type === PEER_PROMPT_OUTCOME_FRAME) { // Another server's prompt ended: only the notification detector reads it (that server owns the prompt's state). - const { type, ...outcome } = isRecord(event.outcome) ? event.outcome : {}; - if (type === "prompt_result") this.publishNotifications({ ...outcome, type }); - else if (type === "prompt_error") this.publishNotifications({ ...outcome, type, errorMessage: typeof outcome.error === "string" ? outcome.error : "Prompt failed" }); + const outcome = isRecord(event.outcome) ? event.outcome : {}; + if (outcome.type === "prompt_error") this.publishNotifications({ ...outcome, errorMessage: typeof outcome.error === "string" ? outcome.error : "Prompt failed" }); return; } if (this.hostOwnedLifecycle && event.type === "host_tool_call" && typeof event.id === "string") { From 8f7737bd47cb46002a86a97bb33724bc105dac39 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Sun, 22 Nov 2026 21:34:17 +0000 Subject: [PATCH 3/3] fix: drop the peer prompt outcome pi refuses a message command only in that command's response, and the owning server does not notify for its own refusal. Fanning a refusal out as a peer prompt_error made the elected notifier report "Run failed" for a prompt pi merely declined (a bare prompt during another server's run, a compaction) and drop the next completed notice. A refusal now reaches only the server that sent it; the frame, its consumer and their tests are gone. --- AGENTS.md | 2 +- lib/hosts/daemon-channels.test.mjs | 10 ++++------ lib/hosts/daemon-channels.ts | 9 +-------- lib/hosts/link-protocol.ts | 3 --- lib/rpc-manager.test.mjs | 9 --------- lib/rpc-manager.ts | 8 +------- 6 files changed, 7 insertions(+), 34 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 020d304a..a86a07e0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -559,7 +559,7 @@ The todo plan (`TodoList`) and subagent roster sit pinned above the input, each `hooks/useAudio.ts` stores the toggle (`tau-sound-enabled`) and reuses one `AudioContext`, unlocked from a user gesture in `ChatInput`; `ChatWindow` plays the tone from `onAgentEnd`. ### Notifications (`lib/notification-*.ts`, `public/sw.js`, Settings → Notifications) -- Detection runs on the server in `AgentSessionWrapper.handleFrame` (and `handleProcessExit`), so unwatched sessions notify. `createNotificationDetector()` inspects top-level frames only (subagent frames never notify). "Completed" fires on `session_settled`; a failed or aborted last prompt suppresses it. Other servers on a shared channel get the prompt's outcome as `peer_prompt_outcome`. Failures arrive as `prompt_error` and `process_exit`; one failure per run. A crash notifies "Run failed" while a run or its background work is unsettled. +- Detection runs on the server in `AgentSessionWrapper.handleFrame` (and `handleProcessExit`), so unwatched sessions notify. `createNotificationDetector()` inspects top-level frames only (subagent frames never notify). "Completed" fires on `session_settled`; a failed or aborted last prompt suppresses it. A refused message command reaches only the server that sent it (pi answers it only in that command's `response`). Failures arrive as `prompt_error` and `process_exit`; one failure per run. A crash notifies "Run failed" while a run or its background work is unsettled. - **Presence vs streams.** Tabs report `{clientId, deviceId, visible, sessionId, seq}` to `/api/notifications/presence` (on change, input after idling, every 30 s; expires 60 s after receipt; `visible` = visible and input within 3 min; `sessionId` null while Settings hides the chat; an older `seq` is dropped). Streams are the tab's open `notifications` subscriptions. Prefs PUTs run one at a time. - **Routing** (`routeNotification`): a visible tab on the session drops the event everywhere; else, with a visible connected tab, `whenActive: "toast"` devices get a toast on their active tabs; else push (subscribed devices) or in-page `showNotification`. The server decides before pushing (iOS revokes permission for silent pushes; `sw.js` always shows what it receives). - Prefs and subscriptions are per device (`localStorage`, mirrored to the SQLite store in `/tau/`, 0600, WAL; it holds the VAPID key and the history). Push text is rendered server-side in the device's locale. diff --git a/lib/hosts/daemon-channels.test.mjs b/lib/hosts/daemon-channels.test.mjs index 2e843fc7..08aa5a8d 100644 --- a/lib/hosts/daemon-channels.test.mjs +++ b/lib/hosts/daemon-channels.test.mjs @@ -235,19 +235,17 @@ test("a prompt's response returns under the sending link's own id, to that link await h.table.stop(); }); -test("a prompt's outcome reaches the other members uncorrelated, so the elected notifier sees a peer's failure", async () => { +test("a refused prompt reaches only its sender: the owner reports it, and peers hear a run's failure from its broadcast events", async () => { const h = harness(), a = await h.table.open(h.a, { sessionId: SAVED, launch }); await h.table.open(h.b, { sessionId: SAVED, launch }); h.table.release(h.a, a.ch); h.table.release(h.b, a.ch); h.table.stdin(h.a, a.ch, cmd(1000, "prompt", { message: "hi" })); h.table.stdin(h.a, a.ch, cmd(1001, "prompt", { message: "again" })); const [first, second] = own(h.children[0]); - // pi answers a message command with a response only: an accepted one tells the peers nothing, a refused one is their prompt_error. + // pi answers a message command with a response only, accepted or refused. h.children[0].emit({ type: "response", id: first.id, command: "prompt", success: true, data: {} }); h.children[0].emit({ type: "response", id: second.id, command: "prompt", success: false, error: "No API key" }); - const outcomes = frames => frames.filter(frame => ["response", "peer_prompt_outcome"].includes(frame.type)); + const outcomes = frames => frames.filter(frame => frame.type === "response"); assert.deepEqual(outcomes(stdoutFrames(h, "l1")).map(frame => [frame.type, frame.id, frame.success]), [["response", 1000, true], ["response", 1001, false]]); - assert.deepEqual(outcomes(stdoutFrames(h, "l2")), [ - { type: "peer_prompt_outcome", outcome: { type: "prompt_error", command: "prompt", error: "No API key" } }, - ]); + assert.deepEqual(outcomes(stdoutFrames(h, "l2")), []); await h.table.stop(); }); diff --git a/lib/hosts/daemon-channels.ts b/lib/hosts/daemon-channels.ts index 73aa0c90..3ec40f3a 100644 --- a/lib/hosts/daemon-channels.ts +++ b/lib/hosts/daemon-channels.ts @@ -5,7 +5,7 @@ import { readSessionHeaderSync } from "../pi/session-files"; import { isValidSessionId } from "../session-file-references-core"; import { isRecord } from "../type-guards"; import type { DaemonLink } from "./daemon-link"; -import { CONFIG_VERSION_RE, CREATION_ID_RE, HISTORY_MUTATING_COMMANDS, HostOpError, LINK_LIMITS, MESSAGE_COMMANDS, PEER_MESSAGE_FRAME, PEER_PROMPT_OUTCOME_FRAME, type HelloChannel, type OpenChannelRequest, type OpenChannelResult, type Unsequenced, type UpMessage } from "./link-protocol"; +import { CONFIG_VERSION_RE, CREATION_ID_RE, HISTORY_MUTATING_COMMANDS, HostOpError, LINK_LIMITS, MESSAGE_COMMANDS, PEER_MESSAGE_FRAME, type HelloChannel, type OpenChannelRequest, type OpenChannelResult, type Unsequenced, type UpMessage } from "./link-protocol"; import { idOf, parseWire, PendingRequests, wireEvent, type WireFrame } from "./pending-requests"; import { StreamSnapshot } from "./stream-snapshot"; import { ChannelLifecycle } from "./channel-lifecycle"; @@ -359,13 +359,6 @@ export class ChannelTable { channel.commands.delete(fid); const member = owner.link && channel.members.get(owner.link.id); if (member) this.deliver(channel, member, { type: "stdout", ch: channel.ch, line: JSON.stringify({ ...frame, id: owner.id }) }, true); - // pi refuses a message command only in its response: the other members hear it as a prompt_error, so the - // elected notifier reports the failure whichever server prompted. - if (MESSAGE_COMMANDS.has(owner.op) && frame.success === false) { - const outcome = { type: "prompt_error", command: frame.command, error: typeof frame.error === "string" ? frame.error : "Prompt failed" }; - const peer = JSON.stringify({ type: PEER_PROMPT_OUTCOME_FRAME, outcome }); - for (const other of channel.members.values()) if (other !== member) this.deliver(channel, other, { type: "stdout", ch: channel.ch, line: peer }); - } return; } return; diff --git a/lib/hosts/link-protocol.ts b/lib/hosts/link-protocol.ts index dc34367e..2ce370cb 100644 --- a/lib/hosts/link-protocol.ts +++ b/lib/hosts/link-protocol.ts @@ -66,9 +66,6 @@ export const HISTORY_MUTATING_COMMANDS = new Set([ export const MESSAGE_COMMANDS = new Set(["prompt", "steer", "follow_up", "followUp"]); /** Shared-channel marker a daemon puts in the other members' output when one link writes a message command. */ export const PEER_MESSAGE_FRAME = "peer_message_command"; -/** Shared-channel frame `{type, outcome}` a daemon puts in the other members' output when pi refuses one link's - * message command (`outcome`: `{type: "prompt_error", command, error}`): the elected notifier must hear a run failed whichever server prompted it. */ -export const PEER_PROMPT_OUTCOME_FRAME = "peer_prompt_outcome"; /** Named `req.args` keys for each session op, in parameter order. Named, not * positional, so an omitted optional argument never turns into `null`. */ diff --git a/lib/rpc-manager.test.mjs b/lib/rpc-manager.test.mjs index 245cd02c..a994d34a 100644 --- a/lib/rpc-manager.test.mjs +++ b/lib/rpc-manager.test.mjs @@ -920,15 +920,6 @@ test("an asynchronous prompt failure (prompt_error) notifies the user", async (t assert.deepEqual(delivered, [["error", "No API key for provider"]]); }); -test("a peer server's failed prompt suppresses completion and notifies its failure", async (t) => { - const { feed, delivered } = await notifyingSession(t); - feed({ type: "agent_start" }); - feed({ type: "agent_end", isTerminal: true, messages: [] }); - feed({ type: "peer_prompt_outcome", outcome: { type: "prompt_error", command: "prompt", error: "No API key" } }); - feed({ type: "session_settled" }); - assert.deepEqual(delivered, [["error", "No API key"]]); -}); - test("a crash of an idle session does not notify", async (t) => { const { wrapper, delivered } = await notifyingSession(t); wrapper.handleProcessExit({ code: 1, signal: null, stderrTail: "out of memory" }); diff --git a/lib/rpc-manager.ts b/lib/rpc-manager.ts index c5d3a34d..0ca70405 100644 --- a/lib/rpc-manager.ts +++ b/lib/rpc-manager.ts @@ -42,7 +42,7 @@ import type { import type { AgentConfirmPayload, AgentMessage, CrossSessionHostToolCall, CrossSessionHostToolEvent, ExitedRpcSession, ExtensionWidgetItem } from "./types"; import { isLinkUp, type Host, type HostStatus, type SpawnRequest } from "./hosts/host"; import { freezeHostLinks, getHost, hostOwnsLifecycle, isNotifier, lastUplinkAt, listHosts, orphanExit } from "./hosts/hub"; -import { CREATION_ID_RE, HISTORY_MUTATING_COMMANDS, HostOpError, PEER_MESSAGE_FRAME, PEER_PROMPT_OUTCOME_FRAME } from "./hosts/link-protocol"; +import { CREATION_ID_RE, HISTORY_MUTATING_COMMANDS, HostOpError, PEER_MESSAGE_FRAME } from "./hosts/link-protocol"; import { LOCAL_HOST_ID } from "./hosts/registry"; import type { OpResult } from "./hosts/session-ops"; import { hostForSessionId, invalidateHostSessionList, listSessionsAllHosts, sessionSpawnTarget } from "./hosts/session-index"; @@ -911,12 +911,6 @@ export class AgentSessionWrapper { this.peerMessageCommands += 1; return; } - if (event.type === PEER_PROMPT_OUTCOME_FRAME) { - // Another server's prompt ended: only the notification detector reads it (that server owns the prompt's state). - const outcome = isRecord(event.outcome) ? event.outcome : {}; - if (outcome.type === "prompt_error") this.publishNotifications({ ...outcome, errorMessage: typeof outcome.error === "string" ? outcome.error : "Prompt failed" }); - return; - } if (this.hostOwnedLifecycle && event.type === "host_tool_call" && typeof event.id === "string") { const key = `${event.type}:${event.id}`; if (this.deliveredCallbacks.has(key)) return;