Skip to content

ref(chat): Drop dead turn-session model metadata - #1328

Closed
sentry-junior[bot] wants to merge 7 commits into
mainfrom
ref/turn-session-honest-runtime-metadata
Closed

sentry-junior[bot] wants to merge 7 commits into
mainfrom
ref/turn-session-honest-runtime-metadata

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Stop threading model/skills/reasoning through turn-session writes. After the Redis ops-bag cutover those fields were never restored from storage, so the write path was pretending they were session metadata.

Honest write path

runtimeMetadata is now runtimeMetrics and only carries SQL-backed channel name plus execution duration/usage. Resume still rebuilds those from the conversation row. Model, reasoning, and loaded skills stay on live turn route/diagnostics.

Dead resume plumbing removed

Dropped the stale existingSessionRecord.reasoningLevel fallback, the skill-name sync callback used only to feed session writes, and unused recovery projection/model lookups on stranded-session repark paths.

Checked: tsc --noEmit; focused vitest for turn-session-record + agent-resume (36/36).

Refs #1267

Requested by David Cramer.

--

View Junior Session [Sentry]

Model, reasoning, and loaded skills were never restored from storage after
the Redis ops-bag cutover, so stop threading them through session writes.
Keep SQL channel/metrics writes as the durable runtime path and remove the
stale TODO(#1267) dual-write framing.

Refs #1267

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

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

Request Review

upsertAgentTurnSessionRecord no longer accepts model metadata, so the
behavior harness resume fixtures must stop passing it.

Refs #1267
Fire-and-forget running summaries can finish after a later terminal write
and resurrect an unfinished recovery view. When collapsing the append-only
index, keep terminal entries over lagging non-terminal ones.

Refs #1267

Co-Authored-By: David Cramer <[email protected]>
Resume discovery treats the newest recovery summary as stranded when it
is still `running`. A fire-and-forget start write can land after a
timeout/yield boundary and hide that pause, so collapse by lifecycle
rank: running < awaiting_resume < terminal.

Refs #1267

@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 ff1cf3b. Configure here.

Pure lifecycle rank let a stale awaiting_resume summary hide a live
post-resume running upsert, blocking stranded mid-resume recovery.
Collapse by version first; use rank only to break same-version races
from fire-and-forget start writes.

Refs #1267
Keep one same-version rank tiebreak and one higher-version win. Drop the
extra terminal/pause matrix that reasserted the same collapse rule.

Refs #1267

Co-Authored-By: David Cramer <[email protected]>
The recovery-index collapse changes exposed separate continuation behavior
and made this metadata-removal PR own unrelated lifecycle policy. Restore
the existing newest-summary rule and remove its added component coverage.

Refs #1267
@sentry-junior

sentry-junior Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Design review (post-#1344)

Do not merge this branch. It is stale against main (CONFLICTING, ~28 behind). #1344 moved the surfaces this PR edits (turn-session* → turn-cursor / checkpoint). The cleanup goal is still right; redo it on current code.

Ownership design (still correct)

Concern Authority Loss OK?
Resume cursor (status, boundary into SQL history, slice) Redis turn checkpoint Yes — next worker stops the turn; SQL history remains
Agent history / skills evidence SQL conversation events No
Turn route (model profile + reasoning) SQL turn_routed (+ history replacement after handoff) No
Channel + duration/usage SQL conversation row No

This matches TERMINOLOGY.md, task-execution/README.md, and #1267: Redis = bounded ops; SQL = durable truth. Do not dual-write SQL-owned fields into the checkpoint “just in case.”

Why dropping the three fields is still right

On current main, modelId / loadedSkillNames / reasoningLevel are still:

  • not stored on StoredTurnRecord
  • not restored on read (materializeStoredTurnRecord only rebuilds channel + metrics)
  • not kept by recordExecution (metrics only)
  • already owned elsewhere: route via loadTurnRoute / turn_routed; skills via inferLoadedSkillNamesFromPiMessages + restoreSkillRuntime

So threading them through resume/checkpoint/upsertTurnRecord is still a lying write path. The dead existingSessionRecord?.reasoningLevel handoff fallback still cannot fire after a real read. TODO(#1267) is still on upsertTurnRecordLocked.

Design pushback (do not redo as a pure mechanical delete)

  1. Wrong slogan in this PR: “live turn route/diagnostics” collapses durable route with ephemeral diagnostics. Sharper rule:

    • profile + reasoning → turn route / history replacement
    • concrete modelId → resolve at execution from profile config (do not checkpoint a vendor id)
    • skills → derive from history + catalog
    • checkpoint → only what is needed to find the boundary and wake the turn
  2. Post-handoff reasoning authority is still fuzzy. Resume-after-handoff still does profileConfig.reasoning ?? existingSessionRecord.reasoningLevel ?? storedTurnRoute.reasoningLevel. The middle term never survives a real read. Deleting it is fine only if the contract is explicit: after handoff, profile config (else inherited old route) is authority, because handoff does not write a new turn_routed. If mid-turn reasoning must round-trip, record it on handoff/history replacement — do not stash it on the cursor.

  3. runtimeMetadata remains a smell after cleanup. Piggybacking SQL channel/metrics on every cursor upsert can stay, but calling it a temporary dual-write is dishonest post-ref(chat): Simplify durable conversation execution #1344. Either own it as “checkpoint commit also updates conversation execution metrics,” or split recordExecution out. Renaming toward metrics-only and dropping dead fields is the right direction.

  4. This does not finish Keep chat Redis data short-lived and schema-light #1267. Remaining work still includes mailbox metadata, dispatch durability, artifacts, and channel config. This is turn-cursor honesty only.

Redo target

Close or supersede this PR. Re-implement on task-execution/turn-cursor.ts, checkpoint.ts, and resume wiring with the ownership rule above — not a rebase of the old file paths.

@sentry-junior sentry-junior Bot closed this Aug 9, 2026
@sentry-junior

sentry-junior Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Superseding: this branch is stale against main after #1344 moved turn-session* → turn-cursor / checkpoint. Cleanup goal stays valid; redoing on current surfaces in a fresh PR. No recovery-index changes.

@sentry-junior

sentry-junior Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1356 on current main (post-#1344 turn-cursor/checkpoint surfaces). Same cleanup goal; no recovery-index changes.

dcramer added a commit that referenced this pull request Aug 9, 2026
Supersedes #1328 after #1344 moved `turn-session*` → turn-cursor /
checkpoint.

Stop threading `modelId` / skills / `reasoningLevel` through turn-cursor
writes. Those fields were never restored from storage, so the write path
was pretending they were checkpoint metadata.

**Ownership (unchanged)**
- checkpoint = resume boundary only (status, history boundary, slice)
- profile + reasoning = turn route / history replacement
- concrete model id = resolve at execution from profile config
- skills = derive from history + catalog
- channel + duration/usage = SQL conversation row

**What changed**
- Drop the three dead fields from `TurnRecord`, `upsertTurnRecord`, and
checkpoint write args
- Rename `runtimeMetadata` → `runtimeMetrics` for SQL-backed
channel/metrics only
- Remove the dead resume `existingSessionRecord.reasoningLevel` fallback
- Explicit post-handoff contract: profile config, else inherited old
route
- No recovery-index policy changes

Checked: `tsc --noEmit` (@sentry/junior + @sentry/junior-evals); focused
vitest checkpoint + agent-resume + paused-turn **45/45**.

Refs #1267

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

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AG6MCDB51U%3A1786211808.864869 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AG6MCDB51U%3A1786211808.864869)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AG6MCDB51U%3A1786211808.864869/?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 — 6118d737 Deployed Aug 8, 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.

0 participants