Skip to content

fix(sessions): raise InvocationNotFoundError instead of bare ValueError on rewind - #7069

Open
ecanlar wants to merge 1 commit into
google:mainfrom
ecanlar:fix/invocation-not-found-error
Open

fix(sessions): raise InvocationNotFoundError instead of bare ValueError on rewind#7069
ecanlar wants to merge 1 commit into
google:mainfrom
ecanlar:fix/invocation-not-found-error

Conversation

@ecanlar

@ecanlar ecanlar commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

rewind_session (in _rewind_utils.py) raises a bare ValueError with a hardcoded message when rewind_before_invocation_id matches no event in the session:

raise ValueError(f"Invocation ID not found: {rewind_before_invocation_id}")

Callers of Runner.rewind_async have no stable way to distinguish this specific failure from any other ValueError, short of matching against that exact message string. That string is not part of any documented contract, so a future wording change to it would silently break any caller relying on it — with no test able to catch the break, since a hand-constructed ValueError in a test can't detect a wording drift in the library's own raised message.

This mirrors the situation SessionNotFoundError was already introduced to solve for the "session not found" case.

Change

  • Add InvocationNotFoundError (errors/invocation_not_found_error.py), a ValueError subclass — for backward compatibility — following the exact pattern of SessionNotFoundError.
  • rewind_session now raises InvocationNotFoundError instead of the bare ValueError, keeping the same message text.
  • Document the new exception in Runner.rewind_async's docstring (Raises: section).
  • Update the existing unit test asserting on this path to check the new type.

Test plan

  • pytest tests/unittests/sessions/test_rewind_utils.py tests/unittests/runners/test_runner_rewind.py — all 9 tests pass.
  • pyink, isort, ruff check on the changed files — no issues.
  • Backward compatible: InvocationNotFoundError is still a ValueError, so any existing except ValueError handling keeps working unchanged.

…or on rewind

rewind_session raised a bare ValueError with a hardcoded message when rewind_before_invocation_id matched no event in the session. Callers had no stable way to distinguish it from other failures short of matching that exact string, which a future wording change could break silently.

Add InvocationNotFoundError (a ValueError subclass, for backward compatibility, mirroring SessionNotFoundError) and raise it instead so callers can catch it by type.
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.

2 participants