Skip to content

fix: replace assert with runtime guards in tools/ and plugins/ (6 sites) - #81471

Open
JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/assert-runtime-guards-tools-plugins
Open

JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/assert-runtime-guards-tools-plugins

Conversation

@JonthanaHanh

Copy link
Copy Markdown
Contributor

Summary

Replace assert statements with explicit runtime guards in 5 files (6 sites) across tools/ and plugins/. Assert statements are stripped by python -O, silently removing invariant checks in production.

Changes

File Line Old New
tools/tts_tool.py 3597 assert streamer is not None if streamer is None: return
tools/tts_tool.py 3704 assert streamer is not None if streamer is None: return
tools/computer_use/doctor.py 226 assert proc.stdin is not None and proc.stdout is not None if ... raise RuntimeError(...)
tools/computer_use/browser_route.py 481 assert selected_tab is not None and self.state.target_id is not None if ... return _refusal(...)
hermes_cli/session_recovery.py 1281 assert output is not None if ... raise SessionRecoverySourceError(...)
plugins/platforms/buzz/adapter.py 131 assert spec is not None and spec.loader is not None if ... raise ImportError(...)

Guard Selection Rationale

  • tts_tool.py: _playback_worker and _enqueue_audio are closures where streamer is captured from the enclosing scope. Early return is the safest guard — if streamer is somehow None, the function has nothing to do.
  • doctor.py: _mcp_rpc needs both stdin and stdout pipes to communicate with the MCP subprocess. RuntimeError is appropriate since this is a precondition for the function.
  • browser_route.py: Returns a _refusal response matching the existing error pattern in this file — keeps the browser action pipeline consistent.
  • session_recovery.py: Raises SessionRecoverySourceError which is the existing exception type for this module's error paths.
  • buzz/adapter.py: Raises ImportError since the assert guards an importlib loading operation.

Test Plan

  • python3 -c "import ast; ast.parse(open(f).read())" passes for all 5 files
  • Existing tests pass (no behavioral change — guards only activate under python -O or edge-case None values)

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
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change comp/cli CLI entry point, hermes_cli/, setup wizard comp/plugins Plugin system and bundled plugins comp/tools Tool registry, model_tools, toolsets tool/browser Browser automation (CDP, Playwright) tool/tts Text-to-speech and transcription sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P3 Low — cosmetic, nice to have labels Aug 8, 2026
@spfcraze

spfcraze commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Summary:
All six assert sites converted in this PR already carry open conversions in sibling PRs — #76617, #77778, #80861, and #80910 together cover every one — so this PR re-files conversions the series already carries.

Problems:

Solution:
The six conversions already exist across the open series; carrying them in the siblings (#76617, #77778, #80861, #80910) instead of a parallel PR keeps each assert site to a single open conversion.


Checked against 9f55696 — the tip of fix/assert-runtime-guards-tools-plugins when this was written.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/plugins Plugin system and bundled plugins comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/browser Browser automation (CDP, Playwright) tool/tts Text-to-speech and transcription type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants