Skip to content

feat(conversations): Run private API turns on the shared worker - #1371

Merged
dcramer merged 16 commits into
mainfrom
feat/api-conversation-turns
Aug 10, 2026
Merged

dcramer merged 16 commits into
mainfrom
feat/api-conversation-turns

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Close the extract-only path from #1370 and land a real #1200 slice instead.

Private dashboard/API root turns now enter the existing mailbox + worker path with publishExternally: false. Replies stay in the conversation log. Mailbox, lease, and checkpoint behavior stay the shared execution system.

What this adds

  • api-turns/: enqueue + worker consumer for API root turns
  • POST /api/conversations and POST /api/conversations/:id/messages
  • junior/email actor identity so private API conversations keep participant access
  • integration coverage for enqueue, idempotency, worker run, transcript messages, and completed checkpoint publishExternally: false

Still out of scope

  • continuing Slack-rooted conversations from the dashboard
  • destinationless agent routing without a local destination
  • dashboard composer UI

Refs #1200

Checks

  • pnpm --filter @sentry/junior exec tsc -p tsconfig.json --noEmit
  • pnpm --filter @sentry/junior exec vitest run tests/integration/api-turn-work.test.ts

Requested by U039RR91S.

--

View Junior Session [Sentry]

Add mailbox-backed API root turns with publishExternally false so dashboard
messages use the existing lease/checkpoint path instead of a second runtime.

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

vercel Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview Aug 10, 2026 4:32pm

Request Review

@sentry-junior sentry-junior Bot left a comment

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.

Full pass against #1200, TERMINOLOGY.md, and the chat runtime policies. The direction is right (mailbox + worker, publishExternally false), but several contracts still break before this should merge.

Create is not idempotent. createAndEnqueueApiConversation always mints a new conversationId with createApiConversationId() before the key is applied. A browser retry with the same idempotencyKey therefore creates a second private conversation instead of one message and one turn. #1200 requires the opposite. Derive a durable conversation id from the authenticated viewer + key (or store a create record the way agent-dispatch does) and only then enqueue.

Yielded API turns cannot resume on this worker. isApiTurnWork only matches mailbox rows with kind: "api_turn". After status: "yielded", the next wake is empty/paused work, so routing falls through toward the Slack consumer. Agent invocations already solve this with durable active-state lookup when the mailbox is empty. API turns need the same resume hook, and the completed checkpoint must not hard-code sliceId: 1 once multi-slice resume exists.

Source / Actor wording fights TERMINOLOGY.md. Mailbox source: "api" is correct, but durable sessionSource and agent routing both call createLocalSource (platform: "local"). Local is the CLI source branch, not dashboard/API work. Storing dashboard actors through LocalActor and mapping userName onto slackUserName makes the same mistake on identity. Keep one Source discriminant for what produced the work; if the Source union still lacks an API branch, add that branch (or an honest interim type) instead of overloading local/CLI shapes.

conversations/sql/store.ts is over the 1000-line limit (1022). Main was already at the ceiling; this identity change pushes CI lint red. Extract the actor/identity helpers or another cohesive slice before merge rather than adding a length exception for a small growth.

The worker still owns a full second turn orchestrator (~700 lines). Unlike the closed extract-only PR, this path is a real consumer, but it still copies local-runner lifecycle, delivery, failure, and plugin-completion shape. That will drift from agent-invocation and local CLI. Prefer the thinner agent-invocation-style worker entry over another complete runtime clone, especially while resume and auth pauses remain incomplete.

Verification gaps. The integration test locks the happy worker path, but not create-key retries, POST auth/403 participant checks, or empty-mailbox resume after yield. Those are the contracts above.

Could not submit REQUEST_CHANGES on Junior's own PR; treat the items above as merge blockers either way.

input: CreateApiConversationInput,
options: EnqueueOptions,
): Promise<ApiConversationMessageAccepted> {
const conversationId = createApiConversationId();

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.

New UUID every call means idempotencyKey only dedupes mailbox rows inside one conversation id that the client does not yet know. A retry of POST /api/conversations creates another conversation. Make the conversation id durable for (viewer, idempotencyKey) before enqueue.

}

/** True when this leased attempt is API-authored root work. */
export function isApiTurnWork(context: ConversationWorkerContext): boolean {

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.

Empty resume wakes after yield will not match api_turn metadata, so this route falls through. Mirror the agent-invocation pattern: resolve active API turn state when the mailbox batch is empty.

Make create idempotent, resume empty wakes, use API Source/Actor terms,
and keep store.ts under the file-length limit.

Co-Authored-By: David Cramer <[email protected]>
Update routing error assertions and remove unused imports/spreads that
failed lint and unit/component checks.
@dcramer
dcramer marked this pull request as ready for review August 10, 2026 06:21
@github-actions github-actions Bot added the risk: high PR risk score: high label Aug 10, 2026
Dashboard-created conversations are shareable by default. Local destination
writes only refresh visibility when a live signal is present so later
execution metadata cannot clobber public roots. Private create stays a
later product option.

Co-Authored-By: David Cramer <[email protected]>
API resume matched any active surface "api" turn. Agent-dispatch uses that
same surface with a dispatchId, and the API router runs first, so empty
dispatch wakes could be claimed by the dashboard worker. Require no
dispatchId before treating a wake as an API turn resume.
Conversation visibility can be public for shareable links. Passive memory
still only learns from public Slack channels and local QA, not API roots.
Passive learning opts in by Source branch. Personal API scope matches
junior email identities. Stop collapsing unknown platforms to local.

Co-Authored-By: David Cramer <[email protected]>
Passive extraction stays Source-branch aware. Public API and public Slack
both learn; private sources stay out. Local QA is unchanged.

Co-Authored-By: David Cramer <[email protected]>
Stop rewriting dashboard API actors/sources to local before plugins.
Durable memory source_platform now stores api, and tool contexts carry
ApiSource/ApiActor through registration and runtime.

Co-Authored-By: David Cramer <[email protected]>
Comment thread packages/junior-memory/src/api.ts Resolved
API memories now write source_platform=api. The dashboard detail client
still only allowed local|slack, so permalink Zod parse failed.
Dashboard/web is a Source branch, not an HTTP-layer name. Collapse
extra API-only tool context types into the shared non-Slack local
destination shape. Keep AgentTurnSurface "api" for dispatch routing.

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.

Cursor Bugbot has reviewed your changes 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 5fff986. Configure here.

Too early for enqueue rate limiting on dashboard create/message.
Keep stable 500 responses so store/queue failures do not leak internals.

Co-Authored-By: David Cramer <[email protected]>
Shared product store/queue/state wiring and a scripted runner so the
integration cases stop repeating the same setup in every test.
Require auth viewer for create/append after main's context change.
Pass the User into access checks instead of verifiedViewerEmail.
@dcramer
dcramer merged commit f9afff6 into main Aug 10, 2026
37 checks passed
@dcramer
dcramer deleted the feat/api-conversation-turns branch August 10, 2026 16:40
dcramer added a commit that referenced this pull request Aug 10, 2026
Next #1200 slice after private API root turns (#1371).

Verified participants can append dashboard/API messages to Slack-rooted
conversations. Those turns stay on the shared mailbox + worker with
`publishExternally: false`, so replies land only in the conversation
log.

**What this adds**
- `POST /api/conversations/:id/messages` accepts Slack destinations for
participants
- web Source may keep a Slack Destination when publish is off
- continues inherit existing visibility and keep the original Slack
session source
- conversation origin `source` is set-once so continues cannot rewrite a
Slack root

**Still out of scope**
- dashboard composer UI
- Open in Junior Slack link copy
- later Slack turns announcing dashboard-only activity
- private dashboard create UI

Refs #1200

**Checks**
- `pnpm --filter @sentry/junior exec tsc -p tsconfig.json --noEmit`
- `vitest run tests/unit/agent-request.test.ts
tests/integration/api-turn-work.test.ts` (10/10)

<!-- junior-request-attribution:start -->
Requested by **U039RR91S**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0B595QDZLL%3A1786380106.199919 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0B595QDZLL%3A1786380106.199919)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0B595QDZLL%3A1786380106.199919/?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]>
dcramer added a commit that referenced this pull request Oct 30, 2026
Personal spend (profile menu 7d/30d), the People profile, and the People
list left out conversations started from the dashboard.

`verifiedActorWhere` required `juniorIdentities.provider = "slack"`.
That filter came in with the SQL people API (#738). At that time, Slack
was the only provider with human identities; `junior` identities were
only system actors (scheduler, local CLI). Dashboard actors were added
later (#1371) as `kind: "user"`, `provider: "junior"` identities that
have a verified email and a linked user. The Slack-only filter skipped
them.

The predicate now matches verified identities with `kind = "user"` from
any provider. System identities stay out explicitly, even if one were
linked to a user. Identity upsert links users only for user-kind
identities. The predicate checks this directly so the guard does not
depend on that write-path rule.

With web identities included, the grouped `MAX(providerSubjectId)` /
`MAX(handle)` columns could return a web identity's email as
`slackUserId`. Those columns now read only Slack identities.
`locations/query.ts` already uses the same pattern.

The Slack provider filter in `api/mentions.ts` stays. It resolves Slack
mention ids, so Slack-only is correct there.

Refs #2431 (bug 1 only; bug 2 is handled separately).

<!-- junior-request-attribution:start -->
via **David Cramer**.
<!-- junior-request-attribution:end -->

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

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A901e63bb3d7f99c7c9f72ab34879e092)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A901e63bb3d7f99c7c9f72ab34879e092/?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]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 7da36975 Deployed Aug 10, 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