CODY-021: a removed agent is reconciled the moment its turn settles

If the current agent was taken off the bridge's list while its request was
in flight, start-up rightly kept it for that request, but nothing fell back
afterwards: the screen named the default (first in the list) while state,
storage and the conversation were still the removed agent's.

The controller now reconciles inside dispatch, in the same step as any
state change and before anything is drawn: on a resting screen, if the
stored agent is not offered, the stored agent and thread are swapped to the
default's own and the state follows (agent_reconciled). While a request is
in flight nothing changes, so the turn is never moved or repeated. This
also covers an abandoned turn at start.

CODY-022: README scope list no longer says multiple agents are excluded.

Not reviewed, not deployed, not uploaded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-21 16:24:48 -08:00
co-authored by Claude Fable 5.2
parent c8b4fb0310
commit bb3a309427
5 changed files with 114 additions and 3 deletions
+4 -3
View File
@@ -17,7 +17,7 @@ the implementer read from the server's log, and what Cody reproduced independent
| Path | State | | Path | State |
|---|---| |---|---|
| Client, bridge and contract | Implemented. | | Client, bridge and contract | Implemented. |
| Automated tests with fakes (296) | Passing. | | Automated tests with fakes (299) | Passing. |
| Client in Even's official simulator | Passing (7 scenarios). Simulator only. | | Client in Even's official simulator | Passing (7 scenarios). Simulator only. |
| Bridge against a real Hermes gateway | Passing (9 scenarios) with a **stub model**. | | Bridge against a real Hermes gateway | Passing (9 scenarios) with a **stub model**. |
| Built-in speech-to-text (Whisper, in the bridge) | Passing (11 scenarios) on a real speech recording, including with no network. Not yet on audio from the glasses. | | Built-in speech-to-text (Whisper, in the bridge) | Passing (11 scenarios) on a real speech recording, including with no network. Not yet on audio from the glasses. |
@@ -120,5 +120,6 @@ What each suite does and does not show is in `docs/test-evidence.md`.
## Not in this slice ## Not in this slice
Wake words, always-on listening, camera features, text-to-speech, multiple agents, billing, store Wake words, always-on listening, choosing an agent by saying its name, camera features,
launch, and running alongside Even's native captions (the public SDK does not offer it). text-to-speech, billing, store launch, and running alongside Even's native captions (the public
SDK does not offer it).
+23
View File
@@ -43,6 +43,8 @@ interface AgentThread {
} }
const DEFAULT_AGENT = 'default'; const DEFAULT_AGENT = 'default';
/** Screens on which nothing is recording or in flight. */
const RESTING: ReadonlySet<AppState['phase']> = new Set(['ready', 'answer', 'error', 'cancelled']);
function validAgents(value: unknown): Agent[] | undefined { function validAgents(value: unknown): Agent[] | undefined {
if (!Array.isArray(value)) return undefined; if (!Array.isArray(value)) return undefined;
@@ -355,6 +357,25 @@ export class Controller {
void this.save(); void this.save();
} }
/**
* The current agent has been taken off the bridge's list. While its request is still in
* flight it stays the current agent, so that turn is followed to its end and never moved or
* repeated elsewhere. The moment nothing is in flight, the stored agent, its conversation and
* the state all fall back to the default together; otherwise the screen would name the
* default while the next question was still filed under the removed agent's conversation.
*/
private reconcileRemovedAgent(): void {
if (!this.stored) return;
const current = this.stored.agentId ?? DEFAULT_AGENT;
if (current === DEFAULT_AGENT) return;
if (!RESTING.has(this.state.phase)) return;
if (this.state.agents.some((a) => a.id === current)) return;
this.swapStoredAgent(DEFAULT_AGENT);
void this.save();
this.note('agents', `${current} is no longer offered: back to the default agent`);
this.state = reduce(this.state, { type: 'agent_reconciled', agentId: DEFAULT_AGENT, conversationId: this.stored.conversationId }).state;
}
/** A swipe at Ready: move to the next or previous agent. Does nothing unless there is a choice. */ /** A swipe at Ready: move to the next or previous agent. Does nothing unless there is a choice. */
private cycleAgent(delta: 1 | -1): void { private cycleAgent(delta: 1 | -1): void {
const agents = this.state.agents; const agents = this.state.agents;
@@ -495,6 +516,8 @@ export class Controller {
const before = this.state; const before = this.state;
const step = reduce(before, event); const step = reduce(before, event);
this.state = step.state; this.state = step.state;
// In the same step, before anything is drawn or another question can start.
this.reconcileRemovedAgent();
if (before.phase !== step.state.phase) this.note('state', `${before.phase} -> ${step.state.phase}`); if (before.phase !== step.state.phase) this.note('state', `${before.phase} -> ${step.state.phase}`);
for (const effect of step.effects) void this.run(effect); for (const effect of step.effects) void this.run(effect);
this.render(); this.render();
+17
View File
@@ -109,6 +109,12 @@ export type AppEvent =
} }
/** The user picked another agent (a swipe at Ready). `conversationId` is that agent's own, if it has one. */ /** The user picked another agent (a swipe at Ready). `conversationId` is that agent's own, if it has one. */
| { type: 'agent_selected'; agentId: string; conversationId: string | null } | { type: 'agent_selected'; agentId: string; conversationId: string | null }
/**
* The current agent is no longer offered and nothing is in flight with it: fall back to the
* default agent and ITS conversation. Unlike a selection this applies on any resting screen,
* and leaves what is on screen (the removed agent's last answer or error) in place.
*/
| { type: 'agent_reconciled'; agentId: string; conversationId: string | null }
| { type: 'unpaired' } | { type: 'unpaired' }
/** Semantic actions. `freshId` is a new UUID supplied by the caller in case a turn starts. */ /** Semantic actions. `freshId` is a new UUID supplied by the caller in case a turn starts. */
| { type: 'activate'; freshId: string } | { type: 'activate'; freshId: string }
@@ -234,6 +240,17 @@ export function reduce(state: AppState, event: AppEvent): Step {
}); });
} }
case 'agent_reconciled': {
if (!IDLE.has(state.phase)) return same(state);
return same({
...state,
agentId: event.agentId,
conversationId: event.conversationId,
conversationEpoch: state.conversationEpoch + 1,
creatingConversation: false,
});
}
case 'unpaired': { case 'unpaired': {
const effects: Effect[] = state.phase === 'listening' ? [{ type: 'discard_capture' }] : []; const effects: Effect[] = state.phase === 'listening' ? [{ type: 'discard_capture' }] : [];
return { return {
+14
View File
@@ -422,6 +422,20 @@ describe('choosing an agent', () => {
expect(late.creatingConversation).toBe(false); expect(late.creatingConversation).toBe(false);
}); });
it('falling back from a removed agent: applied on any resting screen without disturbing it, never while something is in flight', () => {
const base = run(readyWithAgents(), select).state;
const back: AppEvent = { type: 'agent_reconciled', agentId: 'default', conversationId: CONV };
const answered = run(base, { type: 'submit_text', freshId: ID1, text: 'q' }, { type: 'turn_update', generation: base.generation + 1, result: result(ID1), pages: ['her answer'] }).state;
const after = reduce(answered, back).state;
expect(after.phase).toBe('answer');
expect(after.pages).toEqual(['her answer']); // what she said stays on screen
expect([after.agentId, after.conversationId]).toEqual(['default', CONV]);
expect(after.conversationEpoch).toBe(answered.conversationEpoch + 1);
for (const busy of [run(base, { type: 'activate', freshId: ID1 }).state, run(base, { type: 'submit_text', freshId: ID1, text: 'q' }).state]) {
expect(reduce(busy, back).state, busy.phase).toBe(busy);
}
});
it('with one agent, or none listed, no screen mentions an agent', () => { it('with one agent, or none listed, no screen mentions an agent', () => {
for (const agents of [[], [AGENTS[0]!]]) { for (const agents of [[], [AGENTS[0]!]]) {
const state = run(initialState, { type: 'init', paired: true, conversationId: CONV, captureMaxSeconds: 30, resumeRequestId: null, agents }).state; const state = run(initialState, { type: 'init', paired: true, conversationId: CONV, captureMaxSeconds: 30, resumeRequestId: null, agents }).state;
+56
View File
@@ -513,6 +513,62 @@ describe('glasses: which agent it reopens on', () => {
expect(snapshot.state.agents.map((a) => a.id)).toEqual(['default', 'cody']); expect(snapshot.state.agents.map((a) => a.id)).toEqual(['default', 'cody']);
}); });
it('CODY-021: removed while her question is in flight: the turn stays hers and settles honestly, then screen, state, storage and routing all move to the default', async () => {
await paired();
await ask('pepper one');
await backToReady();
device.swipeDown(); // Wendy
h.hermes.next({ kind: 'hang' });
controller.askText('wendy, do the thing');
await until('in flight with Wendy', () => phase() === 'thinking' && h.hermes.executions === 2);
const wendyRequest = snapshot.state.requestId!;
await until('request id saved', () => JSON.parse(device.storage.get('hermeven.v1')!).activeRequestId === wendyRequest);
// The owner takes Wendy off the list and restarts the bridge; the page is reopened.
(h.config.agents as unknown[]).splice(1, 1);
await h.restartBridge();
const before = JSON.parse(device.storage.get('hermeven.v1')!);
device.storage.set('hermeven.v1', JSON.stringify({ ...before, bridgeUrl: h.url }));
await relaunch();
// Still her turn while it is unresolved: re-attached by id, not moved, not repeated.
expect(snapshot.state.requestId ?? wendyRequest).toBe(wendyRequest);
await until('her turn settled', () => phase() === 'error');
expect(snapshot.state.error?.code).toBe('outcome_unknown');
expect(h.hermes.executedBy).toEqual([null, 'wendy']);
// The moment it settled, everything agrees on the default agent.
expect(snapshot.state.agentId).toBe('default');
await until('saved', () => JSON.parse(device.storage.get('hermeven.v1')!).agentId === 'default');
await backToReady();
expect(device.frame.body).toBe('Pepper\n\nReady.');
expect(snapshot.state.agentId).toBe('default');
// The next question goes to the default agent, in the DEFAULT agent's own conversation.
await ask('pepper two');
expect(device.frame.body).toContain('turn=2');
expect(device.frame.body).toContain('pepper one');
expect(h.hermes.executedBy).toEqual([null, 'wendy', null]);
const posts = h.hermes.requests.filter((r) => r.method === 'POST' && r.path === '/v1/runs');
expect(posts.filter((p) => p.profile === 'wendy').length).toBe(1);
expect(snapshot.state.conversationId).toBe(JSON.parse(device.storage.get('hermeven.v1')!).conversationId);
});
it('CODY-021: the same when the question is asked straight from the removed agent\'s result screen, without going back to Ready', async () => {
await paired();
device.swipeDown(); // Wendy
h.hermes.next({ kind: 'hang' });
controller.askText('wendy, do the thing');
await until('in flight with Wendy', () => phase() === 'thinking' && h.hermes.executions === 1);
await until('request id saved', () => typeof JSON.parse(device.storage.get('hermeven.v1')!).activeRequestId === 'string');
(h.config.agents as unknown[]).splice(1, 1);
await h.restartBridge();
const before = JSON.parse(device.storage.get('hermeven.v1')!);
device.storage.set('hermeven.v1', JSON.stringify({ ...before, bridgeUrl: h.url }));
await relaunch();
await until('her turn settled', () => phase() === 'error');
await ask('straight on'); // from the error screen
expect(h.hermes.executedBy).toEqual(['wendy', null]);
expect(device.frame.body).toContain('turn=1');
expect(sent.filter((s) => s.path === '/v1/conversations').map((c) => JSON.parse(c.body).agent_id)).toEqual(['wendy', 'default']);
});
it('the bridge cannot be reached for the list at start: the last known list is used', async () => { it('the bridge cannot be reached for the list at start: the last known list is used', async () => {
await paired(); await paired();
device.swipeDown(); device.swipeDown();