Skip to content

ops/engine-exec.sh: hold a unit on the engine's death, not on a slow /health - #179

Open
AgentSparko wants to merge 1 commit into
TandemLLM:mainfrom
AgentSparko:engine-exec-hold-on-death
Open

AgentSparko wants to merge 1 commit into
TandemLLM:mainfrom
AgentSparko:engine-exec-hold-on-death

Conversation

@AgentSparko

@AgentSparko AgentSparko commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A Type=simple systemd unit that supervises the engine needs a main process that outlives start.sh's return; this PR ships the reference one in ops/engine-exec.sh — and, its real point, the hold it runs survives a stalled-but-live engine instead of bouncing it.

The failure mode it removes: a while curl -sf -m 10 /health loop that exits on the first miss treats silence as death. A live engine can be silent far past 10 s — a long disk-tier save or a GPU sync holds every Python thread while the kernel still accepts connections, so a client on keep-alive finishes its request while a fresh probe hears nothing. The supervisor's exit then took the engine down with the unit's cgroup mid-request: a serving engine was bounced four times in one morning, each exit followed by a clean drain and a minutes-long reload.

What the hold requires now, all three before the unit lets go:

  • QSE_HOLD_FAILS (default 6) consecutive failed probes — one slow probe is logged and held, a healthy answer resets the count
  • the engine pid dead — kill -0, with a port-owner fallback when the pidfile never appeared
  • nothing listening on the port — so a self-respawned engine or a kernel moment between pid death and socket close can't trigger the exit either

A dead engine fails all three at once (~35 s at the defaults); a busy one fails none of them for long.

Also in the diff: start.sh is invoked through bash like every sibling call (OPS-167), the pidfile gets 120 s with a port-owner fallback so the script never exits while the engine lives, and an optional ops/engine-slot.sh (claim|release, not shipped) lets a box share one accelerator between engines. install.sh does not copy it — a box's unit is its own file, like ops/qwen38-engine.service — and the changelog entry says why.

Test plan

  • tests/test_engine_exec_hold.py — new; drives a stub engine (pidfile of a sleep, control-file curl/ss on a stub PATH) through the four cases: silent-but-alive is held past the old single-miss line, a recovered probe restarts the count at 1, a dead pid with a claimed port still holds (respawn), and a truly dead engine lets the unit go. 6/6 pass.
  • tests/test_no_exec_bit.py — 5/5 pass (the direct-call tokenizer is clean for the new script).
  • bash -n clean.
  • Deployed on the incident box's live unit: the restart that loaded this code is serving, and the log line per missed probe gives the stall timing the old silent exit never recorded.

Note on the local suite: tests/test_install_ops_copy.py cannot run its fixture on a host whose global pre-commit hook pins a specific author identity — the fixture commits as t <t@example.com> and the hook refuses. Environmental, unrelated to this diff.

@github-project-automation github-project-automation Bot moved this to Triage in TandemLLM Nov 21, 2026
@github-actions github-actions Bot added install install.sh and the first start on a new machine ops Service scripts, profiles, watchdog, release tooling labels Nov 21, 2026
…/health

The unit's ExecStart must outlive start.sh (which backgrounds the engine and
returns) so the unit's cgroup owns the engine; but a hold loop that exits on
the first `curl -m 10 /health` miss mistakes a stalled engine for a dead one.
A long disk-tier save or a GPU sync parks every Python thread past the timeout
while the kernel still accepts connections — a keep-alive client finishes its
request while a fresh probe hears nothing — and the exit then took a serving
engine down with its cgroup (four times in one morning, 2026-11-21).

The reference supervisor ships in ops/, not installed: a box's unit is its own
file, like ops/qwen38-engine.service. It passes the engine-slot guard's exit
75 through when the guard is present, finds the engine by pidfile with the
port's owner as fallback, and releases the unit only when QSE_HOLD_FAILS (6)
probes in a row fail AND the pid is dead AND nothing listens on the port: a
dead engine fails all three at once, a busy one fails none of them for long.

tests/test_engine_exec_hold.py drives a stub engine through the cases (a dead
engine lets go, a silent-but-live one holds, a recovered probe resets the
count, a dead pid with a claimed port holds, install.sh does not copy the
script): 6/6.
@AgentSparko
AgentSparko force-pushed the engine-exec-hold-on-death branch from 39cefe4 to 7fe894b Compare November 21, 2026 10:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

install install.sh and the first start on a new machine ops Service scripts, profiles, watchdog, release tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant