Files
huskies/server/src/agents/pool/pipeline/merge/time.rs
T
TimmyandClaude Fable 5 f39c4b7c4b Remove all alternate update paths — fleet redeploy is release + upgrade all
Killed:
- rebuild_and_restart (in-container cargo self-compile): the MCP tool,
  the `rebuild` chat command in all four transports, the web-ui bot
  command, and the underlying function. This was the path that caused
  the exec() deadlocks.
- upgrade_sled gateway MCP tool: second entry point to sled upgrades,
  defaulted to serving the gateway's own macOS binary to Linux sleds.
- GET /api/huskies-binary (both sled and gateway route trees): served
  current_exe(), wrong platform when the gateway is macOS. Superseded
  by /api/artifacts/ which now also serves on the gateway route tree.
- `huskies upgrade` CLI subcommand and --source flag: third way of
  doing the same download-and-replace. Escape hatch for a bricked sled
  is `docker cp` + restart.

Kept, distinct jobs: `project-rebuild` (container/image updates),
`rebuild gateway` + script/local-release (gateway self-update).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019fHdm92yjvguPi2LiXfLB9
2026-07-15 16:46:11 +01:00

38 lines
1.5 KiB
Rust

//! Server-start-time utilities for stale-merge detection.
/// Wall-clock time captured the first time this server process touches the
/// merge subsystem. Used to detect merge_jobs left over from a previous
/// server instance: PIDs can collide across restarts (PID 1 in a container
/// is always the server), so PID alone cannot distinguish "current" vs
/// "previous" server. This timestamp is fresh per-process and is the source
/// of truth for stale-merge detection.
static SERVER_START_TIME: std::sync::OnceLock<f64> = std::sync::OnceLock::new();
/// Return this server process's start time (lazily captured on first call).
pub(crate) fn server_start_time() -> f64 {
*SERVER_START_TIME.get_or_init(unix_now)
}
/// Encode the current server's start-time into the CRDT `error` field for
/// a Running merge job.
pub(crate) fn encode_server_start_time(t: f64) -> String {
format!("{{\"server_start\":{t}}}")
}
/// Decode the server-start-time from a Running merge job's `error` field.
/// Returns `None` for legacy entries (which encoded `pid` instead) — those
/// are treated as stale by the cleanup pass.
pub(crate) fn decode_server_start_time(error: Option<&str>) -> Option<f64> {
error
.and_then(|e| serde_json::from_str::<serde_json::Value>(e).ok())
.and_then(|v| v["server_start"].as_f64())
}
/// Current Unix timestamp in seconds as `f64`.
pub(crate) fn unix_now() -> f64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs_f64()
}