From 5c66eecc8e066b2cec0dbed3a32698314ca9693a Mon Sep 17 00:00:00 2001 From: fl0l0u Date: Sun, 15 Nov 2026 21:24:41 +0000 Subject: [PATCH] device: the stuck-exit watchdog does not fire during load scheduler.stuck-exit (2.1.0, 60 s by default everywhere) turns the stall verdict into a process exit so a restart policy can act on a hung card. The verdict watches queue read-indices and the direct-IO counter -- and a cold load moves neither: a mapped tier faulting its tables through the page cache is not counted, a barrier-waiting rank parks its index, and "zero progress for 60 s" is then a description of a big model starting, not of a hang. Under a restart policy that misfire is a crash loop with a captive audience: the same load runs on every restart, and the exit was armed from process start. The watchdog now reads dev_engine_ready: set when an Engine::start() completed once, never unset, and the exit fires only after it. A hang during the very first bringup is what it always was -- dumps, the log line, /health 503; the supervisor's hammer hits a process that has not started serving, which is exactly the case the exemption keeps it off. The verdict's own log line says which of the two futures it has, per this file's rule that a report never states less than it will do. No fast-suite test reaches the backend watchdog thread (the exit path kills the process and the watch ticks in wall-clock seconds); the config parse stays pinned by fleet_config_test and the exemption is one flag read at the fatal's gate. Found by the 2.1.0 review pass (axis: hostile sockets / runtime; the load-phase scenario is the mapped-tier fault storm the release itself describes). --- core/device/aql.cpp | 26 ++++++++++++++++++++------ core/device/device.h | 7 +++++++ core/device/dispatch.cpp | 1 + core/engine_bringup.cpp | 4 ++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/core/device/aql.cpp b/core/device/aql.cpp index dba45d63..8357ba5a 100644 --- a/core/device/aql.cpp +++ b/core/device/aql.cpp @@ -958,7 +958,11 @@ void stuck_watch() { std::this_thread::sleep_for(std::chrono::seconds(1)); const int64_t ms = stuck_ms(); const int64_t limit = rad::dev_stuck_exit_ms.load(std::memory_order_relaxed); - if (limit > 0 && ms >= limit) { + /* The load phase is exempt (device.h): a verdict standing before the first engine + * finished bringup is a slow load, not a hang, and killing on it trades a patient + * start for a crash loop. The dumps and the log line still fire -- an operator + * watching a stuck load sees the queue state exactly as before. */ + if (limit > 0 && ms >= limit && rad::dev_engine_ready.load(std::memory_order_acquire)) { dump_queues("the device"); fatal("the device has advanced nothing for %lld s (the queue dumps above name the " "packets it is stuck on); exiting so a restart can bring the server back", @@ -1008,11 +1012,21 @@ struct Stall { g_stuck_progress.store(p, std::memory_order_relaxed); g_stuck_at.store(steady_ns() - (uint64_t)kStallMs * 1000000u, std::memory_order_release); dump_queues(where); - RAD_ERR("device: nothing has advanced in the %u s since: the GPU is not running the " - "packet named above -- a hung kernel, or a queue the driver evicted and could " - "not restore (amdgpu cwsr_enable=0 is one cause). The process exits once this " - "has stood for scheduler.stuck-exit (%lld s; 0 never)", kStallMs / 1000, - (long long)(rad::dev_stuck_exit_ms.load(std::memory_order_relaxed) / 1000)); + /* The verdict says what the verdict will DO (L-02's rule: never a silent difference): + * before the first engine finished bringup the exit is not armed -- a stall standing + * during a load is a slow load (device.h's dev_engine_ready). */ + if (rad::dev_engine_ready.load(std::memory_order_acquire)) + RAD_ERR("device: nothing has advanced in the %u s since: the GPU is not running the " + "packet named above -- a hung kernel, or a queue the driver evicted and could " + "not restore (amdgpu cwsr_enable=0 is one cause). The process exits once this " + "has stood for scheduler.stuck-exit (%lld s; 0 never)", kStallMs / 1000, + (long long)(rad::dev_stuck_exit_ms.load(std::memory_order_relaxed) / 1000)); + else + RAD_ERR("device: nothing has advanced in the %u s since: the GPU is not running the " + "packet named above -- a hung kernel, or a queue the driver evicted and could " + "not restore (amdgpu cwsr_enable=0 is one cause). The engine is still in " + "bringup, so scheduler.stuck-exit is not armed yet: this verdict is reported, " + "not fatal, until the first engine has finished loading", kStallMs / 1000); if (!g_stuck_watch.exchange(true, std::memory_order_acq_rel)) std::thread(stuck_watch).detach(); return; diff --git a/core/device/device.h b/core/device/device.h index 0d9f9108..5634025a 100644 --- a/core/device/device.h +++ b/core/device/device.h @@ -454,6 +454,13 @@ int64_t dev_stuck_ms(); * reported hangs stood for hours, and a stall that clears does so within seconds. */ extern std::atomic dev_stuck_exit_ms; +/* Whether at least one engine has finished bringup. The stuck-exit watchdog reads it: a stall + * verdict standing DURING load is a slow load -- a cold start faulting a mapped tier from disk + * advances none of the counters the verdict watches, and that is legitimate work, not a hang. + * A watchdog that fires there turns one patient start into a supervisor's crash loop. Nothing + * disarms: the phase the flag exempts is only the engine's first. */ +extern std::atomic dev_engine_ready; + /* Longest run of dispatches a played tape leaves unordered. Of any kTapeOverlapRun + 1 * consecutive packets on a queue one carries the barrier bit, so a launched packet still proves * that everything more than that many packets earlier has completed. Argument slots and tape diff --git a/core/device/dispatch.cpp b/core/device/dispatch.cpp index 396e4de0..3ec5bd48 100644 --- a/core/device/dispatch.cpp +++ b/core/device/dispatch.cpp @@ -875,6 +875,7 @@ std::string dev_pci_address(int device) { return dev_string(64, [&](char* b, int n) { return dev()->pci_address(device, b, n); }); } std::atomic dev_stuck_exit_ms{60000}; +std::atomic dev_engine_ready{false}; int64_t dev_stuck_ms() { const auto f = dev()->stuck_ms; return f ? f() : 0; diff --git a/core/engine_bringup.cpp b/core/engine_bringup.cpp index 58f49200..5c8d6d19 100644 --- a/core/engine_bringup.cpp +++ b/core/engine_bringup.cpp @@ -5261,6 +5261,10 @@ int Engine::start() { * restore reads it again (refill_weights). */ if (file_) dev_page_refilled(base); } + /* Bringup done: everything this engine loads is loaded. From here the stuck-exit watchdog + * treats a device that advances nothing as a hang; before here it treats it as a slow load + * (device.h's dev_engine_ready). */ + dev_engine_ready.store(true, std::memory_order_release); return RAD_OK; }