fix: replace bare asserts with explicit exceptions (P0 — python -O survival) - #58837
Open
AlexFucuson9 wants to merge 1 commit into
Open
AlexFucuson9 wants to merge 1 commit into
AlexFucuson9 wants to merge 1 commit into
Conversation
…ival Bare assert statements are stripped when Python runs with -O flag (optimized mode), causing silent failures in production. Replace with explicit exceptions that survive optimization. Files fixed: - tools/browser_supervisor.py: WebSocket guard in _read_loop - plugins/google_meet/realtime/openai_client.py: WebSocket guards - gateway/relay/ws_transport.py: WebSocket guard in _read_loop - tools/environments/docker.py: container guard in exec_bash - gateway/platforms/weixin.py: session guards in poll/send methods - tools/skill_manager_tool.py: target guards in file operations
tonydwb
reviewed
Jul 5, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (LGTM)
P0 critical fix: replaces bare assert statements with explicit RuntimeError exceptions. This ensures assertions are not stripped by python -O (optimization flag). The changes span 6 files covering critical initialization and state checks in async/web code paths (WeChat, WebSocket, Google Meet, browser supervisor, Docker).
What looks good:
- Properly converts validation assertions to actual runtime checks
- Each replacement includes a descriptive error message
- Covers critical initialization guards that would cause cryptic failures if stripped
Collaborator
|
Thanks for addressing a real runtime-safety issue. Current GitHub main still contains the exact bare assertions this PR targets, including Problems
Suggested changes
Automated hermes-sweeper review. |
This was referenced Jul 29, 2026
Closed
19 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 bare
assertstatements with explicit exceptions that survivepython -O(optimized mode).Problem
Bare
assertstatements are stripped silently when Python runs with-Oflag. This means critical runtime guards (WebSocket connections, session initialization, container state) simply disappear in production, leading to confusingAttributeErrororNoneTypecrashes with no useful error message.Changes
tools/browser_supervisor.pyassert self._ws is not Nonein_read_loopif ... raise RuntimeErrorplugins/google_meet/realtime/openai_client.pyassert self._wsin_send_jsonand_recvif ... raise RuntimeErrorgateway/relay/ws_transport.pyassert self._wsin_read_loopif ... raise RuntimeErrortools/environments/docker.pyassert self._container_idinexec_bashif not ... raise RuntimeErrorgateway/platforms/weixin.pyif ... raise RuntimeErrortools/skill_manager_tool.pyif ... return error dictImpact
-O, creating false confidenceTesting
All 6 files pass
python3 -m py_compileverification.