Skip to content
Open
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_round41.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_inprocess/Cargo.toml":"Patch","crates/vespera_jni/Cargo.toml":"Patch","crates/vespera_macro/Cargo.toml":"Patch","libs/vespera-bridge/build.gradle.kts":"Patch","libs/vespera-bridge-gradle-plugin/build.gradle.kts":"Patch"},"note":"Runtime round 41. vespera_jni: the DIRECT overflow stash never evicts an entry before its 30 s TTL (a live response awaiting redemption was evicted under count or byte pressure, so its fetch or stream failed after the handler had run); only expired entries are swept, and a fresh overflow is refused with a retryable 503 only past the hard ceilings (4096 entries, 1 GiB). vespera_inprocess: try_on_shared_runtime refuses a hook once the shared runtime build has failed (cron reports it instead of claiming it accepted); the RequestEnvelope headers single-value limit is documented. vespera_core: OpenApi::merge ignores an empty webhooks map from the other side; unescape_schema_name doc states the lossy UTF-8 replacement. Docs only: the DirectStash and StashedOverflowException javadoc describe the retention and fetch0 contract.","date":"2026-11-24T00:00:00.000Z"}
4 changes: 3 additions & 1 deletion crates/vespera_core/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,9 @@ impl OpenApi {

// Webhooks: union by name, self-wins on a name conflict. Before the
// components move below: an adopted reference reads `path_items`.
if let Some(other_webhooks) = other.webhooks {
// An empty map adds nothing (as `merge_component_map` does), so a
// `Some({})` from the other side does not turn a `None` into `Some({})`.
if let Some(other_webhooks) = non_empty_component_map(other.webhooks) {
let self_webhooks = self.webhooks.get_or_insert_with(BTreeMap::new);
for (name, mut item) in other_webhooks {
if name_clash && let Some(path_items) = path_items {
Expand Down
15 changes: 15 additions & 0 deletions crates/vespera_core/src/openapi/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,21 @@ fn merge_adopts_webhooks_when_self_has_none() {
assert!(base.webhooks.unwrap().contains_key("hook"));
}

/// R41-CJ1-L1: an empty `webhooks` map on the other side adds nothing, so a
/// `None` receiver stays `None` (no empty `webhooks` object is serialized).
#[test]
fn merge_ignores_an_empty_webhooks_map_from_other() {
let mut base = create_base_openapi();
let mut other = create_base_openapi();
other.webhooks = Some(BTreeMap::new());

base.merge(other);

assert!(base.webhooks.is_none(), "an empty map must not be adopted");
let value = serde_json::to_value(&base).unwrap();
assert!(value.get("webhooks").is_none());
}

/// Round 14: a `3.0.x` document's body is read into 3.1 shapes, so its
/// version is read as `3.1.0` too (a hand-built `3.0.x` still serializes).
#[rstest]
Expand Down
4 changes: 3 additions & 1 deletion crates/vespera_core/src/schema/schema_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ pub fn escape_schema_name(name: &str) -> String {

/// Inverse of [`escape_schema_name`]: percent-decode, then undo the JSON
/// Pointer escaping. A `%` not followed by two hex digits, or a `~` that is
/// not part of `~0` / `~1`, is kept as written.
/// not part of `~0` / `~1`, is kept as written. Decoded bytes that are not
/// valid UTF-8 are replaced lossily (each invalid sequence becomes U+FFFD),
/// so the result is always a valid `String`.
#[must_use]
pub fn unescape_schema_name(segment: &str) -> String {
pointer_unescape(&percent_decode(segment.as_bytes()))
Expand Down
6 changes: 6 additions & 0 deletions crates/vespera_inprocess/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ pub struct RequestEnvelope {
/// UTF-8 text arrives as the bytes `63 61 66 E9`, not `63 61 66 C3 A9`.
/// A value with a `char` above `U+00FF` keeps its UTF-8 bytes. Send
/// ASCII header values when the exact bytes matter.
///
/// Single value per name: a map cannot carry a repeated header, so when a
/// name repeats the last value wins (serde keeps the last entry). The
/// binary wire API keeps every repeat (`header_read.rs`). Changing this
/// field's type would be a semver break, so the limit is documented here
/// instead.
#[serde(default)]
pub headers: HashMap<String, String>,
#[serde(default)]
Expand Down
49 changes: 45 additions & 4 deletions crates/vespera_inprocess/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,15 @@ pub fn on_shared_runtime(hook: RuntimeHook) {
}

/// [`on_shared_runtime`], reporting whether the hook was accepted. `false`
/// once [`shutdown_runtime`] has closed the runtime: the hook is dropped and
/// never runs, so a caller that claimed its work (cron's per-job claims)
/// must release it.
/// once [`shutdown_runtime`] has closed the runtime, and `false` once the
/// runtime build has failed (no flush would ever run the hook): the hook is
/// dropped and never runs, so a caller that claimed its work (cron's per-job
/// claims) must release it.
#[must_use]
pub fn try_on_shared_runtime(hook: RuntimeHook) -> bool {
if matches!(RUNTIME.get(), Some(None)) {
return false;
}
let accepted = lock_hooks().push(hook);
if accepted {
HOOKS_PENDING.store(true, Ordering::SeqCst);
Expand All @@ -451,7 +455,8 @@ pub fn try_on_shared_runtime(hook: RuntimeHook) -> bool {
accepted
}

/// Build the runtime now when hooks wait for it. Returns whether it runs.
/// Build the runtime now when hooks wait for it. Returns whether it runs
/// (`false` as well when the build has already failed).
pub fn start_runtime_for_hooks() -> bool {
HOOKS_PENDING.load(Ordering::SeqCst) && runtime().is_some()
}
Expand Down Expand Up @@ -563,4 +568,40 @@ mod tests {
assert!(!start_runtime_for_hooks());
assert!(!RAN.load(Ordering::SeqCst), "a refused hook never runs");
}

/// R41-IP1-L1. A runtime build that failed (`RUNTIME` settled as `None`
/// while the gate stays open) refuses a hook: nothing would ever flush it,
/// so the caller (cron) must take its error path, not report it accepted.
/// Child process: it settles the process-global runtime slot.
#[test]
#[cfg_attr(miri, ignore = "re-executes the test binary as a child process")]
fn hooks_are_refused_after_a_failed_build() {
static RAN: AtomicBool = AtomicBool::new(false);
const CHILD_ENV: &str = "VESPERA_RUNTIME_BUILD_FAILED_CHILD";
if std::env::var_os(CHILD_ENV).is_none() {
crate::test_child::run_isolated(
"runtime::tests::hooks_are_refused_after_a_failed_build",
CHILD_ENV,
&[],
&[],
);
return;
}
// The build failed: the slot is settled as unbuilt, the gate is open.
assert!(
RUNTIME.set(None).is_ok(),
"fresh process: nothing was built"
);
assert!(
!try_on_shared_runtime(Box::new(|_| RAN.store(true, Ordering::SeqCst))),
"a failed build refuses the hook"
);
assert!(
lock_hooks().pending.is_empty(),
"no hook is queued that no flush would take"
);
assert!(!start_runtime_for_hooks());
assert!(runtime().is_none());
assert!(!RAN.load(Ordering::SeqCst), "a refused hook never runs");
}
}
4 changes: 3 additions & 1 deletion crates/vespera_inprocess/tests/tracing_instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ fn unknown_app_is_a_rejected_request() {
});
assert_eq!(status_of(&resp), 404);
let span = capture.dispatch_span();
// The raw client value of an app that did not resolve is never recorded.
// Only the span's `app` field withholds the raw client value of an app
// that did not resolve; the WARN event's detail text (the 404 "no app
// registered with name ..." message) does name it.
assert_eq!(field(&span, "app"), "<unset>");
assert_eq!(field(&span, "status"), "404");
assert_eq!(
Expand Down
Loading
Loading