Repository navigation
feat(permissions): add conversations namespace and update permissions… - #617
Conversation
… for agent events
There was a problem hiding this comment.
ℹ️ Minor suggestion inline — the security fix itself looks correct.
Reviewed changes
conversationsnamespace added — newEventNamespacevalue mapped toconversations:readinNAMESPACE_PERMISSIONS(permissions.ts:21,:31).agent.*re-routed —eventNamespace()now sends project-scopedagent.*events toproject:<id>:conversationsinstead oftasks(permissions.ts:70).- Join/leave need no change —
server.tsiteratesNAMESPACE_PERMISSIONS, so the new room is joined for users withconversations:read. Owner-private and global-chatagent.*events keep routing to the per-user room insubscriber.ts.
I verified the project-scoped branch actually carries conversation content: agent.conversation.*, agent.thinking/action/observation/message, and agent.agent_message_chunk are all correctly gated behind conversations:read now, closing the #615 leak. One agent.* event is not conversation content and is affected by the blanket rule — flagged inline.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
The agent.session.started tasks-room copy this PR adds is unreachable for the events the API actually publishes — the event instead lands in the whole conversations room with no per-conversation check. Details inline.
Reviewed changes
- Per-conversation delivery added —
conversation-access.tschecks each candidate socket's account againstGET /projects/:id/conversations/:id(30s cache), serializes events per conversation, and fails closed; a 401 disconnects the socket so it re-handshakes. - API client extended —
canReadConversation(api-client.ts) calls the REST route that enforces per-conversationconversations:read, returning false on 403/404 and throwing otherwise. - Project-scoped
agent.*routing reworked — events with a top-levelconversation_idgo through the per-conversation check;agent.session.startedis copied to the tasks room;agent.acp_bridge.statusreturns totasks. - Prior review feedback addressed —
agent.acp_bridge.statusis now special-cased to thetasksroom ahead of the genericagent.*rule (permissions.ts:69), resolving the earlier inline thread. - Docs and tests added — README documents the
conversationsroom and delivery model;conversation-access.test.tscovers caching, ordering, allow/deny, fail-closed, 401 handling, and namespace mapping.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| ): void { | ||
| // Task boards refresh on a conversation starting. The task-room copy | ||
| // carries no conversation content, only which conversation it was. | ||
| if (event.type === "agent.session.started") { |
There was a problem hiding this comment.
This tasks-room copy never runs for real traffic. The API fans agent.session.started out as a task activity whose payload keeps conversation_id inside the stringified content field ({"conversation_id":…,"agent_id":…}), not at the top level, so the guard at subscriber.ts:179 is false, routeConversationEvent is never entered, and the event falls through to the whole project:<id>:conversations room — bypassing the per-conversation check this PR introduces. The README's "payload-free … also goes to the tasks room" exception (README.md:116) therefore doesn't hold.
Technical details
# `agent.session.started` never reaches `routeConversationEvent`
## Affected sites
- `services/realtime/src/subscriber.ts:179-184` — guard requires a top-level string `conversation_id`; the activity payload has none.
- `services/realtime/src/subscriber.ts:225-230` — the dead tasks-room copy.
- `services/api/internal/service/activity/service.go:85-99` — `EntityPayload` puts `conversation_id` inside the stringified `content`.
- `services/api/internal/service/task/activity_service.go:232-243`, `services/api/internal/transport/http/handler/agent_handler.go:1684-1696`, `services/api/internal/worker/notification_consumer.go:355-366`, `services/api/internal/worker/automation_consumer.go:2238-2249` — all record `agent.session.started` with `content = {conversation_id, agent_id}`; `FanoutTo` publishes the payload verbatim.
- `services/realtime/README.md:116-118`, `services/realtime/src/subscriber.ts:20-21`, `:223-224` — document an exception that does not occur.
## Required outcome
- Task boards receive the payload-free `agent.session.started` signal as documented (or the README/PR body drops the claim), and the event is not broadcast to the whole `conversations` room unchecked.
## Suggested approach (optional)
- Lift `conversation_id` to the top level of the `agent.session.started` realtime payload (in the producer's `RecordActivity` payload shape), so the guard matches; or parse the nested `content` in `routeEvent`.
- Consider making the generic branch fail closed for `agent.*` events without a top-level `conversation_id`, so a future content-bearing agent event (or a plugin-emitted topic via `paca.event_emit`/`paca.activity_record`) cannot reach the whole room unchecked.
- Update the now-inaccurate "no per-message permission checks are needed" headers in `subscriber.ts:29-33` and `server.ts:29-32`.
## Open questions for the human
- Is the task-board refresh a real requirement? The web client's `applyRealtimeAgentEvent` (`apps/web/src/lib/agent-api.ts:1839`) also keys on a top-level `conversation_id`, so `use-project-realtime.ts:302`'s `invalidateTaskViews()` for this type was already dead before this PR.
Summary
Fixes #615.
services/realtimerouted everyagent.*event to a project'stasksroom, which anyone withtasks.readjoins. Those events carry full conversation content (messages, reasoning, tool actions), so users withoutconversations.read, or excluded from a specific conversation, received it live even though the REST API denies them.Changes (
services/realtime)conversationsnamespace gated onconversations:read(permissions.ts);agent.*events no longer route totasks.conversation-access.ts,subscriber.ts,api-client.ts): theconversationsroom only lists candidates (project-wide read). For each event, the service asks the API (GET /projects/:p/conversations/:id, as the socket's account, the same check the REST routes use) and emits only to accounts that can read that conversation. This covers IAM policies that exclude a single conversation (e.g. by environment), which a project-wide permission list cannot see.agent.session.startedis also sent to thetasksroom with onlyproject_idandconversation_id.agent.acp_bridge.status(no conversation content) stays ontasks.conversationsroom and the delivery model.conversation-access.test.ts): caching, uncached failures, ordering, allowed/denied delivery, fail-closed and 401 handling, namespace mapping.Owner-private and global-chat events are unaffected (they already route to the owner's per-user room).
Testing
tsc --noEmit,biome checkandbun test(11 tests) pass inservices/realtime.Known limitations
conversations:readis only conditional (not project-wide) are not in the room, so they get no live events, same as the other namespaces.fetchSocketsassume a single realtime instance; scaling out would need revisiting.tasks,docs,sprints,environments,workflows) still use project-wide room membership fixed atjoin, so a conditionalDeny(a folder, a status, one environment) can still leak events, an account with only conditional grants gets none, and role changes apply only after a reconnect.Planned follow-up
A separate PR series will replace the conversation-only check with one mechanism for every event type, so that realtime follows the IAM resource-level policies. Proposal:
docs/architecture/realtime-authorization.md(to be added in that series). In short:ifchain inpermissions.ts; a contract file pins the routing.all/scoped/none.allaccounts keep using shared rooms (O(1) per event). Onlyscopedaccounts get per-resource checks, answered by the Go IAM engine through a batched API endpoint, with a short-lived cache. This replacesconversation-access.tsand closes the gaps above.iam.access_changedevent makes realtime re-run joins and drop cached decisions when roles, policies or members change.Open points: telling a client it lost access to a resource after an update, a bulk-authorize endpoint for hot resources with many scoped accounts, and whether plugin event topics need a namespace.