Skip to content

fix: replace assert with proper runtime validation guards (7 files) - #56866

Open
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/assert-runtime-validation
Open

AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/assert-runtime-validation

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Summary

Replace assert statements with explicit if/raise guards across 7 files. Asserts are stripped in -O mode.

Files

  • agent/transports/codex_app_server_session.py
  • gateway/platforms/api_server.py
  • gateway/platforms/bluebubbles.py
  • gateway/platforms/weixin.py
  • gateway/relay/ws_transport.py
  • hermes_cli/main.py
  • hermes_cli/mcp_picker.py

Assert statements are stripped when Python runs with -O flag,
leaving None checks silently skipped and causing AttributeError
or TypeError at runtime. Replace with explicit if/raise patterns
that work in all Python optimization levels.

Files fixed:
- agent/transports/codex_app_server_session.py: client/thread_id guard
- gateway/platforms/api_server.py: remove redundant assert after assignment
- gateway/platforms/bluebubbles.py: HTTP client initialization check
- gateway/platforms/weixin.py: poll/send session and token guards
- gateway/relay/ws_transport.py: WebSocket connection guard
- hermes_cli/main.py: subprocess stdout guard
- hermes_cli/mcp_picker.py: catalog entry guard
@teknium1

Copy link
Copy Markdown
Collaborator

Thanks for the focused runtime-validation cleanup. The central premise holds on current main, and the patch applies cleanly there.

Problems

  • agent/transports/codex_app_server_session.py:661 retains the same post-ensure_started() assertion pattern in compact_thread() that this PR replaces in run_turn(). compact_thread() subsequently dereferences _client at line 667 and _thread_id at line 669, so the optimization-mode gap remains on that sibling Codex path.

Suggested changes

  • Replace the assertion at agent/transports/codex_app_server_session.py:661 with the corresponding explicit runtime guard.
  • Add focused coverage for that uninitialized compaction path.

Automated hermes-sweeper review.

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/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/wecom WeCom / WeChat Work adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants