STRA-338 S23: output-event.md after the second review: what adding a family touches, the stronger golden, the worker metrics of an early cancel

This commit is contained in:
Pavlo Ratushnyi
2026-11-06 23:37:58 +01:00
parent 34c7f74e25
commit 906b64ae2d
2 changed files with 38 additions and 17 deletions
+34 -13
View File
@@ -39,8 +39,8 @@ wrote that markup.
| Site | What it did | After S23 |
|---|---|---|
| `gateway-domain/responses/effort.rs` `reasoning_enabled(request, family)` | `family == GptOss` means always reasoning; used by `text.rs` (which stream), `buffered.rs`, `answer.rs`, `reasoning.rs` | `reasoning_enabled(request, codec)` reads `TextCodec::always_reasons()` |
| `responses/create/admit.rs` `check_live_features` | gpt-oss: refuse samplers the worker `GEN` line lacks (a hard-coded field list in `effort.rs`) | `TextCodec::sampling_limit()` returns the set of samplers and the message; `unsupported_sampler` reads it |
| `responses/create/admit.rs` `apply_sampling_defaults` | gpt-oss: drop the samplers it lacks (a second hard-coded list) | `drop_unsupported_samplers` reads the same set |
| `responses/create/admit.rs` `check_live_features` | gpt-oss: refuse samplers the worker `GEN` line lacks (a hard-coded field list in `effort.rs`) | `TextCodec::sampling_limit()` returns the set of samplers and the message; `sampler_limit::unsupported_sampler` reads it |
| `responses/create/admit.rs` `apply_sampling_defaults` | gpt-oss: drop the samplers it lacks (a second hard-coded list) | `sampler_limit::drop_unsupported_samplers` reads the same set |
| `responses/stream/*.rs`, `create/answer.rs` | `tokenizer.decoder()` bytes, then `</think>` and `<tool_call>` scanning in each loop | `TextCodec::live_decoder` / `at_end_decoder`; the loops read `OutputEvent` |
| `responses/intake/parts.rs` `render_prompt` | `match family`: ChatML template with control-token marks, or the Harmony renderer | unchanged (input side, see below) |
| `responses/intake.rs` `expand_images` | needs the Qwen tokenizer (`qwen()`) for pictures | unchanged (input side) |
@@ -64,8 +64,10 @@ OutputError::Parse(msg) a tool call in the text is not acceptable
```
A family hands out one decoder per generation and per reading: `TextCodec::live_decoder(LivePlan) -> LiveDecoder` and
`TextCodec::at_end_decoder(AtEndPlan) -> AtEndDecoder`. Both sit on the same private `Bytes` enum (`Qwen`, `Harmony`), so a token
costs a `match`, not a virtual call, and what one reading offers cannot be asked of the other:
`TextCodec::at_end_decoder(AtEndPlan) -> AtEndDecoder`. Both sit on the same private `TokenBytes` enum (`Qwen`, `Harmony`), so a
token costs a `match`, not a virtual call, and what one reading offers cannot be asked of the other. `live_decoder` has the default
`None`: a model that always reasons (gpt-oss) is read at its end, and the two live streams fail the response if they are ever given
`None`:
* `LiveDecoder` (`LivePlan { tools, recovery, keep_raw }`): text and whole calls as the bytes arrive (UTF-8 completion, then
`tool_output::Incremental`). Every event of `push` and `finish` is final; `finish` also takes the bytes the family held back.
@@ -80,11 +82,16 @@ costs a `match`, not a virtual call, and what one reading offers cannot be asked
A generation ends once: `push` or `finish` after `finish` is a decode error (in the buffered stream it is a `response.failed`, not a
panic). `output_items(events, response_id)` turns the events into `OutputItem`s and the reasoning token count. The cut of a finished
generation into reasoning and answer is text-level code in `output/split.rs` (`cut_text`, also exposed as `split_reasoning` for the
tool corpus tests); the `</think>` search and hold-back are in `think_marker.rs`, used by the reasoning previewer, the cut and the
generation into reasoning and answer is text-level code in `output/cut.rs` (`cut_text`, one `CutGeneration`, also exposed as
`cut_reasoning_for_corpus` for the tool corpus tests; the tokens are counted from its `extent`); the `</think>` search and hold-back are in `think_marker.rs`, used by the reasoning previewer, the cut and the
reasoning budget.
A new family adds a `Bytes` arm and states `always_reasons()` and `sampling_limit()`; no consumer changes.
Adding a family touches, for the output side: a `TokenBytes` arm and the constructors `LiveDecoder::<family>` and
`AtEndDecoder::<family>`, all inside `gateway-domain` (the enum is private to it, so those constructors are the only way in); a
`TextCodec` implementation in the crate that holds the family's tokenizer (`harmony_family.rs` in `strata-control` for gpt-oss) with
`at_end_decoder`, `live_decoder` only if the family can be read live, `always_reasons`, `sampling_limit`, `terminal_ids`, `encode` and
`family()` (a `Family` variant); and the choice of the codec in `serve/state.rs`. The stream loops and the answer builder do not
change. The input side (`render_prompt`, pictures, the reasoning budget) still has its own `Family` and `qwen()` branches.
## Migrated sites
@@ -97,14 +104,17 @@ A new family adds a `Bytes` arm and states `always_reasons()` and `sampling_limi
| 4 | `stream/buffered.rs` | at end: `ReasoningDelta` live, the rest at DONE |
| 5 | `reasoning_enabled`, `admit.rs` | `TextCodec::always_reasons`, `sampling_limit` |
| 6 | the replaced readers | `decode_generation_noted`, `decoded_items`, `ReasoningStream`, `drain_utf8` copies removed |
| 7 | the review fixes | live and at-end decoder types, `TokenDecoder` and the legacy item builder removed, the tool corpus on the gateway's cut, the sampler set |
| 7 | the first review | live and at-end decoder types, `TokenDecoder` and the legacy item builder removed, the tool corpus on the gateway's cut, the sampler set |
| 8 | the second review | names, one `CutGeneration`, `sampler_limit.rs`, no gpt-oss live reading, 29 more golden cases and the tests of the store, the worker's sampling and the disconnect at `DONE` |
## Identity proof
`control-plane/tests/output_golden` (a test binary of its own, because the cases switch the process-wide tool-call recovery) drives
the real `create` handler with 130 scripted token sequences, each as a stream and as a buffered answer: 260 captures of status,
the real `create` handler with 159 scripted token sequences, each as a stream and as a buffered answer: 318 captures of status,
content type and body bytes, SSE framing included. **The expected captures were recorded on `08afbf216`** (`cbc1a9587`, the code before
S23, plus the first harness) in a temporary worktree, and are checked against the new code; none was recorded on it and none differs.
S23, plus the first harness) in a temporary worktree, and are checked against the new code; none was recorded on it and none differs. `regenerate_output_golden`
refuses to run unless `OUTPUT_GOLDEN_RECORD` names the pre-S23 commit and the tree has no `output` module, and
`output_events.recorded_on` names the commit the captures were recorded on (a test pins it).
Volatile text is normalised so that nothing identity-relevant is lost: every distinct id becomes `<kind>_ID<k>` by order of first
appearance and **keeps its numeric suffix** (`call_ID3_1`), so the index inside `call_<response>_<n>` is pinned, and
@@ -113,7 +123,9 @@ appearance and **keeps its numeric suffix** (`call_ID3_1`), so the index inside
The scripts cover: plain text; a terminal token followed by more tokens (also with reasoning, tools and structured output on); tools
with text, one call, two calls, unknown tool, schema violation, an unfinished call at the length limit, a missing closer, a custom
tool; reasoning that closes, that never closes (length and natural stop), that ends on whole calls, that closes and is followed by a
call cut at the length limit; a second `</think>` in the answer and inside a tool argument; structured output valid and invalid; the
call cut at the length limit; the request's `max_output_tokens` reached in every reading; a second `</think>` in the answer and inside a tool argument; structured output valid and invalid, also with reasoning on and for gpt-oss, also with tools; namespaced tools; `DONE` before the first
token and an error after `DONE`; a worker that reports fewer generated tokens than the reasoning took (the clamp of the reasoning
tokens); the
tool-call recovery on and off with two drifted forms in the live tool stream, the buffered stream and the buffered answer; non-ASCII
call arguments, also as multi-byte tokens; **a vocabulary with multi-byte tokens** (a euro sign, an emoji, a token holding the whole
`</think>` and a token that ends in the middle of it, with `reasoning_tokens` asserted: 2 and 3) and raw byte tokens; characters cut
@@ -125,8 +137,10 @@ Scripts are synthetic.
Timing, which captures cannot show: with a worker that waits for a gate before `DONE`, the first `response.reasoning_text.delta`
(both families), the first text delta and the first whole call reach the client before `DONE` is sent; a client that leaves closes the
source in five stream modes; a gpt-oss request that sets a sampler the worker lacks gets a 400 that names the first one. All nine tests of
the binary pass on `08afbf216` and on the new code.
source in five stream modes, and also when it leaves at `DONE`; a stored response equals the one the client was sent (streamed and
not); a gpt-oss request that sets a sampler the worker lacks gets a 400 that names the first one; the server defaults for those
samplers do not reach the gpt-oss worker (top_k 20 and penalty_last_n 64 among them), neutral values are accepted, and Qwen keeps all
five samplers. All fifteen tests of the binary pass on `08afbf216` and on the new code.
Results on the tip: `cargo test --no-fail-fast --all-targets` for `strata-control`, `leleka-gateway-domain`, `leleka-gateway-text`,
`leleka-harmony`, `leleka-tokenizer` and `leleka-runtime-client` on Linux (WSL), before (`cbc1a9587`) and after, compared with
@@ -157,6 +171,13 @@ No response byte changes (the golden). What changes besides:
* **Flags are read at stream start.** The buffered stream builds its plan (tool-call recovery, debug copy) when the stream starts and
not at DONE; the tool-call stream already read the recovery when it started. A recovery switch flipped during a request therefore
no longer reaches that request's buffered stream (only the tests flip it).
* **The worker sees an out-of-vocabulary id as a client that left.** In the structured-output stream on Qwen the new code fails at
the offending token and drops the source then; `backend_worker/generation_run.rs` sees the closed result (`Wake::ClientGone`) and
cancels the engine's generation at that point, and `conclude.rs` counts the request as `disconnected` (`metrics.rs`: outcome
`disconnect`, `cancelled` plus one) where the code before S23 let the generation run to `DONE` and counted a finished generation with
its stop or length. So the worker metrics of such a request differ (earlier cancel, `disconnect` instead of the finish reason) while
the client sees the same `response.failed`. The reasoning stream and the live streams already behaved so for a decode or parse
error.
* **A generation ends once.** `finish` twice, or `push` after it, is a decode error.
Behaviours kept on purpose (they are in the golden):
+4 -4
View File
@@ -430,10 +430,10 @@ What changed in the move, apart from `pub(super)` becoming `pub`:
## OutputEvent and the output decoders (STRA-338 S23)
`crates/gateway-domain/src/output/` is new (pure, L2): `event.rs` (`OutputEvent`, `OutputError`), `bytes.rs` (the family's bytes),
`live.rs` (`LiveDecoder`) and `at_end.rs` (`AtEndDecoder`) with `split.rs` (the cut of a finished generation), `harmony.rs` (the
gpt-oss decoder, moved from `control-plane/src/harmony_family.rs`), `reasoning_split.rs`, `utf8.rs`, `fold.rs` (`output_items`); the
`</think>` marker is `think_marker.rs`. The four consumers in `strata-control` read events; `docs/architecture/output-event.md` has
`crates/gateway-domain/src/output/` is new (pure, L2): `event.rs` (`OutputEvent`, `OutputError`), `token_bytes.rs` (the family's bytes),
`live.rs` (`LiveDecoder`) and `at_end.rs` (`AtEndDecoder`) with `cut.rs` (the cut of a finished generation), `harmony.rs` (the
gpt-oss decoder, moved from `control-plane/src/harmony_family.rs`), `reasoning_preview.rs`, `utf8.rs`, `fold.rs` (`output_items`); the
`</think>` marker is `think_marker.rs`; the sampler limit of a worker is `sampler_limit.rs`. The four consumers in `strata-control` read events; `docs/architecture/output-event.md` has
the flow analysis, the table of the sites that asked for the family, the identity proof, the behaviour changes and the list of what
was kept on purpose. What it did not do: