Skip to content

fix: replace assert with explicit check in codex app-server session#56736

Open
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/assert-in-production-codex-session
Open

fix: replace assert with explicit check in codex app-server session#56736
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/assert-in-production-codex-session

Conversation

@AlexFucuson9

Copy link
Copy Markdown

Summary

agent/transports/codex_app_server_session.py:399 uses assert to check that _client and _thread_id are not None after ensure_started(). In production, assert statements are stripped when Python runs with -O flag, silently removing the invariant check.

If _client or _thread_id is None after startup, the code would continue and crash later with an unhelpful AttributeError or NoneType error.

Fix

Replace the bare assert with an explicit if/return that sets result.error and result.should_retire = True, matching the pattern already used for startup failures in the same function (lines 391-398).

Changes

  • agent/transports/codex_app_server_session.py: assert self._client is not None and self._thread_id is not None → explicit if/return with error message

Test Plan

  • Lint passes
  • Verify codex session startup still works

Production code should not use assert statements — they are
stripped when Python runs with -O flag, silently removing the
invariant check. If _client or _thread_id is None after
ensure_started(), the code would continue and crash later with
an unhelpful AttributeError.

Replace with explicit if/return that sets result.error and
result.should_retire, matching the pattern used for startup
failures just above.
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have labels Jul 2, 2026
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 P3 Low — cosmetic, nice to have type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants