Skip to content

Serialize the nlp-engine model-loading tests and bound model load with a timeout - #1769

Merged
mstomar125 merged 1 commit into
mainfrom
issue-1761-nlp-test-deadlock
Jul 28, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-1761-nlp-test-deadlock

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

cargo test -p nodespace-nlp-engine hung indefinitely at 0% CPU: the parallel harness ran the 11 model-loading integration tests concurrently, racing to initialize the process-global llama.cpp/Metal backend and deadlocking. --test-threads=1 passed all 11 in ~13s.

Change

  • Serialize the model-loading tests with serial_test's #[serial] (added as a dev-dependency) on all 11 integration tests, so first-time backend init can no longer race under the parallel harness. The 3 stub tests are untouched.
  • Bound the load with a timeout: load_model_with_timeout runs the blocking backend-init + model-load on a dedicated worker thread with a 120s budget, returning an error instead of hanging forever if a first-time Metal/GPU init genuinely stalls.

The deliberate Mutex<Option<LlamaBackend>> drop-at-exit design is unchanged — the backend MutexGuard is created and dropped entirely inside the worker thread and never crosses a thread boundary; only the Send LlamaModel is returned. Loads across services stay serialized exactly as before.

Verification

  • Before: parallel run hung at 0% CPU (killed after ~4 min); serial passed 11/11.
  • After: cargo test -p nodespace-nlp-engine (no --test-threads) passes — 108 lib + 11 integration tests, process pinned at ~95% CPU (the decisive contrast with the 0% hang).
  • cargo clippy -p nodespace-nlp-engine --all-targets -- -D warnings + cargo fmt --check clean, no suppression.

Closes #1761.

…h a timeout (closes #1761)

cargo test -p nodespace-nlp-engine hung at 0% CPU: the parallel harness ran the
11 model-loading integration tests concurrently, racing to initialize the
process-global llama.cpp/Metal backend and deadlocking. Serialize those tests
with serial_test's #[serial] so first-time backend init cannot race, and bound
the backend-init + model-load on a dedicated worker thread with a 120s timeout so
a genuinely stuck load fails fast with an error instead of hanging forever. The
Mutex-based drop-at-exit backend design is unchanged; the guard never leaves the
worker thread.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mstomar125
mstomar125 merged commit fd6ec90 into main Jul 28, 2026
2 checks passed
@mstomar125
mstomar125 deleted the issue-1761-nlp-test-deadlock branch July 28, 2026 09:54
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.

cargo test -p nodespace-nlp-engine deadlocks: parallel integration tests race on shared llama.cpp/Metal backend init

1 participant