mirror of
https://github.com/openai/codex.git
synced 2026-11-16 14:55:43 +00:00
Preserve floating-point values when decoding rollout lines (#38399)
## Why Serde's generic buffering for flattened and internally tagged fields is incompatible with `serde_json`'s `arbitrary_precision` representation. As a result, persisted rollout items containing nested floating-point values can fail to decode. ## What changed - Decode the rollout envelope at the JSON persistence boundary before deserializing the item payload. - Use the shared decoder for both session resume and thread-history projection. - Cover token-count floats, response-item metadata, field ordering, and ignored metadata in the decoder compatibility test. GitOrigin-RevId: 59c7f6fbcf83162b5ed6980a69381fe45fc20a0a
This commit is contained in:
1 parent
053dda6b89
commit
2bd8727a0c
4 files changed
+60
-4
No files matched your search
@@ -3,6 +3,8 @@
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use serde::de::Error as _;
|
||||
use serde_json::Value;
|
||||
|
||||
pub(crate) mod compression;
|
||||
pub(crate) mod config;
|
||||
@@ -30,6 +32,38 @@ pub use codex_history::RolloutItem;
|
||||
pub use codex_history::RolloutLine;
|
||||
pub(crate) use codex_protocol::protocol;
|
||||
|
||||
/// Decodes a persisted rollout record without Serde's flattened-envelope buffering.
|
||||
///
|
||||
/// With `serde_json/arbitrary_precision`, Serde's generic buffer cannot replay
|
||||
/// floating-point values nested inside flattened or internally tagged fields:
|
||||
/// https://github.com/serde-rs/json/issues/721
|
||||
/// https://github.com/serde-rs/serde/issues/1183
|
||||
///
|
||||
/// Keep this JSON-specific workaround at the persistence boundary so history
|
||||
/// remains format-neutral and resume and projection use the same item decoder.
|
||||
/// Remove it once Serde supports format-specific buffering.
|
||||
pub fn decode_rollout_line(value: Value) -> serde_json::Result<RolloutLine> {
|
||||
let Value::Object(mut fields) = value else {
|
||||
return serde_json::from_value(value);
|
||||
};
|
||||
let timestamp = fields
|
||||
.remove("timestamp")
|
||||
.ok_or_else(|| serde_json::Error::missing_field("timestamp"))
|
||||
.and_then(serde_json::from_value)?;
|
||||
let ordinal = fields
|
||||
.remove("ordinal")
|
||||
.map(serde_json::from_value::<Option<u64>>)
|
||||
.transpose()?
|
||||
.flatten();
|
||||
let item = serde_json::from_value(Value::Object(fields))?;
|
||||
|
||||
Ok(RolloutLine {
|
||||
timestamp,
|
||||
ordinal,
|
||||
item,
|
||||
})
|
||||
}
|
||||
|
||||
pub const SESSIONS_SUBDIR: &str = "sessions";
|
||||
pub const ARCHIVED_SESSIONS_SUBDIR: &str = "archived_sessions";
|
||||
pub static INTERACTIVE_SESSION_SOURCES: LazyLock<Vec<SessionSource>> = LazyLock::new(|| {
|
||||
|
||||
Reference in new issue
Block a user