Skip to content

fix: only rewind matching session suffixes#3090

Open
Aphroq wants to merge 2 commits intoopenai:mainfrom
Aphroq:fix/session-rewind-suffix-match
Open

fix: only rewind matching session suffixes#3090
Aphroq wants to merge 2 commits intoopenai:mainfrom
Aphroq:fix/session-rewind-suffix-match

Conversation

@Aphroq
Copy link
Copy Markdown
Contributor

@Aphroq Aphroq commented May 2, 2026

Summary

Fixes rewind_session_items() in src/agents/run_internal/session_persistence.py so retry cleanup only removes the exact session tail that belongs to the retry being rolled back.

Previously, the helper popped session items before confirming the tail matched the rewind target, which could delete unrelated tail records. The server-tracker cleanup path could also keep popping until it found a known server item, removing the unrelated suffix and the first known server item itself. This change switches both paths to exact-suffix matching before deletion, adds best-effort restoration on mid-rewind mismatches, and restricts tracker cleanup to retry-owned tail items only.

Also adds regression coverage in tests/test_agent_runner.py for mismatched tails, server-tracker cleanup preserving unrelated items, and stripping only retry-owned local suffixes before a known server item.

Test plan

  • Ran targeted rewind tests with uv run pytest tests/test_agent_runner.py -k rewind
  • Ran the repository verification stack via bash .agents/skills/code-change-verification/scripts/run.sh
  • Confirmed format, lint, typecheck, and full tests passed

Issue number

Closes #3089

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

@github-actions github-actions Bot added bug Something isn't working feature:core labels May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rewind_session_items can delete unrelated tail session items during retry cleanup

1 participant