Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Still post a start notice when its placements are not taken (review)

Simon Flackdf9ed9d14469
diff --git a/console/packages/agent-providers/src/host/agent-host.test.ts b/console/packages/agent-providers/src/host/agent-host.test.ts
index e48773666..ac6a4079e 100644
--- a/console/packages/agent-providers/src/host/agent-host.test.ts
+++ b/console/packages/agent-providers/src/host/agent-host.test.ts
@@ -2549,6 +2549,49 @@ it('stops starting a session whose host failed, keeps its message, and tells its
}
});
+it('still tells the owner a session could not start when its placements are not taken', async () => {
+ // A statement that is refused (the controller hub reconnecting, say) used
+ // to skip the notice after it, and the notice is sent once per message, so
+ // the room heard nothing.
+ const root = await mkdtemp(join(tmpdir(), 'shared-watch-failed-start-unplaced-'));
+ roots.push(root);
+ paths.root = root;
+ const config = await spawning(root);
+ const hosts = sessionHosts();
+ hosts.fail = SIGN_IN;
+ const calls = switchOperations({ owner: 'ada' });
+ placementsRefusal.error = new Error('the agent controller hub is not connected');
+ vi.spyOn(console, 'error').mockImplementation(() => {});
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+
+ const abort = new AbortController();
+ const run = runAgentHost(
+ root,
+ config,
+ abort.signal,
+ hosts.supervision,
+ new WatcherControl(),
+ openSwitchStream
+ );
+ try {
+ await eventually(() => streams.length === 1);
+ await streams[0]!.onEvent!(addressed(1, 'room'));
+ await eventually(() => calls.some((call) => call.name === 'send_targeted_message'));
+ expect(calls.find((call) => call.name === 'send_targeted_message')?.body).toMatchObject({
+ body: `I couldn't start a session, and it needs you to fix it: ${SIGN_IN} Then address me again.`,
+ target_names: ['ada'],
+ });
+ expect(
+ warn.mock.calls.some(([line]) =>
+ String(line).startsWith('Could not state the session placements before telling room room')
+ )
+ ).toBe(true);
+ } finally {
+ abort.abort();
+ await run;
+ }
+});
+
it('tells the room without addressing anyone when the owner cannot be addressed, and survives a refused post', async () => {
const root = await mkdtemp(join(tmpdir(), 'shared-watch-failed-owner-'));
roots.push(root);
diff --git a/console/packages/agent-providers/src/host/agent-host.ts b/console/packages/agent-providers/src/host/agent-host.ts
index 4ea779348..8bc238474 100644
--- a/console/packages/agent-providers/src/host/agent-host.ts
+++ b/console/packages/agent-providers/src/host/agent-host.ts
@@ -1046,6 +1046,19 @@ export async function runAgentHost(
* that runs into it is answered once, however often the host is retried.
*/
const announced = new Set<string>();
+ /**
+ * States the placements before a notice posted as the session, so Switch
+ * answers it from the room it is in. A statement that is not taken is
+ * said and the notice still tried: it is posted once, and a room left
+ * with no word of its session is worse than a notice that fails too.
+ */
+ const publishBeforeNotice = async (what: string) => {
+ await publish().catch((error: unknown) =>
+ console.warn(
+ `Could not state the session placements before ${what}: ${error instanceof Error ? error.message : String(error)}`
+ )
+ );
+ };
/** Says in the room that a session is starting for its message, once per message. */
const startingNoticed = new Set<string>();
const tellStarting = async (config: SharedHostConfig, event: Handoff) => {
@@ -1053,7 +1066,7 @@ export async function runAgentHost(
if (startingNoticed.has(key)) return;
startingNoticed.add(key);
try {
- await publish();
+ await publishBeforeNotice(`telling room ${event.roomId} a session is starting`);
await announceSessionStart({
identity,
connectionId,
@@ -1077,7 +1090,9 @@ export async function runAgentHost(
announced.add(key);
try {
// Switch answers the call from where it holds the session placed.
- await publish();
+ await publishBeforeNotice(
+ `telling room ${event.roomId} session ${sessionId} failed to start`
+ );
await announceStartFailure({
identity,
connectionId,