From 649e3683d173df21e9c60c03fb3101ac30348d9d Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 03:04:10 -0600 Subject: [PATCH 1/3] fix(id): validate world manifest profile bounds and schedule count at parse time (#3015) WorldManifest::validate() never checked the requested execution profile or the number of pending schedules, so a manifest could parse and plan clean, then fail partway through a live apply when resolve() refused the bounds. - Extract the six bound checks from WorldExecutionProfile::resolve() into WorldExecutionProfile::validate() in id-core; resolve() calls it, so apply-time and parse-time enforcement can never drift. - WorldManifest::validate() now runs profile.validate() and refuses a schedules map longer than MAX_PENDING_SCHEDULES (64). - Parse-level regression tests: each invalid bound rejected, the boundary-valid minima (64 KiB Wasm / 16 MiB native) accepted, 64 schedules accepted and 65 rejected. --- pkgs/id/crates/id-core/src/world_limits.rs | 19 +++++- pkgs/id/src/world_manifest.rs | 67 +++++++++++++++++++++- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/pkgs/id/crates/id-core/src/world_limits.rs b/pkgs/id/crates/id-core/src/world_limits.rs index d71e6f6507..3afd1e75aa 100644 --- a/pkgs/id/crates/id-core/src/world_limits.rs +++ b/pkgs/id/crates/id-core/src/world_limits.rs @@ -141,7 +141,19 @@ impl WorldExecutionProfile { /// /// A requested bound of zero or a value that cannot be represented on /// this host. - pub fn resolve(self, hard: RuntimeLimits) -> Result { + /// Validate the requested bounds on their own: every bound that is set + /// must be positive and at or above its floor. inherits the + /// server ceiling and is always valid. + /// + /// This is the single source of truth for the bound checks: [] + /// runs it against the live profile at apply time, and the world + /// manifest validator runs it at parse time, so a manifest can never + /// accept bounds that apply would later refuse (#3015). + /// + /// # Errors + /// + /// Names the first offending bound. + pub fn validate(&self) -> Result<()> { ensure!(self.wasm_fuel != Some(0), "world Wasm fuel must be nonzero"); ensure!( self.wasm_memory_bytes.is_none_or(|bytes| bytes >= 64 * KIB), @@ -164,6 +176,11 @@ impl WorldExecutionProfile { self.native_call_deadline_ms != Some(0), "world native call deadline must be nonzero" ); + Ok(()) + } + + pub fn resolve(self, hard: RuntimeLimits) -> Result { + self.validate()?; #[cfg(feature = "sandbox")] let sandbox = { diff --git a/pkgs/id/src/world_manifest.rs b/pkgs/id/src/world_manifest.rs index aaf8940817..d8b8795644 100644 --- a/pkgs/id/src/world_manifest.rs +++ b/pkgs/id/src/world_manifest.rs @@ -17,7 +17,9 @@ use std::path::PathBuf; use anyhow::{Result, ensure}; use serde::{Deserialize, Serialize}; -use crate::world_caps::{MAX_NAME_BYTES, validate_ceiling_names, validate_grant_names}; +use crate::world_caps::{ + MAX_NAME_BYTES, MAX_PENDING_SCHEDULES, validate_ceiling_names, validate_grant_names, +}; use crate::world_limits::WorldExecutionProfile; /// A declarative description of a world. Fields the manifest omits are left @@ -204,7 +206,9 @@ fn reject_unknown_profile_keys(text: &str) -> Result<()> { impl WorldManifest { /// Validate the manifest: grants and ceiling name only known capabilities, - /// schedule ids are bounded printable ASCII, and fire times are positive. + /// the requested profile bounds satisfy the execution-profile floors, the + /// schedule count is within the pending-schedule cap, schedule ids are + /// bounded printable ASCII, and fire times are positive. /// /// # Errors /// @@ -216,7 +220,17 @@ impl WorldManifest { if let Some(ceiling) = &self.ceiling { validate_ceiling_names(ceiling)?; } + // The requested profile bounds are refused here, at parse time, + // with the same checks resolve() runs at apply time — an invalid + // manifest must never parse and plan clean, then fail partway + // through a live apply (#3015). + self.profile.validate()?; if let Some(schedules) = &self.schedules { + ensure!( + schedules.len() <= MAX_PENDING_SCHEDULES, + "too many schedules: {} exceeds the maximum of {MAX_PENDING_SCHEDULES} pending schedules", + schedules.len() + ); for (id, at_ms) in schedules { crate::world_caps::validate_schedule_id(id)?; ensure!(*at_ms > 0, "schedule {id:?} must fire in the future"); @@ -537,6 +551,55 @@ wasm_fuel = 5_000_000 assert!(format!("{err}").contains("wasm_fuell"), "{err}"); } + #[test] + fn invalid_profile_bounds_are_rejected() { + // #3015: each bound resolve() refuses at apply time must already + // fail parse(), with the same checks. + for text in [ + "[profile] +wasm_fuel = 0", + "[profile] +wasm_memory_bytes = 1024", + "[profile] +wasm_message_bytes = 0", + "[profile] +native_memory_bytes = 1024", + "[profile] +native_cpu_seconds = 0", + "[profile] +native_call_deadline_ms = 0", + ] { + assert!(parse(text).is_err(), "parsed clean: {text}"); + } + } + + #[test] + fn minimum_profile_bounds_are_accepted() { + // #3015: the boundary-valid values (one Wasm page, 16 MiB native) + // sit exactly on the floors and must parse. + let manifest = parse("[profile] +wasm_memory_bytes = 65536 +native_memory_bytes = 16777216") + .unwrap(); + assert_eq!(manifest.profile.wasm_memory_bytes, Some(65_536)); + assert_eq!(manifest.profile.native_memory_bytes, Some(16_777_216)); + } + + #[test] + fn schedule_count_is_capped_at_parse() { + // #3015: a manifest may declare at most MAX_PENDING_SCHEDULES + // pending schedules; one more must fail parse, not a live apply. + let build = |count: usize| { + let entries: Vec = (0..count) + .map(|i| format!(""s{i}" = 1800000000000")) + .collect(); + format!("schedules = {{ {} }}", entries.join(", ")) + }; + assert!(parse(&build(MAX_PENDING_SCHEDULES)).is_ok()); + let err = parse(&build(MAX_PENDING_SCHEDULES + 1)).unwrap_err(); + assert!(format!("{err}").contains("too many schedules"), "{err}"); + } + #[test] fn full_width_u64_values_still_parse() { // Regression (Codex review of the fix for this issue): the From 22291238886d9de69bcd42ac7b7b1c8fd5be7365 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 05:57:41 -0600 Subject: [PATCH 2/3] fix(id): repair format string in schedule-count parse test (#3015) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The schedule_count_is_capped_at_parse test built its entries with an unescaped quote (format!(""s{i}" = ...")), so the id lib test target did not compile: cargo error at world_manifest.rs:594, expected comma, found {. CI on PR #4294 has been QUEUED since 2026-11-02T09:04Z and never caught it; found by running the targeted tests on the laptop this shift. Escape the quotes. Targeted tests now pass: cargo test --manifest-path pkgs/id/Cargo.toml --lib world_manifest::tests — 17 passed. --- pkgs/id/src/world_manifest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/id/src/world_manifest.rs b/pkgs/id/src/world_manifest.rs index d8b8795644..5b1b796826 100644 --- a/pkgs/id/src/world_manifest.rs +++ b/pkgs/id/src/world_manifest.rs @@ -591,7 +591,7 @@ native_memory_bytes = 16777216") // pending schedules; one more must fail parse, not a live apply. let build = |count: usize| { let entries: Vec = (0..count) - .map(|i| format!(""s{i}" = 1800000000000")) + .map(|i| format!("\"s{i}\" = 1800000000000")) .collect(); format!("schedules = {{ {} }}", entries.join(", ")) }; From 25c17efa5b03404706e68f9548094e49edc25bec Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 06:11:04 -0600 Subject: [PATCH 3/3] test(id): prefix new world_manifest tests with test_ (#3015) Codex P1 on PR #4294 (head 222912388): pkgs/id/AGENTS.md requires test_ prefix for test functions. Rename test_invalid_profile_bounds_are_rejected, test_minimum_profile_bounds_are_accepted, test_schedule_count_is_capped_at_parse accordingly. Targeted tests re-run on laptop: 17 passed. --- pkgs/id/src/world_manifest.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/id/src/world_manifest.rs b/pkgs/id/src/world_manifest.rs index 5b1b796826..cfeb7be915 100644 --- a/pkgs/id/src/world_manifest.rs +++ b/pkgs/id/src/world_manifest.rs @@ -552,7 +552,7 @@ wasm_fuel = 5_000_000 } #[test] - fn invalid_profile_bounds_are_rejected() { + fn test_invalid_profile_bounds_are_rejected() { // #3015: each bound resolve() refuses at apply time must already // fail parse(), with the same checks. for text in [ @@ -574,7 +574,7 @@ native_call_deadline_ms = 0", } #[test] - fn minimum_profile_bounds_are_accepted() { + fn test_minimum_profile_bounds_are_accepted() { // #3015: the boundary-valid values (one Wasm page, 16 MiB native) // sit exactly on the floors and must parse. let manifest = parse("[profile] @@ -586,7 +586,7 @@ native_memory_bytes = 16777216") } #[test] - fn schedule_count_is_capped_at_parse() { + fn test_schedule_count_is_capped_at_parse() { // #3015: a manifest may declare at most MAX_PENDING_SCHEDULES // pending schedules; one more must fail parse, not a live apply. let build = |count: usize| {