Skip to content

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

fix: show a no-target control as asked of everyone; skip only a direct reset's follow-up

raullopez-sandboxd64c082be736
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.ts
index 5c6e5e7fc..6e6fcdb0c 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
@@ -28,6 +28,15 @@ describe('hiddenStopRows', () => {
expect(hiddenStopRows(messages)).toEqual(new Set(['$stop', '$ack']));
});
+ it('hides a Stop asked of everyone and each acknowledgement', () => {
+ const messages = [
+ row('$stop', 'Stop requested for everyone by ana', system),
+ row('$ack1', 'Interrupted my current turn.', agent, '$stop'),
+ row('$ack2', 'Interrupted my current turn.', agent, '$stop'),
+ ];
+ expect(hiddenStopRows(messages)).toEqual(new Set(['$stop', '$ack1', '$ack2']));
+ });
+
it('hides a Stop still waiting for its answer', () => {
expect(hiddenStopRows([row('$stop', 'Stop requested for coder by ana', system)])).toEqual(
new Set(['$stop'])
diff --git a/console/packages/agent-providers/src/host/shared-host.test.ts b/console/packages/agent-providers/src/host/shared-host.test.ts
index 4518f146a..a0fc13fc2 100644
--- a/console/packages/agent-providers/src/host/shared-host.test.ts
+++ b/console/packages/agent-providers/src/host/shared-host.test.ts
@@ -137,6 +137,8 @@ async function start(
/** The provider reports work, such as subagents, still running outside any turn. */
backgroundWork?: { running: boolean };
resettable?: boolean;
+ /** The provider compacts its conversation natively. */
+ compactable?: boolean;
/**
* Stopping a conversation reports it stopped and exited, as every provider
* adapter does, and returns only after the host has had time to look.
@@ -273,6 +275,7 @@ async function start(
};
},
};
+ if (opts.compactable) adapter.compactSession = vi.fn(async () => {});
const continuing = opts.continuing;
if (continuing) adapter.conversationHistory = vi.fn(async () => structuredClone(continuing));
if (opts.conversationLost)
@@ -1076,6 +1079,36 @@ it('owes no follow-up for a reset asked for in a direct chat', async () => {
}
}, 20000);
+it('still owes the follow-up for a compaction asked for in a direct chat', async () => {
+ const host = await start({ compactable: true });
+ try {
+ const compact: Command = {
+ ...relayed('current', 'room-compact', { type: 'session.compact' }),
+ origin: {
+ actorId: '@person:test',
+ surface: 'console',
+ roomId: 'room',
+ threadId: 'thread',
+ messageId: 'message-9',
+ },
+ };
+ const answer = await host.parent.ask({
+ type: 'command',
+ command: compact,
+ requesterName: 'louisa',
+ direct: true,
+ });
+ expect(answer).toMatchObject({
+ ok: true,
+ value: { commandId: 'room-compact', status: 'applied' },
+ });
+ await until(() => expect(host.turns).toHaveLength(1));
+ expect(host.turns[0]!.text).toContain('Connect to Switch room "room"');
+ } finally {
+ expect(await host.stop()).toBeNull();
+ }
+}, 20000);
+
it('tells the room at once when it refuses a compaction asked for there mid-turn', async () => {
const host = await start({ rooms: true });
const asks = () =>
diff --git a/console/packages/agent-providers/src/host/shared-host.ts b/console/packages/agent-providers/src/host/shared-host.ts
index bd7254e95..9be13f529 100644
--- a/console/packages/agent-providers/src/host/shared-host.ts
+++ b/console/packages/agent-providers/src/host/shared-host.ts
@@ -588,7 +588,7 @@ export async function runSharedHost(
direct: boolean
): Followup | null => {
// A direct chat's reset is meant to forget the conversation; its placement survives, so nothing is owed.
- if (direct) return null;
+ if (direct && command.body.type === 'session.reset') return null;
const action =
command.body.type === 'session.reset'
? 'reset'
diff --git a/console/packages/plugins/src/switch-skill/SKILL.md b/console/packages/plugins/src/switch-skill/SKILL.md
index 131a11432..f961568f9 100644
--- a/console/packages/plugins/src/switch-skill/SKILL.md
+++ b/console/packages/plugins/src/switch-skill/SKILL.md
@@ -1106,8 +1106,9 @@ An unknown outcome is never a reason to resend the action automatically.
After a confirmed reset or compaction, Switch queues a follow-up to reconnect,
read context, re-assume the previous role if one was held, and post a short
confirmation in the original thread with `post_message`. If the role cannot be
-restored, report that limitation. In a direct chat nothing is queued: a reset
-there is meant to start the conversation fresh, so do not read back its history.
+restored, report that limitation. In a direct chat a reset queues nothing: it
+is meant to start the conversation fresh, so do not read back its history. A
+compaction there still queues the follow-up.
Failed or unknown controls do not queue a success announcement.
## Tool index
diff --git a/core/switch_core/chats/views.py b/core/switch_core/chats/views.py
index 44068c7ac..0d0f799c6 100644
--- a/core/switch_core/chats/views.py
+++ b/core/switch_core/chats/views.py
@@ -349,11 +349,16 @@ def _command_text(message: Message) -> str:
return ""
command = message.content.get("command")
args = message.content.get("args")
- target = args.split()[0] if isinstance(args, str) and args.split() else ""
+ text_args = args if isinstance(args, str) else ""
+ target = text_args.split()[0] if text_args.split() else ""
line = _COMMAND_LINES.get(command) if isinstance(command, str) else None
- if line is None or not target.startswith("@"):
+ if line is not None and target.startswith("@"):
+ text = line.format(agent=target[1:])
+ elif line is not None and "@" not in text_args:
+ # Without an `@` the command addresses every agent in the room.
+ text = line.format(agent="everyone")
+ else:
return f"!{command} {args}".strip() if args else f"!{command}"
- text = line.format(agent=target[1:])
return f"{text} by {message.sender_name}" if message.sender_name else text
diff --git a/core/tests/switch_core/gateway/test_chats_controls.py b/core/tests/switch_core/gateway/test_chats_controls.py
index 5332d481d..d4fff58d6 100644
--- a/core/tests/switch_core/gateway/test_chats_controls.py
+++ b/core/tests/switch_core/gateway/test_chats_controls.py
@@ -6,6 +6,7 @@ from __future__ import annotations
from types import SimpleNamespace
import httpx
+import pytest
from sqlalchemy import select, update
from switch_core.addressing import owner_only_policy
@@ -140,6 +141,40 @@ async def test_a_posted_control_is_shown_in_the_chat(chats: _Harness) -> None:
)
+ ("command", "args", "body"),
+ [
+ ("interrupt", "", "Stop requested for everyone by alice"),
+ ("retry", "message-1", "Retry requested for everyone by alice"),
+ ("reset", "", "Context reset requested for everyone by alice"),
+ ("compact", "", "Compaction requested for everyone by alice"),
+ ("interrupt", "please @helper", "!interrupt please @helper"),
+ ("unknown", "", "!unknown"),
+ ],
+)
+async def test_a_control_with_no_target_is_shown_as_asked_of_everyone(
+ chats: _Harness, command: str, args: str, body: str
+) -> None:
+ agent = await chats.agent("helper", owner=chats.alice)
+ room_id = await chats.new_chat(chats.alice, agent, "c1")
+ response = await _control(chats, chats.alice, room_id, agent, "k1", "reset")
+ command_id = response.json()["commandId"]
+ async with chats.factory() as session:
+ await session.execute(
+ update(Message)
+ .where(Message.transport_event_id == command_id)
+ .values(content={"command": command, "args": args})
+ )
+ await session.commit()
+
+ page = await chats.client.get(
+ f"/chats/{room_id}/messages", headers=chats.as_user(chats.alice)
+ )
+ [shown] = [m for m in page.json()["messages"] if m["messageId"] == command_id]
+ assert shown["body"] == body
+ assert shown["sender"]["kind"] == "system"
+
+
async def test_stop_refuses_unless_the_agents_current_turn_is_in_this_chat(
chats: _Harness,
) -> None: