Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_runtime_round50.json
Original file line number Diff line number Diff line change
@@ -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"}
20 changes: 12 additions & 8 deletions crates/vespera/src/multipart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ pub trait TryFromMultipartWithState<S: Send + Sync>: 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>,
}
Expand Down Expand Up @@ -181,9 +183,11 @@ impl From<&MeteredField<'_>> for FieldMetadata {
pub trait TryFromFieldWithState<S: Send + Sync>: 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<usize>,
Expand Down
5 changes: 3 additions & 2 deletions crates/vespera/tests/validated_form_query_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions crates/vespera_core/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Expand All @@ -17,7 +18,6 @@
//! object. Inline those references before loading such a document into
//! [`crate::openapi::OpenApi`]. Accepting them would need a `RefOr<T>` 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;
Expand Down
7 changes: 4 additions & 3 deletions crates/vespera_jni/src/daemon_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions crates/vespera_jni/src/jni_impl_runtime_config_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading