fix: replace assert with runtime guards in tools/ and plugins/ (6 sites) - #81471
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 statements are stripped by `python -O`, silently removing invariant checks in production. Replace with explicit if/raise guards that survive optimization. Files changed: - tools/tts_tool.py:3597,3704 — streamer None guard in playback/enqueue - tools/computer_use/doctor.py:226 — subprocess stdin/stdout guard - tools/computer_use/browser_route.py:481 — target tab/page guard - hermes_cli/session_recovery.py:1281 — output path guard - plugins/platforms/buzz/adapter.py:131 — importlib spec guard
Contributor
|
This was generated by AI during triage. Summary: Problems:
Solution: Checked against |
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
Replace
assertstatements with explicit runtime guards in 5 files (6 sites) acrosstools/andplugins/. Assert statements are stripped bypython -O, silently removing invariant checks in production.Changes
tools/tts_tool.pyassert streamer is not Noneif streamer is None: returntools/tts_tool.pyassert streamer is not Noneif streamer is None: returntools/computer_use/doctor.pyassert proc.stdin is not None and proc.stdout is not Noneif ... raise RuntimeError(...)tools/computer_use/browser_route.pyassert selected_tab is not None and self.state.target_id is not Noneif ... return _refusal(...)hermes_cli/session_recovery.pyassert output is not Noneif ... raise SessionRecoverySourceError(...)plugins/platforms/buzz/adapter.pyassert spec is not None and spec.loader is not Noneif ... raise ImportError(...)Guard Selection Rationale
_playback_workerand_enqueue_audioare closures wherestreameris captured from the enclosing scope. Early return is the safest guard — if streamer is somehow None, the function has nothing to do._mcp_rpcneeds both stdin and stdout pipes to communicate with the MCP subprocess. RuntimeError is appropriate since this is a precondition for the function._refusalresponse matching the existing error pattern in this file — keeps the browser action pipeline consistent.SessionRecoverySourceErrorwhich is the existing exception type for this module's error paths.ImportErrorsince the assert guards an importlib loading operation.Test Plan
python3 -c "import ast; ast.parse(open(f).read())"passes for all 5 filespython -Oor edge-case None values)