Skip to content

fix: exclude grammar-only requests from loop detection (#977) - #982

Merged
inureyes merged 1 commit into
mainfrom
fix/issue-977-schema-loop-detection
Jul 30, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/issue-977-schema-loop-detection

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Prevent Gemma 4 grammar-constrained structured output from being silently truncated when a schema-valid value repeats beyond the token-loop threshold. Automatic detection remains active for tool-shaped prompts, while explicit request and global overrides keep their existing precedence.

What changed

  • Remove grammar constraints from the family-default loop-detection amplifier signal across chat, Responses, and completion routes.
  • Preserve automatic detection for rendered tool declarations and replayed tool_calls / tool_call_id message content.
  • Add a regression fixture for the 30-identical-values json_schema case and retain route-level tool-protection coverage.
  • Update supported-model and environment-variable documentation to describe the resulting policy and tradeoff.

Test plan

  • cargo test --lib server::request_options::tests
  • cargo check --lib --tests
  • cargo clippy --lib --tests -- -D warnings
  • cargo fmt --all
  • git diff --check

Closes #977

Schema-valid structured output can legitimately repeat the same value beyond any fixed token-loop threshold, causing valid JSON to be truncated with an ordinary stop reason.

Remove grammar constraints from the Gemma 4 automatic activation signal while retaining tool declarations and replayed tool content. Explicit request and global overrides keep their existing precedence, and route-level regression coverage pins both the structured-output fix and tool-call protection.

Validation: cargo test --lib server::request_options::tests; cargo check --lib --tests; cargo clippy --lib --tests -- -D warnings.

Refs #977
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority area:inference Generation, sampling, decoding (incl. speculative, DRY) status:review Under review status:done Completed and removed status:review Under review labels Jul 30, 2026
@inureyes
inureyes merged commit 9102cb9 into main Jul 30, 2026
5 checks passed
@inureyes
inureyes deleted the fix/issue-977-schema-loop-detection branch August 4, 2026 12:08
@inureyes inureyes self-assigned this Aug 31, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…ablup#982)

## Summary

Prevent Gemma 4 grammar-constrained structured output from being silently truncated when a schema-valid value repeats beyond the token-loop threshold. Automatic detection remains active for tool-shaped prompts, while explicit request and global overrides keep their existing precedence.

## What changed

- Remove grammar constraints from the family-default loop-detection amplifier signal across chat, Responses, and completion routes.
- Preserve automatic detection for rendered tool declarations and replayed `tool_calls` / `tool_call_id` message content.
- Add a regression fixture for the 30-identical-values `json_schema` case and retain route-level tool-protection coverage.
- Update supported-model and environment-variable documentation to describe the resulting policy and tradeoff.

## Test plan

- [x] `cargo test --lib server::request_options::tests`
- [x] `cargo check --lib --tests`
- [x] `cargo clippy --lib --tests -- -D warnings`
- [x] `cargo fmt --all`
- [x] `git diff --check`

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

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Loop detection truncates schema-valid output when a json_schema array holds 12 or more identical values

1 participant