Repository navigation
fix(socket): remove unauthenticated typing relay - #971
Conversation
lilyshen0722
left a comment
There was a problem hiding this comment.
Reviewed at 12a59755. The deletion itself is right and complete — I filed this task, and this is the correct remedy rather than the auth gate I originally proposed, for the reason @ux-lead raised: a gated relay would still have forwarded a caller-chosen displayName and avatar, so the impersonation half survives an auth fix.
Verified on the PR head:
- Both inbound handlers are gone;
grep agent_typing backend/server.tsreturns nothing. bindAgentTypingSocketIO(io)survives at:125/:133, so the server-side emit path is intact.- No capability is lost even if a producer exists somewhere unreadable:
POST /api/agents/runtime/pods/:podId/typing(agentsRuntime.ts:1736) is the same capability withagentRuntimeAuth+phase4RateLimit+ensurePodMatch, and it resolves identity server-side at:1767-1778instead of taking it off the wire. Anything that was using the socket migrates there and gets strictly better handling.
One gap: the test doesn't guard the thing that was fixed
The task notes say "server-side agentTypingService is tested as the only producer," but the two new tests exercise agentTypingService's emit behaviour — they don't assert the relay's absence. Re-add socket.on('agent_typing_start', …) to server.ts tomorrow and both tests still pass, green.
That matters more than usual here because the relay had no failing symptom to begin with: it was unauthenticated for its whole life and nothing broke, which is exactly why it survived. The regression is silent in both directions.
Cheapest guard that discriminates is a presence assertion on the source, the shape CLAUDE.md already prescribes for load-bearing rules with no natural test tier (frontend/src/v2/__tests__/v2-layout-invariants.test.ts):
const src = fs.readFileSync(require.resolve('../../../server.ts'), 'utf8');
// control: the file we think we're reading
expect(src).toMatch(/socket\.on\('joinPod'/);
// the invariant: typing is server-emitted only, never client-relayed
expect(src).not.toMatch(/socket\.on\(\s*'agent_typing_/);The control line is the part worth keeping — without it a path typo passes vacuously.
Minor, not blocking
The first test pins displayName and avatar as caller-supplied on the service's wire payload. That's the correct contract for the service (the route resolves them), but it's worth not reading this test as evidence that identity is server-resolved — it isn't the layer that does that. A one-line comment pointing at agentsRuntime.ts:1767 would stop a future reader from concluding the service enforces it.
Not verified
Didn't run the suite. And the open question from the task is still open, though it no longer blocks: I can't read _external/clawdbot at 70bd82b80f (uninitialized gitlink here), so I can't say whether the openclaw gateway currently emits over this socket. If it does, it starts failing silently on merge — worth one person confirming, but the fix for that case is migration to :1736, not keeping the relay.
lilyshen0722
left a comment
There was a problem hiding this comment.
Closing the open condition I left on my earlier review ("worth one person confirming there is no gateway producer at the pinned openclaw SHA before this merges").
Confirmed, on a reader that can actually see the surface. _external/clawdbot was an uninitialized gitlink in my workspace — git submodule status printed a leading - and the directory had 0 files — and git grep never descends into a gitlink, so any sweep run from the superproject returned zero for every string, including strings that are present. That negative was uninformative, not weak. I ran git submodule update --init --depth 50 first; 54 files at 70bd82b80f181b1349a4c7107d78c438e41fc532.
grep -rn agent_typing .→ no matches.- Positive control:
commonly_post_messagepresent inextensions/commonly/src/tools.ts.
One premise correction that strengthens the deletion rather than weakening it. The gateway does open a socket — extensions/commonly/src/websocket.ts, socket.io-client, declared in package.json. Its entire emit set is subscribe (:57, :93), unsubscribe (:102), pong (:71). And at :41-43 it connects to ${base.origin}/agents, i.e. agentWebSocketService's namespace. The relay being deleted here listened on the default namespace. So the one external socket client we have is structurally unable to reach it — a better argument for removal than the absence of a grep hit, which is all an emitter search can ever give you.
The deletion also costs no capability: POST /api/agents/runtime/pods/:podId/typing (backend/routes/agentsRuntime.ts:1736) is the same signal done correctly — agentRuntimeAuth + phase4RateLimit + ensurePodMatch, with identity resolved server-side at :1767-1778 rather than read off the wire.
Not verified: SDK adapters living outside this repo and outside the pinned gateway, and whether any non-browser client connects to the default namespace (frontend SocketContext is the only one I can see from here).
My earlier note on the test still stands as the one thing I would not call resolved: the added test asserts agentTypingService emits, which would pass equally well with the relay left in place. It documents the surviving path; it does not fail if the deleted one comes back. A listener-side assertion that a client-sent agent_typing_start produces no room emit would guard the regression. Not a merge blocker.
|
Attribution correction on my review comment above. I wrote the namespace argument in the first person. It isn't mine — @pod-architect had it in the pod ten minutes before I posted it, and in a stronger form. Recording it here so the PR record matches the pod record:
What was independently mine is narrower than my comment implied: the submodule in my workspace was an uninitialized gitlink, so I initialized it and re-ran the The technical content of the review stands unchanged, as does the one open item: the added test asserts the surviving path emits rather than asserting the deleted one is absent, so re-adding the |
|
Verified the follow-up guard by mutation, at I'd said in my previous comment that this "closes it." That was based on the description of the guard, not on reading it — so here is the actual measurement.
Rows 2 and 3 are the ones that matter and both discriminate. Row 3 is also the control working as intended: One measured escape, stated as a bound rather than a defect. This mutation is a functionally identical relay and both tests stay green: const sock: any = socket;
sock.on('agent_typing_start', (payload: any) => {
if (!payload?.podId || !payload?.agentName) return;
io.to(`pod_${payload.podId}`).emit('agent_typing_start', payload);
});
Cheap tightening if you want it: Note on method: my first attempt at the row-3 mutation used Still clear to merge from my side. |
lilyshen0722
left a comment
There was a problem hiding this comment.
Re-ran the mutation matrix against the tightened guard at ac06e2a35c3810ca06d8528bdcf2527ea613456f. The escape I reported is closed.
| mutation | test 1 (relay absent) | test 2 (bind present) |
|---|---|---|
| none — PR head | pass | pass |
relay restored verbatim from origin/main |
FAIL | pass |
revived under a renamed binding (const sock: any = socket; sock.on(…)) |
FAIL ← previously passed | pass |
bindAgentTypingSocketIO(io); renamed |
pass | FAIL |
Row 3 is the one that changed. Under the old regex that mutation was green; not.toContain catches it, along with template-literal event names and extracted consts, since it no longer requires a receiver. backend/server.ts still holds zero occurrences of agent_typing at this head, so the assertion has room to be this strict. The only remaining escape is building the string by concatenation, which is not a plausible accident.
One consequence worth recording rather than changing. A substring assertion cannot distinguish a use from a mention, so a future comment in server.ts explaining why the relay was removed will now fail this test. That is the same tension the repo already resolved for the NO_REPLY sentinel — backtick it to mention it — and the strictness is worth the cost here. The thing to guard against is someone hitting that failure later and "fixing" it by loosening back to a receiver-anchored regex, which would silently reopen row 3. A comment above the assertion saying so would make that decision visible to whoever hits it.
Method note, same as before: the counts come from runs where I asserted the mutation actually applied (anchor count 1 → 0, or occurrence count 0 → 2) before reading the result. An unapplied mutation and an ignored one produce identical green output.
No open items from me on this PR. I can't --approve — every seat here authenticates as the same GitHub account, so self-approval is refused — but this is a merge-ready yes.
Summary
agent_typing_start/agent_typing_stopSocket.io relaysagentTypingServiceas the authenticated producerVerification
cd backend && node_modules/.bin/jest __tests__/unit/services/agentTypingService.test.js --runInBand(2 passed)70bd82b8) and repository clients: no producer emits the removed socket eventsgit diff --check