Repository navigation
feat(conversations): Add Conversation kind (root, thread, task) - #2834
Conversation
Store an immutable kind on each Conversation. Roots get root, and every child is still a Task. Titles and Briefs skip Tasks instead of every child. Agent invocation behavior (child prompt mode, Guardian intent, reportBlocked, review desk, user customization, messageAgent binding) now reads run.agentInvocationId instead of run.parentConversationId. parentConversationId stays the tree edge. Part of #2792. Co-Authored-By: David Cramer <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
15 screenshot changes — 15 changed · 0 added · 0 removed Review screenshots in Frameshift Show 9 more changed screenshots |
There was a problem hiding this comment.
I found nothing that blocks merge. The split looks right. I have one change to make before merge and a few small follow-ups.
What I checked
- I looked at every
parentConversationIduse left inpackages/junior/src. Each one is a tree edge: routing, root and depth walks, stop cascade, access, root-only SQL filters, the Destination lookup that reads roots only, fork refusal, andsearchAgents/top-levelmessageAgentreach. All Run-behavior checks now readagentInvocationId: prompt mode, Guardian provenance and intent,reportBlocked, the review desk, user customization, themessageAgentbinding, and the CLI binding. All child work goes throughcreateChildConversationWorker→createAgentInvocationWorker, so every child Run still getsagentInvocationId, and behavior does not change today. Mutation check: when I removeagentInvocationIdfrom the worker's Run,agent-invocation-work"finishes a 'blocked' child Turn" fails. - Deploy window: no production path can reach the new throws with legitimate data.
upsertConversationcallers getkindfrom the stored row, or fromparentConversationIdwhen the stored kind is null (conversationKindFromRow). On conflict, no write path changesparent_conversation_id. The onlycreateChildcaller is spawn, which always passestask. Rows that old writers leave with a null kind decode the same way, and the next upsert fills them throughcoalesce. Fork, scheduler, ACP and Slack all create roots with no parent. These are invariant assertions at the store boundary, the same as the existing "parent changed" throw, so they fitpolicies/error-handling.md. - The brief skip reason (
child_conversation→task_conversation) is only alog.infofield. Nothing inTELEMETRY.mdor the tests reads it. pnpm typecheckpasses.drizzle-kit generateshows no schema drift. I ran 30 files with Postgres fromcompose.yaml: every touched test, allagent-invocation-*,dashboard-reporting, andapi/conversations/detail. 202 of 202 pass.
Fix before merge
- Drop
AgentRun.conversationKindfrom this PR. Nothing reads it. It makes about 60 test call sites change, and it is the only reason for the extragetConversationStore().getand the new "is not a child" throw inwork.ts. That row is already read insidereadChildDepthAndRootLocation. The later rules for "a person's Turn in a Thread" do not need a kind on the Run. Guardian intent,reportBlockedand the review desk already follow!agentInvocationId. "NospawnAgent/messageAgentin a person's Turn" can usedisabledFeatures: ["subagents"], which the web Turn worker sets fromstoredConversation.kind(the spawn gate inagent-runner.ts). Destination, Location and Delivery handling is also a worker decision. Add the field in the PR that first reads it, if that PR needs it. If you keep it, return the kind fromreadChildDepthAndRootLocationand do not add a second read.
Small follow-ups
- The contract TODO in
db/schema/conversations.tsshould say that the contract migration must run theWHERE kind IS NULLbackfill again beforeNOT NULL. Rows that old writers create during the deploy window, and rows that no write touches later, stay null. TERMINOLOGY.mdLocation still says "(Slack channel or thread)". That breaks the new "Slack thread" rule two entries above it.- In
agent-invocation-message.test.ts,childRunsays "as the invocation worker builds it", but it does not setagentInvocationId. Optional: addagentInvocationId: created.invocationIdto the Run assertion inagent-invocation-work("reads the parent Location…"). That would lock the field that now gates Guardian intent and the prompt mode, not onlyreportBlocked.
| /** Durable conversation advanced by this run. */ | ||
| conversationId: string; | ||
| /** Kind of the stored Conversation. */ | ||
| conversationKind: ConversationKind; |
There was a problem hiding this comment.
Nothing reads this in this PR. The later rules for a person's Turn in a Thread can use !agentInvocationId plus a worker-level disabledFeatures decision from the stored kind. Suggest dropping it, together with the extra child read and the throw in work.ts, until a PR reads it.
| (): AnyPgColumn => juniorConversations.conversationId, | ||
| ), | ||
| // `root` exactly when parent_conversation_id is null. Set once at create. | ||
| // TODO(dcramer): Add NOT NULL and a check constraint after every deployed |
There was a problem hiding this comment.
Say here that the contract migration must run the kind IS NULL backfill again before NOT NULL. Rows from old writers in the deploy window, and rows that no write touches later, stay null.
Nothing reads it yet. Later PRs gate a person's Turn in a Thread on a missing agentInvocationId. Assert agentInvocationId in the invocation worker Run, and clarify the kind contract TODO and the Location term. Co-Authored-By: David Cramer <[email protected]>
This comment has been minimized.
This comment has been minimized.
|
my only concern: is kind=root a useful thing? it feels dirty to me, but it might be safer just having something like that so its explicit |
…s no parent Co-Authored-By: David Cramer <[email protected]>
dcramer
left a comment
There was a problem hiding this comment.
just need to get CI green i think
Co-Authored-By: David Cramer <[email protected]>
…#2837) Stacked on #2834. Prep for #2792. `agent-invocations/store.ts` had 955 lines, and #2792 adds Thread cap and `archiveAgent` logic to it. No behavior change: locking, error types, and statuses stay the same. ## Why it's organized this way - **`create.ts` gives work to child agents.** It holds spawn (`createAgentInvocation`), message (`createAgentInvocationForMessage`), and child input (`createAgentInvocationFromLatest`), plus the per-parent and per-child caps. All three paths insert their row through `insertAgentInvocation`. Each path's guards now run over one `listOpenAgentInvocations` read under the parent lock. Before, they made four separate queries. - **`assertChildAgentCapacity` is the only cap rule.** Create and message used to check the parent cap separately, and message had its own "idle child becomes active" rule. Both now call this one helper, and the Thread rule in #2792 goes here. - **`store.ts` is the invocation record.** It holds reads, status changes, completion, and the parent mailbox state (`replaced`, `steered`). The name follows the other feature stores (`task-execution/store`, `events/store`). - **`ids.ts` holds stable ids and the lock name.** Seven modules across spawn, stop, list, results, the worker, markers, and pending cards use them, so they live in one place. - **Reporting stays split between `store.ts` and `result.ts`.** Moving completion into `result.ts` would make `work.ts` and `result.ts` import each other, because `result.ts` builds the worker from `work.ts`. Against #2834, the three files have 926 lines (`create.ts` 377, `store.ts` 445, `ids.ts` 104), down from 955. The last commit alone removes 45 lines. Importers use the new modules directly, with no re-exports. `work.ts` changes only in its import lines. The cap scenario in `agent-invocation-concurrency` now also covers messages: at the cap, a message to an idle child is rejected, and a message to a busy child is queued (`queued: true`). <!-- junior-request-attribution:start --> via @dcramer. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A20bb357b261893c4d2ad080279457c57 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A20bb357b261893c4d2ad080279457c57) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A20bb357b261893c4d2ad080279457c57/?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]>
Part of #2792 (PR 1 of 8).
Adds an immutable
kind(root,thread, ortask) to each Conversation. No behavior change: every child is still a Task. Nothing creates a Thread until PR 6.Storage
0083_conversation_kind: nullablekind textonjunior_conversations, typed withtext().$type<ConversationKind>(). It backfillsrootfor rows with no parent andtaskfor the rest. Then it adds two checks, so validation runs after the backfill:junior_conversations_kind_check:kind in ('root', 'thread', 'task').junior_conversations_kind_parent_check:kind is null or ((kind = 'root') = (parent_conversation_id is null)). The DB now enforcesrootexactly when there is no parent. Thekind is nullarm keeps older writers working during the rolling deploy, because they do not writekind.check()indb/schema/conversations.ts.db:generateput them in a separate migration, so I moved its SQL into 0083 after the backfill and kept the 0083 snapshot.db:generatenow reports no drift.kind.ensureConversationRowandupsertConversationwriterootfor roots.createChildtakeskind(Exclude<ConversationKind, "root">), andcreateAgentInvocationpasses"task".createChildthrows when an existing child has a different kind. On conflict, upsert keeps the stored kind (coalesce), and this also fills a null kind left by an older deploy.junior_conversationsinserts areensureConversationRow(alwaysroot, no parent) andupsertConversation(recordActivity,recordExecution,createChild; all Slack, web, ACP, scheduler, and fork roots go through these). No update setsparent_conversation_idorkindafter insert. TheupsertConversationkind/parent throw stays: on conflict the stored parent and kind win, so the check does not see a bad incoming value.conversationKindFromRowreads a null kind from the parent edge while older writers are still deployed. The contract migration is a follow-up after deploy: rerun thekind IS NULLbackfill, addNOT NULL, and drop thekind is null orarm (see the TODO indb/schema/conversations.ts).Agent invocation vs. kind (differs from the issue text)
The issue says to move the
run.parentConversationIdchecks torun.conversationKind === "task". That is not what they mean today. Only the Agent invocation worker setsrun.parentConversationId(the web Turn worker never sets it). So these checks mean "this Run advances an Agent invocation". In a Thread, an Agent invocation must keep this behavior, and a person's Turn must not get it. A kind check cannot tell the two apart.So this PR adds an explicit invocation fact instead, and no Run-level kind.
AgentRun.agentInvocationId(andToolRuntimeContext.agentInvocationId) is set only by the Agent invocation worker. These checks moved to it, and their behavior is the same:agent/prompt.ts:child_agentprompt modeagent/index.ts: agent instruction provenance (childAgent)agent/tools.ts: GuardianCHILD_AGENT_USER_INTENT(childAgent)tools/index.ts:reportBlocked, and the review desk disabled reasontools/user-customization.ts: noupdateUserCustomizationruntime/agent-runner.ts: themessageAgentbinding when too deep to spawncli/chat.ts: the local CLIbindMessageAgentLater PRs gate a person's Turn in a Thread on a missing
agentInvocationId, and ondisabledFeatures: ["subagents"]that the web Turn worker sets from the stored Conversation kind.parentConversationIdstays the tree edge only: routing, root and depth lookups, stop cascade, access,searchAgents, top-level messages, and the root filters in SQL.Kind as a Conversation fact
services/conversation-title.ts) and Briefs (briefs/task.ts) skip Tasks instead of every child. The Brief skip reason is nowtask_conversation.TERMINOLOGY.md: Thread, Task, Subagent, and the "Slack thread" rule (also applied to the Location entry).dashboard-reporting.ts,conversation-retention.ts) andcreateChildtest callers passkind. The dashboard mock fixtures do not change, because the API does not returnkindyet (PR 2).Files
No file splits.
agent-invocations/store.tsandagent-invocations/work.tseach have a one-line change.Checks
pnpm typecheck,pnpm lint,pnpm file-length:check: pass.db:generate: no drift.pnpm cli -- upgradeon a DB migrated at the branch base (same migrations as main), with a root, two children, and a grandchild: applies 0083, backfillsroot/task, adds both checks. A null-kind child insert (older writer) passes. Arootrow with a parent fails.conversation-sql,conversation-sql-store,conversation-storage-sql,agent-invocation-*,api/conversations,api/people,api/locations,dashboard-reporting, briefs, retention, and plugin reports: pass. Full@sentry/juniorsuite: 3,195 pass. Two tests outside this change hit 5s timeouts under full-suite load (any-resource-event-automations,sandbox-egress-proxy), and both pass on rerun.conversation-sql-storechecks that each Conversation keeps its kind, that a kind change is rejected, and that the DB rejects arootwith a parent and ataskwith no parent. The cyclic-parent fixture indashboard-reporting.test.tsnow also setskind: "task"on the row it gives a parent.agent-invocation-workassertsagentInvocationIdon the invocation worker Run.via @dcramer.
--
View Session [Sentry]