Skip to content

Store visibility on each Conversation #2380

Open

Description

@sentry-junior

Step 4 of #2207. Step 5 (GitHub webhook) depends on it. Step 2 is #2217.

Problem

Today Junior reads Conversation visibility from the shared Destination row of the Slack channel (junior_destinations.visibility). All Conversations in one channel or DM share that value. It has only two values: public (the company) and private.

This blocks #2207:

  • Work that starts from a public GitHub repository and runs in a person's private DM needs its own value. A shared row cannot hold it. If one dispatch marked the DM row public, every other Conversation in that DM would show as public.
  • Two values are not enough. "The company can see it" and "anyone can see it" are different audiences. Junior must not move company data to a public repository without review.

Design

The model is like Linux file permissions: a tier of readers, plus one group reference.

Readers

Tiers in order, from the fewest readers to the most:

Tier Readers Examples Slice 1 value
self one person a DM direct
group the members of one group a private channel, a private repository private
tenant the whole company a public channel internal
public anyone anywhere a public GitHub repository, external email, a Slack Connect channel world
  • tenant is a built-in group that contains every other group in the tenant. It is the only implicit superset.
  • Code compares tiers by their position in the list. SQL uses the same order (array_position). The repo does not allow Postgres enums (no-drizzle-pg-enums lint), so the column is text with a CHECK constraint.
  • Slice 1 (feat(conversations): Store ordered visibility on each root Conversation #2382) stores direct/private/internal/world. Slice 2 renames them in one step, so nothing is renamed twice.

Group reference

  • A Conversation at tier group also stores one group id. The id is a reference, not a member list: a Slack channel id, a GitHub repository id, and so on.
  • The plugin owns the id format. Ids have a namespace, for example slack:C123.
  • One function (membersOf(group) or similar) gets the members when a person reads. The plugin that owns the namespace answers it.
  • Flow checks compare the tier and the group id only. They never need member lists.
  • At tier self, the reader is the person who owns the Conversation (the root actor), so no extra id is stored.

Level: the intersection of all inputs

The level of a Conversation is the intersection of the readers of every input. It only gets narrower. Only an explicit publish action by a participant (#1545) can widen it.

Inputs Level
public and anything the other input
tenant and group A group A
group A and group A group A
group A and group B self
self and anything self

Two different non-tenant groups give self. Junior cannot name their intersection without member lists, so this fallback fails closed.

Every input counts:

  • The origin. Example: a public GitHub repository is public.
  • Each place that a message comes from. Examples: a DM reply is self. A reply in a Slack thread has the readers of that channel. A GitHub comment has the readers of its repository.
  • Each tool read, as core or the plugin reports it. Examples: memory recall (tenant since fix(memory): Make all memory public #2684), Brief and event search, and provider reads of private resources. Plugins report the readers of what a tool read, the same way as for writes.

Example: in a public Conversation that runs in a DM, the person's reply can contain private data. So the reply makes the level self. Later writes to the public repository still work, but each one gets forced Guardian review of the exact content.

Write check

  • The plugin that owns a write target reports its readers (tier, plus group id at group) through resolveApprovalMetadata. For example, GitHub repository visibility public, internal, or private maps to public, tenant, or group with the repository id.
  • A write needs no forced review when the readers of the target are a subset of the readers of the Conversation, by tier plus group id.
  • Every other write moves data up. It gets forced Guardian review and redaction (see below).

Read and write are separate

  • Write implies read. policies/conversation-access.md already says this.
  • A writer's messages are inputs, so they also narrow the level.
  • Only the readers decide the flow rules.
  • There is no execute bit. The credential rules decide who can make Junior act.

Why one group, not a list of groups

  • With flat groups and flow checks by id only, a list allows no more writes without review. One target group is a subset of A∩B only when it is self.
  • A list helps only read access, for people who are in both groups.
  • A list can come later with one migration that wraps the id in an array, plus a change to the membership function. Conversations that already fell back to self stay self, which is safe.

No nested groups

The tenant is the only implicit superset. Nested groups can come later inside the membership function, with cycle detection, and with no schema change.

Guardian

Code: packages/junior/src/chat/guardian/.

  • Core computes the flow { level, audience } for each write. Both carry the tier and, at group, the group id.
  • A write whose target readers are a subset gets no data-exposure check. The other Guardian rules still apply.
  • Every other write gets Guardian review, also for approvalMode: "approve" and core tools. level and audience are authoritative core fields in ToolActionProposal.context. The data_exposure rule judges the exact payload against them.

Writes that move data up

  • Every write is checked. Each write that moves data up gets forced Guardian review, every time. The approval of one write never clears a later write. A person's confirmation covers only that exact payload. There is no cache and no "approved for this Conversation".
  • A rejection must be rare. A Guardian rejection costs at least one more Turn. Three layers keep it rare. Steering lowers the cost, but it never skips the check.
    1. Steer first (no extra Turn). Core tells the model the current Conversation level. Per policies/system-prompt.md, the level is a fact for one request, so it goes in <runtime-turn-context>. A tool result states the new level when a read narrows it. The cross-tool rule goes in the system prompt: a write to a target with more readers than the Conversation must hold only content that those readers can already see. So the model writes one version for each audience, for example the full version for the DM and a clean version for the public issue or PR. When a tool knows the readers of its target before the call, its description or result states them. The plugin owns that fact.
    2. Guardian redacts in place (no extra Turn). Today Guardian rules can only ask or deny, and data_exposure is a deny rule. For a write that moves data up, Guardian can return a redacted payload instead of a rejection. The redaction can only remove spans, or replace them with one fixed placeholder. Code checks that the redacted payload is the original payload minus those spans. If the check fails, the write is rejected. Otherwise the write goes out with the redacted payload. The tool result tells the agent what Guardian removed, so the agent can tell the person. Code never changes a payload in any other way, so Junior always posts what Guardian reviewed. Redaction runs inside the Guardian review call, not as a separate model call. By default, Guardian already uses the same model as the fast model (DEFAULT_GUARDIAN_MODEL_ID is openai/gpt-6-luna in chat/config.ts), and each write that moves data up gets a review anyway. A separate redactor would add a second call to each write, and Guardian would still need to review its output. Revisit this only if Guardian moves to a more expensive model.
    3. Rejection only as a fallback. When the private parts cannot be removed cleanly, for example when the whole post is about private data, Guardian rejects the write with data_exposure, as today.
  • The same check everywhere. It applies to tool writes (slice 4) and to sandbox writes through the egress proxy (slice 5). It is also the reverse-case check of step 3 of Trigger Junior from trusted GitHub issue requests #2207 (Audit actor/instruction provenance across plugins #773): a private DM run that writes to a public issue or PR. Slice 4 delivers that check.

Sandbox writes

The egress proxy (chat/sandbox/egress/ and the plugin egress-policy.ts files) runs the same check. Today bash has no approvalMode, so Guardian never reviews it. A git push to a public repository passes only the GitHub egress policy, and that policy does not check repository visibility. Fix: the proxy denies a sandbox write that moves data up, for example a push to a public repository from a Conversation below public. The denial tells the agent to use a reviewed tool. The proxy does not redact. The reviewed tool gets the redact outcome.

Write rule for the stored level

Stored Signal Result
unknown a value the signal
unknown none the known Destination value, else unknown
a value a value the intersection of the two
a value none no change

One SQL upsert in SqlStore.upsertConversation owns this rule. Slice 1 compares tiers only. Slice 2 adds the group id.

Destination changes

  • A channel becomes private. Its Conversations narrow to that group. Slice 1 does this at read time: a Destination below tenant makes the Conversation read private. Slice 2 replaces this with a cascade write.
  • A channel becomes public. Its old Conversations keep their level. New Conversations start at tenant. Today all of them become public. This is a deliberate fail-closed change.

GitHub-started Conversations (step 5 of #2207)

They start at public, because the trigger is public. The first input with fewer readers narrows the level. Then the write check sends any write of that data to the public repository to Guardian review. This replaces "start private" as the real fix. Until slices 4 to 6 land, step 5 must still start these Conversations as private.

Fail closed

  • Unknown or invalid values read as private. resolveConversationPrivacy logs conversation.visibility.defaulted.
  • A group level without a group id reads as self.
  • After the slice 2 cutover, readers do not fall back to the Destination value.

Slack Connect

Finding from the code on main:

  • Junior sets Slack visibility only from the event channel_type (channel is public, all others are private, in conversationVisibilityFromSlackChannelType), or from conversations.info is_private.
  • The event field is_ext_shared_channel is parsed, but only the telemetry attribute app.slack.is_ext_shared_channel uses it.
  • So a public Slack Connect channel is stored as public (the company), and a private one as private. Nothing marks a channel as shared with people outside the company.

Slice 4 maps a shared channel to public as a write target. A Conversation that starts in a shared channel starts at public.

Slices

Each slice is a small vertical slice with its own tests.

  1. Ordered column and write rule. PR: feat(conversations): Store ordered visibility on each root Conversation #2382.
    • junior_conversations.visibility: text with direct/private/internal/world and a CHECK constraint.
    • The migration copies the Destination value to each root Conversation. public becomes internal.
    • The write rule above, by tier only.
    • A Destination below internal makes the Conversation read private. This rule is temporary.
    • ConversationPrivacy stays public/private. The storage edge maps public to internal.
    • The runtime readers read the column: Turn privacy, Brief input, forks, plugin tasks, resume, searchConversationEvents, and Conversation lineage. A child reads its own Destination value, but never less private than its root.
  2. Cascade, backfill, reader cutover, rename, and group id.
    • Rename the values to self/group/tenant/public, and ConversationPrivacy to ConversationVisibility, in a hard cutover.
    • Add the group id column. Fill it from the Destination for rows at group.
    • Copy the Destination value again to rows that are still unknown.
    • Cascade for a channel that becomes private, in one lock order: the Destination row, then the Conversation rows. Remove the slice 1 read rule.
    • Move the SQL readers below to the column. Children read the value of their root.
  3. Dispatch split. An optional conversationVisibility on the dispatch record writes only the Conversation column. fix(conversations): Refresh destination visibility only from live signals #2440 already stopped dispatches from writing the Destination row, so this slice only adds the input. dispatchForIdentity (feat(dispatch): Start public web Conversations for linked identities and verified emails #2217) stays private.
  4. Target readers, Guardian flow, and redact. This slice ships in two PRs:
    • 4a: Plugins report the readers of each target in resolveApprovalMetadata: GitHub repository visibility and id, and Slack channels, with Slack Connect as public. Core runs the tier-plus-group subset check and puts level and audience in ToolActionProposal.context. Each write that moves data up gets forced Guardian review, every time, with no cache. data_exposure stays a deny. This is the reverse-case check of Audit actor/instruction provenance across plugins #773. 4a also adds the steering (layer 1): the level in <runtime-turn-context>, the write rule in the system prompt, and the target readers in tool descriptions or results.
    • 4b: The in-place redact outcome (layer 2): Guardian returns the redacted payload in the same review call, code checks that it is the original minus the removed spans, and the tool result tells the agent what was removed. A data_exposure rejection stays only as the fallback (layer 3). I made it a separate PR because it changes the Guardian reviewer output contract and needs its own Guardian evals. 4a is safe alone: without redact, a write that moves private data up is denied.
  5. Egress flow check. The egress proxy denies sandbox writes that move data up and points the agent to a reviewed tool.
  6. Intersection on every input. The level becomes the intersection of the origin, each place that a message comes from (a DM reply, a Slack thread, a GitHub comment), and each tool read (memory recall, Brief and event search, provider reads). Two different non-tenant groups give self.
  7. Read and write split for sharing. Later. Separate read access from write access when a Conversation is shared. Step 5 of Trigger Junior from trusted GitHub issue requests #2207 does not need it.

Step 5 of #2207 needs slices 1 to 6. Then it can start GitHub Conversations at public.

Slices 4 and 5 protect tenant Conversations that write to public targets as soon as they land. Slice 6 must land before any Conversation starts at public.

Readers that move in slice 2

Each reader below gets visibility from the Destination row of the root Conversation. Each must read the column of the root Conversation:

  • chat/conversations/sql/privacy.ts: resolveRootVisibility (Brief storage and tasks, retention).
  • api/conversations/access.ts: readConversationAccessFromSql (dashboard payload access).
  • api/conversations/list.ts: feed filters and Brief search.
  • api/conversations/stats.query.ts and api/people/profile.query.ts: private titles and counts.
  • api/locations/query.ts: Conversation rows and counts at a Location. The Location itself can still use the Destination value.
  • chat/conversations/sql/message-search.ts and chat/briefs/search.ts: cross-Conversation search.
  • chat/conversations/sql/purge.ts: retention windows.
  • policies/data-redaction.md.

Readers that stay on the Destination value: slack/tool-support/channel-access.ts, Automations, and resolveDestinationVisibility (the channel signal for a Slack message).

Out of scope

Test plan

  • Slice 1: extend "stores visibility on each Conversation and only makes it more private" in tests/component/conversation-sql-store.test.ts.
  • Slice 2: extend the dashboard access and feed scenarios (tests/integration/api/conversations/*) with one Conversation that differs from its Destination, and with two Conversations at group with different group ids.
  • Slices 4 and 5: extend the Guardian gate scenario and the egress proxy scenario with a write to a public repository from a tenant Conversation, and a write to group B from a Conversation at group A. Cover two writes in a row: the second one gets its own review. For 4a, add a behavioral eval: a Conversation below public writes one version to the DM and a clean version to a public issue. For 4b, add guardian eval cases for redact and for a deny when the private parts cannot be removed. Extend the Guardian gate scenario with a redacted payload that is not the original minus its spans, and check that the write is rejected.
  • Slice 6 and step 5: extend tests/integration/identity-dispatch.test.ts (feat(dispatch): Start public web Conversations for linked identities and verified emails #2217), including inputs from two groups that give self.
  • No tests for migration SQL. Use db:generate and the migration metadata checks.

via @BYK.

--

View Session [Sentry]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions