fix(sessions): raise InvocationNotFoundError instead of bare ValueError on rewind - #7069
Open
ecanlar wants to merge 1 commit into
Open
fix(sessions): raise InvocationNotFoundError instead of bare ValueError on rewind#7069ecanlar wants to merge 1 commit into
ecanlar wants to merge 1 commit into
Conversation
…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.
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
rewind_session(in_rewind_utils.py) raises a bareValueErrorwith a hardcoded message whenrewind_before_invocation_idmatches no event in the session:Callers of
Runner.rewind_asynchave no stable way to distinguish this specific failure from any otherValueError, 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-constructedValueErrorin a test can't detect a wording drift in the library's own raised message.This mirrors the situation
SessionNotFoundErrorwas already introduced to solve for the "session not found" case.Change
InvocationNotFoundError(errors/invocation_not_found_error.py), aValueErrorsubclass — for backward compatibility — following the exact pattern ofSessionNotFoundError.rewind_sessionnow raisesInvocationNotFoundErrorinstead of the bareValueError, keeping the same message text.Runner.rewind_async's docstring (Raises:section).Test plan
pytest tests/unittests/sessions/test_rewind_utils.py tests/unittests/runners/test_runner_rewind.py— all 9 tests pass.pyink,isort,ruff checkon the changed files — no issues.InvocationNotFoundErroris still aValueError, so any existingexcept ValueErrorhandling keeps working unchanged.