Skip to content

fix(gateway): isolate channel direct messages per sender by default - #5440

Merged
freeqaz merged 5 commits into
mainfrom
fix-3191
Nov 11, 2026
Merged

freeqaz merged 5 commits into
mainfrom
fix-3191

Conversation

@freeqaz

@freeqaz freeqaz commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

OCE sets no session.dmScope, so OpenClaw's default "main" applies. An Agent can run Slack or Microsoft Teams (a dedicated workload with an Installation channel runtime) and browser chat at the same time, and nothing refuses that combination. With "main":

  • every approved channel direct-message sender shares one model context with the other senders and with agent:main:main, the session that members' browser chat opens by default;
  • OpenClaw also turns on recall across conversations when dmScope resolves to "main".

So external channel users, who are not OCE principals, can get the Agent to repeat members' chat content and tool output.

Not changed: members can still read channel conversations. That is the documented native admin pilot sharing (docs/design.md, "Native admin pilot exception").

Change

  • packages/occ/src/gateway-security-defaults.ts: when the Configuration enables a channel and leaves session.dmScope unset, deployment admission fills "per-account-channel-peer". An explicit value, including "main", is kept. A route binding's bindings[].session.dmScope still wins for its route (and, like any non-main scope, turns cross-conversation recall off). After the next deployment, new browser chat sessions on such an Agent are no longer grouped under main. A conformance test pins the duplicated enabled-channel rule to enabledChannelEntries.
  • Only with a channel. An enabled channel follows the rule of enabledChannelEntries (packages/occ/src/channel-secret-bindings.ts), which decides the channel runtime and the channel Secret bindings: any channels key except defaults and modelByChannel whose enabled is not false. The module must stay import-free (the Console serves it and scripts/first-agent-model.mjs loads it without packages), so it repeats that rule, with a comment in both places. A browser-only Agent gets no session settings, so OpenClaw's "main" and its recall across conversations stay. If a channel is added later, the next deployment fills the default.
  • The defaults' predicates now receive the document root as well as the object that would hold the setting. The other defaults keep their behavior.
  • Why per-account-channel-peer and not per-channel-peer: OCE channels accept named accounts. slackAccountTargets (packages/occ/src/channel-secret-bindings.ts) starts each channels.slack.accounts entry, and docs/reference/configuration/secrets.md documents binding named Slack accounts. The account-scoped key keeps one sender's sessions separate across two accounts. For a single-account channel it is the same isolation as per-channel-peer, with default in the session key.
  • Docs:
    • docs/reference/configuration.md lists the default beside the others and links to a new "Direct-message sessions" subsection in docs/reference/configuration/secrets.md. That subsection gives the channel rule, the reason, the recall default, how to keep "main", and what existing Agents see. The page was at the 2500-word limit, so the detail lives in the channel reference. One sentence was removed: the values.channels lifecycle sentence, which the Configuration lifecycle text above it already covers.
    • docs/design.md says that channel conversations are among the shared conversations, and that each channel direct-message sender gets a separate session by default.
    • The Console guide no longer tells former corporate preset users to set dmScope themselves when a channel is enabled.

Where it applies

The fill runs in agentRuntimeConfiguration (packages/occ/src/index.ts) for every deployment, for every Compute Driver and execution mode. Console create, the API and provisioning all deploy through that path. The stored Configuration and existing AgentRevisions do not change. An existing Agent gets the new default on its next deployment.

What existing Agents see after their next deployment

Agents without an enabled channel: no change.

For an Agent with an enabled channel that did not set session.dmScope:

  • Each channel direct-message sender starts a new session (agent:main:<channel>:<account>:direct:<sender>). Earlier direct-message turns stay in the main session's history; the new per-sender session does not include them.
  • The main session that browser chat opens keeps its history. New channel direct messages no longer go into it.
  • Recall across conversations (memory.search.rememberAcrossConversations) is off unless the Configuration sets it.

To keep the old behavior, set session.dmScope: "main" in the Configuration.

Verification

  • tests/conformance/configuration-occ.test.mjs deploys through deployAgent. The new block checks each case with a dedicated Agent:

    • no channel: no session is filled, so recall is unchanged;
    • a disabled channel: no session is filled;
    • a Slack channel: per-account-channel-peer;
    • named Slack accounts: per-account-channel-peer;
    • an explicit "main" with a channel: kept.

    The existing case matrix keeps an explicit session.dmScope: "main" without channels.

  • tests/helpers/admitted-configuration.mjs has a new GATEWAY_SECURITY_DEFAULTS row whose predicate sees the root. It is kept separate from the product module, so a dropped or widened default fails the tests. Like admission, the helper no longer adds empty objects for a fill it does not admit.

  • tests/integration/first-agent-startup.test.mjs: the first-Agent Configuration enables no channel, so the subset loop now runs over the defaults that apply to it (no session.dmScope). The explicit-drift loop still covers every row, so an explicit "main" there is drift.

  • Runner VM, at head f6e199335c: bun fmt --check and eslint --max-warnings 0 on touched files are clean, and pnpm typecheck passes. node --test tests/conformance/configuration-occ.test.mjs tests/integration/first-agent-startup.test.mjs tests/conformance/console-gateway-safety.test.ts: 83 pass, 0 fail. pnpm docs:check passes; docs/reference/configuration.md is 2491 words.

  • No runtime dogfood. The OpenClaw session-key behavior comes from the pinned commit (src/routing/session-key.ts, per-account-channel-peer branch).

Risks

  • Behavior change on the next deployment of an Agent that has an enabled channel and no explicit session.dmScope: channel direct-message senders lose the shared main context, and recall across conversations turns off by default. This is intended. session.dmScope: "main" restores the old behavior. Browser-only Agents do not change.
  • gateway-security-defaults.ts repeats the enabled-channel rule instead of importing it. If enabledChannelEntries changes, this rule must change too; both places say so.
  • No upgrade notice is added. The change is described here and in the configuration reference.

OCE set no session.dmScope, so OpenClaw's "main" applied: every approved
Slack or Teams direct-message sender shared one model context with the
others and with the main session that browser chat opens, and recall
across conversations was on. Deployment admission now fills
session.dmScope = "per-account-channel-peer" when unset; explicit values
are kept. OCE channels accept named accounts, so the scope includes the
account. Finding 3191.
…l reference

The configuration reference hit the 2500-word limit. Keep a one-line
pointer beside the other defaults, and describe the per-sender sessions,
the recall default and the effect on existing Agents in the channel
configuration reference. Drop the channels lifecycle sentence, which the
Configuration lifecycle text above already covers.
@freeqaz
freeqaz requested a review from a team as a code owner November 11, 2026 08:59
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

…abled

A browser-only Agent has no direct-message senders to isolate, and
OpenClaw's "main" scope keeps its recall across conversations. The
session.dmScope default now applies only when the Configuration enables
a channel, by the rule enabledChannelEntries uses for the channel
runtime and Secret bindings. Defaults now see the document root, not
only the object that would hold the setting. The test helper adds no
empty objects for a fill it does not admit, as admission does.
Finding 3191.
…rift check

The first-Agent Configuration enables no channel, so admission fills no
session.dmScope there and a revision without it is not drift. Format the
touched files.
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
gateway-security-defaults.ts repeats the enabled-channel rule so it can stay import-free. A
table test now fails if the two copies disagree (shared keys, enabled "false", non-object
entries). Docs: new browser chat sessions on a channel Agent are no longer grouped under
main after the next deployment; design.md keeps only the architectural clause.
@clawsweeper

clawsweeper Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): isolate channel direct messages per sender by default This is item 1/1 in the current shard. Shard 0/1.

This temporary status tracks the active review worker. The completed review will appear in the durable ClawSweeper review comment.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@freeqaz
freeqaz merged commit 6905a20 into main Nov 11, 2026
42 of 45 checks passed
@freeqaz
freeqaz deleted the fix-3191 branch November 11, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant