perf(conversations): Fence commits on caller-owned history cursors - #1228
Open
sentry-junior[bot] wants to merge 8 commits into
Open
perf(conversations): Fence commits on caller-owned history cursors#1228sentry-junior[bot] wants to merge 8 commits into
sentry-junior[bot] wants to merge 8 commits into
Conversation
Make append return the inserted delta and live history cursor so commitMessages can advance committedSeq/messageSeqs without a second loadCurrentHistory of the entire active version. Co-Authored-By: David Cramer <david@sentry.io>
Co-Authored-By: David Cramer <david@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dcramer
marked this pull request as ready for review
August 4, 2026 18:20
Separate message and turn-context appends, return committedSeq from append, and let turn-session checkpoints pass an already-materialized base so commitMessages only writes the delta after verifying the live cursor. Co-Authored-By: David Cramer <david@sentry.io>
Exact global-cursor equality rejected checkpoints after MCP connects, auth requests, and other non-agent events advanced seq. Fence on agent message prefix and message seqs instead, and adopt the live cursor when only host-only facts moved it.
Session summaries use a strict schema without fence fields. messageSeqs was left on the summary payload, so index readers rejected every new summary and hid sessions from operational listings.
Reject non-prefix session bases so handoff/compaction take the cold path, adopt concurrent same-prefix agent commits past a stale fence, and cover the product checkpoint/resume path with integration tests. Co-Authored-By: David Cramer <david@sentry.io>
History fences can adopt concurrent same-prefix commits, but session metadata must not regress. Re-check the live turn session after commit and refuse delayed running checkpoints that would overwrite awaiting_resume/completed/failed state. Co-Authored-By: David Cramer <david@sentry.io>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ab58929. Configure here.
expectedVersion must prefer the stale caller base over a fresh store read at upsert entry; otherwise delayed running checkpoints skip the lifecycle guard and can still overwrite awaiting_resume. Co-Authored-By: David Cramer <david@sentry.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Stop durable agent-history checkpoints from reloading and deep-comparing the full active history on every write. Callers that already hold a committed projection can fence on that cursor and append only the delta.
Cursor-fenced commits
commitMessagesaccepts an optionalbasewithcommittedSeq,historyVersion,messageSeqs, messages, and provenance. When present, it verifies the live cursor, then writes only new durable messages. Turn-session checkpoints pass the already-materialized session as that base and persistmessageSeqsfor the next fence.Fence hardening
Session checkpoints only reuse a prior base when the next durable messages are a true prefix extension, so handoff/compaction replacements take the cold path. After handoff, resume materialization adopts the replacement epoch's fence cursors instead of keeping the pre-handoff
committedSeq/messageSeqs. When the live store advanced past a stale base, commits adopt concurrent same-prefix agent writes (for example a racingturn_endbefore timeout continuation) and still reject divergent rewrites. Host-only cursor advances remain allowed.Session lifecycle guard
History adoption alone is not enough: a delayed
runningcheckpoint must not overwriteawaiting_resume/completed/failedsession metadata that landed meanwhile. After the history commit,upsertAgentTurnSessionRecordre-reads the live session and rejects lifecycle regressions (and older same-rank slices). Completed delivery retries stay idempotent once a terminal record exists.Separate appends
Native agent-history messages and host-only
turn_contextevents are appended in separate store calls. Message sequence assignment no longer depends on mixed-event ordering.Append result
appendreturns{ historyVersion, inserted: [{ seq }], committedSeq }so commit paths advance without a post-write full history reload. Session summaries strip fence fields (messageSeqs,committedSeq,historyVersion) so strict summary readers keep working.Cold paths without a base still load current history once for prefix validation. Coverage includes fenced deltas, host-only cursor advances, concurrent same-prefix adoption, delayed running-vs-awaiting_resume session races, handoff yield/resume, tool-timeout continuation, and product-path mid-turn checkpoints after MCP connect.