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
6 changes: 6 additions & 0 deletions crates/mesh-llm-host-runtime/src/inference/skippy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ pub(crate) struct SkippyModelStatus {
pub(crate) projector_path: Option<String>,
pub(crate) ctx_size: u32,
pub(crate) lane_count: u32,
/// Per-lane session state, possibly a frozen snapshot. Display only.
pub(crate) lanes: Vec<SkippySessionLaneStatus>,
pub(crate) max_session_tokens: u64,
/// When [`Self::lanes`] and [`Self::max_session_tokens`] were read, which
/// may be arbitrarily earlier than this status.
pub(crate) sessions_captured_at_unix_nanos: i64,
pub(crate) n_batch: Option<u32>,
pub(crate) n_ubatch: Option<u32>,
pub(crate) n_gpu_layers: i32,
Expand Down Expand Up @@ -1156,6 +1160,7 @@ fn status_from_parts(
})
.collect(),
max_session_tokens: embedded.sessions.max_session_tokens,
sessions_captured_at_unix_nanos: embedded.sessions_captured_at_unix_nanos,
n_batch: config.n_batch,
n_ubatch: config.n_ubatch,
n_gpu_layers: config.n_gpu_layers,
Expand Down Expand Up @@ -1306,6 +1311,7 @@ mod tests {
total_session_tokens: 0,
lanes: vec![],
},
sessions_captured_at_unix_nanos: 111,
telemetry: TelemetryStats {
queued: 0,
sent: 0,
Expand Down
37 changes: 36 additions & 1 deletion crates/mesh-llm-host-runtime/src/runtime/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,17 @@ impl LocalRuntimeModelHandle {
let status = model.status();
let ctx_size = status.ctx_size as u64;
let now = current_time_unix_ms();
// Lane data may be a cached snapshot, so report when it was
// captured: a wedged runtime then shows a success time that
// stops advancing instead of looking fresh every tick.
let captured_unix_ms =
unix_nanos_to_unix_ms(status.sessions_captured_at_unix_nanos).unwrap_or(now);
Some(RuntimeLlamaSlotsSnapshot {
status: RuntimeLlamaEndpointStatus::Ready,
model: Some(model_name.to_string()),
instance_id: instance_id.map(str::to_string),
last_attempt_unix_ms: Some(now),
last_success_unix_ms: Some(now),
last_success_unix_ms: Some(captured_unix_ms),
error: None,
slots: status
.lanes
Expand Down Expand Up @@ -182,6 +187,15 @@ pub(super) fn current_time_unix_ms() -> u64 {
.as_millis() as u64
}

/// Convert a unix-nanosecond capture time to unix milliseconds. `None` for a
/// non-positive input, meaning "never captured" rather than the epoch.
fn unix_nanos_to_unix_ms(unix_nanos: i64) -> Option<u64> {
u64::try_from(unix_nanos)
.ok()
.filter(|nanos| *nanos > 0)
.map(|nanos| nanos / 1_000_000)
}

pub(super) struct ManagedModelController {
pub(super) model_name: String,
pub(super) profile: String,
Expand Down Expand Up @@ -848,3 +862,24 @@ pub(super) fn skippy_stage_activation_width(activation_width: u32, model_ref: &s
)
})
}

#[cfg(test)]
mod tests {
use super::unix_nanos_to_unix_ms;

#[test]
fn unix_nanos_to_unix_ms_converts_a_real_capture_time() {
assert_eq!(
unix_nanos_to_unix_ms(1_700_000_000_123_000_000),
Some(1_700_000_000_123)
);
}

#[test]
fn unix_nanos_to_unix_ms_treats_non_positive_as_never_captured() {
// A zero or negative capture time means "never read", not "read at the
// epoch". Callers must not project 1970 as a success timestamp.
assert_eq!(unix_nanos_to_unix_ms(0), None);
assert_eq!(unix_nanos_to_unix_ms(-1), None);
}
}
Loading
Loading