Skip to content

fix: handle f64 extraction in kvbm-config under arbitrary_precision#317

Merged
xiaguan merged 1 commit into
openinfer-project:mainfrom
mvanhorn:fix/296-kvbm-config-f64-precision
Jun 9, 2026
Merged

fix: handle f64 extraction in kvbm-config under arbitrary_precision#317
xiaguan merged 1 commit into
openinfer-project:mainfrom
mvanhorn:fix/296-kvbm-config-f64-precision

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

kvbm-config's cache_size_gb: Option<f64> fields now deserialize correctly whether figment hands them a native JSON number or the serde_json arbitrary_precision "number map" form. This unblocks the documented workspace test command cargo test --release --workspace --lib, which was failing on main.

Why this matters

Per #296, test_profile_with_defaults_and_overlay panics with InvalidType(Map, "f64") at path ["cache", "host", "cache_size_gb"]. The crate is green in isolation but red when co-compiled with pegainfer-server: vllm-chat (a transitive git dep) enables serde_json/arbitrary_precision, and Cargo feature unification turns that feature on for every serde_json user in the workspace. Under arbitrary_precision, JSON numbers deserialize as an internal map {"$serde_json::private::Number": "2.0"}, so figment's Json source hands kvbm-config a Map where a plain f64 is expected.

Pinning or stripping the feature isn't viable: it's owned by a git dependency and would regress on the next bump. The robust, behavior-preserving fix is to make the float fields tolerant of either representation, so the config-load path stays correct no matter which workspace features get unified on.

Changes

A small, self-contained deserialize_opt_f64 serde helper was added in cache.rs and applied to cache_size_gb on both HostCacheConfig and DiskCacheConfig. It accepts a native JSON number, the arbitrary_precision single-entry map form, or an omitted/null value (yielding None). The helper uses only serde, so there is no dependency change and serde_json stays a dev-dependency.

It also rejects non-finite parses (such as 1e10000 overflowing to inf), matching what serde_json's native f64 deserializer already does. Without this guard, a malformed config could smuggle in an infinite cache size that later casts to usize::MAX in compute_num_blocks.

Testing

cargo fmt --check and cargo clippy --all-targets are both clean for the crate, and cargo test --release -p kvbm-config --lib passes 65 tests (up from 63). To confirm the fix targets the exact feature-unification path, I forced serde_json/arbitrary_precision on the crate's dev serde_json: on main this reproduces the failure (test_profile_with_defaults_and_overlay FAILED), and with this change it passes.

Two new tests cover the behavior. test_cache_size_gb_arbitrary_precision_map asserts the map form, a plain integer (4 -> 4.0), and a fractional value all extract correctly and that an omitted field yields None. test_cache_size_gb_rejects_non_finite asserts that an out-of-range value is rejected rather than becoming Some(inf).

Fixes #296

…peninfer-project#296)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a custom deserializer deserialize_opt_f64 for the cache_size_gb fields in HostCacheConfig and DiskCacheConfig. This custom deserializer correctly handles serde_json's arbitrary-precision numbers (using the internal $serde_json::private::Number map representation) and ensures that non-finite values are rejected, preserving the behavior of the native f64 deserializer. Unit tests have been added to verify these behaviors. No review comments were provided, and the implementation is clean and well-tested.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@xiaguan xiaguan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified fmt plus kvbm-config lib tests and the kvbm-config + pegainfer-server feature-unification repro locally.

@xiaguan xiaguan merged commit 85eda1a into openinfer-project:main Jun 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kvbm-config: workspace test run breaks figment f64 extraction via serde_json arbitrary_precision unification

2 participants