29 more cases (159 cases, 318 captures), recorded on 08afbf216 in a temporary worktree and checked against the new code; none
differs. New cases: the request's max_output_tokens reached (text, reasoning, closed reasoning, tools, structured, gpt-oss);
Qwen reasoning on with json_schema valid and violated; gpt-oss json_schema, tools with structured output, effort none with
tools; Qwen reasoning plus tools at the length limit with calls inside the unclosed reasoning, and without; namespaced tools
through the stream and the buffered reading (Qwen with and without reasoning, gpt-oss); DONE before the first token and an error
after DONE (all four readings); a worker that reports fewer generated tokens than the reasoning took (the reasoning_tokens
clamp, usage output_tokens).
New tests of the binary (15 pass on 08afbf216 and on the new code): the stored response equals the one the client was sent
(streamed and not, six cases); a client that leaves at DONE closes the source (five cases, among them the final preview
flush); what reaches the worker: gpt-oss gets none of the server defaults for the samplers it lacks (top_k 20 and
penalty_last_n 64 included), accepts neutral values, Qwen keeps all five samplers and penalty_last_n, own and default.
In the lib: BufferedRun finishing its generation twice returns the shared GENERATION_ENDED error and fail() sends
response.failed; a token after the end fails the stream.
regenerate_output_golden now refuses unless OUTPUT_GOLDEN_RECORD names the pre-S23 commit and the tree has no output module
(checked: it panics on this tree); output_events.recorded_on names 08afbf216 and a test pins it.
Renames: ReasoningSplit to ReasoningPreview, Bytes to TokenBytes, Split and Cut to the one CutGeneration (the tokens are
counted from its extent by Generation::count_tokens), split_reasoning to cut_reasoning_for_corpus. AtEndDecoder::read_answer
returns the events and the notes, and build_events keeps the notes (two steps). decode_lossy has its doc comment. The
message of a decode error after the generation ended is one constant, output::GENERATION_ENDED, used by the decoders and by
the buffered stream. The sampler types and the admission functions move from codec.rs and effort.rs to sampler_limit.rs
(with their tests); lib.rs no longer names TokenDecoder.
TextCodec::live_decoder returns Option and defaults to None: a model that always reasons is read at its end, so the
gpt-oss live arm and LiveDecoder::harmony are deleted; the two live streams fail the response with NO_LIVE_READING if they
ever get None. harmony_family tests pin reasoning_enabled(effort none, gpt-oss) = true and the missing live reading.
New unit tests: preview off with an unclosed block at the length limit, and the same reasoning tokens with preview on and
off when the marker is split over two multi-byte tokens.
Proof: golden (260 captures recorded on 08afbf216) identical, strata-control lib 316, gateway-domain 36, tool corpus 4.
TextCodec::sampling_limit returns SamplingLimit { unsupported: &[Sampler], message }; gpt-oss lists TopK, MinP,
RepetitionPenalty, FrequencyPenalty, PresencePenalty in the order they were checked. unsupported_sampler and
drop_unsupported_samplers (effort.rs) read the set, so neither admit.rs nor effort.rs names a gpt-oss field any more
(unsupported_gptoss_sampling is gone; clearing penalty_last_n goes with the repetition penalty, as before). Unit tests of
both functions in gateway-domain; a_sampler_the_gptoss_worker_lacks_is_refused_and_named in the golden binary (400, the
param named, the family's message, the first sampler of the list wins) passes on 08afbf216 and on the new code.
Proof: golden (260 captures recorded on 08afbf216) identical, strata-control lib 315, gateway-domain 34, tool corpus pass.
parse_output_items_with and segment_item (gateway-domain) and parse_output_items, parse_output_items_after and tool_options
(strata-control) are removed. The pure-protocol golden (responses/golden.rs, 'parse' cases) and the custom/console tool
tests build their items with answer_items (tests/fixtures.rs): the Qwen test tokenizer, an AtEndDecoder without reasoning,
output_items. The recorded expectations of the pure golden are unchanged. flat_tools lives in
responses/tool_declarations.rs. Proof: output_golden (260 captures recorded on 08afbf216) identical, strata-control lib
315 and gateway-domain 32 tests pass.
OutputDecoder split into two types over the shared Bytes, so what one reading offers cannot be asked of the other:
LiveDecoder (raw_text, notes) and AtEndDecoder (notes, accepted_call_in_reasoning, split_text) replace the enum with its
mode-specific accessors that returned None or false in the wrong mode. TextCodec gets live_decoder and at_end_decoder.
LiveDecoder::finish now hands the Harmony tail to the reader, so a live reading of gpt-oss would lose nothing.
push and finish after the generation ended return a decode error. AtEndPlan.preview: the non-stream answer no longer runs
the reasoning previewer. The two expect calls of the buffered stream are a response.failed path (DECODER_GONE).
TokenDecoder, QwenDecoder, decode_all and TextCodec::decoder are gone (HarmonyDecoder has push and finish of its own;
its tests drive it directly). AtEndReader::finish is split: Generation::split (split.rs) cuts the bytes and counts the
tokens, the plan flush, the debug copy, the events and the answer reading are functions of their own; the rule 'an
answer has one text event, empty if nothing else' is ensure_text. Names: decode_lossy, convert_segments, build_item,
wrap_reasoning_delta, finish_generation, BufferedRun::build (one result, the initial events are a field).
drain_utf8 is private to the output module (its test reads through the live decoder). The </think> marker search and
hold-back live in think_marker.rs, used by the previewer, the at-end split and the reasoning budget.
Unit tests added: keep_raw/raw_text/split_text, the no-preview plan, finishing twice, a cut character at the end.
Proof: the golden recorded on 08afbf216 (130 cases, 260 captures) passes unchanged; strata-control lib 315 and
gateway-domain 32 tests pass; architecture-baseline.json tightened (dyn-trait gateway-domain 4 to 2, strata-control 12
to 11).
The golden moves from a lib test to control-plane/tests/output_golden (its own process: the cases switch the process-wide
tool-call recovery). 130 synthetic cases, 260 captures. The expected captures in output_events.json were recorded on
08afbf216 (cbc1a9587 plus the first harness) in a temporary worktree and are checked against the new code; none was
recorded on it, and none differs.
What is stronger: ids are numbered by first appearance as <kind>_ID<k> and keep their numeric suffix (call_ID3_1), and
two_calls_of_one_response_have_different_call_ids pins the call ids Codex pairs outputs by; a vocabulary with multi-byte
tokens (a euro sign, an emoji, a token that holds the whole </think> marker, a token that ends in the middle of it) and
raw byte tokens; characters cut at length and at stop in the live text, the live tool stream, the reasoning preview and
the structured stream; a lone continuation byte in reasoning and in the answer; reasoning_tokens pinned for the marker
inside a token and across two tokens; a second </think> in the answer and in a tool argument; reasoning closed and the
answer cut inside a call; the tool-call recovery on and off in the live tool stream, the buffered stream and the
buffered answer; non-ASCII call arguments; a terminal token followed by more tokens with reasoning, tools and
structured output on; an id outside the vocabulary in the middle of the script (the code before S23 fails at DONE, the
new code at the offending token; the failure code, the message and every byte of the response are the same); a source
that closes without DONE; Finish::Cancel. Timing: a gated worker proves the first reasoning delta, text delta and whole
call reach the client before DONE, and a client that leaves closes the source in five stream modes.
Not covered end to end: STRATA_DEBUG_FAILED_OUTPUT (read once per process through a OnceLock; the keep_raw paths get
unit tests in leleka-gateway-domain).
Removed: decode_generation_noted and DecodedGeneration (gateway-domain), decode_generation_with / decoded_items /
decode_generation (strata-control), ReasoningStream and the drain_utf8 copy (their code lives in output/). The test ids are
kept: reasoning_marker_and_unicode_split_at_every_byte and the unclosed-reasoning test now read through the output decoder,
the utf8 test calls the domain drain_utf8; two unit tests of the moved pieces are added to gateway-domain.
docs/architecture/output-event.md: how output flows for each family, every site that asked for the family (before and after),
the canonical type, the identity proof, the behaviours kept on purpose and what is not done and why; hexagonal.md and
tech-debt.md point to it. architecture-baseline.json tightened with --update-baseline (dyn-trait: gateway-domain 5 to 4,
strata-control 14 to 12; nothing raised).
TextCodec gets always_reasons() (gpt-oss: true) and sampling_limit() (gpt-oss: the worker takes temperature, top_p and
seed only; the error message is the family's own). reasoning_enabled(request, codec) and admit.rs (check_live_features,
apply_sampling_defaults) read them instead of comparing Family::GptOss, and text.rs / reasoning.rs / tool_recovery.rs pass
the codec instead of its family. Proof: output_golden (132 captures) identical, strata-control and gateway-domain lib tests
pass, gates green, 0 warnings.
responses/stream/buffered.rs holds one reading-at-the-end OutputDecoder for the whole stream: ReasoningDelta events become
the reasoning deltas of the SSE stream, and at DONE the decoder is finished off the async threads (post_decode stage) and
the remaining events become the response with output_items. The stream no longer keeps token ids, no longer runs
ReasoningStream or decode_generation_with, and no longer asks the codec for its family (the decoder plan says whether the
output starts inside a reasoning block). Proof: output_golden (132 captures) identical, strata-control lib tests 317 pass,
gates green. Logging difference: a refused tool call in this stream now also writes the STRATA_DEBUG_FAILED_OUTPUT debug
copy to stderr when that variable is set (the non-stream answer already did); no response byte changes.
spawn_engine turned the spawn error into StartupFailed with map_err, which cannot await, so the worker status stayed at Starting
(the original run_session set WorkerState::Failed before returning). The Err arm awaits the update again; same log text, same exit.
New test a_failed_engine_spawn_marks_the_worker_failed spawns a nonexistent executable and asserts StartupFailed and WorkerState::Failed.
responses/create/answer.rs reads the generated ids through a reading-at-the-end OutputDecoder (decode and tool-call parse
errors keep their classes: detokenization_failed and tool_call_parse_failed) and builds the items with output_items,
replacing decode_generation_with / decoded_items. tool_recovery.rs gets the two helpers both buffered sites share
(at_end_plan, finish_output: the notes log, the call-in-reasoning log and the debug copy of a refused call).
Proof: output_golden (132 captures) identical, strata-control lib tests 317 pass, gates green.
responses/stream/tool_run.rs (the stream of a response whose request declares tools, no reasoning) takes the text and the
whole calls from a live OutputDecoder instead of draining UTF-8 and driving tool_output::Incremental itself;
ToolStream::event_item publishes an OutputEvent. The debug copy of a failed output and the notes log come from the
decoder. Proof: output_golden (132 captures) identical, strata-control lib tests 317 pass, gates green, 0 warnings.
New pure module leleka-gateway-domain::output: OutputEvent (reasoning delta, reasoning, text, whole tool call),
OutputError (decode / parse), OutputDecoder (an enum over the families: Qwen3.5 tokenizer bytes, the Harmony decoder),
a live reading (text and tool calls as bytes arrive) and a reading at the end (reasoning split on </think>, batch parse
of the answer, the unclosed-reasoning rules, reasoning token count), and output_items (events to response items).
The Harmony decoder moved from control-plane/src/harmony_family.rs unchanged (it still writes the Qwen-style markup
the readers parse); TextCodec gets output_decoder(plan). The readers are ports of the code in stream/ and tool_calls.rs.
Migrated site: responses/stream/text.rs (plain-text stream) now takes OutputEvent::Text from the decoder instead of
draining UTF-8 itself. Proof: output_golden (132 captures) identical, strata-control and gateway-domain lib tests
pass, check-limits / check-architecture / check-ci-coverage green, 0 new warnings.
Adds a test that drives the real create handler with 66 scripted token sequences (33 Qwen3.5, 33 gpt-oss/Harmony) as a
stream and as a buffered answer, and compares the bytes a client would read (status, content type, SSE frames, JSON
body, with ids and timestamps normalised) with tests/fixtures/golden/output_events.json. The cases cover plain text,
tool calls, reasoning, structured output, unclosed reasoning, length cuts, invalid and unknown calls, calls without
declared tools and worker failures. The captures were recorded on cbc1a9587 and are the identity proof of the S23
steps; the test also checks that two runs give the same captures. Synthetic scripts only, nothing from a real session.