Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2fd0f0c
Send Bot rows' Needs you, Failed, last reply and preview from aiden s…
claude Nov 24, 2026
ef11fd6
Say in the server README that its Bot rows now carry Needs you, Faile…
claude Nov 24, 2026
2a29694
Merge branch 'claude/project-thread-awyxuf-pr4' into claude/project-t…
claude Nov 24, 2026
d7fe79d
Merge branch 'claude/project-thread-awyxuf-pr4' into claude/project-t…
claude Nov 24, 2026
ad2cec8
Refresh aiden serve's host feed when a Bot turn ends
claude Nov 24, 2026
9e5e5bc
Merge branch 'claude/project-thread-awyxuf-pr4' into claude/project-t…
claude Nov 24, 2026
9f53143
Merge branch 'claude/project-thread-awyxuf-pr4' into claude/project-t…
claude Nov 24, 2026
175a7f6
Report a Bot run that ends while its live feed opens as settled
claude Nov 24, 2026
53719c7
Merge branch 'claude/project-thread-awyxuf-pr4' into claude/project-t…
claude Nov 24, 2026
e9a3c9e
Never apply a running notice over the state a Bot's live feed opened …
claude Nov 24, 2026
2762eab
Merge branch 'claude/project-thread-awyxuf-pr4' into claude/project-t…
claude Nov 24, 2026
e5c5614
Merge branch 'claude/project-thread-awyxuf-pr4' into claude/project-t…
claude Nov 24, 2026
6f71a42
Read a Bot's state again once its live feed opens
claude Nov 24, 2026
d8c7c87
Merge remote-tracking branch 'origin/claude/project-thread-awyxuf-pr4…
claude Nov 24, 2026
490695f
Merge branch 'claude/project-thread-awyxuf-pr4' of https://github.com…
claude Nov 24, 2026
450a2d7
Report each Bot run's end once
claude Nov 24, 2026
7a77cde
Merge branch 'claude/project-thread-awyxuf-pr4' of https://github.com…
claude Nov 24, 2026
65b3080
Settle a failed Bot feed opening once for every notice that joined it
claude Nov 24, 2026
80ef14f
Merge branch 'claude/project-thread-awyxuf-pr4' of https://github.com…
claude Nov 24, 2026
79ba58e
Merge branch 'claude/project-thread-awyxuf-pr4' of https://github.com…
claude Nov 24, 2026
69382e7
Merge branch 'claude/project-thread-awyxuf-pr4' of https://github.com…
claude Nov 24, 2026
c3e430f
Merge branch 'claude/project-thread-awyxuf-pr4' of https://github.com…
claude Nov 24, 2026
a887515
Merge branch 'claude/project-thread-awyxuf-pr4' of https://github.com…
claude Nov 24, 2026
5a2ce0f
Merge remote-tracking branch 'origin/claude/project-thread-awyxuf-pr4…
sambitcreate Nov 24, 2026
dcb2afb
Settle a run for a running notice that joins a failed feed opening be…
sambitcreate Nov 24, 2026
8dc792f
Merge remote-tracking branch 'origin/claude/project-thread-awyxuf-pr4…
claude Nov 24, 2026
ff21e3b
Check that aiden serve marks its host feed Bot rows summarized
claude Nov 24, 2026
080b82c
Merge remote-tracking branch 'origin/claude/project-thread-awyxuf-pr4…
claude Nov 24, 2026
75502a9
Merge remote-tracking branch 'origin/claude/project-thread-awyxuf-pr4…
claude Nov 24, 2026
608b2bd
Merge remote-tracking branch 'origin/claude/project-thread-awyxuf-pr4…
claude Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .memory/bot-chat-activity.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ If `main` has moved past 29, change every `30` D introduced to the next free rev
- PR 3 (desktop only, no revision): the desktop asks for `bot:cards`, `bot:access-requests` and `bot:plans` (each `own_call`, only when the host lists them) and answers them through new peer ops `botRespondRoutineProposal`, `botAnswerAccessRequest`, `botRespondPlan`. `remote-bot-session.ts` maps plan/access frames onto `snapshot.plan`/`accessRequest` (plan items get place ids; `revision` is a hash of what the card shows, so re-reading the same plan keeps the card mounted) and memory/routine entries onto local rows. `RemoteBotChatView` puts access and pending plan cards in the Needs-you slot, an active plan in the body, echoes sends at once (shared `BotPendingSend` helpers from bot-chat-pane) and shows a re-pair hint group for old pairings (`remoteBotGroups`). Host: `AidenRemoteBotService.list()` leaves out (and logs by id) a Bot whose summary fails the contract instead of failing the whole list (and the host feed); a transient summary read error fails the list so clients keep their last rows.
- PR 3 follow-up: `peerBotSessionCompat` dropped `accessRequest` and `plan` from session reads, so a reload lost the card; both are now kept (an unreadable one becomes null).
- PR 3b (Remote revision 67, provisional; re-claim at merge): `GET /bots/{botId}/session/entries?before=&limit=` (projector `olderEntries`, same audience as the snapshot; unknown `before` = 409 operation_stale) and `POST /bots/{botId}/queued/{submissionId}/withdraw` (needs `bot:activity`; routine/intro inputs read `gone`; runtime gained `withdraw`). No feature tokens: the server feature list is at its 32-token cap, so the desktop treats a 404 as an older host. Peer ops `botSessionEntries`, `botWithdrawQueued`; the follower's `loadOlder` + `carryOlderRemoteBotEntries` keep loaded pages across same-epoch snapshots. "Every waiting approval" was dropped: the next approval already follows each answer, and a count would need a new opt-in because phone approval decoders are strict.
- PR 4 (2026-11-24, provisional revision 68, `bot:needs-you`): `GET /bots` summaries carry `needsYou: true` only for devices holding the opt-in (Android's Bot decoder rejects unknown keys). Router dependency `botNeedsYou(botIds)` reads `botLiveProjection().needsYou` (no transcript read); a failed read sends the list without it. iOS and Android ask for it alone; home rows read "Waiting for you" and stop showing as working, an approval the phone sees keeps "Needs your OK"; iOS inbox counts it. `aiden serve` doesn't wire it yet (PR 5).
- Still to come: PR 5 (headless server sends the same Bot signals). Not planned yet: a model picker for a remote Bot with a model problem (no remote route sets a Bot's model).
- PR 4 (2026-11-24, provisional revision 68, `bot:needs-you`): `GET /bots` summaries carry `needsYou: true` only for devices holding the opt-in (Android's Bot decoder rejects unknown keys). Router dependency `botNeedsYou(botIds)` reads `botLiveProjection().needsYou` (no transcript read); a failed read sends the list without it. iOS and Android ask for it alone; home rows read "Waiting for you" and stop showing as working, an approval the phone sees keeps "Needs your OK"; iOS inbox counts it.
- PR 5 (2026-11-24): `aiden serve` with durable Bots builds a `BotLiveProjection` (`createCliBotSignals` in `packages/cli/src/remote-bots.ts`: conversation, state, quietInputs, `approvalPending` from the CLI approvals bridge). It feeds host-feed `botSignals` (needsYou, failed, lastReplyAt, preview) and the router's `botNeedsYou`, so the server offers `bot:needs-you`. The feed refreshes on the durable runtime's state changes and `approvals.onChange`. CLI Bots ask no questions or hand-offs, so an approval is the only wait. Without durable sessions nothing changes. Not planned yet: a model picker for a remote Bot with a model problem (no remote route sets a Bot's model).

2 changes: 1 addition & 1 deletion docs/aiden-on-the-go-remote-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ When the paired Mac offers it (contract revision 42, `bot:issues`), a Bot's **Ne

## Bots waiting on you on the phone

When the paired Mac offers it (contract revision 68, `bot:needs-you`, provisional), a Bot that waits on you there (an approval, a question, a hand-off, an access request, a plan to OK or a Needs you card) reads **Waiting for you** on the Bots list of Aiden On The Go for iPhone and Android, instead of looking busy. An approval the phone can already see in that Bot's chat keeps its own line, such as "Needs your OK". On iPhone the Inbox also lists that Bot under **Needs you**. The phone picks this up whenever it reads the Bots list again. An `aiden serve` host, or a Mac on an older Aiden, doesn't offer it yet, and the list looks as before.
When the paired Mac offers it (contract revision 68, `bot:needs-you`, provisional), a Bot that waits on you there (an approval, a question, a hand-off, an access request, a plan to OK or a Needs you card) reads **Waiting for you** on the Bots list of Aiden On The Go for iPhone and Android, instead of looking busy. An approval the phone can already see in that Bot's chat keeps its own line, such as "Needs your OK". On iPhone the Inbox also lists that Bot under **Needs you**. The phone picks this up whenever it reads the Bots list again. An `aiden serve` server with durable Bot sessions offers it too, for a Bot waiting on an approval. A Mac on an older Aiden doesn't, and the list looks as before.

## Bot messaging on the phone

Expand Down
4 changes: 2 additions & 2 deletions docs/aiden-remote-api-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ A desktop that wrote triage keeps its own answer until the host reports a `triag
- Run control stops runs and answers approvals, including approvals raised by a phone's turn. Only a one-time decision applies: an approval answer with any `scope` other than `once` is refused with `400 invalid_request`, because the CLI keeps no remembered approvals. The CLI's runs ask no questions and take no mid-run input: an answer is refused, and input is refused as `run_not_active`. The server does not advertise `chat-run-input-v1` or `chat-question-prompts-v1`, so a paired desktop shows Stop and approvals on its runs, but no Steer and no question answers.
- Phones paired to the CLI hear `phone-run-control-v1`, `chat-read-state-v1` and `chat-triage-v1`, as on a Mac. They may negotiate `runs:observe` and `runs:control`, then watch, stop and answer approvals on runs another device started, and share read markers and unread state. They are still refused `GET /host/events`. Phones offer no Steer or Queue on a run they did not start, and show a question card only when a run asks one, which a CLI run never does.
- Revoking a device (`aiden remote revoke <id>`) ends its host feed, run streams and Bot session streams. It never cancels a run.
- Host-feed Bot rows carry no `needsYou`, `failed` or `lastReplyAt`, and a Bot edit reaches the feed only with its next other change (a chat, workspace, run, read marker or triage change).
- With durable Bot sessions on (`aiden bots enable-durable`), host-feed Bot rows carry `needsYou` (an approval waiting on the person; CLI Bots ask no questions and take no hand-offs), `failed`, `lastReplyAt` and the revision-66 `preview`, from the same live summary the desktop uses. A Bot's turn starting or ending, a pause and an approval opening or settling refresh the feed. Without durable sessions the rows carry none of them. A Bot edit (its name or avatar) still reaches the feed only with its next other change (a chat, workspace, run, read marker or triage change).
- A snooze is re-checked at least once a minute while `aiden serve` runs. The host does not re-check it when the computer wakes or unlocks.

## New worktree from a phone, revision 53 (`chat:new-worktree`, provisional)
Expand Down Expand Up @@ -1522,7 +1522,7 @@ Revision 67 is provisional: it was written when `main` was at 65 and revision 66

Revision 68 is provisional: it was written when `main` was at 65 and revisions 66 and 67 were still open, and the host keeps it in one constant (`AIDEN_REMOTE_BOT_NEEDS_YOU_CONTRACT_REVISION`), so claiming the next free number at merge changes only that constant.

**Negotiation.** The host lists `bot:needs-you` in `serverCapabilities` to a device that may hold Bot opt-ins, whenever it can tell which Bots wait on the person. A device asks for it with `POST /device/capabilities {accepts: ["bot:needs-you"]}` in a call of its **own**: a host older than revision 68 refuses the unknown name with `400 invalid_request`, and a host that cannot tell answers `404 not_found`. Pairing never issues it, and there is no `/server` feature token (the list is at its 32-token limit).
**Negotiation.** The host lists `bot:needs-you` in `serverCapabilities` to a device that may hold Bot opt-ins, whenever it can tell which Bots wait on the person: the desktop app, and `aiden serve` with durable Bot sessions on (there an approval is the only wait, since its Bots ask no questions and take no hand-offs). A device asks for it with `POST /device/capabilities {accepts: ["bot:needs-you"]}` in a call of its **own**: a host older than revision 68 refuses the unknown name with `400 invalid_request`, and a host that cannot tell answers `404 not_found`. Pairing never issues it, and there is no `/server` feature token (the list is at its 32-token limit).

**Audience-gated `needsYou`.** `GET /bots` summaries (`BotSummary`) carry `needsYou: true` only for a device holding `bot:needs-you`, and only for a Bot the person owes an answer: an open approval, question, hand-off, access request, pending plan or issue. That is the same signal the host's own Bots list, the host feed's revision-52 `needsYou` and the Dock badge use, read without the Bot's transcript. It is never sent as `false`, and other devices never see the key: Android's Bot decoder rejects unknown keys. If the host cannot read the signal for a list, it sends the list without it rather than failing.

Expand Down
219 changes: 219 additions & 0 deletions main/services/bot-runtime/live-projection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as os from "node:os";
import * as path from "node:path";
import { after, test } from "node:test";
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
import type { WatchEnd } from "@earendil-works/chord/watch";
import { fauxAssistantMessage, fauxText, fauxThinking, fauxToolCall } from "@earendil-works/pi-ai/providers/faux";
import {
applyBotLiveEvent,
Expand Down Expand Up @@ -323,6 +324,224 @@ test("a routine turn shows as its label, and a [SILENT] answer hides the whole t
}
});

test("a run that ends while its feed is still opening is reported settled, and never reads running again", async () => {
const fauxModels = createFauxModels([fauxAssistantMessage("Done already.")]);
let release: (() => void) | undefined;
let held = true;
const opened = new Promise<void>((resolve) => (release = resolve));
const settled: Array<{ botId: string; kind: string }> = [];
let service: BotSessionRuntime | undefined;
const live = await start(fauxModels, {
projection: {
// Opening the feed waits until the turn is over.
conversation: async (botId) => {
if (held) await opened;
return service!.conversation(botId);
},
onRunSettled: (botId, state) => settled.push({ botId, kind: state.kind }),
},
});
service = live.service;
try {
const sent = await live.service.send("bot:a", { text: "Quick one", requestId: "desk-1" });
const outcome = await live.service.awaitReply("bot:a", sent.submissionId, new AbortController().signal);
assert.equal(outcome.kind, "completed");
assert.deepEqual(settled, [], "nothing is reported before the feed opens");
held = false;
release!();
await waitFor(() => settled.length > 0, { what: "the settled run to be reported" });
assert.deepEqual(settled, [{ botId: "bot:a", kind: "idle" }]);
const view = await live.projection.subscribe("bot:a", recorder().sink);
view.unsubscribe();
assert.equal(view.snapshot.state.kind, "idle", "the stale running notice was not applied");
assert.deepEqual(visibleText(view.snapshot).slice(-1), ["assistant:Done already."]);
} finally {
await live.close();
}
});

test("a run that ends after its opening feed read the state is reported settled once", async () => {
const fauxModels = createFauxModels([fauxAssistantMessage("Done already.")]);
let release: (() => void) | undefined;
let held = true;
const planRead = new Promise<void>((resolve) => (release = resolve));
let reachedPlan: (() => void) | undefined;
const atPlan = new Promise<void>((resolve) => (reachedPlan = resolve));
const settled: string[] = [];
const live = await start(fauxModels, {
projection: {
// The plan is read after the state and the transcript, so the run's last frame is still to come.
plan: async () => {
if (held) {
reachedPlan!();
await planRead;
}
return null;
},
onRunSettled: (_botId, state) => settled.push(state.kind),
},
});
try {
const sent = await live.service.send("bot:a", { text: "Quick one", requestId: "desk-1" });
await atPlan;
const outcome = await live.service.awaitReply("bot:a", sent.submissionId, new AbortController().signal);
assert.equal(outcome.kind, "completed");
held = false;
release!();
await waitFor(() => settled.length > 0, { what: "the settled run to be reported" });
// Give a second report, if any, time to arrive.
await new Promise((resolve) => setTimeout(resolve, 200));
assert.deepEqual(settled, ["idle"], "one run, one report");
} finally {
await live.close();
}
});

test("a Bot paused while its feed is still opening reads paused, not running", async () => {
const fauxModels = createFauxModels([slowAnswer()], { tokensPerSecond: 20 });
let release: (() => void) | undefined;
let held = true;
const opened = new Promise<void>((resolve) => (release = resolve));
const settled: string[] = [];
let service: BotSessionRuntime | undefined;
const live = await start(fauxModels, {
projection: {
conversation: async (botId) => {
if (held) await opened;
return service!.conversation(botId);
},
onRunSettled: (_botId, state) => settled.push(state.kind),
},
});
service = live.service;
try {
await live.service.send("bot:a", { text: "Take your time", requestId: "desk-1" });
assert.equal((await live.service.pause("bot:a", "mac")).kind, "paused");
held = false;
release!();
await waitFor(() => settled.length > 0, { what: "the paused run to be reported" });
assert.deepEqual(settled, ["paused"]);
const view = await live.projection.subscribe("bot:a", recorder().sink);
view.unsubscribe();
assert.equal(view.snapshot.state.kind, "paused", "the earlier running notice was not applied");
} finally {
await live.close();
}
});

test("a Bot paused after its opening feed read the state is still reported paused", async () => {
const fauxModels = createFauxModels([slowAnswer()], { tokensPerSecond: 20 });
let release: (() => void) | undefined;
let held = true;
const planRead = new Promise<void>((resolve) => (release = resolve));
let reachedPlan: (() => void) | undefined;
const atPlan = new Promise<void>((resolve) => (reachedPlan = resolve));
const settled: string[] = [];
const live = await start(fauxModels, {
projection: {
// The plan is read after the state, so holding it holds the feed open past its state read.
plan: async () => {
if (held) {
reachedPlan!();
await planRead;
}
return null;
},
onRunSettled: (_botId, state) => settled.push(state.kind),
},
});
try {
await live.service.send("bot:a", { text: "Take your time", requestId: "desk-1" });
await atPlan;
// A second running notice (a follow-up accepted mid-run) joins the same opening.
live.projection.notifyState("bot:a", await live.service.state("bot:a"));
assert.equal((await live.service.pause("bot:a", "mac")).kind, "paused");
held = false;
release!();
await waitFor(() => settled.length > 0, { what: "the paused run to be reported" });
// Give a second report, if any, time to arrive.
await new Promise((resolve) => setTimeout(resolve, 200));
assert.deepEqual(settled, ["paused"], "one opening, one report");
const view = await live.projection.subscribe("bot:a", recorder().sink);
view.unsubscribe();
assert.equal(view.snapshot.state.kind, "paused", "the feed shows the pause, not the running state read before it");
} finally {
await live.close();
}
});

test("a running notice that joins a failed opening behind a notice that wasn't running still reports its run settled", async () => {
const fauxModels = createFauxModels([fauxAssistantMessage("unused")]);
let endFirstWatch: (() => void) | undefined;
const firstWatchEnded = new Promise<WatchEnd>((resolve) => (endFirstWatch = () => resolve({ kind: "ended" })));
let failing = false;
let failedOpens = 0;
let failOpening: (() => void) | undefined;
const openingFailed = new Promise<void>((resolve) => (failOpening = resolve));
const failure = new Error("the conversation closed while the feed opened");
const settled: string[] = [];
let reports = 0;
let service: BotSessionRuntime | undefined;
const live = await start(fauxModels, {
// The test sends every state notice itself.
service: { onStateChange: () => undefined },
projection: {
conversation: async (botId) => {
if (failing) {
failedOpens += 1;
await openingFailed;
throw failure;
}
// The first feed follows the real conversation until the test ends its watch.
const real = await service!.conversation(botId);
return new Proxy(real, {
get(target, property) {
if (property === "watch") {
return async (context: Parameters<typeof real.watch>[0]) => {
const watch = await target.watch(context);
return new Proxy(watch, {
get(inner, key) {
if (key === "closed") return Promise.race([inner.closed, firstWatchEnded]);
const value = Reflect.get(inner, key, inner) as unknown;
return typeof value === "function" ? value.bind(inner) : value;
},
});
};
}
const value = Reflect.get(target, property, target) as unknown;
return typeof value === "function" ? value.bind(target) : value;
},
});
},
onRunSettled: (_botId, state) => settled.push(state.kind),
onError: () => {
reports += 1;
},
},
});
service = live.service;
try {
// A window keeps watching the Bot while its feed ends underneath it.
const watching = await live.projection.subscribe("bot:a", recorder().sink);
endFirstWatch!();
await new Promise((resolve) => setTimeout(resolve, 20));
// An idle notice reopens the feed for that window; a running notice joins the same opening.
failing = true;
live.projection.notifyState("bot:a", { kind: "idle" });
live.projection.notifyState("bot:a", { kind: "running", submissionId: "sub-joined" });
assert.equal(failedOpens, 1, "both notices share one opening");
failOpening!();
await waitFor(() => settled.length > 0, { what: "the joined running notice's run to be reported" });
// Give a second report, if any, time to arrive.
await new Promise((resolve) => setTimeout(resolve, 200));
assert.deepEqual(settled, ["idle"], "the run the running notice named is reported settled, once");
assert.equal(reports, 1, "the failed opening is reported once");
watching.unsubscribe();
} finally {
await live.close();
}
});

test("a failed reply is a typed failed turn, and Retry as a new submission answers after it", async () => {
const failure = fauxAssistantMessage("", { stopReason: "error", errorMessage: "provider is down" });
const fauxModels = createFauxModels([failure, fauxAssistantMessage("Here it is.")]);
Expand Down
Loading
Loading