Repository navigation
feat(spend-logs): rust spend log row builder - #52161
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance1 warning
Comparing Footnotes |
613305f to
466360f
Compare
466360f to
80009ad
Compare
80009ad to
f3c5bb9
Compare
6a785b8 to
8fe1e8b
Compare
285377a to
6b98f66
Compare
PR overviewThe PR introduces a Rust-backed spend log row builder, including preparation of model and error information for spend logging. One issue has been addressed, and one remains open in error scrubbing. Removing NUL characters from model names before computing redaction variants can leave sensitive model text in logged error information for certain failed requests, even when prompt storage is disabled. The remaining concern is a narrow logging privacy regression rather than a broader access-control issue. Open issues (1)
Fixed/addressed: 1 · PR risk: 4/10 Reviews |
There was a problem hiding this comment.
Devin Review found 2 potential issues.
4 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| litellm_params: LitellmParams::parse(get_or_none(value, "litellm_params")), | ||
| kwargs: Kwargs::parse(get_or_none(value, "kwargs")), |
There was a problem hiding this comment.
🟡 Python coercion outside the required boundary
For ledger-on requests, RowInput::from_value coerces Python kwargs inside the callback crate. Workspace rules restrict these coercions to python-bridge and config.
Learn more
The Rust workspace's Python boundary skill restricts coercion of Python kwargs to python-bridge and configuration input to config. The callback crate currently receives JSON and interprets Python scalar types through Kwargs::parse, text_of, number_of, and RowAuthFacts::parse. RustSpendLogRowBuilder::build_row invokes that parsing inside the callback implementation rather than constructing its typed input at the bridge.
Example: A request's response_cost enters the callback crate as a generic value. Kwargs::parse decides whether it counts as a number there, rather than receiving an already resolved optional cost.
Recommended fix: Construct the typed row input in python-bridge and pass it to the callback crate. Keep opaque request, response and metadata documents as data where necessary, but resolve scalar kwargs and flags at the designated boundary.
Was this helpful? React with 👍 or 👎 to provide feedback.
| #[derive(Clone, Debug)] | ||
| pub(crate) struct RowAuthFacts { | ||
| /// `metadata.get("user_api_key")`, `None` when absent: its type decides how it is redacted. | ||
| pub(crate) user_api_key: Option<Value>, |
0d85f52 to
de4838a
Compare
de4838a to
40461d6
Compare
40461d6 to
cfd2f70
Compare
cfd2f70 to
0992d64
Compare
0992d64 to
a6eedb9
Compare
| **_request_metadata(litellm_params), | ||
| }, | ||
| "kwargs": { | ||
| **_projected(kwargs, _KWARGS_KEYS | _STORED_PROMPT_KWARGS_KEYS if stores_prompts else _KWARGS_KEYS), |
There was a problem hiding this comment.
Low: Preserve raw model spellings until error scrubbing
_projected() applies safe_json_structure() to model, removing NUL characters before Rust computes its redaction spellings: a model containing medical\u0000 records no longer matches an error echo containing the escaped \x00 or \u0000 form, although the Python builder scrubbed both. For failed requests whose model is replaced with the placeholder, this leaves sensitive model text in error_information even with prompt storage disabled; pass the original model or precomputed spellings to the scrubber and remove NULs afterward.
a6eedb9 to
f39de83
Compare
f39de83 to
031416b
Compare
031416b to
557ecfd
Compare
557ecfd to
d6b5c96
Compare
Main now builds spend rows in Rust (BerriAI#52161), so the sub-call session fallback under missing_session_id: omit moves into the Rust row builder too, with a golden scenario for it
…_spend_name main moved the spend log row body into legacy_spend_log_rows.py and made the Rust row builder the default (#52161, #52182), so the rule that keeps a registered agent's name on a failed /a2a row is carried into the legacy builder, the Rust builder and its row input, and the golden recorder
accounting_payloadis built in Rustlitellm-callbacks-spend-log(no pyo3), exported through python-bridge asRustSpendLogRowBuilder; Python gluelitellm/proxy/spend_tracking/rust_spend_log_rows.pycache_key,served_from_cache, unknown-model message, router lookups, savings pricing, accounting windowstest_configurable_string_length_env_var, which reloadslitellm.constantsand leaks a truncation default into later tests (existing leak)