fix: replace assert with runtime guard in session recovery - #73050
Open
JonthanaHanh wants to merge 1 commit into
Open
JonthanaHanh wants to merge 1 commit into
JonthanaHanh wants to merge 1 commit into
Conversation
`assert output is not None` at session_recovery.py:1241 is stripped by `python -O`, silently removing the invariant check before `output.parent` is accessed on the next line. Replace with an explicit `if output is None: raise` using the same `SessionRecoverySafetyError` that other validation checks in this function already use.
teknium1
reviewed
Jul 30, 2026
teknium1
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for tightening this recovery invariant. The targeted guard matches the module's existing safety-error convention.
Problems
- The change has no regression test for its stated optimized-Python behavior.
recover_session_database()still relies on the assertion athermes_cli/session_recovery.py:1241on current main, while existing recovery calls intests/hermes_cli/test_session_recovery.py:435and:516provide valid output paths.
Suggested changes
- Add a focused
python -Oregression test passingoutput_path=Nonedirectly torecover_session_database()and assertingSessionRecoverySafetyError. The CLI already rejects a missing output athermes_cli/sessions_cmd.py:143-145, so direct API coverage is the relevant path.
Automated hermes-sweeper review.
| work_dir=work_dir, | ||
| ) | ||
| assert output is not None | ||
| if output is None: |
Collaborator
There was a problem hiding this comment.
Please add a regression test that invokes this path under python -O with output_path=None and asserts SessionRecoverySafetyError; that directly protects the optimization-sensitive behavior this guard replaces.
2 tasks
13 tasks
This branch has not been deployed
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
assert output is not Noneatsession_recovery.py:1241is stripped bypython -O, silently removing the invariant check beforeoutput.parentis accessed on the next line.Replace with an explicit
if output is None: raise SessionRecoverySafetyError(...)using the same error class that other validation checks in this function already use.Changes
hermes_cli/session_recovery.py:1241:assert output is not None→if output is None: raise SessionRecoverySafetyError(...)Test Plan
SessionRecoverySafetyErroris already imported in the file