Repository navigation
Breaking changes
- Stream chunks are now incremental deltas.
Session::stream_responsepreviously delivered the framework's cumulative snapshot on every callback; it now delivers only the newly generated suffix, so concatenating chunks yields the full response (Unicode-safe, computed on UTF-8 bytes).stream_jsonkeeps cumulative-snapshot semantics and now documents them. TokenUsagegained anestimated: boolfield. The chars/4 heuristic fallback is now distinguishable from a framework tokenizer measurement. Code constructing or exhaustively destructuringTokenUsagemust be updated.ContextUsage::utilizationchanged denominator. It is now measured against the available budget (window minus reserved response tokens) so it aligns withover_limit, instead of the raw window size.- Compaction fails fast instead of degrading silently.
compact_transcripterrors on an empty summarizer response, andcompact_session_if_needederrors when the compacted session still exceeds the budget.
New
Session::cancellation_handle()— aSend + Synchandle that cancels an in-flight blocking or streaming generation from another thread and exposesis_responding(). Handles are session-scoped:cancel()targets whichever generation is active at call time.Error::Cancelled— cancellation is now a typed error preserving the framework message (Python: still raised asGenerationError, matching the documented contract).- Stream callbacks no longer require
'static, so they can borrow local accumulators.
Fixed
- Tool-enabled sessions leaked their
ToolCallbackData(and every registered tool) for the life of the process (#3, thanks @maxiboch). - Panics in
Tool::call, stream chunk callbacks, or toolDropimpls no longer abort the host process; they surface as tool/stream errors, and a chunk-callback panic now cancels the generation. - Blocking generations are registered for cancellation, and completion vs. cancellation is arbitrated under a lock — a cancel landing after the last chunk no longer misreports a delivered stream, and cancel/timeout now unblocks a generation stuck inside a blocking Rust tool.
- Error strings returned over FFI are owned copies (
strdup) instead of pointers into bridged temporaries. - Tool dispatch: names are matched trimmed end to end, schema-declared string arguments are no longer coerced to numbers/booleans, and the model is told which required arguments it omitted so it retries instead of the tool silently running on defaults.
- Tool callbacks run off the Swift cooperative thread pool, removing a deadlock path for re-entrant tools.
- Compaction splits messages that exceed the chunk budget (single pass) so summarization can no longer blow the very context window it protects.
- Streaming clears stale per-response usage;
extractBalancedJsonis linear instead of quadratic. - iOS builds get the correct Swift runtime search path, and the Swift FFI layer is compiled with
-O/-Osizematching the Cargo profile instead of always-Onone.
Docs
SystemTool::Ocr/BarcodeReader: label image attachments withwith_label(...)and reference the label in the prompt for reliable tool invocation.- Timeout methods document that cooperative cancellation lets an abandoned generation drain in the background (
ConcurrentRequestson retry, late tool side effects).
Rust
[dependencies]
fm-rs = "0.3.0"Python
pip install fm-rs==0.3.0Documentation
What's Changed
- fix: reclaim ToolCallbackData handed to Swift by @maxiboch in #3
- style: format leak_repro and fix clippy pedantic lints by @blacktop in #4
New Contributors
Full Changelog: v0.2.1...v0.3.0