fix: add missing default case in resolve_client and guard kwargs.pop in token client#1330
Conversation
…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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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)) |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit 0493b0b. Configure here.


Problem
Two bugs in the client resolution layer:
1.
resolve_client()silently returnsNonefor unrecognizedclient_typeIn
verifiers/clients/__init__.py, thematchstatement has nocase _:default. Ifclient_typeis an unrecognized string, execution falls through the match and theelifblock, and the function implicitly returnsNonedespite the-> Clientreturn type annotation. Any caller will get aNonedereference (likelyAttributeErrororTypeError) when trying to use the client.2.
kwargs.pop("state")without default in token clientIn
verifiers/clients/openai_chat_completions_token_client.py:102,kwargs.pop("state")has no default value. Every other client useskwargs.pop("state", None). Without the default, calling this method without"state"in kwargs raises an unhelpfulKeyErrorinstead of a clear error message.Fix
case _:with a clearValueErrorto the match statement inresolve_client()Nonedefault tokwargs.pop("state", None)in the token client, consistent with all other clientsTests
ast.parse()syntax checkresolve_client()now raisesValueError("Unsupported client_type: 'unknown'")instead of returningNoneAttributeErroronNone.stateaccess (clear traceback) instead ofKeyErroron popNote
Low Risk
Low risk: small error-handling tweaks that mainly change failure mode from silent
None/KeyErrorto explicitValueError/Nonedefaulting.Overview
Prevents
resolve_client()from silently returningNoneby adding a defaultcase _that raises a clearValueErrorfor unsupportedclient_typevalues.Makes
OpenAIChatCompletionsTokenClient.get_native_response()tolerant of missingstateinkwargsby switchingkwargs.pop("state")tokwargs.pop("state", None), aligning behavior with other clients and avoidingKeyError.Reviewed by Cursor Bugbot for commit 0493b0b. Bugbot is set up for automated code reviews on this repo. Configure here.