Repository navigation
perf(frontend): [P2] optimize GPT-OSS v2 continuation state - #17476
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Resolve stream prefill and pass request policy lib/llm/src/protocols/openai/chat_completions/unified_parser.rs, lib/llm/src/protocols/openai/chat_completions/aggregator.rs, lib/llm/src/preprocessor.rs |
UnifiedRequestPolicy now records multiple-choice state and resolves GPT-OSS prefill based on guidance conditions. The stream route passes the policy inputs. Tests cover prefill selection; the preprocessor tests now use a plain Hello body and remove several continuation cases. |
Cache prefix tokens and replay in chunks lib/llm/src/protocols/openai/chat_completions/unified_parser.rs |
HarmonyPrefill lazily encodes the shared prefix. Choice initialization uses cached tokens only for matching native Harmony prefixes. Replay processes tokens in bounded chunks and clears consumed events. Tests check chunk limits and compare parser output across chunk sizes and generated-text splits. |
Share the cache across choices lib/llm/src/protocols/openai/chat_completions/unified_parser.rs |
Stream setup creates an optional cache for eligible multi-choice GPT-OSS requests and passes it to each choice. Tests check cache reuse, separate parser state, and that guided and vendor initialization do not use the cache. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Merge Risk: 
Minimal · up to 1df43
-
No merge-blocking risk was identified in the checked prefill and replay behavior.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 inconclusive Passed checks: 4 passed-
Full details: Description check
-
Explanation
The PR description is detailed and follows the repository template's main sections. It has Overview, Details (Key Changes equivalent), Verification (Validation equivalent), and Review scope and follow-up plus a reviewer start point. It includes the Pull Request Checklist with the /pr-checklist box checked. It references DIS-3171 and related PRs as follow-up work. It does not include a 'Closes
#XXXX' issue link, and the template's 'Issues and Ongoing Work' heading does not appear verbatim; follow-up work is covered under 'Review scope and follow-up'. The description is mostly complete. The missing or differently named sections are non-critical, so the check passes.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files. (2 skipped: 2 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
✅ Dynamo PR CI passed — run 41151564243 (attempt 1) on
|
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
There was a problem hiding this comment.
Questions for the author:
- lib/llm/src/protocols/openai/chat_completions/unified_parser.rs: For supported multi-choice GPT-OSS streaming, the supplied n=4, 65,608-byte-prefix microprobe increases retained allocation from 1,189,808 to 1,233,552 bytes because the shared token-ID cache remains alive for the request. Please provide the expected maximum-prefix × concurrent-in-flight memory calculation, or a representative steady-state RSS measurement, to assess whether this retention regresses high-concurrency serving.
|
Replying to the memory review and the CPU question: The measurements below were collected before the rebase and have not been rerun on For
Seven rotated samples per method; 42 raw samples were retained and independently recomputed. Encoding/replay is included; destruction is excluded. Spread is substantial, and optimized-serving CPU/TTFT remain unmeasured. For four forks, the API probe retained 30,748 requested heap bytes after their first generated append at both prefix lengths, with zero net charged bytes after drop. It excludes the prebuilt seed, input/tokenizer, Dynamo stream, and allocator/RSS overhead. One consumed body remains shared per request; JSON completion still rescans it, so this does not establish production memory or concurrency limits. |
|
Replying to CodeRabbit's summary:
Deferred (P3): this is a documentation follow-up, and the report does not identify a runtime defect. The parser ownership and consumed-output comments remain; DIS-3171 tracks the continuation lifecycle and ownership documentation.
Clarified: DIS-3171 is an umbrella with remaining work, so the PR keeps a non-closing tracker link. The The full |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain
I cannot resolve the requested conversation through GitHub’s review-thread API. The linked CodeRabbit summary is a top-level PR comment, which has no review-thread resolve operation. The separate inline thread belongs to No conversation state or PR approval state changed. You are interacting with an AI system. |
There was a problem hiding this comment.
Questions for the author:
- lib/llm/src/protocols/openai/chat_completions/unified_parser.rs:
replay_consumed_harmonychanges every built-in native GPT-OSS continuation, including the commonn=1path that does not use the new shared token cache, from oneparse_token_ids_intocall to one call per 256 consumed tokens. The PR supplies allocation measurements but explicitly no TTFT measurement. Please provide before/after parser-initialization CPU time or request TTFT for supported single-choice streaming with a representative long consumed prefix (ideally including the 131,072-token case) so the cost of hundreds of extra parser calls can be weighed against the reduced temporary allocation.
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
d81169d to
f5f5406
Compare
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
b420df6 to
3e8dbbb
Compare
luckyq
left a comment
There was a problem hiding this comment.
Summary: re-review after the 2026-10-30 20:03 force-push (my earlier approval at ba878df was dismissed). The continuation logic in unified_parser.rs / preprocessor.rs / aggregator.rs is byte-identical to the approved version; the only substantive deltas are the MiniMax M3 Auto-route exclusion and the dynamo-parsers-v2 pin moving to a git revision. Requesting changes for the pin only: it breaks Dynamo's crate release staging, and a published equivalent now exists.
Blocking
Cargo.toml:89—dynamo-parsers-v2is pinned togit = frontend-crates @ bc5386b→.github/scripts/stage_crates.py::strip_git_deps(run byrelease.yml) removes any git workspace dependency from publishable manifests, solib/llm/Cargo.tomllosesdynamo-parsers-v2,cargo publishofdynamo-llmfails to resolvedynamo_parsers_v2, and every dependent crate in the release train is skipped → pin the registry release instead: crates.iodynamo-parsers-v2 0.9.1(published 2026-10-30 06:21, release commit 4f240edb) has aparsers/v2/srctree identical to bc5386b and containsUnifiedParserContinuation/continuation()/harmony/reader.rs. Details inline.
Non-blocking
Cargo.toml:87-88— both comments are stale: 0.9.1 is published, anddynamo-parsers-v2has nodefaultfeature (onlyarbitrary-precision,test-utils), sodefault-features = falseis a no-op and does not control JSON number handling.lib/llm/src/protocols/openai/chat_completions/unified_parser.rs:167— the MiniMax M3 Auto exclusion is safe (main is on 0.8.9 which has no M3 unified family, so behaviour is unchanged), but the stated reason ("unified route puts guided output inreasoning_content") has no linked issue or frontend-crates reference; please link one so the gate can be lifted when it is fixed upstream.- PR body says the API was "merged at bc5386b"; bc5386b is the #506 head, the squash merge is 7aad6ff8 and the release is 4f240edb. Harmless, worth correcting.
Checked: PR diff at ba878df vs 3e8dbbb (each against its merge base) hunk by hunk; diff -rq of frontend-crates bc5386b parsers/v2/src vs the crates.io 0.9.1 tarball (zero differences); crates.io 0.8.9 / 0.9.0 / 0.9.1 contents for the continuation API; stage_crates.py, release.yml, release-artifacts.mdx; the other five frontend-crates deps in Cargo.toml (all registry exact pins); CI green at 3e8dbbb; no open review threads. Not run locally.
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
|
Replying to LuckyQ's review:
P1 fixed in
Fixed in
Tracked in DIS-3171: remove the gate when explicit guided output reaches
Corrected: the description now identifies The focused routing regression passed on |
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
luckyq
left a comment
There was a problem hiding this comment.
Summary: the pin issue is resolved at 12888d6: dynamo-parsers-v2 now comes from crates.io (= "=0.9.1", the release built from frontend-crates #506), all three lockfiles resolve it to the registry with no git+ source left, the stale comments and the no-op default-features = false are gone, and the MiniMax M3 Auto exclusion now points at DIS-3171 as its removal condition. The continuation logic is unchanged from the version I approved at ba878df. Approving.
Checked: Cargo.toml and Cargo.lock / lib/bindings/python/Cargo.lock / lib/bindings/kvbm/Cargo.lock at 12888d6 (registry source, checksum 54e64018…); unified_parser.rs:164-180; diff 3e8dbbb..12888d6 limited to those files; CI green on the head; no conflicts. Not run locally.
Signed-off-by: Keiven Chang <keivenchang@users.noreply.github.com>
Overview
This fixes a P2 performance issue in GPT-OSS streamed tool-call continuations: Dynamo repeats the same parser initialization for each requested completion and retains a separate copy of the consumed tool-call body. Long prefixes therefore cost more CPU and memory as the number of completions increases.
For example,
n=4asks for four independent completions of the same unfinished tool call. Previously, Dynamo encoded and replayed the common prefix four times and kept four consumed-body copies. This PR processes that prefix once, shares its consumed body, and gives each completion its own generated continuation.This continues Ryan's #17146 and #17342.
Details
The change applies to built-in native GPT-OSS streaming (approximately +190/-42 core-code lines). It replays the consumed prefix once, shares that body, gives each choice a private generated tail, discards replay output in batches, and centralizes guidance/prefill selection. Auto keeps MiniMax M3 on the legacy route because its unified route currently sends explicit guided output to
reasoning_content; explicit V2 remains available. DIS-3171 tracks removing this exclusion after guided output is emitted throughcontent, with a response-field regression.The continuation API is from frontend-crates #506, squash-merged as
7aad6ff8and first published indynamo-parsers-v2 0.9.1. This PR now pins the newer crates.io release0.9.6and synchronizes the root, Python-binding and KVBM-binding lockfiles. Itsarbitrary-precisionfeature remains disabled. The release also includes fixes outside GPT-OSS: batch JSON projection preserves sibling arguments when a number is out of range, representing that number as a string; raw streamed arguments remain unchanged.Verification
At
98f07d27263b30811c15c85aa164c004f93ac3ef,cargo test --locked -p dynamo-llm --libpassed (4,011 passed, 15 ignored), andcargo test --locked -p dynamo-llm --test postprocessor_parsing_streampassed (115 passed). Locked metadata resolution passed for the root, Python-binding and KVBM-binding workspaces. Formatting, Clippy for the dynamo-llm library, and changed-file pre-commit hooks passed. GitHub CI is pending for this upgraded head. An independent audit of the 0.9.1-to-0.9.6 dependency changes found no API or continuation compatibility blocker. Full parser-gate requalification was not performed for 0.9.6; production CPU, TTFT and RSS remain unmeasured for this version.CPU and allocation measurements
These historical measurements compare 0.7.35 with parser commit
3b1eba21and Harmony commit32530bcc. They are not a current-main A/B benchmark or a measurement of the rebased candidate.Single-choice initialization thread CPU, warmed debug build, median of seven rotated samples:
All 42 raw samples were retained and the medians independently recomputed. Encoding/replay is timed; parser destruction is excluded. Spread is substantial. Optimized-serving CPU, TTFT and production RSS remain unmeasured.
CPU probe inputs and raw samples
Native GPT-OSS with an open lookup(q) string, repeated
hello worldtext and no tool schema. Parent feeds the prefix in one call; both batched paths use 256 tokens per call. Each method is warmed once, then execution order rotates across seven rounds. Token IDs are asserted equal across versions.The API fork probe retained 30,748 requested heap bytes for four forks after their first generated append at both prefix lengths. The prebuilt seed, input/tokenizer, Dynamo stream and allocator/RSS overhead are excluded; this probe does not measure total single-choice initialization memory. A shared consumed body remains per request and JSON completion still rescans it.
Review scope and follow-up
I'll address P0/P1 findings in this PR. Let's handle P2/P3 in follow-up PRs, tracked in DIS-3171. For AI reviewers, report reproducible P0/P1 findings here; record P2/P3 as follow-up work without requesting changes for them on this PR.
Remaining follow-ups are incremental argument validation, header/generated-state growth, production memory/latency measurements, and removing the MiniMax M3 Auto-route exclusion after guided output is emitted in content. The current probes do not establish production RSS, TTFT or concurrency limits.
Where should the reviewer start?
lib/llm/src/protocols/openai/chat_completions/unified_parser.rs, thenlib/llm/src/protocols/common/preprocessor.rs.Pull Request Checklist
/pr-checklistskill.Summary by CodeRabbit