chore(agent): turn-overlap tripwire — warn when a turn starts before the previous persist (salvage #64936) - #65499
Merged
Conversation
Collaborator
…turn's persist Two turns interleaving on one session corrupt the durable transcript: flushes race (user rows persist out of arrival order), the identity-marker dedup over shared history dicts can swallow a row, and the second turn runs on a history base that never saw the first turn's exchange. The dispatch route that lets the second turn through the busy guard is not yet identified. Add note_turn_start (build_turn_context) / note_turn_persisted (_persist_session funnel): one WARNING naming both turn_ids when a turn starts before the previous turn's turn-end persist. Ownership transfer keeps a crashed turn from warning more than once; the unconditional clear makes the tripwire under-report rather than double-report under a real overlap. Log-only, no behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
teknium1
force-pushed
the
salvage/64936-turn-overlap-tripwire
branch
from
July 16, 2026 11:52
9f3ae7c to
4597886
Compare
teknium1
enabled auto-merge (rebase)
July 16, 2026 11:52
This was referenced Jul 16, 2026
12 tasks
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.
Summary
When a turn starts on a session whose previous turn has not completed its turn-end persist, the agent now logs one WARNING naming both turn_ids, the session, and the previous turn's age — so the next concurrent-turn occurrence (#64934) identifies which dispatch route bypassed the gateway busy guard directly from logs. Log-only, zero behavior change.
Salvages #64936 by @Rival (authorship preserved) onto current main. Companion to #65492 (restore-boundary repair); together they cover the #64934 cluster's cause-agnostic half.
Changes
agent/agent_runtime_helpers.py:note_turn_start(agent, turn_id)— warns on overlap, takes ownership of the in-flight slot (a turn that crashed before its persist warns at most once);note_turn_persisted(agent)— unconditional clear, so under a real overlap the tripwire under-reports rather than double-reports. Same-turn_id re-entry (retry paths) is silent.agent/turn_context.py:build_turn_contextcallsnote_turn_startwhen the turn_id is minted.run_agent.py:_persist_sessioncallsnote_turn_persistedin both lock branches.Validation
test_turn_context.py: 21 passed, 0 failed._persist_sessionfunnel: serial turns silent in BOTH lock branches (with and without_session_persist_lock); overlap fires exactly one WARNING containing both turn_ids; same-turn re-entry silent.Infographic