Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pr_agent/algo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
'gpt-5.4-mini-2026-03-17': 400000, # 400K, but may be limited by config.max_model_tokens
'gpt-5.4-nano': 400000, # 400K, but may be limited by config.max_model_tokens
'gpt-5.4-nano-2026-03-17': 400000, # 400K, but may be limited by config.max_model_tokens
'gpt-5.5': 1050000, # 1.05M, but may be limited by config.max_model_tokens
'gpt-5.5-2026-04-23': 1050000, # 1.05M, but may be limited by config.max_model_tokens
Comment on lines +52 to +53
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Action required

1. _thinking model token crash 🐞 Bug ☼ Reliability

If the configured model is set to a GPT-5.5 “_thinking” variant (e.g., "gpt-5.5_thinking"),
get_max_tokens() will raise because MAX_TOKENS only contains the base names added in this PR and
lookup is exact-match. This blocks get_pr_diff() (and thus all tools) before LiteLLMAIHandler can
strip the “_thinking” suffix.
Agent Prompt
### Issue description
`get_max_tokens(model)` performs an exact key lookup in `MAX_TOKENS`. The codebase supports GPT-5 “_thinking” model names in `LiteLLMAIHandler` (it strips `_thinking` before calling the provider), but `get_pr_diff()` calls `get_max_tokens(model)` before the AI handler runs. As a result, configuring `config.model = "gpt-5.5_thinking"` (or any `gpt-5.*_thinking`) will raise an exception and prevent PR processing.

### Issue Context
- This PR adds `gpt-5.5` entries to `MAX_TOKENS`, but does not address `_thinking` variants.
- There are existing tests asserting `_thinking` suffix handling for GPT-5 models.

### Fix Focus Areas
- pr_agent/algo/utils.py[991-1012]
- pr_agent/algo/pr_processing.py[68-80]
- pr_agent/algo/ai_handlers/litellm_ai_handler.py[296-317]
- tests/unittest/test_get_max_tokens.py[64-76]

### Implementation direction
- Normalize `model` inside `get_max_tokens()` before lookup by stripping a trailing `_thinking` suffix (and optionally any internal provider prefixes if applicable in your config patterns).
- Add a unit test ensuring `get_max_tokens("gpt-5.5_thinking")` returns the same value as `get_max_tokens("gpt-5.5")` (and similarly for the dated variant, if you want full coverage).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

'o1-mini': 128000, # 128K, but may be limited by config.max_model_tokens
'o1-mini-2024-09-12': 128000, # 128K, but may be limited by config.max_model_tokens
'o1-preview': 128000, # 128K, but may be limited by config.max_model_tokens
Expand Down
13 changes: 13 additions & 0 deletions tests/unittest/test_get_max_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ def test_gpt54_nano_model_max_tokens(self, monkeypatch, model):

assert get_max_tokens(model) == 400000

@pytest.mark.parametrize("model", ["gpt-5.5", "gpt-5.5-2026-04-23"])
def test_gpt55_model_max_tokens(self, monkeypatch, model):
fake_settings = type('', (), {
'config': type('', (), {
'custom_model_max_tokens': 0,
'max_model_tokens': 0
})()
})()

monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)

assert get_max_tokens(model) == 1050000

# Test situations where the model is not registered and exists as a custom model
def test_model_has_custom(self, monkeypatch):
fake_settings = type('', (), {
Expand Down
2 changes: 2 additions & 0 deletions tests/unittest/test_litellm_reasoning_effort.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ async def test_gpt5_model_detection_various_versions(self, monkeypatch, mock_log
"gpt-5.4-mini",
"gpt-5.4-mini-2026-03-17",
"gpt-5.4-2026-03-05",
"gpt-5.5",
"gpt-5.5-2026-04-23",
"gpt-5-turbo",
"gpt-5.1-codex",
"gpt-5.3-codex",
Expand Down
Loading