Skip to content

fix(conversations): Skip archived children in the tree state and move the feed token on a starter wait - #3768

Merged
BYK merged 1 commit into
mainfrom
fix/tree-state-archived-and-feed-token
Nov 19, 2026
Merged

BYK merged 1 commit into
mainfrom
fix/tree-state-archived-and-feed-token

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Two follow-ups to the tree state from #3672, both from Bugbot findings on that PR.

Archived children no longer count. readConversationTreeStates read the whole subtree, so an archived Thread or Task could keep its parent at needs_you, working or watching, even though the feed hides that child, so there was no row to open. The query now skips each archived child. Archive takes a child's descendants with it, so its descendants drop out as well. A Conversation still counts for itself when it is archived, so the archived view keeps its own state.

The feed token moves when the root starts to wait on the viewer. conversationFeedVersionQuery stored each root's shared status. A root that already read needs_input for someone else, such as a Review item for Bob, could then start to wait on its starter, for example after a partial or blocked Brief. The status stayed the same, so the token didn't move, and the starter's needs_you icon stayed stale until something else refreshed the feed. The token's status input now also holds conversationWaitsOnUserSql for the viewer.

This changes only server behavior; the dashboard UI code is the same.

via @BYK.

--

View Session [Sentry]

… the feed token on a starter wait

An archived child and its descendants no longer set the tree state of the
Conversation above them, since the feed hides them.

The feed version token now holds the root's own wait on the viewer. A root
that already reads needs_input for someone else could start to wait on its
starter without moving the token, so the starter's icon stayed stale.

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 19, 2026 12:53
@vercel

vercel Bot commented Nov 19, 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 19, 2026 12:53pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 19, 2026
@BYK
BYK enabled auto-merge (squash) November 19, 2026 13:07
@BYK
BYK merged commit cf8280c into main Nov 19, 2026
51 of 52 checks passed
@BYK
BYK deleted the fix/tree-state-archived-and-feed-token branch November 19, 2026 13:08
@github-actions

Copy link
Copy Markdown
Contributor

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

Review screenshots in Frameshift

Automation Run Details · Desktop
Automation Run Details · Desktop
Changed
Automation Skill Editor · Desktop
Automation Skill Editor · Desktop
Changed
Automation Skill Editor · Mobile
Automation Skill Editor · Mobile
Changed
Automations Runs Filters · Desktop
Automations Runs Filters · Desktop
Changed
Code · Desktop
Code · Desktop
Changed
Conversation Attachment Zoom · Desktop
Conversation Attachment Zoom · Desktop
Changed
Show 3 more changed screenshots
Conversation Attachment Zoom · Mobile
Conversation Attachment Zoom · Mobile
Changed
Conversation Event Log Virtual · Desktop
Conversation Event Log Virtual · Desktop
Changed
Person Profile · Desktop
Person Profile · Desktop
Changed

BYK added a commit that referenced this pull request Nov 21, 2026
…zation lookups (#3965)

The no-ids part of `GET /api/versions` (feed, Inbox items, spend) got
slower in 0.311.0. Most of that time is the feed token from
`conversationFeedVersionQuery`. #3954 covers the other
part, the per-Conversation tokens.

## Cause

Feed token time on a local prod-shaped seed: 32k roots, 100 roots with
70-node trees, about 655k events, and a 50-row page.

| Feed token shape (p50) | ms |
| --- | --- |
| 0.310.0 | 22–23 |
| + derived page status and waits-on-viewer (#2951,
#3768) | 40–42 |
| + tree state (#3672, #3768) | 61–66 |
| `main` | 80–93 |

The tree state runs the authorization-wait check on every member of
every page root's tree. It also derives the status of every Thread.
Inbox items (about 1.5 ms) and spend (about 15 ms) did not change.

These per-Conversation probes cost more than they need to:

- `conversationWaitsOnStarterSql` names the same subquery several times.
It reads the latest Brief status twice, the latest reply `seq` up to
four times, and the starter user three times. Postgres runs a subquery
at each place that names it.
- The authorization wait reads each Conversation's newest wait event
with a backward scan of the events primary key. Almost no Conversation
has a recent request, so most of these reads find nothing.

## Change

- `status.ts`: the starter-wait rule reads the starter, the latest Brief
(status and `through_seq`) and the latest reply (`seq` and Slack
delivery) once, in one row: an `offset 0` subquery plus two `lateral`
joins. The guards outside it (stopped, Task, active, failed Turn) are
the same.
- `authorization-wait.ts`: the check first looks in a new partial index
for an `authorization_requested` event inside the 24h window. With none,
the rule is false, as before. The check is a scalar subquery and not
`exists`. An `exists` lets Postgres pick a hashed subplan that reads
every recent request.
- Migration `0147` adds
`junior_conversation_events_authorization_request_idx` on
`(conversation_id, created_at) WHERE type = 'authorization_requested'`,
built `CONCURRENTLY IF NOT EXISTS` like `0090`.

No status or token changes. On the seed, the feed token and the status,
waits-on-user and authorization-wait values of all ~39k Conversations
are identical to `main`. That includes live, expired, other-person and
Turn-ended requests.

## Before / after (local seed)

| Feed token | `main` | This PR |
| --- | --- | --- |
| p50, JIT off | 79.5–93.1 ms | 57.2–66.8 ms |
| Shared buffers hit | 49,397 | 35,734 |
| Estimated plan cost | 34,834 | 23,076 |
| Tree-state subplan (50 loops) | 49.9 ms | 30.4 ms |
| Authorization lookups (3,039 tree members) | 18.2 ms | 6.1 ms |

The whole no-ids statement is 73–85 ms p50 on the seed after this
change. It shrinks the 0.311.0 regression but does not remove it. The
tree state does per-member work that 0.310.0 did not: an Inbox probe, an
authorization check, and a status for each Thread. A larger gain needs a
cheaper tree-state definition. The plan cost goes down, so the statement
is not nearer to `jit_above_cost`.

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

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

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A49221e97cd717f9141560b0efd29c5ae)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A49221e97cd717f9141560b0efd29c5ae/?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 — ae082cc6 Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant