[PR #5318] [CLOSED] [Engine] Preserve external cache and sum prefill work across BYIELD #5384

Closed
opened 2026-11-07 16:34:48 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5318
Author: @YusenZhang0601
Created: 11/5/2026
Status: ❌ Closed

Base: main ← Head: codex/fix-prefill-yield-accounting


📝 Commits (1)

  • 82ffb65 Fix external cache and prefill accounting across prompt yields

📊 Changes

2 files changed (+149 additions, -0 deletions)

View changed files

📝 serve/server.py (+17 -0)
➕ serve/test_yield_accounting.py (+132 -0)

📄 Description

Problem and result

A prompt read can yield through BYIELD and resume more than once within one API request. The later DONE then reports a larger reused prefix because it includes work performed earlier in that same request. The server publishes that internal prefix as external cached input and loses earlier prompt time.

I reproduced this on base 9f7d977d220e9fdf2ec53cf2620cdadac1cfb24e with the real Service and StrataEngine over a subprocess fake native engine. Three of four new regressions fail on the base. For example, the solo-yield request reports 384 cached tokens although only 3 preceded the request. Cancellation after two yields records (128, 64, 64) for input/cache/read instead of (128, 3, 125).

The fix retains DONE records from yielded reads, preserves the original external cache boundary, sums their work and excludes the final DONE from the earlier list when cancellation ends on that exact record.

I checked the existing discussions, including #1603, #2275 and #5307. This addresses prompt-read/cache accounting across BYIELD. #5307 addresses admission/slot decode accounting. Both touch the request finalizer, so the textual hunk there needs reapplication when combining them. I also reapplied this fix on #5307 commit 08519d46405ec720cda411f08af556bee54c9df0 and ran the combined regressions successfully.

The existing two-yield budget is preserved. This PR adds 17 lines to the Python server and a focused regression module.

Validation

On macOS arm64, Python 3.14.6, in a project-local virtual environment using the repository-pinned regex and Jinja2 packages.

Passed

  • python -B -m unittest serve.test_yield_accounting serve.test_request_accounting -v — 14 tests, 10.783 s.
  • python -B -m unittest serve.test_parallel serve.test_yield_accounting serve.test_request_accounting -v — 62 tests, 59.380 s.
  • The same three modules on top of #5307 with this fix reapplied — 72 tests, 65.026 s.
  • git diff --check.

Failed controls and setup attempts

  • Unmodified base plus the new module — 4 tests, 3 assertion failures, 1 pass.
  • Initial setup attempts stopped on missing regex/Jinja2 before the local environment was prepared.
  • The first #5307 compatibility attempt stopped at a textual patch conflict and then lacked the new test module. After reapplying the fix, the complete 72-test run passed.

Remaining validation

GPU/model execution and Windows runtime testing remain unperformed for this upstream port. The reproduction uses synthetic local input and a Python fake producer. The native engine sources and wire format are outside this patch.

I developed the original fix during local deployment research and used AI assistance to prepare this focused port and its validation. Thank you for reviewing it.


🔄 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/5318 **Author:** [@YusenZhang0601](https://github.com/YusenZhang0601) **Created:** 11/5/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `codex/fix-prefill-yield-accounting` --- ### 📝 Commits (1) - [`82ffb65`](https://github.com/Niko1221/Strata/commit/82ffb65680baae7b13ab15ccb431d77834fb0eea) Fix external cache and prefill accounting across prompt yields ### 📊 Changes **2 files changed** (+149 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+17 -0) ➕ `serve/test_yield_accounting.py` (+132 -0) </details> ### 📄 Description ## Problem and result A prompt read can yield through BYIELD and resume more than once within one API request. The later DONE then reports a larger reused prefix because it includes work performed earlier in that same request. The server publishes that internal prefix as external cached input and loses earlier prompt time. I reproduced this on base `9f7d977d220e9fdf2ec53cf2620cdadac1cfb24e` with the real Service and StrataEngine over a subprocess fake native engine. Three of four new regressions fail on the base. For example, the solo-yield request reports 384 cached tokens although only 3 preceded the request. Cancellation after two yields records `(128, 64, 64)` for input/cache/read instead of `(128, 3, 125)`. The fix retains DONE records from yielded reads, preserves the original external cache boundary, sums their work and excludes the final DONE from the earlier list when cancellation ends on that exact record. ## Related work and scope I checked the existing discussions, including #1603, #2275 and #5307. This addresses prompt-read/cache accounting across BYIELD. #5307 addresses admission/slot decode accounting. Both touch the request finalizer, so the textual hunk there needs reapplication when combining them. I also reapplied this fix on #5307 commit `08519d46405ec720cda411f08af556bee54c9df0` and ran the combined regressions successfully. The existing two-yield budget is preserved. This PR adds 17 lines to the Python server and a focused regression module. ## Validation On macOS arm64, Python 3.14.6, in a project-local virtual environment using the repository-pinned regex and Jinja2 packages. ### Passed - `python -B -m unittest serve.test_yield_accounting serve.test_request_accounting -v` — 14 tests, 10.783 s. - `python -B -m unittest serve.test_parallel serve.test_yield_accounting serve.test_request_accounting -v` — 62 tests, 59.380 s. - The same three modules on top of #5307 with this fix reapplied — 72 tests, 65.026 s. - `git diff --check`. ### Failed controls and setup attempts - Unmodified base plus the new module — 4 tests, 3 assertion failures, 1 pass. - Initial setup attempts stopped on missing regex/Jinja2 before the local environment was prepared. - The first #5307 compatibility attempt stopped at a textual patch conflict and then lacked the new test module. After reapplying the fix, the complete 72-test run passed. ### Remaining validation GPU/model execution and Windows runtime testing remain unperformed for this upstream port. The reproduction uses synthetic local input and a Python fake producer. The native engine sources and wire format are outside this patch. I developed the original fix during local deployment research and used AI assistance to prepare this focused port and its validation. Thank you for reviewing it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:34:48 +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#5384
No description provided.