Skip to content

npu: a live orphan serve holds the device lock indefinitely, and the wait says nothing — name the holder #1241

Closed

Description

@bong-water-water-bong

What happened (measured, 2026-11-06 00:02–00:50 AST, strixhalo)

A 1bit serve --device npu from an aborted install-test run was left running as an orphan (ppid 1) with no clients:

pid 2689658  ~/wt/payload-c28/opt/1bit-package/1bit/1bit serve -m <FastFlowLM Qwen3-0.6B-NPU2> \
             --port 8111 --device npu --ctx-size 32768      started 00:02:24, ppid 1

It held /tmp/1bit-npu-device.lock for ~32 minutes. Two lanes' npu-hold tickets were granted the NPU token in that window
and could not use the device:

  • my 1bit forward-serve printed [npu] waiting for the exclusive device lock (/tmp/1bit-npu-device.lock)... and then sat
    there for the whole 1375 s ticket; the logprobs harness reported serve never became ready on both binaries of an A/B
    pair, i.e. a device-ticket was spent and measured nothing;
  • a retry that pressed on produced 72 kernel errors in ~10 s —
    aie2_alloc_resource: Allocate AIE resource failed, ret -19 → aie2_hwctx_init → amdxdna_drm_create_hwctx_ioctl.
    The engine surfaced that as npu runtime: device error (code 102): No such device from I8Ctx::init_elf. Nothing in that
    message says "another process owns the device", so it reads as a broken device/ELF/container;
  • another lane reported the same pid blocking three of its servers in the same window.

Stopping the orphan cooperatively (SIGTERM, per NPU-LANE-RULE-20261104.md rule 4 — no -9) freed the lock and port in 2 s
and the very next ticket ran clean.

Why the lock itself is not the bug

app/npu_device_lock.h uses flock(2), so the lock dies with its holder: there is no stale lock to reap. The failure mode
is a live orphan, and the engine has no diagnostic for it and no way out of the wait:

std::fprintf(stderr, "[npu] waiting for the %s device lock (%s)...\n", ...);
if (::flock(fd, op) != 0) { ... }        // blocks indefinitely, prints nothing further

gpu-hold reaps dead tickets, and npu-serve-keeper stops/reaps the owner's serve; neither looks at the lock, so a leaked
serve is invisible to the fleet's own coordination until someone runs fuser.

Proposed cures (small, and each one converts a 30-minute stall into a 5-second diagnosis)

  1. Name the holder. After ~2 s of a blocking wait, print the pid(s) that hold the flock — /proc/locks gives
    FLOCK ADVISORY ... <pid> <maj>:<min>:<ino> for the file, so match the lock file's st_dev/st_ino and print the pids with
    their cmdline (truncated). Repeat at most once a minute. One line like
    [npu] device lock held by pid 2689658 (1bit serve --device npu ...) for 41 s would have replaced an hour of guessing.
  2. The same line on the refusal path. When a dispatch fails with code 102, say whether the lock is held by another pid —
    No such device for "somebody else owns the array" is the single most misleading message this route can emit (it sent me
    looking at container/ELF generation first).
  3. Optional bounded wait. ONEBIT_NPU_LOCK_WAIT_MAX (seconds, default unlimited) so a gate/harness can fail fast with the
    holder's name instead of consuming a device ticket. Unlimited must stay the default: a shared box's normal contention is
    exactly what the wait is for.
  4. Not proposed: reaping the orphan automatically. Killing another lane's live NPU client is the box-crashing path
    (NPU-LANE-RULE-20261104.md rule 4), so a diagnostic is the right shape for an engine fix.

Separate, related, and mine to fix in the harness

scripts/npu-window11.sh via ~/.p4-gate/repeat-window11.sh hardcodes --port $((8110 + r % 2)) and never checks the port is
free; the leaked serve above was listening on :8111, so round 1 of my A/B block was answered by that process (3
transcripts, 0 prof rows, another build's text shape). A bind() failure that says so, or a free-port check, belongs in that
harness — it is on the #808 gate lane, not here.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions