Skip to content

feat(agents): Merge the root kind into thread - #4377

Merged
dcramer merged 4 commits into
mainfrom
agents/merge-thread-into-root
Nov 26, 2026
Merged

dcramer merged 4 commits into
mainfrom
agents/merge-thread-into-root

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Steps 2 and 3 of #4275 (step 1 landed in #4278 and #4292), with the merged kind named thread instead of root.

A child Thread differed from a top-level Conversation only by having a parent, so both are now one kind, thread. This lets a later move between Spaces change only the parent, never the kind. root_conversation_id and "tree root" keep their names.

  • ConversationKind is now thread, automation, lead, or task. A thread may have a parent. task stays its own kind.
  • turnBehavior takes hasParent with the kind and the sender. A thread with a parent gets the Thread behavior and the thread Prompt mode: the top-level rules for a person's input, plus the rules for its parent's input.
  • copiesRootVisibility and the store's kind check read the parent edge. kindAllowsParent replaces isTopLevelKind: a thread may have a parent, a task must, and an automation or lead never does.
  • startAgent, listAgents, and searchConversations already use thread, so the stored kind is the tool kind. The mapping helpers (childConversationKind, childAgentKind, toolConversationKind) are gone.
  • The API kind drops root. The dashboard labels and the Move to Space item read thread, and treat only a parentless one as top-level.
  • TERMINOLOGY.md and the kind-behavior baseline are updated.

Migrations, as a hard cutover:

  • The first drops and re-adds both kind checks NOT VALID (no scan under lock), and both accept root and thread. This way an update to a row that still stores root passes before the backfill runs. It also adds the junior_conversations_kind_root_to_thread trigger, which stores a root that a writer of the previous deploy sends as thread. So no reader needs a root fallback.
  • The second moves the stored root rows to thread in its own transaction.
  • A later change drops the trigger and root from the checks, once every deployed writer stores thread (TODO in db/schema/conversations.ts).

No design/ text changes here.

via @dcramer.

--

View Session [Sentry]

@vercel

vercel Bot commented Nov 25, 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 12:42am UTC

Request Review

@dcramer

dcramer commented Nov 25, 2026

Copy link
Copy Markdown
Member

Okay, but it doesn't make sense to call it a root if it's a child. That's why I was suggesting we rename it

@dcramer

dcramer commented Nov 25, 2026

Copy link
Copy Markdown
Member

Let's just rename root to thread. I think it makes more sense for what we're doing

@dcramer
dcramer marked this pull request as ready for review November 25, 2026 22:13
@sentry-junior
sentry-junior Bot requested a review from dcramer November 25, 2026 22:13
@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 25, 2026
@sentry-junior sentry-junior Bot changed the title feat(agents): Store a Thread as a root with a parent feat(agents): Merge the root kind into thread Nov 25, 2026
@sentry-junior
sentry-junior Bot marked this pull request as draft November 25, 2026 23:16
@sentry-junior

sentry-junior Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Okay, but it doesn't make sense to call it a root if it's a child.
Let's just rename root to thread.

Done in b17a499. The merged kind is now thread (automation, lead, and task stay), so a top-level Conversation and a child Thread share one kind, and no child is called a root. root_conversation_id and "tree root" keep their names. Stored root rows are backfilled to thread, and a trigger converts root writes from the previous deploy until a later change drops it.

@blacksmith-sh

blacksmith-sh Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Found 3 test failures on Blacksmith runners:

Failures

Test View Logs
migration-locks/migration-locks View Logs
money-units/money-units View Logs
provider-state/provider-state View Logs

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dcramer
dcramer marked this pull request as ready for review November 25, 2026 23:19
@dcramer
dcramer enabled auto-merge (squash) November 25, 2026 23:19

@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 1 potential issue.

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 b17a499. Configure here.

RETURN NEW;
END
$function$;--> statement-breakpoint
CREATE TRIGGER "junior_conversations_kind_root_to_thread" BEFORE INSERT OR UPDATE ON "junior_conversations" FOR EACH ROW WHEN (NEW."kind" = 'root') EXECUTE FUNCTION "junior_conversations_kind_root_to_thread"();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rollout rewrites roots as child threads

High Severity

The new trigger and backfill store every former root as thread, but a worker still on the previous deploy treats thread as a child Thread. During overlap those workers apply child-thread prompts, tools, and parent reporting to ordinary top-level conversations. conversationKindFromRow also throws on leftover root instead of mapping it, so the two deploys have no compatible dual-read window.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b17a499. 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.

This is a hard cutover on purpose, so I'm leaving it as merged.

  • No root row stays behind to make conversationKindFromRow throw. The trigger rewrites each root write from the previous deploy to thread, and the backfill moves the stored rows.
  • The overlap is real: while the deploy runs, a worker still on the previous release reads a top-level thread as a child Thread. That window lasts only for the length of the deploy, and we accepted it instead of a dual-read release and a cleanup.

@dcramer

dcramer commented Nov 25, 2026

Copy link
Copy Markdown
Member

How are you looking in here? The build still failing

sentry-junior Bot and others added 4 commits November 26, 2026 00:33
Steps 2 and 3 of #4275. turnBehavior decides from the
parent edge and the sender, not from a separate thread kind. The thread
kind is merged into root, and stored rows move to root.

Co-Authored-By: David Cramer <[email protected]>
A top-level Conversation and a child Thread now share the kind `thread`.
The migration backfills stored `root` rows. A trigger stores a `root`
that a writer of the previous deploy sends as `thread`, and both kind
checks accept both values until every writer stores `thread`.

Co-Authored-By: David Cramer <[email protected]>
Chain the kind migration after drop_versions_notify, and name the
release for its constraint drops, as the migration-locks check now
requires.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior
sentry-junior Bot force-pushed the agents/merge-thread-into-root branch from b17a499 to 45d3464 Compare November 26, 2026 00:41
@dcramer
dcramer merged commit 8613cd7 into main Nov 26, 2026
57 checks passed
@dcramer
dcramer deleted the agents/merge-thread-into-root branch November 26, 2026 00:52
Comment on lines +5 to +7
UPDATE "junior_conversations"
SET "kind" = 'thread'
WHERE "kind" = 'root';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Root-to-thread backfill does not invalidate cached detail reports

The backfill changes the detail report’s kind without changing its revalidation token, so clients polling with a pre-backfill token can receive 304 and keep using a report whose kind is root, contrary to the new thread contract.

Evidence
  • The backfill updates only kind; it does not advance detail_version.
  • conversationVersionsQuery derives its token from subtree detail_version totals and other state that does not include kind; readConversationDetailEtag hashes that token for the detail validator.
  • The detail route returns 304 when the sent validator matches. The dashboard’s readRevalidated then returns its cached report without parsing a new response.
  • The current conversationKindSchema excludes root, while conversationSummaryFromStoredConversation projects the stored kind into the report.

Identified by Warden · code-review · NXB-2HN

@sentry-junior

sentry-junior Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

The build still failing

That lint / workspace failure came from two leaf migration snapshots on main (this PR and #4120 both chained from the same parent). #4404 merged them, and this PR went in green at 45d3464.

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]>
BYK added a commit that referenced this pull request Nov 26, 2026
This prepares `main` for a merge queue. Two PRs that each add a
migration off the same parent both pass CI on their own, then leave two
migration leaves on `main`. That happened with #4377 and #4120, and
before them with #4224, #4290, #4313 and #4279. A merge queue tests each
PR merged on top of the ones ahead of it, but only if `ci / required`
reports on `merge_group` runs. That's what this adds.

On `merge_group`, `getsentry/action-filter-paths` matches every filter,
as on a push, so every path-gated job that `ci / required` needs runs.
Two jobs still skip, as they do on a push to `main`, and a skipped job
passes `ci / required`:
- `pack-release-artifacts` runs only on push.
- `ios` runs only on pull requests, because `ios.yml` runs on its own
for pushes to `main`.

Frameshift doesn't save or report screenshots on queue runs.

Turning on the merge queue itself is a separate change to the `main`
ruleset. "Require branches to be up to date" stays off.

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

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

--

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

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

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 45d3464c 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