Skip to content

chore(agent): turn-overlap tripwire — warn when a turn starts before the previous persist (salvage #64936) - #65499

Merged
teknium1 merged 1 commit into
mainfrom
salvage/64936-turn-overlap-tripwire
Jul 16, 2026
Merged

chore(agent): turn-overlap tripwire — warn when a turn starts before the previous persist (salvage #64936)#65499
teknium1 merged 1 commit into
mainfrom
salvage/64936-turn-overlap-tripwire

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

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_context calls note_turn_start when the turn_id is minted.
  • run_agent.py: _persist_session calls note_turn_persisted in both lock branches.

Validation

  • Contributor's 4 unit tests + test_turn_context.py: 21 passed, 0 failed.
  • E2E through the real _persist_session funnel: 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

infographic

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: maintainer salvage of #64936 and diagnostic companion to #64934/#64935. It is log-only instrumentation, not the concurrency fix itself.

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants