Skip to content
Merged
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
50 changes: 25 additions & 25 deletions lib/llm/src/local_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const DEFAULT_KV_CACHE_BLOCK_SIZE: u32 = 16;
/// 'pub' because the bindings use it for consistency.
pub const DEFAULT_HTTP_PORT: u16 = 8080;

/// Default for `LocalModelBuilder::self_host_metadata`. Truthy values opt in.
/// Default for `LocalModelBuilder::self_host_metadata`. On by default;
/// set to an explicitly falsy value (`0`/`false`/`no`/`off`) to opt out.
pub const ENV_SELF_HOST_METADATA: &str = "DYN_SELF_HOST_METADATA";

fn env_self_host_metadata_default() -> bool {
Expand All @@ -46,7 +47,10 @@ fn env_self_host_metadata_default() -> bool {
}

fn self_host_metadata_default(value: Option<&str>) -> bool {
value.is_some_and(dynamo_runtime::config::is_truthy)
// Unset, empty, and unrecognized values keep the default-on behavior.
value
.and_then(dynamo_runtime::config::parse_bool_opt)
.unwrap_or(true)
}

pub struct LocalModelBuilder {
Expand Down Expand Up @@ -207,8 +211,7 @@ impl LocalModelBuilder {
self
}

/// Opt in or out of self-hosting MDC artifacts. Default `false`.
/// Set this at runtime with environment variable DYN_SELF_HOST_METADATA.
/// Opt in or out of self-hosting MDC artifacts. Default `true`.
pub fn self_host_metadata(&mut self, enabled: bool) -> &mut Self {
Comment on lines +214 to 215

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Python binding default still defers to env, so default flips there too

lib/bindings/python/rust/lib.rs:625-626 only calls builder.self_host_metadata(...) when the Python caller passes an explicit value, so all Python-side registrations inherit the new default-on behavior via LocalModelBuilder::default(). That is consistent with the intent, but it means every Python worker without DYN_SYSTEM_PORT set now takes the fallback branch and emits the new warning — worth confirming deployment manifests set DYN_SYSTEM_PORT for the release branch.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

self.self_host_metadata = enabled;
self
Expand Down Expand Up @@ -659,12 +662,15 @@ impl LocalModel {
let component = endpoint.component().name().to_string();
let endpoint_name = endpoint.name().to_string();
let Some(base_url) = self_host_base_url(drt)? else {
tracing::warn!(
model_slug = %self.card.slug(),
"self_host_metadata enabled but system_status_server is not \
running (DYN_SYSTEM_PORT unset); skipping http rewrites — \
set DYN_SYSTEM_PORT to enable",
);
static WARNED: std::sync::Once = std::sync::Once::new();
WARNED.call_once(|| {
tracing::warn!(
"self_host_metadata is ON but DYN_SYSTEM_PORT is unset; \
falling back to shared-storage MDC. Set DYN_SYSTEM_PORT \
(e.g. 9090) to enable self-hosting, or set \
DYN_SELF_HOST_METADATA=0 to silence this warning.",
);
});
return Ok(());
};
let model_slug = self.card.slug().to_string();
Expand Down Expand Up @@ -860,24 +866,18 @@ fn harvest_extra_files(
}

#[cfg(test)]
mod env_self_host_metadata_tests {
mod self_host_metadata_default_tests {
use super::*;

// parse_bool_opt owns the falsy/truthy vocabulary (tested in the `truthy`
// crate); here we only lock the default-on inversion this flag introduced:
// anything that isn't an explicit falsy token stays ON.
#[test]
fn env_default_parsing() {
assert!(!self_host_metadata_default(None), "unset → default OFF");

for v in [
"0", "false", "FALSE", "no", "NO", "off", "OFF", "", "garbage",
] {
assert!(
!self_host_metadata_default(Some(v)),
"expected OFF for {v:?}"
);
}
for v in ["1", "true", "TRUE", "yes", "Yes", "on", "ON"] {
assert!(self_host_metadata_default(Some(v)), "expected ON for {v:?}");
}
fn defaults_on_unless_explicitly_falsy() {
assert!(self_host_metadata_default(None)); // unset
assert!(self_host_metadata_default(Some(""))); // empty
assert!(self_host_metadata_default(Some("garbage"))); // unrecognized
assert!(!self_host_metadata_default(Some("false"))); // explicit opt-out
}
}

Expand Down
Loading