Skip to content

feat(spaces): Make Space Conversations children of the Lead - #4413

Merged
dcramer merged 18 commits into
mainfrom
agents/lead-children
Nov 26, 2026
Merged

dcramer merged 18 commits into
mainfrom
agents/lead-children

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Every Conversation in a Space is now a child of that Space's Lead, so the normal parent-child behavior applies to Space work: results go back to the Lead, and the Lead can messageAgent, listAgents, watch, stop, archive, and roll up its children.

Why: a Lead started Space work as separate roots that stored no link to it, so it could not stop or archive that work, and results did not come back to it. Space work now uses the same tree as every other agent's child agents.

Tree model

This is the normal parent-child tree. A Conversation in a Space has parent_conversation_id = the Space's Lead, and the Lead is the root_conversation_id of every Conversation in its Space, at any depth. No column is added. Only the Lead stores space_id, and a Conversation reads the Space of its root (rootSpaceIdSql). State that keys on the root, such as Participants and access, comes from the Lead, so the Space's Conversations inherit it as any child agent does. Top-level Space work means a Lead's direct child (topLevelConversation: no parent, or a parent that is a Lead).

Behavior

  • The Lead starts Space work with startAgent. startConversation is gone: the tool, its registry entry, the Lead prompt lines, the dashboard transcript card, and its evals. The Lead transcript shows its children as child agent rows, as any parent's does. A person who starts work directly in a Space also makes a child of the Lead, run as that person.
  • A move into, out of, or between Spaces re-parents the Conversation. Into a Space it becomes a child of the Lead. Out of a Space it becomes a root again. Its subtree moves with it: root_conversation_id becomes the new Lead or the Conversation itself, and a move into a private Space makes the subtree private. A move of a private Conversation into a public Space is refused. The moved root's Participants, pins, and choices do not carry over to the Lead.
  • A Slack Conversation that moves into a Space keeps delivering to its own Slack Location, and keeps its own delivery pause. Only a Conversation with its own Location delivers to it.
  • A Lead has no 8-active-child cap, and its children count as roots for maxAgentDepth.
  • A Lead gets a Turn for each result of its children, like any parent.
  • A stop of the Lead stops its children through the parent links.
  • listAgents is now a direct Lead tool.
  • Guardian: a deliberate Lead exception to judging a Lead's task like any parent's. The rule that reads a member's worry as a request moves from startConversation to a Lead's startAgent. Core marks the Lead's Run (context.lead on the proposal), and review adds the rule only for startAgent in that Run. This matches the lead-member rule in design/guardian.md, which stays as it is.
  • Top-level lists, the sidebar, In flight, and the Space roll-up treat a Lead's children as top-level Space work. Access to a private Space's work comes from being a Participant of its Lead.

Space roll-up query

readSpaceStates (the sidebar's roll-up from #4366) now reads the Lead and its direct children. A subquery finds the Leads of the listed Spaces through junior_conversations_space_lead_idx. The outer query reads the rows whose id is a Lead (primary key) or whose parent is a Lead (junior_conversations_parent_idx), unarchived and readable by the viewer, newest activity first, up to 200. readConversationTreeStates then covers each child's own child agents.

Space membership

A Space's members are now the Participants of its Lead. The separate member table is no longer read or written.

  • Creating a Space creates its Lead, with the creator as its first Actor, so the creator is the first member.
  • Joining or adding a person makes them a Participant of the Lead.
  • On the web, only members post in a Space's Conversations. Before, only the Lead refused non-members, so a web post in a public Space Conversation made the poster a member.
  • Leaving deletes the person's Participant row on the Lead. The last member of a private Space still can't leave.
  • Member lists, member counts, the viewer's membership, private-Space access, and user search read Participants of the Lead. The member list drops joinedAt and orders by email.

Migration

20261126033000_space_conversations_lead_children, data only:

  • Makes a Lead for every Space that has none yet. Its first Actor is the Space's creator.
  • A private Conversation in a public Space leaves the Space and stays a private one-off. An Automation run leaves its Space, because it never has a parent.
  • The work of every other non-Lead root with a space_id joins the Lead's tree: root_conversation_id becomes the Lead for the root and all its child agents.
  • Each such root becomes a child of its Space's Lead, with an agent config, and its space_id is cleared.
  • Copies each Space member onto its Lead as a Participant.

junior_space_members stays in the schema, unused. A later migration drops it once a release that does not use it is live, as migration-locks requires.

During the deploy build, the live release runs against the new tree for minutes. In that window it reads a Space Conversation as a child of the Lead, so its Turns report to the Lead instead of their Location. A person who joins a Space through the old release in that window lands only in the old table.

Docs

  • design/spaces.md, design/child-agents.md, and design/agent-teams.md get the confirmed text. The design/agent-teams.md gap "Agents use different tools…" stays as it is, and design/guardian.md does not change.
  • TERMINOLOGY.md defines "Top-level Conversation", updates the Lead, and defines a Member as a Participant of the Lead.
  • policies/conversation-access.md updates the Lead write exception, the start line, and Space membership.

via @dcramer.

--

View Session [Sentry]

@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 26, 2026 6:51am UTC

Request Review

@blacksmith-sh

This comment has been minimized.

@sentry-junior
sentry-junior Bot added this pull request to stack #4420 November 26, 2026 03:31
@dcramer
dcramer marked this pull request as ready for review November 26, 2026 03:50
@sentry-junior
sentry-junior Bot requested a review from dcramer November 26, 2026 03:50
@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 26, 2026
@sentry-junior
sentry-junior Bot force-pushed the agents/lead-children branch from 08b114f to 78a73e7 Compare November 26, 2026 03:54
Comment thread design/agent-teams.md Resolved
sentry-junior Bot and others added 5 commits November 26, 2026 03:58
A Space's Conversations are now child agents of its Lead, so results,
messageAgent, listAgents, Watches, stop, archive, and roll-ups work the
same as for any parent. The Lead is the tree root of its Space, and a
new top_level_conversation_id keeps per-work state, such as Participants,
pins, and lists, on each of the Lead's children.

The Lead starts work with startAgent, and startConversation is removed.
A move into, out of, or between Spaces re-parents the Conversation and its
subtree, and refuses to make private work public. A Lead has no cap on
active children, its children count as roots for maxAgentDepth, and it
hears a child's done as a Conversation note.

Co-Authored-By: David Cramer <[email protected]>
Drop top_level_conversation_id. A Conversation in a Space has the Lead as
its parent and its root, as in any agent tree, so Participants and access
come from the Lead. A move rewrites the root of the moved subtree, and the
migration does the same for existing Space work.

Co-Authored-By: David Cramer <[email protected]>
A Space's members were a separate table. With the Lead as the root of every
Space Conversation, they are now its Participants, like any agent tree.
Creating a Space makes its Lead, joining adds a Participant, and leaving
removes it. The migration makes a Lead for every Space and copies the old
members onto it. The old table stays unused until a release without it is
live.

Co-Authored-By: David Cramer <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

The Lead transcript shows the Conversations it starts as child agent rows,
like any parent. Drop the Lead page state that only the removed started
Conversation card read.
…bers

A person joins a Space before they post in it on the web. Before, only the
Lead refused web posts from non-members, so a web post in a public Space
Conversation made the poster a member.

Co-Authored-By: David Cramer <[email protected]>
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

32 screenshot changes — 32 changed · 0 added · 0 removed

Review screenshots in Frameshift

Composer Skill Card · Desktop
Composer Skill Card · Desktop
Changed
Composer Skill Details · Desktop
Composer Skill Details · Desktop
Changed
Composer Skill Reference · Desktop
Composer Skill Reference · Desktop
Changed
Conversation Agent Messages · Desktop
Conversation Agent Messages · Desktop
Changed
Conversation Agent Messages Light · Desktop
Conversation Agent Messages Light · Desktop
Changed
Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Show 12 more changed screenshots
Conversation Attachment Modal · Desktop
Conversation Attachment Modal · Desktop
Changed
Conversation Attachment Zoom · Desktop
Conversation Attachment Zoom · Desktop
Changed
Conversation Child Agents · Desktop
Conversation Child Agents · Desktop
Changed
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Conversation Pending Attachment · Desktop
Conversation Pending Attachment · Desktop
Changed
Conversation Subagents · Desktop
Conversation Subagents · Desktop
Changed
Conversation Subagents · Mobile
Conversation Subagents · Mobile
Changed
Conversation Task Line · Desktop
Conversation Task Line · Desktop
Changed
Conversation Thread Cards · Desktop
Conversation Thread Cards · Desktop
Changed
Conversation Thread Page · Desktop
Conversation Thread Page · Desktop
Changed
Push Notifications Tip · Desktop
Push Notifications Tip · Desktop
Changed
Push Notifications Tip On · Desktop
Push Notifications Tip On · Desktop
Changed

14 more changed screenshots in Frameshift.

A Lead heard a child's done as a quiet note, so it could not act on the
result, and it broke the rule that a parent gets each child's result.
@dcramer

dcramer commented Nov 26, 2026

Copy link
Copy Markdown
Member

Make sure you clean up any loose ends here. Technically speaking, even things like configuration could actually be tied to the conversation rather than the space, but that's probably a future idea for us.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

dcramer added a commit that referenced this pull request Nov 26, 2026
…ead design (#4428)

States where Spaces and the Lead are heading. A Space uses the core
Conversation tree (parents, roots, Participants, access, stops,
archives, Watches, updates), and only a few Space-specific layers sit on
top of it.

- `design/spaces.md` is rewritten. The Lead is the root of the Space's
tree. Every Space Conversation, whether the Lead starts it, a person
starts it in the Space, or a person moves it in, is a child of the Lead
and has the Lead as its root. Children inherit the Lead's Participants.
Archive and snooze act per child. The file lists the Space layers
explicitly: metadata, membership, configuration, the Lead's prompt and
tools, moves, and rendering (the sidebar, the Threads panel, and
top-level lists).
- `design/lead.md` is new. It covers the Lead's role, its curated
manager tool set (it runs Threads, reads, plans, and asks people, and it
never writes or runs code), and the Turn gates: explicit reply on child
and Event Turns, quiet `done` updates, and child results as claims. Gaps
record what is not on main yet.
- `design/agent-teams.md`: a Lead's team is its Space, and the Lead gaps
move to `lead.md`.
- `design/child-agents.md`: removes contradictions with Spaces. A move
changes a child's parent, a moved Conversation delivers to its own
Location, and the 8-child limit does not apply to a Lead's children.
- `TERMINOLOGY.md`: updates Lead, Space, Thread, Team, Delivery, and
Participant, and adds Top-level Conversation (derived, not stored).

Related: #4377 (`thread` kind), #4411
and #4414 (moves), #4416 (Threads
panel).

#4413 edits some of the same lines. After this merges,
it should drop those doc changes and delete only the gaps it closes.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A56172fc7761dc3a4c09f6bc7 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/local%3Aweb%3A56172fc7761dc3a4c09f6bc7)
[[Sentry]](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A56172fc7761dc3a4c09f6bc7/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>
# Conflicts:
#	design/agent-teams.md
#	design/child-agents.md
#	packages/junior-evals/evals/agent/lead.eval.ts
@sentry-junior
sentry-junior Bot requested a review from dcramer November 26, 2026 05:45
…per Conversation

A Thread that the grouping puts in Needs you because its tree waits on
the viewer now shows that icon, even when its own run failed or is
blocked. The Threads panel gets a key per Conversation, so an open Done
group does not stay open on the next Conversation.
@dcramer

dcramer commented Nov 26, 2026

Copy link
Copy Markdown
Member

Will this also fix all existing conversations in a space so they roll up to the lead

@sentry-junior

sentry-junior Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Yes. The migration (20261126033000_space_conversations_lead_children) makes that change for every existing Space:

  • A Space without a Lead gets one, with the Space's creator as its first Actor.
  • Every root in a Space becomes a child of its Lead, and all of its work moves into the Lead's tree (root_conversation_id = Lead).
  • The Space's members become Participants of the Lead.

There are two exceptions, and both leave the Space and stay one-off roots:

  • A private Conversation in a public Space. A move never makes private work public.
  • An Automation run. It can never have a parent.

dcramer added a commit that referenced this pull request Nov 26, 2026
A `messageAgent` call showed as a generic tool call, so you could not
easily see what one agent told another. It now shows as a compact
message row. A message from another agent (`agent.message`,
`agent.top_level_message`) uses the same row, so the two read as a pair
in the Lead and in other Conversations.

- One component renders the row the same in every Conversation. There is
no Lead-only path.
- Direction cue: ↗ "To" for sent, ↙ "From" for received.
- The other Conversation's title links to it. The title comes from data
the page already holds: the feed list, then the agent tree (including
the parent of a pending message to `parent`), then the Conversations
that the transcript started (the starting call's title, or its Threads
and Tasks). When none of them names it, the row shows "Conversation". No
API change, so no title of a Conversation the viewer cannot read leaks.
- Delivery state comes from the tool result: `started` → Delivered,
`queued` → Queued, `noted` → Saved as a note, a failed call → Refused,
running → Sending.
- Long text is clamped with the existing `ClampedDisplayText`. Sent and
received messages never fold into activity groups.
- The received row strips the `<agent-message>` tag that core writes for
the model. The child's "Parent agent" input message does not change.
- Core change: `isAgentMessageEventType` and the top-level message event
type constant now live in `result-event-type.ts`, so the dashboard can
import them.
- The dashboard first-load bundle baseline goes up 1.3 KB gzip (622.7 →
624.0 KB) for the new rows.

### Normal conversation

| | Desktop | Phone |
| --- | --- | --- |
| Dark |
![](https://junior-prod.sentry.dev/public/artifacts/a6f91d5d-f3a8-40fb-bc39-e61051e5d578.png)
|
![](https://junior-prod.sentry.dev/public/artifacts/7fc999ab-3291-4208-ad54-2c7ae4bf6802.png)
|
| Light |
![](https://junior-prod.sentry.dev/public/artifacts/a0a0d668-0245-41f8-8341-1ecf793a9560.png)
|
![](https://junior-prod.sentry.dev/public/artifacts/dda5f165-4d04-433e-8e22-61536ea958d9.png)
|

### Lead

| | Desktop | Phone |
| --- | --- | --- |
| Dark |
![](https://junior-prod.sentry.dev/public/artifacts/2ea213ef-1726-4cc0-8b88-44663b406c0c.png)
|
![](https://junior-prod.sentry.dev/public/artifacts/bc804f4d-8321-41a0-ad02-cb38ae933d74.png)
|
| Light |
![](https://junior-prod.sentry.dev/public/artifacts/5cb2f6ca-a940-4ed9-826d-d9e1ce5cffb2.png)
|
![](https://junior-prod.sentry.dev/public/artifacts/247c78f4-be49-4ab4-845a-f796fd42b5de.png)
|

### Screenshot changes

The 4 added Frameshift shots are `conversation-agent-messages`. 29 of
the changed shots come from the new mock rows. The Dashboard QA root
(`conversation-*`, `push-notifications-tip*`) has 4 more transcript
rows. The Billing migration Lead (`space-lead*`, `space-threads*`,
`space-edit*`, `space-pane-menu*`, `space-page`) has a sent message and
a received reply. Each pinned transcript now scrolls to a different
place. Nothing else in these pages changed.

`conversation-unsent-answers` also changed. Its Conversation has no
agent messages, and only the scroll position differs.
#4177 lists this shot as one that changes on PRs that do
not touch it.

### Coordination

- #4413: this PR builds on `main` and does not touch
`types.ts`. It edits `TranscriptActivityGroup.tsx`,
`ConversationTranscript.tsx`, and `mock-reporting/lead-transcript.ts`
close to #4413's edits but outside its hunks.
- Threads panel (`feat/space-threads-panel`): none of its files change.
Its `space-threads*` shots change only because the Lead transcript
scrolls to a different place.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A29ac73b21100f02ba9fd1acfbc7506f4 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A29ac73b21100f02ba9fd1acfbc7506f4)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A29ac73b21100f02ba9fd1acfbc7506f4/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>
A Lead's child counts as a root for limits.maxAgentDepth, and the depth
check in spawn.ts already allows it. The tool binding did not know that,
so with depth 0 such a child never got startAgent. The run now passes
whether its Conversation is top-level work.

Co-Authored-By: David Cramer <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

and listed_lead.space_id is not null
))`,
)!;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space feed rows cannot be pinned

High Severity

Lead children now appear in top-level lists and the personal feed, but pinning still rejects any Conversation with a parent. Pinning or unpinning Space work from the feed fails, and already-pinned migrated Space Conversations cannot be unpinned.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b2b20b1. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferred. Whether a Space Conversation gets its own Pin, or none, waits on the membership question in #4413 (comment).

* Archive the tree for everyone when no Participant still has it in their
* feed. Returns the archive time, or null when a subscriber remains. Runs
* under the root's row lock.
* under the root's row lock. A Lead's tree is its whole Space, which only

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsubscribe hits the Lead instead

High Severity

Unsubscribing or leaving a Space Conversation resolves to the Lead and writes unsubscribedAt on the Space membership row. The feed filter still checks a participant row on the child, which members do not have, so the Conversation stays in the feed and the Lead is the row that was unsubscribed.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b2b20b1. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferred. This is the same open question as #4413 (comment): does a Space Conversation get its own Leave and Unsubscribe, or do you leave the Space? 34a9c0c10 already stops this path from archiving the Space.

Co-Authored-By: David Cramer <[email protected]>

# Conflicts:
#	TERMINOLOGY.md
#	design/agent-teams.md
#	design/spaces.md
The Participants of a Lead are its Space's members, and a person joins a
Space on purpose. A mention in a public Space's work added the mentioned
person as a Participant of the Lead, which made them a member without
Join. Mentions in a Space now add nobody, on the dashboard and in Slack.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

There are 5 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7ec7c26. Configure here.

@dcramer
dcramer merged commit d101088 into main Nov 26, 2026
59 of 62 checks passed
@dcramer
dcramer deleted the agents/lead-children branch November 26, 2026 07:19
sentry-junior Bot added a commit that referenced this pull request Nov 26, 2026
#4413 merged into main, so this PR now targets main.
import type { User } from "@sentry/junior-plugin-api";
import { and, asc, desc, eq, gte, isNull, ne, sql } from "drizzle-orm";
import { and, asc, desc, eq, gte, ne, sql } from "drizzle-orm";
import { topLevelConversation } from "@/chat/conversations/sql/listed";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Location aggregates omit Space children from their own destination

A public conversation moved from a Slack location into a Space is included by the new top-level filter, but the location aggregate joins tree rows rooted at the conversation’s own ID; Space rows instead root at the Lead. The Slack location therefore omits the conversation, while its tree usage is grouped under the Lead’s local destination, and its detail endpoint can return 404.

Evidence
  • topLevelConversation() matches direct children of a Lead with a non-null space_id.
  • The migration sets moved work’s root_conversation_id to the Lead and makes it a Lead child without changing its destination, so a moved Slack conversation qualifies for its Slack location but its tree rows are rooted at the Lead.
  • directoryRows and the location detail aggregate queries inner-join treeConversation.rootConversationId to the selected conversation’s conversationId. That join finds no rows for the Space child; the Lead’s row instead aggregates the tree under the Lead’s destination.
  • recentLocationRows uses the top-level filter without that tree join, but detail returns undefined when no aggregate location exists, so a location containing only such a conversation can return 404.

Identified by Warden · code-review · D4Q-7BV

Comment on lines +158 to 171
.where(work);
await db
.update(juniorConversations)
.set({
parentConversationId: target?.leadConversationId ?? null,
// A Lead's children are its child agents.
...(target
? {
agentConfig: sql`coalesce(${juniorConversations.agentConfig}, '{}'::jsonb)`,
}
: undefined),
detailVersion: nextDetailVersion,
})
.where(eq(juniorConversations.conversationId, conversationId));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detaching Lead-created Space work leaves the mover without participation

When a user moves a Conversation created as a Lead child out of its Space, the move makes it a root without copying the user's Participant row from the Lead. The mover then cannot stop, rename, archive, or move it again, and it drops out of their member feed unless they later post and create a Participant row.

Evidence
  • Space work is created with the Lead as its parent (packages/junior/src/chat/conversations/web-input.ts); SqlStore.upsertConversation records the actor as a Participant only when parentConversationId === null, while participant writes resolve a child to its root.
  • setConversationSpace(..., null, ...) changes the subtree root to the moved Conversation and clears its parent, but does not create Participant rows. The API permits moving a direct Lead child out of the Space.
  • After detaching, conversationAccessFromRows considers a parentless Conversation a Participant only when the viewer has a Participant row for that Conversation. Stop, rename, archive, and further moves require that status; member-feed filtering also relies on Participant rows.

Identified by Warden · code-review · EBQ-9DK

Comment on lines 266 to 318
@@ -235,41 +299,40 @@ export async function leaveSpace(
.from(juniorSpaces)
.where(eq(juniorSpaces.id, spaceId))
.for("update");
const member = and(
eq(juniorSpaceMembers.spaceId, spaceId),
eq(juniorSpaceMembers.userId, userId),
);
const lead = inArray(participants.rootConversationId, spaceLeadId(spaceId));
if (space?.visibility === "private") {
const members = await db
.select({ userId: juniorSpaceMembers.userId })
.from(juniorSpaceMembers)
.where(eq(juniorSpaceMembers.spaceId, spaceId))
.select({ userId: participants.userId })
.from(participants)
.where(lead)
.limit(2);
if (members.length === 1 && members[0]!.userId === userId) {
return "last_member";
}
}
await db.delete(juniorSpaceMembers).where(member);
// Leaving ends membership, so the row goes, not only the feed entry.
await db
.delete(participants)
.where(and(lead, eq(participants.userId, userId)));
return undefined;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space membership changes do not invalidate Lead details for former authors

When a Space member who authored a Lead message leaves or is re-added, the Lead’s participants payload changes but joinSpace and leaveSpace do not bump its detail version. Other members can therefore keep the stale payload after a detail poll returns 304.

Evidence
  • joinSpace inserts or upserts a participant row, and leaveSpace deletes one; neither calls touchConversationDetail.
  • readParticipantRows includes Lead event authors only while their user has a participant row. readConversationAuthors supplies that list to the Lead detail report, so removing or restoring a former author changes its participants payload.
  • The detail version token covers subtree detailVersion values and the requesting viewer’s state, not other members’ participant rows. For another member, the ETag stays unchanged, and the detail route returns 304 when it matches.

Identified by Warden · code-review · FV6-3TC

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 120c3857 Deployed Nov 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant