Repository navigation
feat(runtime): stream live model output rate and calibrate token estimates - #68
Merged
Merged
Conversation
…mates Why: - A streaming turn showed no live throughput, and long text deltas were kept as a second event-by-event copy in retained run results. - Request token budgets relied on a fixed bytes-per-token ratio even after the provider reported real input usage for the same request. What changed: - merry-llm: receive every provider attempt through `receive_model_stream`, which keeps semantic events ordered and bounded while publishing latest-only output progress (UTF-8 bytes over the first-to-last receive interval, at most every 100 ms). Progress counts text, tool-call fragments, and reasoning without retaining text, and downgrades timing quality for hidden or summarized reasoning and consumer-limited delivery instead of reporting a false rate. - merry-core: add `ModelOutputRate`, `OutputTokenSource`, and `OutputTimingQuality`, expose them as runtime/journal events, and add `is_transient()` so live-only observations (text deltas, rate samples) are excluded from retained run results and replay. - merry-runtime: reduce provider usage or the calibrated estimate into one rate per attempt, deliver it through a watch-based latest-only channel beside the ordered semantic journal, and reset it at step and compaction boundaries. Session state learns a bounded, provider/model/stable-prefix-scoped input token calibration from complete request estimates plus matching provider usage: underestimation applies immediately and excess headroom is released gradually. The calibration persists with the session document. - merry-cli and sdks/python: show the last measurable sample in the TUI status line (`~N tok/s` when approximate) and expose typed `ModelOutputRate` events, keeping transient updates out of `result.events`. Verification: - cargo fmt --all --check - cargo clippy --all-targets --all-features -- -D warnings - cargo test --all --no-fail-fast: every target passes except four host-dependent sandbox suites that need nested bwrap, a root-owned /etc/ssh/ssh_config, or a writable /root. - sdks/python: ruff check, ty check, pytest (91 passed), uv build
Apply Ruff formatting to the output rate parser, typed values, and tests so the Python SDK CI gate can proceed. Python ASTs are unchanged; no runtime behavior or checks are modified. Verified on Linux with Python 3.14: uv sync --locked; test-utils extension build; Ruff formatting and lint; ty; all 91 Python tests; example and probe compilation; wheel and source archive build; git diff --check. Refs: #68
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
What changed
receive_model_stream, which keeps semantic events ordered and bounded while publishing latest-only output progress (UTF-8 bytes over the first-to-last receive interval, at most every 100 ms). Progress counts text, tool-call fragments, and reasoning without retaining text, and downgrades timing quality for hidden or summarized reasoning and consumer-limited delivery instead of reporting a false rate.ModelOutputRate,OutputTokenSource, andOutputTimingQuality, exposed as runtime/journal events, plusis_transient()so live-only observations (text deltas and rate samples) stay out of retained run results and replay.~N tok/swhen approximate); the Python SDK exposes typedModelOutputRateevents and keeps transient updates out ofresult.events.Rates are client receive-side observations, never a server decode clock, and provider usage does not imply that hidden reasoning timing was observed.
Verification
cargo fmt --all --check- cleancargo clippy --all-targets --all-features -- -D warnings- cleancargo test --all --no-fail-fast- every target passes except four host-dependent sandbox suites that need nested bwrap, a root-owned/etc/ssh/ssh_config, or a writable/root; none of them touch the changed modulessdks/python:ruff check,ty check,pytest(91 passed),uv build- all clean