Skip to content

zmnext: zm-infer start failures, spawn serialization, no host-wide orphan kill; Phase 2 plan - #289

Open
SteveGilvarry wants to merge 5 commits into
ZoneMinder:masterfrom
SteveGilvarry:zmnext/zm-infer-hardening
Open

SteveGilvarry wants to merge 5 commits into
ZoneMinder:masterfrom
SteveGilvarry:zmnext/zm-infer-hardening

Conversation

@SteveGilvarry

Copy link
Copy Markdown
Member

zm-api's side of the shared-inference hardening that landed in zm-next on 2026-11-29 (zm-next 6b757a9, 33bc1f7, b4ddc2c, e9611e8).

Code (src/daemon/manager.rs)

  • zm-infer start failures are no longer swallowed. start_daemon_with_stdin returns Ok with an error response, and no managed process, when the binary is missing or the spec is invalid, so check_daemons could never restart it. Now, if the daemon really isn't running, start_zmnext_worker gets an Err and the worker stays down for reconcile to retry, rather than running with detection silently broken.
  • zm-infer spawns are serialized (infer_spawn_lock), so reconcile and an API start can't both pass the is-running check and spawn two. zm-next's daemon now also holds an flock beside its socket, so a second one exits 69 either way.
  • kill_orphan_daemons no longer kills zm-infer across the host. A host-wide pkill -9 zm-infer would kill another zm-api's daemon on the same machine. Ours dies with zm-api through PR_SET_PDEATHSIG.
  • The liveness comment now describes zm-infer's watchdog accurately: it exits when inference has been in flight for --watchdog-sec with none finishing, and check_daemons restarts it. That's why the CPU-time hang check skips zm-infer.

Docs (docs/ZMNEXT_SHARED_INFERENCE_PLAN.md)

Phase 2 (same-GPU zero-copy) is scoped as deferred and gated on measurements. The precondition (pinned receive buffers, one copy into the batch) and its instrumentation are recorded as built in zm-next e9611e8, with the measurements: pinning cut round trips from 42 to 9.7 ms (p50) under a synthetic 6-client load.

Testing

  • cargo fmt --all -- --check, cargo clippy --locked --all-targets --all-features -- -D warnings: clean
  • cargo test --locked --all-features: 1434 passed, 0 failed (DB-backed #[ignore] tests not run locally)

🤖 Generated with Claude Code

SteveGilvarry and others added 5 commits November 29, 2026 15:58
…s comment

ensure_infer_daemon discarded start_daemon_with_stdin's result, which returns
Ok(error response) (not Err) for executable-not-found / invalid-spec and creates
no ManagedProcess entry — so a misconfigured zm-infer path was a permanent, silent
fleet-wide detection outage (never restarted by check_daemons, never retried by
reconcile, while the worker ran on). Propagate it as Err (with an is_running
re-check for the legitimate already-running race) so start_zmnext_worker aborts and
reconcile retries. Also correct the hung-check comment: the daemon's gray-hang
liveness is enforced by its own watchdog (Increment 4), not an app-level probe.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ll (Inc 4 mediums)

- M2: add infer_spawn_lock and hold it across ensure_infer_daemon's is_running
  check + spawn, so concurrent worker starts (reconcile + an API request) can't
  both pass the read-check and double-spawn the daemon past start_daemon_with_stdin's
  TOCTOU. Pairs with the daemon's flock (zm-next) which makes the loser exit cleanly.
- M8: drop "zm-infer" from kill_orphan_daemons' blanket `pkill -9` — a host-global
  kill would take down a co-located zm-api instance's daemon. Its lifecycle is
  covered by PR_SET_PDEATHSIG (dies with this zm-api) + the daemon's flock.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Records the Phase-2 scoping outcome: defer (3/3 adversarial verdicts worth_it:no).
Motion-gating killed the PCIe-saturation premise, and the daemon's mandatory
d_batch_ staging copy survives every design, so CUDA-IPC only converts that H2D
to a D2D and drops the worker D2H + UDS bytes — net ~1-2 ms latency on Gen3
single-GPU, zero throughput/memory, at the cost of regressing the SPOF daemon's
fault isolation. Captures the cheap pinning precondition (do as hardening), the
instrumentation to ship now, and the T1-T4 re-open trigger + the CUDA-IPC design
for if it ever fires.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…built

Records as-built status for both (zm-next fde326d): the daemon's dedicated
cudaHostAlloc RX buffer (vs the original cudaHostRegister sketch, which the design
panel found UAF-prone), sync-from-pinned (async rejected), stderr-only instrumentation
with per-instance accumulators + an async logger guarding the SPOF dispatcher, and the
first empirical h2d_frac_p99 (~0.1-2%, well under the 20% T1 trigger) confirming DEFER.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The plan cited zm-next fde326d and its internals (read_frame_into,
PongStats, a cudaHostRegister'd worker buffer, pinned=K/N), a June commit
that never reached zm-next main. The work landed as e9611e8 and its three
predecessors on 2026-11-29: describe that, add its measurements, and say
the watchdog is the daemon's --watchdog-sec, not a thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant