Skip to content

fix(chat): resume already-checkpointed running turns - #1237

Draft
sentry-junior[bot] wants to merge 4 commits into
mainfrom
fix/turn-checkpoint-idempotency
Draft

fix(chat): resume already-checkpointed running turns#1237
sentry-junior[bot] wants to merge 4 commits into
mainfrom
fix/turn-checkpoint-idempotency

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Stop poison-turn continue storms by treating an already-checkpointed running session as resume.

Root cause

If a turn checkpoints its prompt, then dies while still running, redelivery treated it like a fresh prompt: rebuild user message → append-only commitMessages rejects prefix → swallowed as commit-lost → lost_lease requeue forever.

Minimal fix

  1. turnStartMessageIndex means the prompt is already owned → shouldPromptAgent = false and resume/continue that history
  2. still-running records with that cursor count as resumed sessions
  3. if a history-boundary mismatch still happens, don't collapse it to false / lost-lease recovery
  4. when prompt is already owned, still ack mailbox ownership on redelivery

Net diff is ~4 files / ~40 lines. No new error types or worker-wide rewrites.

Verification: tsc --noEmit. Component tests need Postgres; not run here.

Refs https://sentry.sentry.io/issues/7629103059/
Refs https://sentry.sentry.io/issues/7650484395/

Redelivery against a still-running turn reused a Date.now() prompt and failed
commitMessages' append-only deep-equal check. That mismatch was swallowed as
TurnInputCommitLost and mapped to lost_lease recovery, requeuing forever.

Reuse the exact durable checkpointed prompt on running-record replay, throw a
typed AgentHistoryBoundaryError for permanent shape mismatches, and fail closed
without lost_lease recovery wakes.

Evidence: JUNIOR-62 / JUNIOR-7A storm on slack:C0B595QDZLL:1785871561.942119
Co-Authored-By: David Cramer <david@sentry.io>
@vercel

vercel Bot commented Aug 4, 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 4, 2026 11:23pm

Request Review

A still-running turn with turnStartMessageIndex already owns its prompt.
Treat that as resume so redelivery continues instead of rebuilding a
Date.now() user message that fails append-only commit and farms lost_lease
retries. Also stop swallowing permanent history-boundary mismatches as false.

Co-Authored-By: David Cramer <david@sentry.io>
@sentry-junior sentry-junior Bot changed the title fix(chat): stop poison-turn checkpoint retry storms fix(chat): resume already-checkpointed running turns Aug 4, 2026
Resume already-checkpointed running turns without fail-closed history throws
that broke handoff follow-ups. Add a consecutive empty-wake ceiling so
lost_lease/continue recovery cannot farm forever without mailbox progress.

Co-Authored-By: David Cramer <david@sentry.io>
Healthy resume+defer slices were treated as empty-wake failures and
forced a yield. Count CONVERSATION_WORK_MAX_EMPTY_WAKES only when
recovery has no mailbox progress, and clear the streak after successful
runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants