Skip to content

Recover PD engine crashes and NATS JetStream filestore failures - #162

Merged
jiejingzhangamd merged 3 commits into
mainfrom
feature/weilei/engine-crash-and-nats-filestore
Sep 9, 2026
Merged

Recover PD engine crashes and NATS JetStream filestore failures#162
jiejingzhangamd merged 3 commits into
mainfrom
feature/weilei/engine-crash-and-nats-filestore

Conversation

@weilei0120

Copy link
Copy Markdown
Collaborator

Summary

  • Engine subprocess SIGKILL and similar crashes now exit the worker non-zero, and an empty PD pool is reported as a named prefill/decode outage rather than a missing mixed worker.
  • JetStream FILE streams/KV buckets that fail with 10077 (empty or corrupt msg-block path) are recreated in MEMORY so kv-aware routing can keep publishing.
  • Infera operator NATS uses nats:2.11.1 and a literal /data/jetstream store dir instead of CRI-dependent $(NATS_STORE_DIR) expansion.

Test plan

  • pytest -n auto tests/unit/kv/test_nats_bus.py tests/unit/kv/test_nats_relay.py tests/unit/engine/test_engine_death_exit.py
  • Confirm a 10077 bucket put rebuilds the KV view instead of flooding logs
  • Confirm operator NATS args are -js -sd /data/jetstream -m 8222

Made with Cursor

weilei0120 and others added 3 commits September 9, 2026 09:57
A SIGKILL on the inference subprocess used to finish the worker with exit 0, and a 1P1D outage was reported as a missing mixed worker. KV bucket put failures now back off geometrically instead of flooding logs.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: leiwei12 <lei.wei@amd.com>
An empty -sd / corrupt filestore cannot open msg blocks, so KV view and event streams retry in MEMORY. The operator pins nats 2.11.1 and passes store_dir as a literal path.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: leiwei12 <lei.wei@amd.com>
Signed-off-by: leiwei12 <lei.wei@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: leiwei12 <lei.wei@amd.com>
@weilei0120
weilei0120 force-pushed the feature/weilei/engine-crash-and-nats-filestore branch from 6b731fa to fc7f524 Compare September 9, 2026 09:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new relay filestore-recovery flags can permanently disable recovery after a failed remediation attempt, which can prevent later self-healing under repeated 10077 conditions.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves resiliency and diagnostics across routing, KV/NATS JetStream persistence, and engine subprocess lifecycle handling, so the system fails with clearer 503s and can keep operating when JetStream FILE storage becomes unusable.

Changes:

  • Router now distinguishes “half PD pool missing” vs “no active worker” (Python + Rust) with clearer 503 error messages.
  • KV/NATS components detect JetStream filestore error 10077 / msg-block failures and recreate streams/KV buckets in MEMORY to keep publishing and bootstrapping.
  • Engine entrypoints propagate observed engine subprocess death as a non-zero launcher exit code; operator NATS defaults updated (pinned image + literal store dir).
File summaries
File Description
tests/unit/router/test_failover.py Adds coverage for empty fleet error messaging in Python auto-router.
tests/unit/kv/test_nats_relay.py Adds validation + tests for geometric logging and filestore rebuild behavior in relay.
tests/unit/kv/test_nats_bus.py Adds unit tests for filestore-failure detection helper.
tests/unit/engine/test_engine_death_exit.py Adds tests for subprocess returncode→exit status mapping and watcher behavior.
rust/router/tests/functional.rs Adds functional coverage for PD-missing-pool vs empty-fleet error messages.
rust/router/src/proxy.rs Improves routed dispatch error reporting for PD pool absence and empty fleets.
rust/router/src/kv_event_nats.rs Adds filestore-failure detection and MEMORY fallback for JetStream stream/KV operations.
infera/router/auto.py Improves 503 error selection for empty fleet vs PD half-pool deployments.
infera/kv/nats_relay.py Adds worker_id validation and recovery behavior for JetStream filestore failures + geometric logging.
infera/kv/nats_bus.py Adds filestore-failure detection and FILE→MEMORY fallback/rebuild for stream + KV bucket creation.
infera/engine/vllm/main.py Propagates observed engine death as non-zero exit status.
infera/engine/sglang/main.py Propagates observed engine death as non-zero exit status.
infera/engine/atom/main.py Propagates observed engine death as non-zero exit status.
infera/engine/base.py Introduces EngineDeath + extends watcher to record returncode and map to exit status.
deploy/operator/internal/controller/nats.go Pins NATS image and uses literal JetStream store dir in args.
Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread infera/kv/nats_relay.py
Comment on lines +160 to +168
if js_store_failed(exc) and not self._stream_healed:
self._stream_healed = True
await self._bus.ensure_event_stream()
try:
await self._bus.js_publish(subject, payload)
except Exception as retry_exc:
logger.warning("KV relay NATS publish failed: %s", retry_exc)
else:
logger.warning("KV relay NATS publish failed: %s", exc)
Comment thread infera/kv/nats_relay.py
Comment on lines +274 to +293
if js_store_failed(exc) and not self._kv_healed:
self._kv_healed = True
store = await self._bus.rebuild_kv_view_store()
if store is not None:
self._kv = store
try:
await self._kv.put(
kv_key_for_worker(self._worker_id, rank),
self._encoder.encode(view),
)
self._dirty[rank] = False
self._bucket_failures = 0
self._next_bucket_warn = 1
logger.warning(
"KV view bucket rebuilt after filestore failure (r%d)", rank
)
return
except Exception as retry_exc:
self._note_bucket_failure(rank, retry_exc)
return
Comment on lines 85 to 88
Image: natsImage(idep),
// K8s expands $(NATS_STORE_DIR) in args from the env below.
Args: []string{"-js", "-sd", "$(NATS_STORE_DIR)", "-m", "8222"},
Env: []corev1.EnvVar{{Name: "NATS_STORE_DIR", Value: "/data/jetstream"}},
Args: []string{"-js", "-sd", "/data/jetstream", "-m", "8222"},
Env: []corev1.EnvVar{{Name: "NATS_STORE_DIR", Value: "/data/jetstream"}},
Ports: []corev1.ContainerPort{
@jiejingzhangamd
jiejingzhangamd merged commit d8f5d07 into main Sep 9, 2026
12 of 15 checks passed
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.

3 participants