Skip to content

Commit 1bcec21

Browse files
authored
fix(gateway): gate session.tool mirrors behind session subscriptions (#124732)
session.tool mirrors the raw agent tool event (full args/result snapshots) onto session subscribers, but the event name was missing from SESSION_SUBSCRIPTION_EVENTS. Clients with the session-scoped-events cap (or browser copilot) that subscribed to one session's messages therefore received every session's tool payloads through the mirror — the exact data the registry gate suppresses on the raw agent event. session.observer was added to the set for precisely this mirror-event class; session.tool carries strictly more data. Root cause: the gate is an allowlist and the newer mirror event never joined it. One set entry; the payload already carries sessionKey so registry keying works unchanged, and unscoped Control UI clients keep full fanout. Regression: new board test drives the server-chat-style targeted fanout and asserts a scoped client subscribed to a different session receives nothing — fails pre-fix.
1 parent b7fb951 commit 1bcec21

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎src/gateway/server-broadcast.board.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,38 @@ describe("collaboration event scope guards", () => {
164164
expect(unsubscribed.socket.events).toEqual([]);
165165
});
166166

167+
it("suppresses session.tool mirrors for scoped clients without a matching subscription", () => {
168+
const subscribed = makeClient("subscribed", "operator", ["operator.read"]);
169+
const otherSession = makeClient("other-session", "operator", ["operator.read"]);
170+
const unscoped = makeClient("unscoped", "operator", ["operator.read"]);
171+
for (const entry of [subscribed, otherSession]) {
172+
entry.client.connect.caps = [GATEWAY_CLIENT_CAPS.SESSION_SCOPED_EVENTS];
173+
}
174+
const sessionMessageSubscribers = createSessionMessageSubscriberRegistry();
175+
sessionMessageSubscribers.subscribe(subscribed.client.connId, "agent:main:main");
176+
sessionMessageSubscribers.subscribe(otherSession.client.connId, "agent:main:other");
177+
const { broadcastToConnIds } = createGatewayBroadcaster({
178+
clients: new Set([subscribed.client, otherSession.client, unscoped.client]),
179+
sessionMessageSubscribers,
180+
});
181+
182+
// Mirrors the server-chat session.tool fanout: targeted at all session
183+
// subscribers, session identity carried in the payload.
184+
broadcastToConnIds(
185+
"session.tool",
186+
{ sessionKey: "agent:main:main", tool: { name: "exec", args: { command: "ls" } } },
187+
new Set(["subscribed", "other-session", "unscoped"]),
188+
{ dropIfSlow: true },
189+
);
190+
191+
expect(subscribed.socket.events).toEqual(["session.tool"]);
192+
// The scoped client subscribed to a different session must not receive
193+
// another session's tool args via the mirror event.
194+
expect(otherSession.socket.events).toEqual([]);
195+
// Unscoped Control UI clients keep full fanout.
196+
expect(unscoped.socket.events).toEqual(["session.tool"]);
197+
});
198+
167199
it("delivers prepared global observer audiences exactly once", () => {
168200
const main = makeClient("main", "operator", ["operator.read"]);
169201
const legacy = makeClient("legacy", "operator", ["operator.read"]);

‎src/gateway/server-broadcast.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ const SESSION_SUBSCRIPTION_EVENTS = new Set([
103103
"chat",
104104
"chat.side_result",
105105
"session.observer",
106+
// Mirrors the raw agent tool event (full args/result snapshots) onto
107+
// session subscribers; omitting it here would hand scoped clients the
108+
// exact payload the registry gate suppresses on the `agent` event.
109+
"session.tool",
106110
]);
107111

108112
function serializeFrameField(name: "payload" | "stateVersion", value: unknown): string {

0 commit comments

Comments
 (0)