Skip to content

Count prepared API prompts before GGUF admission - #15294

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
Imagineer99:fix/gguf-counted-api-admission
Oct 26, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
Imagineer99:fix/gguf-counted-api-admission

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

The OpenAI passthrough, Responses, and Anthropic paths can admit local GGUF requests using character-based estimates rather than the prompt llama-server will render. Numeric text and tool schemas can therefore overcommit the shared KV pool.

Count prepared messages with their tools and rendering options before admission, and reuse the prepared OpenAI body for dispatch. Anthropic counts use resolved native thinking settings and the same normalized forced-tool/schema options as generation, including tool-loop recosting. Prepared top-level images receive one media allowance rather than two. Failed counts continue to reserve the pool conservatively.

Related: #10671. This addresses request accounting; the native speculative sub-batch failure is handled separately in llama.cpp.

Validation:

  • A new dispatch regression fails on unchanged main because no exact count occurs before upstream dispatch, and passes with this change.
  • Broader admission/OpenAI/Responses suites: 1,199 passed, six existing skips.
  • Final focused admission suites: 71 tests passed across the full run and additional dispatch regression.
  • Regressions cover prepared tool/template options, native thinking, server-tool recosting, forced tools, structured output, and a top-level vision image.
  • Repository formatting, lint, static diff checks, and pre-push checks passed.

These fresh API checks use controlled token-count/HTTP backends, not the reporter's original 27B/GPU workload.

@danielhanchen

danielhanchen commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

(Python 3.13, g-r) fails on this PR for a reason specific to it (job 121303172727):

studio/backend/tests/test_mcp_images.py:2398: in test_the_gguf_admission_estimate_parses_off_the_loop
    assert routes_src.count("await _openai_llama_admission_reserve_async(") >= 4
E   AssertionError: assert 1 >= 4

The guard counts the route call sites that reserve through the async (off the loop) form. This PR moves four of them behind the new _reserve_counted_gguf_passthrough, so only one literal call is left in the source even though every route still goes through the async form. The guard needs to follow the refactor: for example, assert that _reserve_counted_gguf_passthrough itself awaits _openai_llama_admission_reserve_async( and count its callers (plus the remaining direct call) towards the same floor of 4, so a route that goes back to the sync _openai_llama_admission_reserve( still fails it.

(Python 3.13, a-f) has the same cause (job 121303172667): tests/test_anthropic_messages.py:6184 (test_the_anthropic_paths_promote_a_replayed_mcp_envelope) looks for the literal messages_override = openai_messages in anthropic_messages. The new _admitted_anthropic still reserves against the translated list, via _anthropic_admission_body(openai_messages, ...) and messages = body["messages"], so the behaviour is kept and only the spelling moved. That assert should be updated to the new form in this PR, and the _reserve_counted_gguf_chat( count of 3 in test_mcp_images.py will need the same review now that the /messages route also calls it.

Chat UI Tests (extra) on this PR failed in playwright_multi_account.py with Page.goto: net::ERR_ABORTED at .../login, which looks unrelated to this change (it passes on the other recent runs); a re-run should clear it. The six Repo tests (CPU, studio) failures (NameError: _fused_pass_logps_re) came from main and are fixed there by #15296; a rebase or re-run picks that up.

@danielhanchen danielhanchen self-assigned this Oct 26, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-26T03:49:15.889941Z
We couldn’t complete this review. Comment @codex review to try again.
a30efed Manual request
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit b90dc40 into unslothai:main Oct 26, 2026
55 of 57 checks passed
danielhanchen added a commit that referenced this pull request Oct 26, 2026
The lifted _anthropic_recost now builds its counted body through the route's
_anthropic_admission_body (main #15294), so the test supplies that builder.
Main's frontend changes put the merged build at 2,051.7 KB transfer, 0.2 KB
over; the transfer limit is set to the measured build plus about 1.2 KB.
danielhanchen added a commit that referenced this pull request Oct 26, 2026
Main #15294 counts the prepared request body before admission, and the
passthroughs now reserve through _reserve_counted_gguf_passthrough:

- the passthrough reservation tests give their fake backend the reasoning
  kwargs the body builder reads;
- the passthrough Stop test mocks the reservation the route now enters;
- the Anthropic finalized-prompt test counts with a counter that sees the
  messages, and expects the counted prompt's margin rather than the
  estimate's.
danielhanchen added a commit that referenced this pull request Oct 26, 2026
…n logout redirect aborts it (#15398)

## Problem

`Chat UI Tests (extra)` fails intermittently in
`tests/studio/playwright_multi_account.py`, always at the same step: the
`/login` navigation right after the test logs the owner out.

```
File "tests/studio/playwright_multi_account.py", line 119, in run
    page.goto(f"{BASE_URL}/login")
playwright._impl._errors.Error: Page.goto: net::ERR_ABORTED at http://127.0.0.1:18894/login
```

Seen on #15294 (job 121303172631) and #15369 (job 121656269753). Neither
PR touches auth, and other runs of the same job pass.

## Why

`log_out()` revokes the token and clears it from `localStorage` while
the chat page is still open. The page's pending and polling requests
then get 401, and `redirectToAuth` in `features/auth/api.ts` sends the
page to `/login` itself, at the same moment the test starts its own
`/login` navigation. Whichever navigation loses is aborted, so the test
fails with `ERR_ABORTED` even though the page ends up on `/login`. A
small local reproduction with independent timings did not hit the race,
so I am not claiming the exact interleaving. The failing line and the
error match this path.

The product is right to redirect a logged-out page to `/login`. What the
test needs is to be on the login page; how it gets there doesn't matter.

## Fix

A small `open_login(page)` helper is used for the two `/login`
navigations that follow a log-out: the one at line 119 and the one
inside `login()`.

- On `ERR_ABORTED` only, it waits for the page to settle and navigates
once more.
- Any other error, or a second abort, still fails.

The assertions that follow (the username field, the setup code login and
the account isolation checks) are unchanged, so this cannot pass a page
that did not reach the login screen.

## Verification

Against a local page with Playwright's own `route.abort("aborted")`,
which produces exactly `net::ERR_ABORTED`:

| | result |
|---|---|
| plain `page.goto`, 1 abort | raises `net::ERR_ABORTED` (the CI
failure) |
| `open_login`, 1 abort | reaches `/login` |
| `open_login`, 2 aborts | raises `net::ERR_ABORTED` |
| `open_login`, no abort | reaches `/login` |

The Playwright driver guards (`test_playwright_suites_run_in_ci.py`,
`test_playwright_server_lifecycle.py`, `test_click_forced.py`,
`test_playwright_brand_labels.py`): 94 passed. ruff format and check are
clean.
danielhanchen added a commit that referenced this pull request Oct 27, 2026
…xt (#15457)

`test_anthropic_admission.py::test_fifo_fairness_across_many_waiters`
starts 8 requests against a 1-slot backend, sleeps 0.2 s and asserts all
8 are queued. Since #15294, admission first awaits prompt preparation,
so on a loaded runner not every waiter has reached the queue after 0.2
s. It failed on the `(Python 3.13, a-f)` backend job with `assert 7 ==
8` (`queued=7`). The same delay also means the arrival order no longer
has to match the task order, which the FIFO assertion relies on.

The test now starts each waiter and waits (up to 5 s) until it is queued
before starting the next. The arrival order is then the task order, and
the FIFO check is deterministic. Test-only change.

Same test, pinned to one CPU core shared with 6 busy loops:

| arm | result |
|---|---|
| main | 3 / 3 failed |
| this PR | 3 / 3 passed |

Without contention, the whole file passes 39 / 39 three times.
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.

2 participants