Skip to content

ref(chat): Load turn-session routing from SQL on resume - #1268

Merged
dcramer merged 11 commits into
mainfrom
ref/turn-session-resume-sql-routing
Aug 7, 2026
Merged

dcramer merged 11 commits into
mainfrom
ref/turn-session-resume-sql-routing

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Resume paths treat SQL junior_conversations as the authority for destination and session source. They no longer prefer nested redis turn-session contracts with a SQL fallback.

Single routing path

resolveTurnSessionRouting always loads destination and sessionSource from the conversation store. Automatic continuation, stranded recovery, and OAuth/MCP OAuth resume use that path for reply routing. Missing SQL fields fail closed; readers do not rebuild or fall back.

Dispatch / channel-level sources

Scheduled and event-task dispatches omit threadTs. Session source normalization now keeps those channel-level locators, and dispatch enqueue writes them into SQL so resume has a durable source.

This is slice 1 of #1267. It does not stop writing nested contracts yet, change TTLs, or drop summary indexes.

Checks

  • tests/unit/services/turn-session-routing.test.ts passed
  • tests/unit/runtime/source.test.ts passed
  • component continue-runner tests not run here (no local postgres/docker)

Refs #1267

Prefer redis source/destination when present, but fill gaps from
junior_conversations so resume no longer depends on nested contracts
surviving the turn-session redis hangover.

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

vercel Bot commented Aug 6, 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 6, 2026 6:45pm

Request Review

Resume paths query junior_conversations for destination and session
source instead of preferring nested redis contracts with a SQL fallback.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior sentry-junior Bot changed the title ref(chat): Rebuild turn-session routing from SQL on resume ref(chat): Load turn-session routing from SQL on resume Aug 6, 2026
@dcramer
dcramer marked this pull request as ready for review August 6, 2026 16:40
Channel-level scheduled/event dispatch sources omitted threadTs, so
normalizeSessionSource dropped them and SQL-only resume failed closed.
Keep channel locators, rebuild from destination for existing rows, and
write sessionSource when enqueueing dispatch conversations.
When sessionSource is missing, recover threadTs from slack conversation
ids so resume routing stays complete for threaded turns and set-once SQL
writes do not persist a channel-only source.
Resume routing now returns only the SQL destination and sessionSource
columns. Missing sessionSource fails closed instead of reconstructing
from destination or conversation id.

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 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 138b96c. Configure here.

Resume routing is SQL-authoritative and drops per-message timestamps.
Update continuation/OAuth fixtures and expectations so local suite coverage matches the hard-fail contract.

Co-Authored-By: David Cramer <[email protected]>
@dcramer dcramer added the trigger-evals Run evals on a PR label Aug 7, 2026
@dcramer
dcramer merged commit 7c6d73d into main Aug 7, 2026
11 of 13 checks passed
@dcramer
dcramer deleted the ref/turn-session-resume-sql-routing branch August 7, 2026 04:49
sentry-junior Bot added a commit that referenced this pull request Aug 7, 2026
Channel-level session sources omit threadTs after #1268. Archive URLs need a
thread, so leave sourceUrl unset instead of failing the package typecheck.

Refs #1267
dcramer added a commit that referenced this pull request Aug 7, 2026
…1285)

Unblock mainline CI. Every job was dying in `packages/junior prepare` on
a type error from #1268, on top of the earlier file-length and
structured-link failures.

**Slack source URL typecheck**

Channel-level session sources omit `threadTs`.
`sourceUrlFromConversation` now skips archive URL construction when that
anchor is missing, so `packages/junior prepare` typechecks again.

**Agent dispatch suite split**

`agent-dispatch-work.test.ts` was over the 1000-line file-length limit.
Recovery cases move into `agent-dispatch-recovery.test.ts`, and shared
helpers land in `tests/fixtures/agent-dispatch.ts`.

**Structured Slack link assertion**

`message-content-behavior.test.ts` now hydrates conversation messages
before asserting full structured link targets, matching how message text
is actually stored.

**Checks**
- `pnpm --filter @sentry/junior lint`
- `pnpm --filter @sentry/junior typecheck`
- `pnpm file-length:check`
- integration tests not re-run here (no Docker/Postgres in this sandbox)

---------

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 Aug 7, 2026
Stop writing nested destination/source into turn-session state. Writers
project through one explicit Zod schema (`.strip()`), so
unknown/deprecated keys never land in durable records or summary
indexes. SQL remains the authority for routing via conversation metadata
dual-writes.

**Projection schemas**

`agentTurnSessionSummarySchema` is the shared field set. The stored
record schema extends that same projection with resume-only fields
(`committedSeq`, `runtimeContext`, …). Summary indexes intentionally
omit the heavier fields; they are not a second domain model.

**Write-path cleanup**

Optional-field ternary walls in the turn-session service collapse behind
`definedProps` + a shared `sessionWriteContext` helper so each persist
path only fills state-specific bits.

**Naming**

Turn-session APIs keep `source` for the structured inbound Source. That
maps to conversation-store `sessionSource` only at the SQL boundary,
because the store already has a separate coarse `source` enum.

Deploy after #1268 is in prod. Leaves actor dual-written for a later
slice.

Refs #1267

---------

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 Aug 7, 2026
Finish the nested-contract cutover for turn sessions after #1268/#1286.
Singular execution `actor` leaves the Redis turn-session projection and
summary indexes; resume rebuilds it from durable sources.

**Identity model (simplified)**
- Set `actor` first (who runs)
- Derive `credentialContext` with `credentialContextForActor(actor,
subject?)`
- They name the same principal except system runs with delegated
`subject` (scheduled/event-task creator tokens)
- resource-event identity owned by `resource-events/actor.ts`

**Resume**
1. caller routingContext (dispatch / OAuth already bound)
2. resource-event markers → system actor
3. Slack author + destination team

**Also**
- live resource-event turns set `routing.actor` to the system principal
- plugin `run.actor` = instruction provenance, else dispatch
- reply / dispatch / local runner use the same actor→credential
projection

**Checks**
- `tsc --noEmit` ✅
- continue-runner, agent-continue-slack, plugin-tasks ✅
- subscribed-message-behavior, agent-dispatch-work/recovery,
slack-runtime ✅

Refs #1267

---------

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 — a3ee039e Deployed Aug 6, 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 trigger-evals Run evals on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant