Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix: a Retry reaches the session a failure took down
raullopez-sandbox87df343e0c5e
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stop-rows.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stop-rows.tsindex fe0919a9a..f8f339d83 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stop-rows.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stop-rows.ts@@ -16,19 +16,30 @@ export function isInterruptAck(message: Pick<ChatMessage, 'body' | 'sender'>): breturn message.sender.kind !== 'human' && message.body.startsWith(INTERRUPT_ACK_MESSAGE);}-function isInterruptCommand(message: Row): boolean {- return message.sender.kind === 'human' && /^!interrupt(\s|$)/.test(message.body.trim());-}+/**+ * The agent's in-room answer to a Retry it passed on (core's `_RETRY.ack`). A+ * Retry is posted as `!retry @agent <message id>`; the turn it runs again shows+ * under the message, so the command and this answer are left out too.+ */+export const RETRY_ACK_MESSAGE = 'Trying that message again.';++/** Each command left out with its acknowledgement, and that acknowledgement. */+const HIDDEN_COMMANDS: [RegExp, string][] = [+ [/^!interrupt(\s|$)/, INTERRUPT_ACK_MESSAGE],+ [/^!retry(\s|$)/, RETRY_ACK_MESSAGE],+];-/** Ids of the Stop commands and their acknowledgements to leave out of the transcript. */+/** Ids of the Stop and Retry commands and their acknowledgements to leave out of the transcript. */export function hiddenStopRows(messages: readonly Row[]): Set<string> {const hidden = new Set<string>();for (const command of messages) {- if (!isInterruptCommand(command)) continue;+ if (command.sender.kind !== 'human') continue;+ const ack = HIDDEN_COMMANDS.find(([pattern]) => pattern.test(command.body.trim()))?.[1];+ if (ack === undefined) continue;const answers = messages.filter((each) => each.threadRootId === command.messageId && each.sender.kind !== 'human');- if (!answers.every(isInterruptAck)) continue;+ if (!answers.every((answer) => answer.body.startsWith(ack))) continue;hidden.add(command.messageId);for (const answer of answers) hidden.add(answer.messageId);}diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chat-stop-rows.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chat-stop-rows.test.tsindex d467164c9..773695355 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chat-stop-rows.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chat-stop-rows.test.ts@@ -48,4 +48,25 @@ describe('hiddenStopRows', () => {];expect(hiddenStopRows(messages).size).toBe(0);});+ it('hides a Retry and its acknowledgement: the turn it runs again shows under the message', () => {+ const messages = [+ row('$ask', 'plan a picnic'),+ row('$retry', '!retry @coder $ask'),+ row('$ack', 'Trying that message again.', agent, '$retry'),+ ];+ expect(hiddenStopRows(messages)).toEqual(new Set(['$retry', '$ack']));+ });++ it('shows a Retry the agent could not carry out, with its answer', () => {+ const messages = [+ row('$retry', '!retry @coder $ask'),+ row(+ '$no',+ "I couldn't try that again: my current session never worked on that message.",+ agent,+ '$retry'+ ),+ ];+ expect(hiddenStopRows(messages).size).toBe(0);+ });});diff --git a/console/packages/agent-providers/src/host/agent-host.test.ts b/console/packages/agent-providers/src/host/agent-host.test.tsindex fd515fe9b..1238d005d 100644--- a/console/packages/agent-providers/src/host/agent-host.test.ts+++ b/console/packages/agent-providers/src/host/agent-host.test.ts@@ -2091,6 +2091,47 @@ it('hands a relayed command to the session it names, and only if it runs here',}});+it('starts the host of a session a failure took down, to hand it a retry', async () => {+ const root = await mkdtemp(join(tmpdir(), 'shared-watch-retry-'));+ roots.push(root);+ paths.root = root;+ const config = await spawning(root);+ const faulted = await existing(root, config);+ const hosts = sessionHosts();+ vi.mocked(ensureSharedProcess).mockImplementation(async ({ root: sessionRoot }) => {+ await hosts.start(sessionRoot);+ return { created: false };+ });+ vi.spyOn(console, 'warn').mockImplementation(() => {});+ const abort = new AbortController();+ const run = runAgentHost(+ root,+ config,+ abort.signal,+ hosts.supervision,+ new WatcherControl(),+ openSwitchStream+ );+ const retry = {+ sessionId: faulted.sessionId,+ commandId: 'retry-1',+ body: { type: 'message.retry', messageId: 'm1' },+ };+ try {+ await eventually(() => streams.length === 1);+ await streams[0]!.onSessionCommand!(retry);+ expect(vi.mocked(ensureSharedProcess).mock.calls.map(([input]) => input.root)).toEqual([+ faulted.sessionRoot,+ ]);+ expect(hosts.to(faulted.sessionRoot)).toEqual([+ { type: 'command', command: retry, requesterName: null },+ ]);+ } finally {+ abort.abort();+ await run;+ }+});+it('hands a room control to the session working in its room, when Switch names only the room', async () => {const root = await mkdtemp(join(tmpdir(), 'shared-watch-room-control-'));roots.push(root);diff --git a/console/packages/agent-providers/src/host/agent-host.ts b/console/packages/agent-providers/src/host/agent-host.tsindex 01b89aade..1afe2862a 100644--- a/console/packages/agent-providers/src/host/agent-host.ts+++ b/console/packages/agent-providers/src/host/agent-host.ts@@ -136,6 +136,10 @@ function isReset(command: Record<string, unknown>): boolean {return z.object({ type: z.literal('session.reset') }).safeParse(command.body).success;}+function isRetry(command: Record<string, unknown>): boolean {+ return z.object({ type: z.literal('message.retry') }).safeParse(command.body).success;+}+function isAssignment(record: WatchRecord): record is Assignment {return 'sequence' in record;}@@ -1284,6 +1288,17 @@ export async function runAgentHost();return false;}));+ // A retry is for a turn that failed, and a failure can take the session's+ // host down with it (a provider error faults it): started again, as a+ // room message would start it, rather than dropped for not running.+ const relaunched =+ isRetry(command) && !links.ready(sharedSessionRoot(sessionId))+ ? await sessionConfig(sessionId).then(async (config) => {+ if (!config) return false;+ await launch(config);+ return true;+ })+ : false;const taken = await askSession(sessionId,{@@ -1292,7 +1307,7 @@ export async function runAgentHost(requesterName: typeof requesterName === 'string' ? requesterName : null,},`command ${command.commandId}`,- restarted ? HOST_START_MS : 0+ restarted || relaunched ? HOST_START_MS : 0);if (!taken)console.warn(diff --git a/console/packages/agent-providers/src/host/session-host.test.ts b/console/packages/agent-providers/src/host/session-host.test.tsindex 08dd72add..e80906a0e 100644--- a/console/packages/agent-providers/src/host/session-host.test.ts+++ b/console/packages/agent-providers/src/host/session-host.test.ts@@ -1710,6 +1710,30 @@ describe('retrying a room message', () => {expect(userItems.map((item) => item.origin?.messageId)).toEqual(['m1', 'm1']);});+ it('runs it again in the host started after a failure took the last one down', async () => {+ const { host, emit, root } = await start('codex');+ await host.command(roomMessage('first'));+ await until(() => expect(host.snapshot().turns[0]?.status).toBe('running'));+ emit({+ type: 'turn.completed',+ turnId: 'first',+ outcome: 'error',+ message: 'model',+ usage: [],+ });+ await until(() => expect(host.snapshot().turns[0]?.status).toBe('error'));+ await host.shutdown();++ const next = setup('codex');+ const recovered = await startHost(root, next.config, next.adapter);+ hosts.push(recovered);+ await until(() => expect(recovered.snapshot().session.status).toBe('ready'));+ // Relayed as the current generation, which the shared host fills in.+ const command = { ...retry('again'), epoch: recovered.snapshot().session.epoch };+ expect((await recovered.command(command)).status).toBe('applied');+ await until(() => expect(next.adapter.sendTurn).toHaveBeenCalledTimes(1));+ });+it('refuses to run again a turn still going, or a message it never worked on', async () => {const { host } = await start('codex');await expect(host.command(retry('nothing'))).rejects.toThrow('NOT_FOUND');