From 131486371097702fc531c6bbaf55e59a75233e99 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 21:08:50 -0600 Subject: [PATCH 1/3] fix(id/world_net): refuse a present-but-mistyped seed in manifest_state (#6626) manifest_state read the world_state reply seed with a bare as_u64(): a present-but-mistyped seed ("42", -1, 1.5, {}, []) silently became None, indistinguishable from the one legitimate None (an absent seed on a capability-only read, #240) -- and the manifest-capture consumer bakes None in as seed 0. The reply now routes through a factored parse_world_state_reply (mirroring parse_caps_reply from #6624): an absent seed stays None, a present seed must be a u64 or the read fails with host sent a malformed seed, and schedules keeps its strict decode. Regression test drives the parser with the numeric and absent controls, every mistyped shape, a mistyped schedules map, and the refusal path. --- pkgs/id/src/world_net.rs | 99 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 6 deletions(-) diff --git a/pkgs/id/src/world_net.rs b/pkgs/id/src/world_net.rs index f50ded77a1..c844eac482 100644 --- a/pkgs/id/src/world_net.rs +++ b/pkgs/id/src/world_net.rs @@ -989,7 +989,9 @@ impl WorldClient { /// /// # Errors /// - /// Fails with the host's message if neither credential is accepted. + /// Fails with the host's message if neither credential is accepted, + /// or with "host sent a malformed seed" if the reply's `seed` field + /// is present but not a `u64`. pub async fn manifest_state( &mut self, admin_token: Option<&str>, @@ -1005,12 +1007,36 @@ impl WorldClient { .recv_json() .await? .context("host closed without replying")?; + Self::parse_world_state_reply(&reply) + } + + /// Validate a `world_state` reply frame and extract the manifest + /// state: a `seed` that is *absent* is the one legitimate `None` + /// (a capability-only read, where the host deliberately hides the + /// seed, #240), but a seed that is present with the wrong type is + /// corruption, not a hidden seed -- reading it with a bare + /// `as_u64()` silently downgraded it to the capability-only shape, + /// and the manifest-capture consumer then baked it in as seed 0 + /// (#6626). `schedules` keeps its strict decode. Factored out of + /// [`WorldClient::manifest_state`] (mirroring + /// [`WorldClient::parse_caps_reply`]) so the validation can be + /// unit-tested without a live host sending frames no real host + /// sends. + fn parse_world_state_reply( + reply: &serde_json::Value, + ) -> Result<(Option, std::collections::BTreeMap)> { match reply["type"].as_str() { - Some("world_state") => Ok(( - reply["seed"].as_u64(), - serde_json::from_value(reply["schedules"].clone()) - .context("host sent a malformed schedule map")?, - )), + Some("world_state") => { + let seed = match reply.get("seed") { + None => None, + Some(value) => Some(value.as_u64().context("host sent a malformed seed")?), + }; + Ok(( + seed, + serde_json::from_value(reply["schedules"].clone()) + .context("host sent a malformed schedule map")?, + )) + } _ => bail!( "{}", reply["message"] @@ -2728,6 +2754,67 @@ mod tests { assert!(refused.err().unwrap().to_string().contains("admin token refused")); } + #[test] + fn world_state_reply_requires_a_u64_seed_when_present() { + // Issue #6626: a present-but-mistyped `seed` must error, not + // silently read as the capability-only `None` (which the + // manifest-capture consumer then bakes in as seed 0). Only a + // genuinely absent seed is `None` (#240 seed-hiding). Driven + // through the factored reply parser manifest_state() uses. + let parse = WorldClient::parse_world_state_reply; + + // Controls: a numeric seed, and the legitimate absent seed. + let (seed, schedules) = parse(&serde_json::json!({ + "type": "world_state", "seed": 42, "schedules": {"a": 1}, + })) + .unwrap(); + assert_eq!(seed, Some(42)); + assert_eq!(schedules.get("a"), Some(&1)); + let (seed, schedules) = parse(&serde_json::json!({ + "type": "world_state", "schedules": {}, + })) + .unwrap(); + assert_eq!(seed, None); + assert!(schedules.is_empty()); + + // Every mistyped shape errors and names the malformed seed. + for bad in [ + serde_json::json!("42"), + serde_json::json!(-1), + serde_json::json!(1.5), + serde_json::json!({}), + serde_json::json!([]), + serde_json::json!(true), + serde_json::Value::Null, + ] { + let err = parse(&serde_json::json!({ + "type": "world_state", "seed": bad, "schedules": {}, + })) + .err() + .unwrap_or_else(|| panic!("seed {bad} must be refused")); + assert!( + err.to_string().contains("malformed seed"), + "seed {bad}: {err}" + ); + } + + // The sibling field keeps its strict decode. + let err = parse(&serde_json::json!({ + "type": "world_state", "seed": 42, "schedules": {"a": "x"}, + })) + .err() + .unwrap(); + assert!(err.to_string().contains("malformed schedule map"), "{err}"); + + // A refusal frame still surfaces the host's message. + let err = parse(&serde_json::json!({ + "type": "error", "message": "admin token refused", + })) + .err() + .unwrap(); + assert!(err.to_string().contains("admin token refused"), "{err}"); + } + #[test] fn caps_reply_requires_a_valid_report() { // Issue #6624: a `caps` frame carrying no valid CapsReport must From f6e8b879a36b663e3f044ce24d67c03047d399c2 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 22:00:16 -0600 Subject: [PATCH 2/3] fix(id/world_net): accept a null seed as the capability-only None (#6626) Codex P1 on PR #6714: the host serializes a hidden seed as null (ServerFrame::WorldState.seed is Option with no skip-serializing; both reply paths set admin_ok.then_some(seed)), so rejecting null broke capability-only manifest_state reads and world diff. Absent and null now both parse as None; string/negative/float/object/array/bool still error as malformed. Regression test covers the actual host shape. --- pkgs/id/src/world_net.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pkgs/id/src/world_net.rs b/pkgs/id/src/world_net.rs index c844eac482..8472fa9d50 100644 --- a/pkgs/id/src/world_net.rs +++ b/pkgs/id/src/world_net.rs @@ -1028,7 +1028,13 @@ impl WorldClient { match reply["type"].as_str() { Some("world_state") => { let seed = match reply.get("seed") { - None => None, + // Absent, or null: the host serializes a hidden seed + // as null (`ServerFrame::WorldState.seed` is an + // `Option` with no skip-serializing, and both + // host reply paths set it to + // `admin_ok.then_some(seed)`), so null is the + // legitimate capability-only shape (#240). + None | Some(serde_json::Value::Null) => None, Some(value) => Some(value.as_u64().context("host sent a malformed seed")?), }; Ok(( @@ -2758,8 +2764,10 @@ mod tests { fn world_state_reply_requires_a_u64_seed_when_present() { // Issue #6626: a present-but-mistyped `seed` must error, not // silently read as the capability-only `None` (which the - // manifest-capture consumer then bakes in as seed 0). Only a - // genuinely absent seed is `None` (#240 seed-hiding). Driven + // manifest-capture consumer then bakes in as seed 0). Only an + // absent seed is `None` outright; a null seed is also `None`, + // because that is how the host serializes a hidden seed + // (`ServerFrame::WorldState.seed`, #240 seed-hiding). Driven // through the factored reply parser manifest_state() uses. let parse = WorldClient::parse_world_state_reply; @@ -2776,6 +2784,13 @@ mod tests { .unwrap(); assert_eq!(seed, None); assert!(schedules.is_empty()); + // The host's actual capability-only shape: `"seed": null`. + let (seed, schedules) = parse(&serde_json::json!({ + "type": "world_state", "seed": null, "schedules": {"b": 2}, + })) + .unwrap(); + assert_eq!(seed, None); + assert_eq!(schedules.get("b"), Some(&2)); // Every mistyped shape errors and names the malformed seed. for bad in [ @@ -2785,7 +2800,6 @@ mod tests { serde_json::json!({}), serde_json::json!([]), serde_json::json!(true), - serde_json::Value::Null, ] { let err = parse(&serde_json::json!({ "type": "world_state", "seed": bad, "schedules": {}, From 5b53b65ca71896fd50a311f7bc8f9bb4cf9ff849 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 22:11:40 -0600 Subject: [PATCH 3/3] test(id/world_net): property coverage for the world_state reply parser (#6626) Codex P1 on PR #6714 (second round): the parser regression coverage was example-only. Add world_state_reply_seed_and_schedule_invariants (proptest, oracle: the typed ServerFrame::WorldState contract) hammering arbitrary u64 seeds and schedule maps (preserved verbatim), null seeds (read as None), and non-numeric seed types (refused as malformed). world_net suite 30/30 on the laptop. --- pkgs/id/src/world_net.rs | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/pkgs/id/src/world_net.rs b/pkgs/id/src/world_net.rs index 8472fa9d50..9e8b21bc43 100644 --- a/pkgs/id/src/world_net.rs +++ b/pkgs/id/src/world_net.rs @@ -2829,6 +2829,58 @@ mod tests { assert!(err.to_string().contains("admin token refused"), "{err}"); } + // Property coverage for the same parser (repo testing doctrine: + // a parser's invariants are stated once and hammered with + // generated inputs, not just the examples above). Oracle: the + // typed frame contract — `ServerFrame::WorldState.seed` is an + // `Option` on the wire (a u64, or null when the host hides + // the seed, #240), and `schedules` is a string→u64 map that + // passes through untouched. + proptest! { + #[test] + fn world_state_reply_seed_and_schedule_invariants( + seed in any::(), + schedules in proptest::collection::btree_map(any::(), any::(), 0..8), + mistyped in prop_oneof![ + any::().prop_map(serde_json::Value::from), + any::().prop_map(serde_json::Value::from), + proptest::collection::vec(any::(), 0..4) + .prop_map(serde_json::Value::from), + proptest::collection::hash_map(any::(), any::(), 0..4) + .prop_map(|m| serde_json::to_value(m).unwrap()), + ], + ) { + let frame = |seed_value: serde_json::Value| { + serde_json::json!({ + "type": "world_state", + "seed": seed_value, + "schedules": serde_json::to_value(&schedules).unwrap(), + }) + }; + // A valid u64 seed is preserved; the schedule map passes + // through verbatim. + let (parsed_seed, parsed_schedules) = + WorldClient::parse_world_state_reply(&frame(serde_json::Value::from(seed))) + .unwrap(); + prop_assert_eq!(parsed_seed, Some(seed)); + prop_assert_eq!(parsed_schedules, schedules.clone()); + // Null (the host's hidden-seed shape) reads as None. + let (parsed_seed, _) = + WorldClient::parse_world_state_reply(&frame(serde_json::Value::Null)).unwrap(); + prop_assert_eq!(parsed_seed, None); + // Any other seed type is refused as malformed. + let result = WorldClient::parse_world_state_reply(&frame(mistyped)); + prop_assert!(result.is_err()); + prop_assert!( + result + .err() + .unwrap() + .to_string() + .contains("malformed seed") + ); + } + } + #[test] fn caps_reply_requires_a_valid_report() { // Issue #6624: a `caps` frame carrying no valid CapsReport must