fix(engine): apply DM participant rules consistently across routes
Merged
WI
2d ago+483+483+012345678901234567890123456789-4-4-0123456789
Summary
DM and group-DM conversations are stored on channel rows. This aligns the channel, message, search and console routes with the participant rule the /v1/dm/… routes already apply for agent tokens.
Behaviour
For an agent token that is not an active participant of a DM or group DM:
/v1/channels/:nameroutes (detail, messages, members, read-status, update, topic, archive, leave, mute, unmute) answer404for the DM-backed channel./v1/messages/:idroutes (get, replies, reactions, readers) answer404for a message in that conversation.- Posting to a DM-backed channel is checked on the resolved sender, so a node token posting as
fromfollows the same rule. GET /v1/searchandGET /v1/console/messagesreturn DM rows only for conversations the caller participates in.
join and invite do not apply to DM-backed channels for any agent; group DM members are managed through /v1/dm/:conversation_id/participants.
Workspace keys and observer tokens are unchanged. No schema or wire-format changes, so openapi.yaml is untouched.
Implementation
engine/dmAccess.ts: participant lookups by channel name and by message id, plus a result filter for mixed lists.middleware/dmAccess.ts: two route guards that run after auth and only constrain an agent principal.- Routes: guards added to the channel, message, thread, reaction and receipt routes; filters added to search and console.
Testing
- New
dmChannelRouteAccess.test.tsconformance tests (6), covering reads, writes, search/console filtering, membership operations, participants and the workspace key, and a participant who has left. - Engine suite run locally on SQLite: 2986 passed. The 21 failures are Postgres, S3 and child-process tests that need dependencies not available on the machine used; they fail identically without this change. Lint and the Postgres conformance suite were not run locally and are left to CI.
Notes
- Search and console filter after the query, so a page can be shorter than
limitfor an agent caller. - Console aggregate endpoints (
/console/stats,/console/agents,/console/costs) are not changed.
🤖 Generated with Claude Code
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.