Skip to content

fix(chat): treat null or blank temperature as unset instead of 0 - #250

Merged
mangeshraut712 merged 1 commit into
mainfrom
fix/temperature-null-fallback
Nov 25, 2026
Merged

mangeshraut712 merged 1 commit into
mainfrom
fix/temperature-null-fallback

Conversation

@mangeshraut712

@mangeshraut712 mangeshraut712 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

resolveChatTemperature ran every non-number through Number(), and Number(null), Number(''), Number(' ') and Number(false) are all 0. So a request with "temperature": null, which is how many clients say "unset", went to the provider as temperature 0 (deterministic sampling) instead of the 0.7 default. resolveChatMaxTokens doesn't have this problem because its < 1 guard rejects the coerced 0.

Now only numbers and non-blank strings count as an explicit temperature. An explicit 0 / '0' is still kept, and the existing test for that still passes.

Tests: a new case in api/__tests__/chat-temperature.test.mjs fails on main and passes with the fix. vitest run: 84 pass.


Devin Review


Note

Low Risk
Narrow parsing change in chat request config with tests; no auth or data-handling impact.

Overview
Fixes resolveChatTemperature so clients sending "temperature": null, empty strings, or other non-numeric values get the default (0.7) instead of 0 (which used to happen because Number(null) and similar coerce to 0).

Only numbers and non-blank strings are parsed; explicit 0 / '0' and clamping in 0–2 are unchanged. Trimmed numeric strings (e.g. ' 1.5 ') still work. Coverage added in chat-temperature.test.mjs for null, blanks, false, arrays, and custom fallbacks.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T12:33:50.386341Z bff96ba PR opened
🔒 Security Review ✅ Completed 2026-11-25T12:34:57.253058Z bff96ba PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@mangeshraut712
mangeshraut712 merged commit 9752367 into main Nov 25, 2026
12 checks passed
@mangeshraut712
mangeshraut712 deleted the fix/temperature-null-fallback branch November 25, 2026 12:36
@kilo-code-bot

kilo-code-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Code Review Roast 🔥

Verdict: No Issues Found | Recommendation: Merge

Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything.

📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are. The fix correctly handles the Number() coercion footgun where null, '', ' ', and false all become 0, and the tests actually cover the edge cases instead of just the happy path.

Files Reviewed (2 files)
  • api/chat.js - Fixed resolveChatTemperature to only accept numbers and non-blank strings as explicit values
  • api/__tests__/chat-temperature.test.mjs - Added comprehensive test coverage for null, blanks, booleans, arrays, custom fallbacks, and trimmed strings

Reviewed by free · Input: 76K · Output: 4.3K · Cached: 219.2K

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