Skip to content

SWF(bug): reject malformed logit_bias token keys - #53

Merged
maplepaladin73 merged 1 commit into
mainfrom
devin/1795371417-reject-malformed-logit-bias
Nov 22, 2026
Merged

maplepaladin73 merged 1 commit into
mainfrom
devin/1795371417-reject-malformed-logit-bias

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

/v1/completions and /v1/chat/completions now return a 400 invalid_request_error (param: logit_bias) for a logit_bias key that is not a u32 token id (e.g. "abc"). Before, the key was dropped and the request ran without that bias.

Failing run (regression test on unfixed code):

test api::completions_exec::logit_bias_tests::logit_bias_rejects_malformed_keys_before_dispatch ... FAILED
assertion `left == right` failed: chat=false, stream=false, key="abc"
  left: 200
 right: 400
test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 3211 filtered out

Passing run (with fix):

test api::completions_exec::logit_bias_tests::logit_bias_preserves_valid_empty_and_absent_maps ... ok
test api::completions_exec::logit_bias_tests::logit_bias_rejects_malformed_keys_before_dispatch ... ok
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 3211 filtered out

Full spark test binary (rebased on main after #51): 3201 passed; 0 failed; 14 ignored.

The tests call both handlers, blocking and streaming. They check that a malformed key returns 400 and never reaches the scheduler, and that valid, empty and absent maps still reach the scheduler unchanged.

Root cause: both lowering paths (completions.rs and chat's openai/to_ir.rs) turn the wire map into (u32, f32) pairs with filter_map(|(k, v)| k.parse::<u32>().ok() ...). A failed parse becomes None and is silently discarded, and nothing earlier checks the keys. The new validate_logit_bias runs in both handlers before dispatch, next to the other request validations, and uses the existing openai_error_response_with_param helper. Valid requests take the same path as before.

Try it:

ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark logit_bias

(needs bash scripts/ci_gpu_stubs.sh on a GPU-less box)

Test plan

  • Blueprint lint: cargo fmt --all -- --check && ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --workspace --tests && bash scripts/check-license-headers.sh && typos: exit 0
  • Added regression tests (api/logit_bias_tests.rs)
  • Not tested against a real model or GPU. The change is request validation that runs before dispatch.

Notes for reviewers

CLA


Software Factory opened this PR for Robert
Implemented in session Reject malformed logit_bias token keys
Review with Devin · Open in Devin Desktop


@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@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

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1795371417-reject-malformed-logit-bias branch from e207e72 to 79e63c1 Compare November 22, 2026 18:30
@maplepaladin73
maplepaladin73 merged commit cd10f8e into main Nov 22, 2026
1 check passed
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