Skip to content

Conversation

@qandrew
Copy link
Contributor

@qandrew qandrew commented Jan 6, 2026

Purpose

Test Plan

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the capability to compute reasoning token metrics within SimpleContext. The implementation involves a new _compute_reasoning_tokens method that gets triggered when the final output is accessed. The changes are accompanied by a good set of tests covering various scenarios. My review focuses on enhancing the robustness of the new logic, specifically around exception handling and ensuring the correctness of the calculated metrics.

Comment on lines +267 to +269
self.num_reasoning_tokens = len(self._accumulated_token_ids) - len(
content_token_ids
)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The calculation for num_reasoning_tokens could result in a negative value if len(content_token_ids) is greater than len(self._accumulated_token_ids). While extract_content_ids should ideally return a subset of the input tokens, a bug in a parser implementation could violate this. To make this more robust, I suggest adding a check to ensure num_reasoning_tokens is not negative, which would also improve debugging by logging the unexpected behavior.

Suggested change
self.num_reasoning_tokens = len(self._accumulated_token_ids) - len(
content_token_ids
)
num_reasoning_tokens = len(self._accumulated_token_ids) - len(content_token_ids)
if num_reasoning_tokens < 0:
logger.warning("Calculated negative reasoning tokens (%d). Clamping to 0.", num_reasoning_tokens)
num_reasoning_tokens = 0
self.num_reasoning_tokens = num_reasoning_tokens

)

self._reasoning_tokens_computed = True
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using a broad except Exception: can mask underlying issues like TypeError or AttributeError, which might indicate programming errors rather than parsing failures. This makes debugging more difficult. It is recommended to catch more specific exceptions that are expected during parsing. If the parser can raise various exceptions, consider defining a custom ReasoningParsingError and wrapping the original exceptions to make the intent clear and avoid catching unrelated errors.

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

Labels

frontend gpt-oss Related to GPT-OSS models

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

1 participant