Repository navigation
fix: session-scoped members cannot start an unused agent conversation - #197151
Conversation
A person with only operator.sessions.write who opened an agent's main conversation before anyone had used it saw "Session agent:main:main was not found" and a disabled composer, although chat.send would already create the conversation and record them as its creator. The Gateway now admits sessions.messages.subscribe to an absent session only for a session writer and only for the agent's own main conversation. Other absent keys, session-only readers and existing rows keep the hidden-session answer; event delivery still filters each event by current visibility. The Control UI enables the first chat.send for a session writer only after a read on the current connection proved the session has no row. Unproven absence, member or viewer rows and other mutations still need ownership.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesAllows session writers to open an agent’s unused main conversation and send its first message. Example: A browser with only operator.sessions.write opens unused agent:main:main.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open for landing: it fixes a current permission mismatch, preserves delivery authorization, and has no actionable findings; the exact-head CI gate remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Control UI derives composer access from negotiated scopes and accepted history, while Gateway subscription and sharing owners authorize admission and outgoing session events. flowchart LR
A[Session writer browser] --> B[Subscription admission]
B --> C[Current scopes and agent policy]
B --> D[Accepted empty history]
D --> E[Composer access]
E --> F[Existing chat send owner]
F --> G[Current event visibility]
G --> A
Technical reviewBest possible solution: Align subscription and composer admission with existing first-turn authority while preserving current authorization at every event delivery. Do we have a high-confidence way to reproduce the issue? Current-main gates explain the supplied before screenshot and reported base-red regressions; this read-only review did not execute a reproduction. Is this the best way to solve the issue? The fix uses existing retained-read, accepted-history, and composer-access owners without adding storage or a competing creation path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 40168696c2d0. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +73, Tests +482, Docs +6, Other +5. Total +566 across 13 files. Added test files: 4. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 11, 2026, 5:42 AM ET / 10:42 UTC (Revision 3). |
A session writer whose role excludes an agent could subscribe to that agent's unused main conversation and learn whether it existed, although its first turn there would be refused. The startable-main check now also requires the same agent limit that chat.send applies. The relaxation now lives only in the subscribe opt-in of the retained session read. The copy in the shared target read was reachable only from sessions.describe and process-stop checks, which never needed it. Tests move to their own file and cover the agent limit, main key aliases, events from another creator's draft main after an early subscribe, refused turns on another creator's main, other reads of an absent main, and the Control UI falling back to row-based gating once a row arrives.
chat.history and chat.startup answer an absent conversation with an empty history for every caller; only a subscription, and reads that need an existing conversation, return the hidden not-found answer.
…n or revoked delivery The real-Gateway narrow test now drives one admitted subscriber to an absent agent:main:main through the rest of its lifetime: another creator's draft main and its turns stay hidden (and the subscriber's chat.send there is refused), a shared main is delivered, a role narrowed to no other sessions keeps the socket but receives nothing, and a role that loses the connection's scopes closes it. With the send-time delivery check removed from the broadcaster, the test fails at the draft step. That replaces the in-process broadcaster case and the separate foreign-main chat.send case in server-methods.session-main-start.test.ts, folds the non-main override key into the alias table, and drops the duplicate viewer row cases from the UI unit and mock-Gateway e2e tests, which row gating already covers. The remaining net test growth (482 lines) gets its own allocation record instead of a scalar raise.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…openclaw#197151) A browser connection capped at operator.sessions.write could not open an agent's unused main conversation: the subscription returned not-found and the Control UI disabled the composer, so a chat-only user could not send the first turn. Such a writer may now subscribe to its own agent's absent main conversation (empty history), when its role may start sessions for that agent; the composer allows the first send only after a read on the current connection proved the conversation absent. Delivery is still re-authorized per event: foreign drafts deliver nothing, a narrowed role delivers nothing, revoked scopes close the socket.
## Problem Open a brand-new main chat (no messages yet, for example right after onboarding sets a model). Session Details shows a red "Session process access changed; refresh the conversation." with Retry until the first reply arrives. The Gateway log shows three refused reads for the same chat: - `sessions.processes.list` → `FORBIDDEN` "Session process access changed; refresh the conversation." - `mcp.app.discover` → `FORBIDDEN` "The requested session is unavailable; open an existing session first." - `talk.catalog` → `INVALID_REQUEST` "No session found: agent:main:main" A config hot reload is not needed: a fresh profile with a model already configured shows the same three refusals.  ## Root cause The agent's main conversation has no session row until its first turn creates it. The chat still starts session-scoped reads for it on open: - Session Details reads processes as soon as it renders (`ui/src/pages/chat/chat-pane-layout-render.ts:293`, process Details since #175041). The Gateway has no row to bind the list to and answers with the access-changed error (`src/gateway/server-methods/session-processes.ts:69-79`, since #164061). - The composer mounts MCP discovery for the chat. The composer already has a `sessionAdmitted` gate for provisional sessions (`chat-composer-view.tsx:414`, #166865), but the chat pane never set it. Discovery needs a session authority, which needs a row (`src/gateway/session-access-authority.ts:246`). - The composer reads the session-scoped Talk catalog. The catalog only uses the key to pick the agent, but `talk.catalog` refused the missing row (`src/gateway/talk/handlers/catalog.ts:536`). Subscriptions already admit the caller's own unstarted main conversation (`isStartableMainSession`, #197151). v2026.11.6 has the same chat pane and process code. ## Fix Each reader is fixed at the owner of the fact it depends on: | Read | Depends on | Owner and fix | |---|---|---| | `sessions.processes.list` | the row's `sessionId` | Control UI: Details stops offering process reads once the chat's history read proved the session absent (`isChatSessionProvenAbsent`, #197151). A cold load of an existing chat keeps its Details layout while rows load. | | `mcp.app.discover` | a session authority built from the row | Control UI: the chat pane sets the composer's existing `sessionAdmitted` gate from the selected row, so composer extensions mount once it exists | | `talk.catalog` | only the agent named by the key | Gateway: answers the caller's own unstarted main conversation from its agent (same `isStartableMainSession` rule as subscriptions); other missing or hidden keys still get "No session found" | Holding `talk.catalog` in the UI instead would keep dictation unavailable for the first message, and the protocol has no agent-only form of the request. Same PR, first send (two causes, both at their owner): - **Diff baseline (session creation owner).** The first turn captures the session diff baseline (`sessionDiffBaseline`, the files that existed before the session) about half a second after `chat.send` creates the row. A diff read in that window either showed pre-existing workspace files as session changes or was refused with "Session workspace changed during file access" when the baseline landed. A new operator conversation now records the pending baseline claim (`sessionDiffBaselineCapture`) with its row, as `sessions.create` already does (`buildNewSessionCreationFields` in `src/config/sessions/session-diff-baseline-capture.ts`), and the diff answers "no changes" while the claim is pending (`src/gateway/server-methods/sessions-diff.ts`). The first turn's existing capture settles the claim. - **Skill-library selection (workspace owner).** The first turn writes an empty selection (`librarySelections: []`) into a row that had none, and the session file workspace compared `undefined` with `[]` strictly. The sandbox owner already treats both as "no selection" (`librarySelections?.length`); the workspace check now does too. The existing access-change refusals (replaced row, revoked sharing) are unchanged. ## Impact - A new chat opens without an error. Processes and MCP controls appear after the first turn, which is when they can have content. The first message can be dictated. - No protocol or schema change.  ## Evidence - Real-Gateway Control UI e2e `ui/src/e2e/chat-new-session-readers.real-gateway.e2e.test.ts`: opens `agent:main:main` before its first turn at 1600x900, sends the first message, checks that no non-retryable Gateway read failed and that process, MCP and diff reads succeed after the row exists. Red on the merge base (the three refusals above), green on this branch. - `src/gateway/talk/handlers/catalog.test.ts` "answers the caller's unstarted main conversation from its agent": red on the merge base, green here. A missing non-main key and a caller who cannot start the conversation still get "No session found". - `src/gateway/server-methods/sessions-diff-reset.test.ts` "shows no changes for a new operator conversation before its first turn captures the baseline": creates the row through the real reply session init, then reads the diff of a repo with a pre-existing file. Red on the merge base (the pre-existing file is listed as a session change), green here. - `src/gateway/server-methods/session-file-live-read.test.ts` "keeps a diff read across the first turn recording no library skills": red on the merge base, green here; a real selection change still invalidates. - Isolated Gateway with a real provider, fresh agent main chat, Control UI at 1600x900: base shows the alert and logs the three refusals; this branch shows no alert and no refusal, and the first reply arrives. - Existing consumers: `chat-pane-side-panels.test.ts`, `chat-details-reload.e2e.test.ts`, `test/vitest-ui-e2e-config.test.ts` green. `chat-pane-state-snapshot.e2e.test.ts` was red on `main` and is fixed separately in #203246. - `pnpm tsgo:ui`, `pnpm check:test-types`, `pnpm check:changed` (the dead-export scan reports two exports in files this PR does not touch; same on `main`). Isolated Gateway first-send log (fresh agent, real provider, head rebased on #203283): from opening the brand-new chat through the first reply, no FORBIDDEN, UNAVAILABLE or INVALID_REQUEST line. The `talk.catalog` first-read "warming" answer is fixed at its owner in #203283. ## Merge danger Two-way door: a revert fully restores the previous behavior. No stored state, config or published contract changes. Blast radius: Control UI chats, `talk.catalog` callers for an unstarted main conversation, new operator session rows (pending diff-baseline claim), and session file/diff reads across the first turn. Co-authored-by: Ayaan Zaidi <[email protected]>
…w#203126) ## Problem Open a brand-new main chat (no messages yet, for example right after onboarding sets a model). Session Details shows a red "Session process access changed; refresh the conversation." with Retry until the first reply arrives. The Gateway log shows three refused reads for the same chat: - `sessions.processes.list` → `FORBIDDEN` "Session process access changed; refresh the conversation." - `mcp.app.discover` → `FORBIDDEN` "The requested session is unavailable; open an existing session first." - `talk.catalog` → `INVALID_REQUEST` "No session found: agent:main:main" A config hot reload is not needed: a fresh profile with a model already configured shows the same three refusals.  ## Root cause The agent's main conversation has no session row until its first turn creates it. The chat still starts session-scoped reads for it on open: - Session Details reads processes as soon as it renders (`ui/src/pages/chat/chat-pane-layout-render.ts:293`, process Details since openclaw#175041). The Gateway has no row to bind the list to and answers with the access-changed error (`src/gateway/server-methods/session-processes.ts:69-79`, since openclaw#164061). - The composer mounts MCP discovery for the chat. The composer already has a `sessionAdmitted` gate for provisional sessions (`chat-composer-view.tsx:414`, openclaw#166865), but the chat pane never set it. Discovery needs a session authority, which needs a row (`src/gateway/session-access-authority.ts:246`). - The composer reads the session-scoped Talk catalog. The catalog only uses the key to pick the agent, but `talk.catalog` refused the missing row (`src/gateway/talk/handlers/catalog.ts:536`). Subscriptions already admit the caller's own unstarted main conversation (`isStartableMainSession`, openclaw#197151). v2026.11.6 has the same chat pane and process code. ## Fix Each reader is fixed at the owner of the fact it depends on: | Read | Depends on | Owner and fix | |---|---|---| | `sessions.processes.list` | the row's `sessionId` | Control UI: Details stops offering process reads once the chat's history read proved the session absent (`isChatSessionProvenAbsent`, openclaw#197151). A cold load of an existing chat keeps its Details layout while rows load. | | `mcp.app.discover` | a session authority built from the row | Control UI: the chat pane sets the composer's existing `sessionAdmitted` gate from the selected row, so composer extensions mount once it exists | | `talk.catalog` | only the agent named by the key | Gateway: answers the caller's own unstarted main conversation from its agent (same `isStartableMainSession` rule as subscriptions); other missing or hidden keys still get "No session found" | Holding `talk.catalog` in the UI instead would keep dictation unavailable for the first message, and the protocol has no agent-only form of the request. Same PR, first send (two causes, both at their owner): - **Diff baseline (session creation owner).** The first turn captures the session diff baseline (`sessionDiffBaseline`, the files that existed before the session) about half a second after `chat.send` creates the row. A diff read in that window either showed pre-existing workspace files as session changes or was refused with "Session workspace changed during file access" when the baseline landed. A new operator conversation now records the pending baseline claim (`sessionDiffBaselineCapture`) with its row, as `sessions.create` already does (`buildNewSessionCreationFields` in `src/config/sessions/session-diff-baseline-capture.ts`), and the diff answers "no changes" while the claim is pending (`src/gateway/server-methods/sessions-diff.ts`). The first turn's existing capture settles the claim. - **Skill-library selection (workspace owner).** The first turn writes an empty selection (`librarySelections: []`) into a row that had none, and the session file workspace compared `undefined` with `[]` strictly. The sandbox owner already treats both as "no selection" (`librarySelections?.length`); the workspace check now does too. The existing access-change refusals (replaced row, revoked sharing) are unchanged. ## Impact - A new chat opens without an error. Processes and MCP controls appear after the first turn, which is when they can have content. The first message can be dictated. - No protocol or schema change.  ## Evidence - Real-Gateway Control UI e2e `ui/src/e2e/chat-new-session-readers.real-gateway.e2e.test.ts`: opens `agent:main:main` before its first turn at 1600x900, sends the first message, checks that no non-retryable Gateway read failed and that process, MCP and diff reads succeed after the row exists. Red on the merge base (the three refusals above), green on this branch. - `src/gateway/talk/handlers/catalog.test.ts` "answers the caller's unstarted main conversation from its agent": red on the merge base, green here. A missing non-main key and a caller who cannot start the conversation still get "No session found". - `src/gateway/server-methods/sessions-diff-reset.test.ts` "shows no changes for a new operator conversation before its first turn captures the baseline": creates the row through the real reply session init, then reads the diff of a repo with a pre-existing file. Red on the merge base (the pre-existing file is listed as a session change), green here. - `src/gateway/server-methods/session-file-live-read.test.ts` "keeps a diff read across the first turn recording no library skills": red on the merge base, green here; a real selection change still invalidates. - Isolated Gateway with a real provider, fresh agent main chat, Control UI at 1600x900: base shows the alert and logs the three refusals; this branch shows no alert and no refusal, and the first reply arrives. - Existing consumers: `chat-pane-side-panels.test.ts`, `chat-details-reload.e2e.test.ts`, `test/vitest-ui-e2e-config.test.ts` green. `chat-pane-state-snapshot.e2e.test.ts` was red on `main` and is fixed separately in openclaw#203246. - `pnpm tsgo:ui`, `pnpm check:test-types`, `pnpm check:changed` (the dead-export scan reports two exports in files this PR does not touch; same on `main`). Isolated Gateway first-send log (fresh agent, real provider, head rebased on openclaw#203283): from opening the brand-new chat through the first reply, no FORBIDDEN, UNAVAILABLE or INVALID_REQUEST line. The `talk.catalog` first-read "warming" answer is fixed at its owner in openclaw#203283. ## Merge danger Two-way door: a revert fully restores the previous behavior. No stored state, config or published contract changes. Blast radius: Control UI chats, `talk.catalog` callers for an unstarted main conversation, new operator session rows (pending diff-baseline claim), and session file/diff reads across the first turn. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes: a person with only
operator.sessions.write(for example a chat-only member behind a trusted proxy that caps the connection's scopes) who opens a fresh agent's chat sees "Couldn't load this conversation: Session "agent:main:main" was not found." and a disabled composer ("You need permission to send messages in this session."). It only starts working after someone with broader access has chatted once.User Impact
User impact: session-scoped people can open an agent's unused main conversation and send its first message, which makes them its creator. They get no new administrative, configuration, device, approval, or cross-session access.
Why This Change Was Made
Two gates disagreed with what the Gateway already allows.
chat.sendfrom a session writer to the absent main conversation already succeeds and records the caller as creator, andchat.history/chat.startupalready return an empty conversation. But:sessions.messages.subscribetreated every absent row as hidden for session-scoped readers, so the Control UI's foreground subscription failed with not-found.sharingRolefor session writers, and an absent session has no row.The Gateway now admits a subscription to an absent session only when the caller holds
operator.sessions.write, its role may start sessions for that agent (the same agent limitchat.sendapplies), and the key is the agent's own main conversation (same canonical store key). Onlysessions.messages.subscribeopts in; other session reads, session-only readers, every other absent key, and existing rows keep the current not-found behavior. Admission grants nothing after it: every event is still authorized against the subscriber's current role, scopes and the row's visibility when it is written to the socket, and a missing row delivers nothing.The Control UI enables
chat.sendfor a session writer only when a successful read on the current connection proved that the session has no row (committed history without a session ID). Unproven absence, existing member/viewer rows, and other mutations still need ownership. Absence never grants broader or administrative scopes.Evidence
Real Gateway and Control UI
On a remote test VM: a Gateway child process built from this head, a header-injecting trusted proxy (
x-forwarded-userplusx-openclaw-scopes: operator.sessions.write, one shared identity as in a proxy-capped deployment), the real Control UI in headless Chromium, and a stub Responses model on loopback (no real credentials). The proof harness was a throwaway Vitest file run against this checkout and is not part of the diff. Frames below are from the browser's WebSocket, trimmed.First turn, one browser with only
operator.sessions.write:sessions.messages.subscribe {key: "agent:main:main"}→Session "agent:main:main" was not found.; the page shows "Couldn't load this conversation" and "You need permission to send messages in this session."scopes: ["operator.sessions.write"]; the same subscribe →subscribed: true, 0 messages, no session ID; the composer is editable;chat.sendruns one model turn and the reply renders.Admitted socket, then a foreign draft and revocations. Two browsers on one Gateway with roles: a member capped by its route to
operator.sessions.write, an owner capped tooperator.read,operator.write; an administrator changes the member's role withusers.setRole.sessions.messages.subscribe→subscribed: true, 0 messages, no session IDagent:main:mainas a draft and runs a turnchat.send→ "Session-scoped writes require your own session."; a fresh subscribe to main → not foundsession.message,chat,agentandsessions.changedevents (26)sessions.others: none(same scopes)Tests
Red/green on the same VM (red = the code before this change, green = this head):
src/gateway/server.chat-main-session-narrow.test.ts(new, real Gateway, trusted proxy):operator.sessions.writesubscribes to absentagent:main:mainand gets an empty, session-less snapshot; another absent key stays not-found;chat.sendsucceeds;config.getstaysFORBIDDEN.chat.sendthere is refused. After the owner shares main the same socket receives the conversation; after the member's role narrows to no other sessions it receives nothing with the socket open; after its role loses its scopes the socket is closed.expected [ 'chat', 'session.message' ] to deeply equal []).src/gateway/server-methods.session-main-start.test.ts(new): admission with and without gateway roles (red on main); another absent key, a session-only reader and another creator's draft main stay not-found with no subscriber registered; the role's agent limit; main key aliases, including asession.mainKeyoverride (red on main) and a non-main key under it;sessions.files.listandsessions.diffon the absent main stay not-found after the subscribe.ui/src/lib/session-method-access.test.tsandui/src/pages/chat/chat-main-session-absent.test.ts(new): the composer allows the first turn only after a read on the current connection proved the session absent. Once a row arrives, row-based gating takes over; a later read that finds the session, or a new connection epoch, removes the exemption (red on main).ui/src/e2e/guest-absent-main-session.e2e.test.ts(Control UI mock Gateway e2e): the composer is editable on an absent main and sendschat.send.Checks on this head: the touched Gateway tests (13 passed) and UI unit tests (17 passed), the mock-Gateway e2e above,
tsgotest:src/test:ui, oxlint, the format check and the max-lines check pass; production code is unchanged since the previous head, wheretsgocore/ui and the consumer tests passed.Test lines: this adds
config/test-lines-allocations/197151-chat-scope-first-session.txtfor exactly the net growth (482 lines) instead of raising the shared scalar. The growth is the real-Gateway proof that admission adds no delivery after it, plus the regression tests for the two gates; duplicated in-process broadcaster and row-gating cases were folded into those.Risks
session.dmScopedefaults tomain, so channel DMs shareagent:main:main. Session writers could already claim that conversation throughchat.sendorsessions.createbefore this change. This PR does not widen that, but deployments that give people session-only access alongside default DM routing should setsession.dmScopeto a per-peer value such asper-channel-peer.chat.sendis refused.