Repository navigation
ref(people): Attribute spend to the Turn Actor - #3023
Merged
Merged
Conversation
People spend, duration, and tokens now come from each Turn's metric rows, grouped by the Actor of that Turn. Conversation counts stay on the Actor that started each Conversation. Someone who only ran Turns in other people's Conversations now appears in People. Metric rows store the Turn Actor's Identity. A migration fills old rows from the Actor of the row's Conversation, else its root. Co-Authored-By: David Cramer <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
14 screenshot changes — 14 changed · 0 added · 0 removed Review screenshots in Frameshift Show 8 more changed screenshots |
# Conflicts: # packages/junior/migrations/meta/0091_snapshot.json # packages/junior/migrations/meta/_journal.json
Member
|
Counts and everythign should just be accounted from turns - there is no "root actor" to care about generally speaking.. thats only 'conversations youve started' |
Conversation counts, active and failed counts, active days, first and last seen, locations, surfaces, and recent Conversations now come from Turns. A person counts a Conversation when they ran a Turn in it. The Actor that started it does not matter. Child Turns count toward their root once.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 85db4bb. Configure here.
Recent Conversations sort by the person's own last Turn, not by other people's activity. Active and failed count once, in the bucket of the person's last Turn in that root, so a status change does not mark every past day.
dcramer
approved these changes
Nov 9, 2026
dcramer
added a commit
that referenced
this pull request
Nov 9, 2026
…3021) A Conversation has no owner. Each Turn has an Actor, and a Conversation's Participants are the Users among those Actors. A Participant is active or inactive depending on whether they are subscribed. `TERMINOLOGY.md` defined an **Owner** (from the #2439 plan), and some code gave the root Actor rights that no other Participant had. This PR removes both. **Behavior** - **Access, feeds, and archive** read only Participant rows. Before, the root Actor also got access by Identity, or by a matching verified email when no row existed. The feed `union`, `viewerConversationMembership`, and the root Actor fallback in `hasSubscriber` are gone. - **Review item defaults:** when a Turn has no person and no Automation creator (for example, an event Turn), the default assignees are now the *active* Participants, not the Owner (#3015). Assignee checks and defaults also resolve a child id to its root. Before, they looked up participants by the child id. - **Forged trees:** a row that has a parent no longer matches its own participant id, so a cyclic root does not grant access. The old test missed this because its viewer was fake. **Keeping root Actors as Participants** - The root write already adds the root Actor as a Participant when its Identity has a User. When an Identity gets its User later, `upsertIdentityRecord` now adds that User as a Participant of each root the Identity started. - Migration `0093` backfills those rows for Identities that were linked before this change. - `actor_identity_id` stays as the root Actor. It only records who started the Conversation. People stats come from Turns (#3023). **Docs and tests** - `TERMINOLOGY.md` drops Owner and adds Participant. - The `actor-identity-end-state` plan now says root Actor where it said Owner, and it records the "no owner" decision. - Many tests used `testViewer()`. Its fake User id only passed access through the email fallback that this PR removes. Those tests now use a persisted viewer (`signedInViewer`), and `createConversationFixture` signs its Actor in the same way that the web harness does. **Not covered:** a later-linked Identity does not get rows backfilled for non-root Turns it authored while it had no User. The event rows do not record whether a message was Turn input or thread context. Today's behavior for those authors does not change. `any-resource-event-automations` and the S3 storage tests also fail on `main` in my sandbox. I did not run evals. <!-- junior-request-attribution:start --> via @dcramer. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0B595QDZLL%3A1794240020.053329 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0B595QDZLL%3A1794240020.053329) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0B595QDZLL%3A1794240020.053329/?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]>
23 tasks done
BYK
added a commit
that referenced
this pull request
Nov 10, 2026
Since #3023 the spend token reads every Turn metric row and includes `max(updated_at)`. A checkpoint deletes and rewrites all metric rows of its Turn (duration, tokens, cost) with a new `updated_at`. So every checkpoint of the viewer's own Turns moved `spend`, including tool steps that add time but no cost. #3023 moved personal spend to the Turn Actor's metric rows. This PR keeps that and restores the cost-only token from #2922. ## Change - **Spend token:** reads only `cost_usd` rows. It holds the window start and the two totals that `/me/spend` shows: 30 days, and 7 days by `occurred_at`. Both are rounded to 9 decimals so float summing order cannot move them. `count(*)` and `max(updated_at)` are gone. - **Spend read:** filters to `cost_usd` rows in `WHERE`. Before, it aggregated all 8 metric rows of each Turn and kept cost through `FILTER`. The result does not change. - `occurred_at` is the Turn start and stays the same across checkpoints, so the 7-day split moves only with new cost or at UTC midnight. ## Bench Local Postgres 17. The viewer has 50 or 500 Turns with cost. One live Turn writes 20 checkpoints, alternating a model step (more tokens and cost) and a tool step (more duration only). The p50 values are over 300 reads, median of 3 interleaved runs. | | before | after | | --- | --- | --- | | checkpoints that move `spend` | 20/20 | 10/20 (only the ones with new cost) | | `/api/versions` p50, 50 Turns | 5.9ms | 5.7ms | | `/api/versions` p50, 500 Turns | 6.7ms | 6.4ms | | spend read p50, 50 Turns | 1.5ms | 1.1ms | | spend read p50, 500 Turns | 2.5ms | 1.5ms | The read still uses `(actor_identity_id, occurred_at)`, so it still visits all metric rows of the viewer's Turns and drops the non-cost ones after the index scan. An index that leads with `metric` would cut that further, but it needs a migration, so I left it out. ## Tests - `versions.test.ts`: a checkpoint of the viewer's Task Turn that adds duration and tokens but no cost moves only `conversation`, not `spend`. This step fails on `main`. - Passed: `pnpm typecheck`, root `pnpm lint`, `tests/integration/api` (74 files, 218 tests), including `people/spend.test.ts`. No UI change. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A1ea20ccbf455ecc4f9e350b69bc5af97 --> -- [View Session in Sentry](https://sentry.sentry.io/explore/conversations/agent%3A1ea20ccbf455ecc4f9e350b69bc5af97/?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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

People stats now come from Turns, not from who started a Conversation. If Ana starts a Conversation and Ben runs a Turn in it, the Conversation and Ben's cost count for Ben.
Behavior
/api/people/me/spendand its version token) read fromjunior_conversation_metrics, grouped by the Actor of each Turn and bucketed byoccurred_at.peopleTreeMetricsJoin) is gone.Write path
actor_identity_id, plus an index on (actor_identity_id,occurred_at).turn-cursor.tspass the Identity of the Turn Actor. Child Task Turns already run as the Actor that invoked them.Backfill (
0092)Not covered: a Conversation with no Turn metrics yet does not show in People. Conversation detail and list costs stay per Conversation.
any-resource-event-automationsandattachment-s3-storagealso fail onmain. I did not run evals.via @dcramer.
--
View Session [Sentry]