[PR #18] [MERGED] serve: treat unset/-1 max_tokens as remaining context, not 1024 #2418

Closed
opened 2026-11-04 01:59:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/18
Author: @coolio986
Created: 9/27/2026
Status: ✅ Merged
Merged: 9/27/2026
Merged by: @Niko1221

Base: main ← Head: fix/unlimited-max-tokens


📝 Commits (1)

  • a40fe52 serve: treat unset/-1 max_tokens as remaining context, not 1024

📊 Changes

2 files changed (+147 additions, -11 deletions)

View changed files

📝 serve/server.py (+17 -11)
➕ serve/test_server.py (+130 -0)

📄 Description

Clients that send max_tokens: -1 (unlimited), 0, null, or omit it were capped at 1024 tokens — the old or 1024 fallback, plus the <= 0 -> 1024 clamp added in #7. Replies stopped at 1024.

Changes

  • Service.prepare(..., max_new=None) resolves the budget after tokenizing and returns (ids, thinking, max_new). Unset/non-positive budget = remaining context.
  • CTX_SLACK = 8: strata --serve rejects prompt + max_new + 8 > context (src/program/generate.cpp), so Python now uses the same margin. Unlimited = max_context - 8 - len(ids); explicit budgets are checked against the same room (400 up front instead of an engine ERR mid-stream).
  • Prompt that already fills the context with an unlimited budget -> 400 "leaves no room to answer".
  • Explicit positive max_tokens / max_completion_tokens still honored exactly; _debug_req logs the resolved budget.

Tests

New serve/test_server.py (unittest, MockEngine behind a real HTTP server): -1/0/missing/null on both APIs, explicit budgets, max_completion_tokens precedence, explicit overflow -> 400, near-full prompt.

python -m unittest serve.test_server -> 5 tests OK. Reverting to the 1024 fallback fails 14–16 checks.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/18 **Author:** [@coolio986](https://github.com/coolio986) **Created:** 9/27/2026 **Status:** ✅ Merged **Merged:** 9/27/2026 **Merged by:** [@Niko1221](https://github.com/Niko1221) **Base:** `main` ← **Head:** `fix/unlimited-max-tokens` --- ### 📝 Commits (1) - [`a40fe52`](https://github.com/Niko1221/Strata/commit/a40fe520cef4fc1e910123702a22fc5235408b5c) serve: treat unset/-1 max_tokens as remaining context, not 1024 ### 📊 Changes **2 files changed** (+147 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+17 -11) ➕ `serve/test_server.py` (+130 -0) </details> ### 📄 Description Clients that send `max_tokens: -1` (unlimited), `0`, `null`, or omit it were capped at 1024 tokens — the old `or 1024` fallback, plus the `<= 0 -> 1024` clamp added in #7. Replies stopped at 1024. ## Changes - `Service.prepare(..., max_new=None)` resolves the budget after tokenizing and returns `(ids, thinking, max_new)`. Unset/non-positive budget = remaining context. - `CTX_SLACK = 8`: `strata --serve` rejects `prompt + max_new + 8 > context` (`src/program/generate.cpp`), so Python now uses the same margin. Unlimited = `max_context - 8 - len(ids)`; explicit budgets are checked against the same room (400 up front instead of an engine `ERR` mid-stream). - Prompt that already fills the context with an unlimited budget -> 400 "leaves no room to answer". - Explicit positive `max_tokens` / `max_completion_tokens` still honored exactly; `_debug_req` logs the resolved budget. ## Tests New `serve/test_server.py` (unittest, MockEngine behind a real HTTP server): -1/0/missing/null on both APIs, explicit budgets, `max_completion_tokens` precedence, explicit overflow -> 400, near-full prompt. `python -m unittest serve.test_server` -> 5 tests OK. Reverting to the 1024 fallback fails 14–16 checks. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 01:59:57 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2418
No description provided.