Skip to content

fix: add missing default case in resolve_client and guard kwargs.pop in token client#1330

Open
vominh1919 wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
vominh1919:fix/client-resolve-missing-default-case
Open

fix: add missing default case in resolve_client and guard kwargs.pop in token client#1330
vominh1919 wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
vominh1919:fix/client-resolve-missing-default-case

Conversation

@vominh1919
Copy link
Copy Markdown

@vominh1919 vominh1919 commented May 10, 2026

Problem

Two bugs in the client resolution layer:

1. resolve_client() silently returns None for unrecognized client_type

In verifiers/clients/__init__.py, the match statement has no case _: default. If client_type is an unrecognized string, execution falls through the match and the elif block, and the function implicitly returns None despite the -> Client return type annotation. Any caller will get a None dereference (likely AttributeError or TypeError) when trying to use the client.

# Before: unrecognized client_type → returns None silently
match client_type:
    case "openai_completions": ...
    case "openai_chat_completions": ...
    # ... no case _:

2. kwargs.pop("state") without default in token client

In verifiers/clients/openai_chat_completions_token_client.py:102, kwargs.pop("state") has no default value. Every other client uses kwargs.pop("state", None). Without the default, calling this method without "state" in kwargs raises an unhelpful KeyError instead of a clear error message.

Fix

  1. Add case _: with a clear ValueError to the match statement in resolve_client()
  2. Add None default to kwargs.pop("state", None) in the token client, consistent with all other clients

Tests

  • Verified both files pass ast.parse() syntax check
  • resolve_client() now raises ValueError("Unsupported client_type: 'unknown'") instead of returning None
  • Token client now raises AttributeError on None.state access (clear traceback) instead of KeyError on pop

Note

Low Risk
Low risk: small error-handling tweaks that mainly change failure mode from silent None/KeyError to explicit ValueError/None defaulting.

Overview
Prevents resolve_client() from silently returning None by adding a default case _ that raises a clear ValueError for unsupported client_type values.

Makes OpenAIChatCompletionsTokenClient.get_native_response() tolerant of missing state in kwargs by switching kwargs.pop("state") to kwargs.pop("state", None), aligning behavior with other clients and avoiding KeyError.

Reviewed by Cursor Bugbot for commit 0493b0b. Bugbot is set up for automated code reviews on this repo. Configure here.

…in token client

Two bugs in the client resolution layer:

1. resolve_client() in clients/__init__.py: The match statement has no
   `case _:` default. If client_type is an unrecognized string, the
   function implicitly returns None despite the -> Client return type
   annotation. Any caller will get a None dereference downstream.

2. OpenAIChatCompletionsTokenClient.get_native_response() uses
   kwargs.pop("state") without a default value. Every other client
   uses kwargs.pop("state", None). Without the default, calling this
   method without 'state' in kwargs raises an unhelpful KeyError.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0493b0b. Configure here.


sampling_args = normalize_sampling_args(sampling_args)
state = cast(State, kwargs.pop("state"))
state = cast(State, kwargs.pop("state", None))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently accepting None state causes deferred confusing error

Medium Severity

Unlike the other clients (anthropic_messages_client, openai_responses_client) that pop state only to discard it from kwargs, this client actually uses state — accessing state["trajectory"] on lines 112, 114, and 204. Adding a None default means if state is ever missing, cast(State, None) yields None, and None["trajectory"] raises a confusing TypeError instead of the old clear KeyError: 'state'. The "consistency with other clients" rationale doesn't apply here since those clients don't use the value.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0493b0b. Configure here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant