From abf6bec203b64b4669d58f95c2c58699fdd2bdc1 Mon Sep 17 00:00:00 2001 From: Jeong Min Oh Date: Sun, 29 Nov 2026 19:57:07 +0900 Subject: [PATCH] fix(runtime): round 50 core/jni/inprocess findings - multipart: MeteredField and TryFromFieldWithState docs now describe the cooperative aggregate count (reads on the extractor task are counted; reads moved off that task are not), matching register_multipart_bytes. - vespera_core: the Reference Object module doc lists Link Objects as accepting a $ref (kept as raw JSON). - vespera tests: the oversized path value comment states the real bound (MAX_ENVELOPE_MESSAGE_CHARS), not the 64 KiB hoist cap. - vespera_jni daemon_env: the module doc says a resuming worker finds its own thread-local cell (empty or holding its own record). - vespera_jni runtime-config test: the first-set worker-count assertion runs in a child process, so it no longer depends on test order. Co-Authored-By: Claude Opus 5.5 --- .../changepack_log_runtime_round50.json | 1 + crates/vespera/src/multipart/mod.rs | 20 ++++++++------ .../tests/validated_form_query_path.rs | 5 ++-- crates/vespera_core/src/route.rs | 6 ++--- crates/vespera_jni/src/daemon_env.rs | 7 ++--- .../src/jni_impl_runtime_config_tests.rs | 26 +++++++++++++++++++ 6 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 .changepacks/changepack_log_runtime_round50.json diff --git a/.changepacks/changepack_log_runtime_round50.json b/.changepacks/changepack_log_runtime_round50.json new file mode 100644 index 000000000..414483115 --- /dev/null +++ b/.changepacks/changepack_log_runtime_round50.json @@ -0,0 +1 @@ +{"changes":{"crates/vespera/Cargo.toml":"Patch","crates/vespera_core/Cargo.toml":"Patch","crates/vespera_macro/Cargo.toml":"Patch","crates/vespera_inprocess/Cargo.toml":"Patch","crates/vespera_jni/Cargo.toml":"Patch","libs/vespera-bridge/build.gradle.kts":"Patch","libs/vespera-bridge-gradle-plugin/build.gradle.kts":"Patch"},"note":"Docs and test robustness only: the multipart MeteredField and TryFromFieldWithState docs now describe the cooperative aggregate count (reads on the extractor task), the Link Object reference rule is documented in vespera_core, the daemon_env TLS module doc matches the per-thread cell behaviour, and the runtime-config JNI test runs in a child process.","date":"2026-11-29T00:00:00.000Z"} diff --git a/crates/vespera/src/multipart/mod.rs b/crates/vespera/src/multipart/mod.rs index 1224c7a66..1bde094ff 100644 --- a/crates/vespera/src/multipart/mod.rs +++ b/crates/vespera/src/multipart/mod.rs @@ -53,14 +53,16 @@ pub trait TryFromMultipartWithState: Sized { } /// A multipart [`Field`] wrapper that meters every byte read against the -/// request-wide `max_total_bytes` aggregate cap — **non-cooperatively**. +/// request-wide `max_total_bytes` aggregate cap — **cooperatively**: the count +/// lives in a task-local of the extractor's task (see +/// [`register_multipart_bytes`]). /// /// `#[derive(Multipart)]` hands each [`TryFromFieldWithState`] parser a /// `MeteredField` instead of a raw [`Field`], so a **custom** field parser that -/// reads bytes via [`MeteredField::chunk`] / [`MeteredField::bytes`] is -/// accounted automatically: it can no longer read unboundedly past the -/// configured `max_total_bytes` the way a raw `field.chunk()` could. The -/// metadata accessors delegate to the wrapped field. +/// reads bytes via [`MeteredField::chunk`] / [`MeteredField::bytes`] on the +/// extractor's task is accounted automatically, as a raw `field.chunk()` would +/// have been on that task. Reading off that task (on another task or thread) +/// is not counted. The metadata accessors delegate to the wrapped field. pub struct MeteredField<'a> { inner: Field<'a>, } @@ -181,9 +183,11 @@ impl From<&MeteredField<'_>> for FieldMetadata { pub trait TryFromFieldWithState: Sized { /// Parse a single field into `Self`, optionally enforcing a byte-size limit. /// - /// The field arrives as a [`MeteredField`]: every byte read through it - /// counts against the request-wide `max_total_bytes` aggregate cap, so even - /// a hand-written custom parser cannot bypass the limit. + /// The field arrives as a [`MeteredField`]: every byte read through it on + /// the extractor's task counts against the request-wide `max_total_bytes` + /// aggregate cap, so a hand-written custom parser that reads on that task + /// cannot bypass it. A parser that moves its reads off that task is not + /// counted toward the aggregate; the per-field `limit_bytes` still applies. fn try_from_field_with_state( field: MeteredField<'_>, limit_bytes: Option, diff --git a/crates/vespera/tests/validated_form_query_path.rs b/crates/vespera/tests/validated_form_query_path.rs index a2814f317..d103249fd 100644 --- a/crates/vespera/tests/validated_form_query_path.rs +++ b/crates/vespera/tests/validated_form_query_path.rs @@ -508,8 +508,9 @@ async fn data_errors_map_to_the_envelope_path(#[case] uri: &str, #[case] expecte /// wire hoist cap) instead of echoing 70 KiB back. #[tokio::test] async fn an_oversized_path_value_is_bounded_in_the_envelope_message() { - // Long enough to echo back past the 64 KiB hoist cap, short enough for - // `http::Uri` (it rejects a URI over 65535 bytes). + // Far longer than the 256-char envelope message cap + // (`MAX_ENVELOPE_MESSAGE_CHARS`), so the raw parse message would be huge; + // short enough for `http::Uri` (it rejects a URI over 65535 bytes). let segment = "a".repeat(60_000); let (status, body) = send(get_req(&format!("/num/{segment}"))).await; assert_eq!(status, 422); diff --git a/crates/vespera_core/src/route.rs b/crates/vespera_core/src/route.rs index e0360f334..b79547b1b 100644 --- a/crates/vespera_core/src/route.rs +++ b/crates/vespera_core/src/route.rs @@ -2,8 +2,9 @@ //! //! # Reference Objects //! -//! Only schema positions ([`SchemaRef`]) and Path Item objects -//! ([`PathItem::ref_path`]) accept an OpenAPI Reference Object +//! Only schema positions ([`SchemaRef`]), Path Item objects +//! ([`PathItem::ref_path`]) and Link Objects ([`Link`], kept as raw JSON, so +//! a referenced link round-trips) accept an OpenAPI Reference Object //! (`{"$ref": ...}`). [`Parameter`], [`RequestBody`], [`Response`], //! [`Header`], [`Example`] and [`SecurityScheme`](crate::schema::SecurityScheme) //! are always inline, and so is a [`Callback`] @@ -17,7 +18,6 @@ //! object. Inline those references before loading such a document into //! [`crate::openapi::OpenApi`]. Accepting them would need a `RefOr` in //! every such field, a breaking change of these public types. -//! ([`Link`] is raw JSON, so a referenced link round-trips.) use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; diff --git a/crates/vespera_jni/src/daemon_env.rs b/crates/vespera_jni/src/daemon_env.rs index e64afe65c..046070820 100644 --- a/crates/vespera_jni/src/daemon_env.rs +++ b/crates/vespera_jni/src/daemon_env.rs @@ -42,9 +42,10 @@ //! is replaced (detaching the old one) before attaching to the new one. //! //! A future polled across `.await` points may resume on a different -//! worker thread; that thread simply finds an empty TLS cell and -//! resolves its own env, so correctness does not depend on thread -//! affinity — only the amortised attach count does. +//! worker thread; that thread finds its own thread-local cell (empty, or +//! holding that thread's own record) and resolves its env there, so +//! correctness does not depend on thread affinity — only the amortised +//! attach count does. use std::cell::RefCell; use std::ffi::c_void; diff --git a/crates/vespera_jni/src/jni_impl_runtime_config_tests.rs b/crates/vespera_jni/src/jni_impl_runtime_config_tests.rs index 405539fe3..25f31e5b5 100644 --- a/crates/vespera_jni/src/jni_impl_runtime_config_tests.rs +++ b/crates/vespera_jni/src/jni_impl_runtime_config_tests.rs @@ -2,8 +2,34 @@ use super::{runtime_worker_threads, set_runtime_worker_threads}; /// One test owns the process-global `OnceLock`: setter wins, /// clamping applies, and later writes are rejected. +/// +/// Runs in a CHILD process: the worker-count `OnceLock` is process-global, and +/// another in-process test (or a future one) that sets it first would make the +/// first-set assertion order-dependent. The child runs only this test. #[test] fn setter_fixes_clamped_value_first_wins() { + const CHILD_ENV: &str = "VESPERA_JNI_RUNTIME_CONFIG_TEST_CHILD"; + if std::env::var_os(CHILD_ENV).is_none() { + let output = std::process::Command::new( + std::env::current_exe().expect("current unit-test executable"), + ) + .args([ + "--exact", + "jni_impl::runtime_config_tests::setter_fixes_clamped_value_first_wins", + "--nocapture", + ]) + .env(CHILD_ENV, "1") + .output() + .expect("run isolated runtime-config child test"); + assert!( + output.status.success() && String::from_utf8_lossy(&output.stdout).contains("1 passed"), + "isolated runtime-config test failed:\nstdout:\n{}\nstderr:\n{}", + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); + return; + } + assert!(set_runtime_worker_threads(99_999), "first set must win"); assert_eq!( runtime_worker_threads(),