Skip to content

rpc: do not abort on shutdown when a teardown round trip fails - #203

Open
danielhanchen wants to merge 329 commits into
base/upstream-af50f2f24from
fix/rpc-teardown-abort
Open

danielhanchen wants to merge 329 commits into
base/upstream-af50f2f24from
fix/rpc-teardown-abort

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

What happens

llama-server built with GGML_RPC aborts on exit, after it has already printed
cleaning up before exit:

ggml/src/ggml-rpc/ggml-rpc.cpp:891: Remote RPC server crashed or returned malformed response
#3  ggml_backend_rpc_get_device_memory ()
#4  common_memory_breakdown_print(llama_context const*) ()
#5  llama_server(common_params&, int, char**) ()

Why

common_memory_breakdown_print() is called after clean_up(), which calls
llama_backend_free(). The RPC device answers get_memory with a round trip to the peer,
and by that point the round trip fails, so RPC_STATUS_ASSERT aborts the process.

This was first seen on a two node layer split where the peer ggml-rpc-server had been
stopped before the local server exited.

Correction, 2026-09-08. This paragraph previously claimed the abort reproduces with a
peer that is alive and healthy, and therefore fires on every shutdown of a server using
--rpc. Re-tested on the pair, that is wrong: with a healthy peer the master exits
cleanly. The trigger is an unreachable peer, which is the case the original report
came from. Three of the four cells below reproduce exactly as written, including the log
line counts, so the defect and the fix are unchanged; only this claim about how often it
fires was too broad.

That still makes it worth fixing rather than a corner case. A peer going away before the
coordinator exits is the normal shutdown order for a split: the orchestrator tears down
the remote servers first, and any crash, kill or network loss on the peer puts the
coordinator in exactly this state. An informational property should not abort a process
that has already finished its work.

The fix

Device memory is an informational property, not part of the data path, and
ggml_backend_rpc_get_device_memory() already has a defined answer for an endpoint it
cannot reach at all: report 0 free and 0 total. Report the same when the query itself
fails, and log an error.

Freeing a remote buffer is released state and is also a teardown operation, so a failure
there is logged instead of aborting: if the peer is gone then so is the buffer, and the
local context is freed either way. Without this second hunk the process still aborts a few
microseconds later in ggml_backend_rpc_buffer_free_buffer from
ggml_backend_sched_free, on the way out of ~llama_context.

Every other RPC_STATUS_ASSERT, including all of the data path ones, is unchanged. A
failure while setting or getting a tensor or running a graph still aborts.

The alternative, teaching common_memory_breakdown_print() to skip backends whose
connection has dropped, was rejected: that code is shared with every non-RPC build and has
no way to ask a backend whether it is still reachable, so it would need a new backend
interface entry for one caller. Caching the last known figure inside the RPC backend was
also rejected: it adds state to keep in sync in order to print a number that is meaningless
by the time it is printed.

What was measured

CPU only, stories15M-q4_0.gguf, --rpc HOST:PORT --device RPC0 -ngl 99, one completion
served, then SIGINT. The verdict is the process exit status: 134 is SIGABRT, 0 is a clean exit.

A fixed delay after SIGINT does not test this. The teardown round trip is microseconds wide, so
a reset injected 20 or 50 ms after the signal always lands outside it and comes back clean on
both arms, saying nothing (rows c7 and c8 below, kept as a negative control). What does work is
a proxy that parses the client to server RPC framing (cmd:1 | size:8 | payload) and resets the
connection the instant a chosen command byte is issued, before forwarding it.
RPC_CMD_GET_DEVICE_MEMORY is 11 and RPC_CMD_FREE_BUFFER is 4.

Single node, 127.0.0.1:

case fault before after
c1 healthy peer, ordinary shutdown clean, rc 0 clean, rc 0
c2 peer SIGKILLed before shutdown abort, rc 134 clean, 1 reporting 0, 3 connection is gone
c3 peer SIGTERMed before shutdown abort, rc 134 clean, same log lines
c4 RST injected by the proxy, peer process still alive abort, rc 134 clean, rc 0
c5 orderly FIN from the peer side, peer process still alive abort, rc 134 clean, rc 0
c6 peer accepts and never answers hang hang, unchanged, see follow ups
c7 peer killed 50 ms after SIGINT clean clean (fault missed the window)
c8 x5 RST 20 ms after SIGINT, five repetitions clean x5 clean x5 (fault missed the window)
c9a RST the instant RPC_CMD_GET_DEVICE_MEMORY is issued abort at ggml-rpc.cpp:831 clean, 1 reporting 0, 3 connection is gone
c9b RST the instant RPC_CMD_FREE_BUFFER is issued abort at ggml-rpc.cpp:397 clean, 3 connection is gone

Two nodes, ggml-rpc-server on a second DGX Spark over the LAN, which is the topology the
original report came from:

case fault before after
n1 healthy peer, ordinary shutdown clean, rc 0 clean, rc 0
n2 remote peer SIGKILLed before shutdown abort, rc 134, core dumped clean, 1 reporting 0, 3 connection is gone
n3 remote peer SIGTERMed before shutdown abort, rc 134, core dumped clean, same

8 of the 8 injections that actually reach the teardown round trip abort before and are clean
after
, across five fault shapes and two topologies. c9b is the row that shows the second hunk
is load bearing rather than defensive: with the reset landing on the free, the abort is in
ggml_backend_rpc_buffer_free_buffer at ggml-rpc.cpp:397, not in get_device_memory.

A healthy peer exits cleanly before the change, on both topologies (c1 and n1). An earlier
revision of this description claimed otherwise; that claim was wrong and is corrected here.

Follow ups this does not fix

Neither is a regression and neither is introduced here, but both are in the same file and both
turned up while testing this change.

1. There is no socket timeout anywhere in the RPC transport, so a peer that accepts a
connection and then never answers hangs the shutdown forever.
ggml/src/ggml-rpc/transport.cpp
sets TCP_NODELAY and SO_REUSEADDR and nothing else: no SO_RCVTIMEO, no SO_SNDTIMEO, no
connect timeout. socket_t::impl::recv_data() loops on recv(fd, ..., 0) until it has the
bytes, gets 0 (peer performed an orderly shutdown) or gets -1. A peer holding the socket open
and sending nothing produces none of those, so the process blocks and SIGINT is never serviced.
Reproduced before and after this change alike, row c6 above.

2. The transport sends with no MSG_NOSIGNAL, so an RPC client that is not llama-server can
be killed by SIGPIPE before either the old abort or the new log line is reached.
Nothing in
the RPC backend installs a SIGPIPE handler or sets SO_NOSIGPIPE; the only place in the tree
that ignores SIGPIPE is tools/server/server.cpp, added for MCP child processes, which is why
llama-server reaches this code path at all. llama-cli, llama-bench and embedders do not.
This one is a source level hazard I could not demonstrate: with llama-cli --rpc and the
peer killed mid session, the first failing operation on this kernel is a recv() that returns
0, so RPC_STATUS_ASSERT in negotiate_hello() (ggml-rpc.cpp:348) fires first, identically
before and after. Stated as unproven rather than as a reproduction.

Also unchanged and out of scope here: negotiate_hello() still has an RPC_STATUS_ASSERT, so a
reconnect to a half dead peer still aborts. That is a connect time path, not a teardown path.

Non-RPC builds

The change touches one file, ggml/src/ggml-rpc/ggml-rpc.cpp. That file is compiled only
through ggml_add_backend(RPC) in ggml/src/CMakeLists.txt, which adds the subdirectory
only if GGML_RPC is set, and GGML_RPC defaults to OFF in ggml/CMakeLists.txt. No
header, no public signature and no shared code path changes, so NVIDIA, AMD and CPU only
builds without RPC are byte for byte unaffected.

danielhanchen and others added 30 commits June 22, 2026 11:39
The Linux and Windows CPU app bundles narrowed the build to
`--target llama-server llama-quantize`, so app-*-{linux,windows}-x64-cpu
shipped without llama-cli and the rest of the tool set that the macOS bins
already include. This broke the consolidated-tests-ci "llama.cpp build +
smoke" assertion that llama-cli exists at the install root.

Drop the --target narrowing so the CPU builds compile the full set like the
macOS/ROCm children, and set LLAMA_BUILD_TOOLS/SERVER=ON explicitly on
Linux. The package step already tars all of build/bin, so the extra
binaries ship automatically.
The add-inkling branch was force-pushed, so the old pin
a015409 is no longer a commit of the PR and the nightly Resolve
tag step refuses it. Repin to the current head ce16fff.
* Prebuilt: carry macOS 14 paravirtual mmap fix; drop stale GGML_METAL_USE_BF16 define

Pin #37 in pr-set.json: on macOS 14 VMs the Apple
Paravirtual GPU returns stale data for mmap-backed weight buffers, so the
patch makes the Metal backend stop advertising buffer_from_host_ptr there
and llama.cpp falls back to copied weights (same path as --no-mmap).

GGML_METAL_USE_BF16 no longer exists in current llama.cpp (bf16 is
runtime-probed since the ggml-metal rewrite), so the define was a no-op;
remove it from the macOS matrix entry.

* Keep the pin-set unchanged; this PR only drops the stale define

GGML_METAL_USE_BF16 no longer exists as a build option in the current
source tree (bf16 is runtime-probed), so passing it was a no-op. The
macOS 14 paravirtual mmap pin moves to a separate decision.
…#39)

Both pins pointed at commits that no longer merge onto the selected
upstream base, so the nightly full release build failed while resolving
the PR set.

ggml-org#24523 was pinned to 66f43aa6, which was not even the
PR head at the time (the resolver logged that the head had moved to
0b78558a). That commit conflicts in common/chat.cpp against both b10107
and b10133. The PR has since been rebased onto current master, so the
pin now points at its new head a58a7fa6, which merges cleanly.

ggml-org#25731 was pinned to ce16fff, which conflicts on its
own in ggml/src/ggml-cuda/mmq.cuh, src/llama-model-saver.cpp and
src/llama-vocab.h. This never surfaced in the log because the resolver
stops at the first failing entry. Its current head 453c438 merges
cleanly by itself.

Note that ggml-org#24523 and ggml-org#25731 still conflict with each other in
common/chat.cpp and src/llama-arch.h: both append a new llm_arch enum
value immediately before LLM_ARCH_UNKNOWN and both add a chat parser in
the same region. Reordering does not help, since whichever entry is
applied second hits the same conflict. Resolving that needs a decision
about which of the two to carry, so it is left alone here.

Requires a base of b10133 or newer: b10107 predates the rename of
common_chat_params::thinking_end_tag to thinking_end_tags, which the
rebased ggml-org#24523 depends on.

Co-authored-by: Daniel Han <[email protected]>
#39 landed the first pin refresh only, so master still points at commits
that have since moved on and that conflict with each other.

ggml-org ggml-org#24523 was force-pushed: it now places LLM_ARCH_MINIMAX_M3 next
to LLM_ARCH_MINIMAX_M2 rather than at the tail of the enum, matching how
llama-arch.cpp already groups the name table. That removes the
src/llama-arch.h half of its collision with ggml-org#25731, which appends
LLM_ARCH_INKLING at the tail. New head baee0f5.

ggml-org ggml-org#25731 has picked up current master and the thinking_end_tags
rename, so it now builds on its own against b10133 and newer. Its entry
is replaced by unslothai #40, which carries what is still unresolvable
between the two: both add a chat parser and a detection block in the
same region of common/chat.cpp, immediately before "namespace
workaround {". chat.cpp has no MiniMax-M2 parser to sit beside, so
there is no principled alternative anchor for that half.

Replaying the resolver sequence on b10133:

  OK  ggml-org ggml-org#24423    @ c3fb972
  OK  ggml-org ggml-org#24523    @ baee0f5
  OK  unslothai #40      @ 233cedb

Drop the #40 entry and repin ggml-org#25731 upstream once either PR lands.

Co-authored-by: Daniel Han <[email protected]>
The nightly died in resolve: #40 carried MiniMax-M3 plus Inkling,
upstream master now ships its own MiniMax-M3, and the two collided in
src/models/models.h and tests/test-backend-ops.cpp. Every build job was
skipped.

Drop the two MiniMax entries (ggml-org#24523 is closed anyway, so it was
already inert) and repin on the four PRs we actually want:

  ggml-org#24423   DiffusionGemma
  ggml-org#25731   TML Inkling
  #44     Kimi-K3 fixes + MoonViT-3d vision tower
  ggml-org#26185   Kimi-K3 text

ggml-org#25731 and #44 both had their conflicts against current master fixed on
their own branches, and #44 also carries the Inkling merge: the two archs
land in the same arch/model/mtmd registries, so they cannot go in as two
independent heads and one of them has to know about the other.

ggml-org#26185 is last on purpose. Its head is an ancestor of #44, so by the time
the resolver gets there the merge is a no-op; listed before #44 it
conflicts on tests/test-llama-archs.cpp. It stays in the set so the
release manifest names it.

Verified locally against b10173: the four merge in this order with zero
unmerged paths, and the merged tree builds with -DGGML_CUDA=OFF
-DLLAMA_CURL=OFF -DLLAMA_BUILD_TESTS=ON.

Assisted-by: Claude Code
…head (#49)

The nightly has been red since 2026-07-31. pwilkin force-pushed
ggml-org#26185 at 21:16Z that day, eleven minutes before the schedule
fired, and the pin in this file still named cf67f0d -- a merge commit
that the rebase wrote out of the branch. The membership gate in the
resolve step caught it and refused, so every build job was skipped.
Runs 30666643530 and 30718507279 both died there.

Two more things were wrong once that was unblocked:

  - Inkling was pinned to d69b7e6, which is the commit three separate
    reporters got garbage output from (CPU, Mac, and ROCm with -fa on).
    ggml-org#25731 fixed all of those in 02142bb; the nightly was
    shipping the broken one.

  - The rebase left ggml-org#26185 unmergeable against current master,
    and Kimi-K3 and Inkling register in the same arch, model and mtmd
    tables. Two independent heads cannot both land, so one of them has
    to know about the other.

#48 now carries that. Its base branch was advanced to the
rebased ggml-org#26185 head, then merged with b10223 and with Inkling,
resolving four collisions:

  src/llama-arch.cpp          KIMI_K3 and INKLING share a fallthrough
  src/llama-model.cpp         same, in the ROPE_TYPE_NONE group
  tests/test-llama-archs.cpp  master's MINIMAX_M3 vs KIMI_K3
  tools/mtmd/                 CMake source list and the graph registry

All four are additive; both arches belong in every group. The two
Kimi-K3 commits were rebased on top, so #48 is still a
10-file stacked diff against its base.

ggml-org#26185 stays listed, last. Its head is now an ancestor of
#48, so the resolver merges it as a no-op and the release
manifest still names it.

Verified against b10223: the four merge in this order with zero
unmerged paths, and the merged tree builds with -DGGML_CUDA=ON. On the
merged tree test-chat passes and test-llama-archs -a kimi-k3 is OK on
both CUDA and CPU (NMSE 8.77e-08); it fails to even load the model
without this repin.
The 2026-08-02 schedule (run 30767267935) failed in resolve:

  ggml-org#25731 (02142bb) does not merge cleanly onto b10229
  + the PRs listed before it

Not the pin rot that broke the previous two nights -- all four pins
passed the membership gate this time. Upstream added LLM_ARCH_DEEPSEEK4
to the same fallthrough group in src/llama-arch.cpp that Inkling
registers in, between b10226 and b10229, and the resolver has no
conflict resolution.

Fixed on the branch rather than here: b10229 is merged into add-inkling
and both cases are kept, since both arches belong in that group. That
also clears ggml-org#25731's own mergeable state against master, which
had gone red for the same reason.

No other pin moves. #48 needed nothing -- it already carries
b10223 and the new arch does not collide with Kimi-K3.

Verified against b10229: the four merge in order with zero unmerged
paths, and the merged tree builds with -DGGML_CUDA=ON. test-chat passes
and test-llama-archs -a kimi-k3 is OK on CUDA and CPU (NMSE 8.77e-08).
The new Inkling head also merge-tree's clean against upstream master,
which is six commits past b10229, so the next tag should resolve too.
The nightly has no failure notification at all. There is no `if: failure()`
step, no webhook and no issue creation anywhere in the repo, so a failed
scheduled run only emails whoever last touched the cron file. That is how
07-31, 08-01 and 08-02 all failed unnoticed and the fork sat three days
behind upstream.

Adds three things:

- .github/actions/prebuilt-alert: opens, updates or closes a deduplicated
  issue. Alerts sharing a key collapse onto one thread, so a multi-night
  outage reads as one issue with a run-by-run history instead of one issue
  per night. Closes itself on the next success.

- An alert job on the orchestrator, gated on publish-intent runs so subset
  test dispatches stay quiet. It quotes the actual refusal out of the failed
  job log, so the issue says which pin broke rather than just "a job failed".
  'skipped' counts as healthy: a scheduled no-op legitimately skips every
  build job.

- unsloth-prebuilt-deadman.yml: a run can go green while publishing nothing,
  which nothing keyed off job failure can see. Upstream cuts releases several
  times a day, so two days without one of ours is a fault.

Also closes a silent capability regression in resolve. A pinned PR that gets
merged or closed upstream currently drops out of $PRS with a plain echo,
which changes SETHASH, which changes the tag, so the release ships without
that architecture under a new tag and nobody is told. Entries may now be
{"url", "required": false}; bare strings stay valid and mean required, so the
file needs no migration. A non-open required pin refuses instead. The lint
workflow takes the same schema.

Verified: bash -n over every run block in both workflows and the action, and
the pin loop exercised for open, merged-required and merged-optional.
@danielhanchen danielhanchen self-assigned this Oct 13, 2026
# Conflicts:
#	ggml/src/ggml-rpc/ggml-rpc.cpp
# Conflicts:
#	.github/workflows/build-cache.yml
#	.github/workflows/build-openvino.yml
#	.github/workflows/release.yml
#	CODEOWNERS
@danielhanchen
danielhanchen changed the base branch from master to base/upstream-af50f2f24 October 13, 2026 20:23
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d29d78ade7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -1,244 +0,0 @@
name: CI (cpu)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Rebase without replacing the repository automation

When this commit is applied to its recorded parent, it removes the existing CPU PR workflow along with dozens of other build, test, release, and maintenance workflows, then installs fork-specific Unsloth automation; for example, the replacement CPU workflow is reusable only and the parent workflow runs on a schedule or manual dispatch, so ordinary pull requests no longer receive the CPU checks that included ggml/src/ggml-rpc/**. This contradicts the commit's stated one-file scope and leaves the RPC change untested in normal PR CI; the commit needs to be rebased so it contains only the intended RPC delta rather than the fork tree overlay.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this: that is the fork's own CI layout, which every branch of this repository carries (master replaces the upstream workflows with the Unsloth ones). The PR targets base/upstream-af50f2f24, upstream b11582, so the overlay shows in the diff the same way it does for #187; the change under review is ggml/src/ggml-rpc/ggml-rpc.cpp alone.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 075faf167f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

3 participants