fix(halogen): refuse a start the host cannot hold, so the router evicts

Halogen sizes its pool from MemTotal, blind to other models, and on a host
short of its weights plus that pool it stalls in the kernel instead of
failing. It now refuses below the weights plus min_resident_gb of
MemAvailable, so the router evicts the other models and retries, as DS4
does. A GTT-only check misses a 22 GB llama.cpp co-tenant.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Jeremy FowersandClaude Opus 5.5 committed 2026-10-30 10:39:38 -04:00
1 parent bed5893b6e
commit 84c23c2862
1 file changed
+21
@@ -6,6 +6,7 @@
#include "lemon/backends/halogen/halogen.h"
#include "lemon/model_manager.h"
#include "lemon/system_info.h"
#include "lemon/system_metrics_platform.h"
#include "lemon/utils/container_manager.h"
#include "lemon/utils/http_client.h"
@@ -13,6 +14,7 @@
#include <algorithm>
#include <filesystem>
#include <iomanip>
#include <map>
#include <sstream>
#include <stdexcept>
@@ -165,6 +167,25 @@ void HalogenServer::load(const std::string& model_name, const ModelInfo& model_i
}
}
// Halogen sizes its KV pool from MemTotal, blind to other models, and on a
// host already short of the weights plus that pool it stalls in the kernel
// instead of failing. Failing here lets the router evict the other models
// and retry. The lookup table is paged on demand and needs no room.
if (model_info.min_resident_gb > 0.0) {
double weights_gb = fs::file_size(checkpoint) / BYTES_PER_GIB;
if (!vision.empty()) weights_gb += fs::file_size(vision) / BYTES_PER_GIB;
const double needed_gb = weights_gb + model_info.min_resident_gb;
const auto metrics = create_metrics_platform();
const double total_gb = metrics ? metrics->get_memory_total_gb() : 0.0;
const double free_gb = total_gb - (metrics ? metrics->get_memory_usage_gb() : 0.0);
if (total_gb > 0.0 && free_gb < needed_gb) {
std::ostringstream message;
message << std::fixed << std::setprecision(1) << "halogen needs " << needed_gb
<< " GiB of free memory to start, and " << free_gb << " GiB is free";
throw std::runtime_error(message.str());
}
}
const json ctx_option = options.get_option("ctx_size");
const int ctx_size = ctx_option.is_number_integer() && ctx_option.get<int>() > 0
? ctx_option.get<int>()