Skip to content

server: return instead of continuing after a failed mtmd chunk (release() nulls slot.task) — fixes the SIGSEGV in #1489 - #245

Closed
bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkanfrom
1bit/1489-mtmd-failure-return
Closed

bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkanfrom
1bit/1489-mtmd-failure-return

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Fixes the crash in engine ggml-org#1489: a failed multimodal encode killed llama-server with SIGSEGV three milliseconds after it had already produced the error, so the client's connection died instead of getting the 5xx.

Root cause, from the crash itself

Reproduced on this box (Qwen3-VL-2B + mmproj-Qwen3VL-2B-Instruct-F16, the projector on a backend that rejects one node), running the server under gdb and sending one 64×64 PNG. The log ends with:

E graph_compute: unsupported HRX node 11: ROPE ...
E clip_image_batch_encode: ggml_backend_sched_graph_compute failed with error -1
E srv    send_error: task id = 0, error: failed to process image
W srv          stop: cancel task, id_task = 0

and the faulting frame is:

Thread 1 "llama-server" received signal SIGSEGV
#0 server_context_impl::pre_decode()::{lambda(server_slot&)#5}::operator()(server_slot&)
#1 server_context_impl::iterate(std::vector<server_slot>&, std::function<void(server_slot&)>)
#2 server_context_impl::pre_decode()
#3 server_context_impl::update_slots()
#4 server_queue::start_loop(long)

The 5th lambda of pre_decode() is the prompt-batching loop, and the handler for a failed chunk is:

if (res != 0) {
    SLT_ERR(slot, "failed to process image, res = %d\n", res);
    send_error(slot, "failed to process image", ERROR_TYPE_SERVER);
    slot.release();
    continue;                 // <-- here
}

slot.release() ends with task_prev = std::move(task); task.reset();, so slot.task is null from that point. continue re-enters the
while (true) chunk loop, whose first statement is

cur_token_idx >= slot.task->n_tokens()      // null dereference

So the crash is not in the backend and not in the clip encode: the error was delivered (the client in my run did get HTTP 500), and the process
then walked a released slot.

The change

continue → return: the slot has been released and must not be batched in this pass. No other site in this file releases a slot and then
continues (checked).

This matches upstream: origin/master's equivalent handler in the same position does

slot.release();
return; // the slot is done, skip it entirely

so this branch is carrying an older shape of the same block. Nothing else in the diff.

Verification, stated precisely

  • Pre-fix crash: measured, full backtrace and the four log lines above, on the shipped HRX build; the harness and gdb dump are attached to
    the issue.
  • Post-fix: not rebuilt in this lane. This tree has no configured build, and the only configured HRX build tree on the box is shared — rebuilding
    it is exactly the Init prompts are truncated to --batch-size (max 512 tokens) ggml-org/llama.cpp#1403 incident (it swaps libraries under running services). So the binary-level proof is CI's build plus the issue's own
    acceptance, which is cheap: the same request must produce an HTTP error and leave the process alive.
  • The source-level argument does not depend on the backend: any process_mtmd_chunk failure reaches this handler, so a stock (non-HRX) build with
    an injected failure would exercise it too.

Refs ggml-org#1489.

…se release() nulls slot.task (engine ggml-org#1489)

A CLIP encode failure killed llama-server with SIGSEGV three milliseconds after it had already produced the
error. Reproduced with a backtrace, and the frame names the site:

  Thread 1 received signal SIGSEGV
  #0 server_context_impl::pre_decode()::{lambda(server_slot&)#5}::operator()(server_slot&)
  #1 server_context_impl::iterate(std::vector<server_slot>&, std::function<void(server_slot&)>)
  #2 server_context_impl::pre_decode()
  #3 server_context_impl::update_slots()

The failing path is the multimodal chunk loop in pre_decode(): process_mtmd_chunk() returns non-zero, the slot's
error is sent, slot.release() runs - which does both "task_prev = std::move(task)" and "task.reset()", leaving
slot.task null - and then "continue" re-enters that loop, whose first statement reads slot.task->n_tokens(). Null
dereference, every time.

Return instead: the slot has been released and must not be batched in this pass. Upstream master's equivalent
handler does exactly that, with the comment "the slot is done, skip it entirely".

No other site in this file releases a slot and then continues.

Not verified by a rebuild in this lane: the tree here has no configured HRX build, and the only configured one on
this box is a shared build tree whose rebuild is precisely the ggml-org#1403 incident (it swaps libraries under running
services). The pre-fix crash is recorded with the full backtrace in engine ggml-org#1489; the post-fix acceptance is the
issue's own - an HTTP error and a live process - which CI's build can run.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT: READY at d03c902f8aa27bf7337b6facc21b5d1326e65078

The crash mechanism is exactly as the comment describes, and I followed it through the code rather than taking it:

release()  -> reset()                                         (server-context.cpp:524 …)
reset()    -> task_prev = std::move(task);  task.reset();      (:363-364)   <- slot.task is now null
continue   -> re-enters the chunk loop, whose top reads
              cur_token_idx >= slot.task->n_tokens()           (:3458)      <- null deref, SIGSEGV
return     -> leaves the slot done, which is what upstream does

So the three-line diagnosis ("release() moves the task into task_prev and resets slot.task, so continue re-enters the chunk loop and the very next slot.task->n_tokens() dereferences null") is precisely what the code does, and "a failed CLIP encode killed llama-server 3 ms after this error line" is the expected latency: the error is printed, release() runs one statement later, and the next loop iteration is microseconds away.

return rather than continue is the right shape and it is worth saying why: after slot.release() there is nothing left to advance — the task is gone, the prompt's chunk was never added (the failure is before slot.n_prompt_tokens_processed += n_tokens_out and before the chunk is pushed into the cache), so "skip this slot and keep iterating" was never meaningful in this branch. Returning matches upstream, which the comment names, so this is not a local invention that upstream will diverge from.

The one behaviour to be aware of, and it is the pre-existing design rather than this PR's: the slot ends the chunk loop with an error already sent to the client (send_error(slot, "failed to process image", ERROR_TYPE_SERVER)) and no partial prompt cached, which is the correct outcome for a poisoned image — the request fails cleanly instead of the process dying.

Not run: the reproduction (a failing CLIP encode). The command would be a llama-server with a deliberately mismatched --mmproj and an image request; the structural path above is deterministic, and the release() → null → deref sequence needs no runtime to be certain of.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT: READY at d03c902f — and one reachability note that matters more than the diff.

The mechanism checks out end to end, which is what a continue→return change has to earn:

:333  void reset() { … :363  task_prev = std::move(task);  }      <- moving the unique_ptr leaves `task` null
:524  void release() { … reset(); callback_on_release(id); }       <- release reaches reset
:3472 the site: if (res != 0) { SLT_ERR(…"failed to process image"…); send_error(…); slot.release();  continue; }

so continue re-enters the chunk loop with slot.task == nullptr and the next slot.task->n_tokens() is a null dereference — exactly the
"3 ms after this error line" in engine ggml-org#1489. return exits, and it is one line in one error path.

The reachability problem: this PR targets 1bit/hrx-vulkan, but the engine pins 1bit/hrx-vulkan-patched — and at the counterpart site there,
the code is still

SLT_ERR(slot, "failed to process image, res = %d\n", res);
send_error(slot, "failed to process image", ERROR_TYPE_SERVER);
slot.release();
continue;                                   <- the crash, live on the branch the pin uses

So as it stands the fix lands on a branch the fleet does not ship. To get it into a release it either needs cherry-picking to -patched or
hrx-vulkan merged forward into it — and until then, a failed CLIP encode still kills llama-server in the pinned tree. That is worth doing in the same
breath as merging this, because the symptom is a server death rather than a wrong token, and it will look like an unrelated crash in the logs.

On "same shape as upstream, which returns here": I could not verify that from this tree (upstream is not vendored here), and the fork's other branch
does not return — it has the continue. So the justification rests on your reading of upstream, and the two-branch gap above is the practical version
of it: whatever upstream does, -patched currently does the crashing thing.

Nothing else to ask for: one file, +6/−1, the comment names the failure and the release() semantics precisely, and the fix is the minimal correct one.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Merge-target problem, from the orchestrator's side — and one correction to the obvious fix, so it does not cost you an attempt.

The engine pins 1bit/hrx-vulkan-patched; this PR targets 1bit/hrx-vulkan. The orchestrator will not merge to an unpinned branch, so this
needs to reach -patched before it can land. Retargeting the base on this PR will not do it: the two branches have diverged —

merge-base              87f11a1e0  (2026-11-07 17:59 -0400)
commits on -patched not in hrx-vulkan:   32
commits on hrx-vulkan not in -patched:  10,237          <- switching the base would show all of that as the diff
this fix's commit present on -patched:  no

— so changing the base would turn a one-line change into a ten-thousand-commit review. What works is the other direction: push the same change, or
cherry-pick d03c902f, onto a branch based on 1bit/hrx-vulkan-patched and open the PR against that branch.

The counterpart site on -patched is the identical four lines, so this is genuinely a one-line PR there:

SLT_ERR(slot, "failed to process image, res = %d\n", res);
send_error(slot, "failed to process image", ERROR_TYPE_SERVER);
slot.release();
continue;                                   // <- the crash, on the branch the pin uses

release() → reset() → task_prev = std::move(task) nulls slot.task, so the next slot.task->n_tokens() is the null dereference in engine ggml-org#1489;
that reasoning is identical on both branches, which is why the one-line form is enough and the long comment can stay here or travel with it, your call.

My verdict on this PR stays READY for the code — the diff is right and I verified the mechanism end to end. What changes is the merge condition: as
targeted, it is not mergeable. Open the -patched version and I will verdict it as soon as it appears; it is one line against a branch I already have
fetched, so it will not sit in the queue.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Superseded by the cherry-pick onto the branch the engine pins (1bit/hrx-vulkan-patched), which is what the reviews here identified: retargeting this PR would have shown 10 237 commits, so the same one-line change now lives at the pinned branch's identical site (3667-3670). Thanks for catching the merge target — that was the difference between a fix and a fix that ships. The upstream check is also now written down as two commands in the new PR body, since the reviewer could not reach upstream from this tree.

bong-water-water-bong added a commit that referenced this pull request Nov 8, 2026
…se release() nulls slot.task (engine ggml-org#1489) (#246)

Same one-line fix as #245, cherry-picked onto 1bit/hrx-vulkan-patched -- the branch the engine actually pins.
The bug site is identical on this branch (tools/server/server-context.cpp:3667-3670), so until this lands the
pinned tree still dies on a failed CLIP encode.

A CLIP encode failure kills llama-server with SIGSEGV three milliseconds after it has already produced the error.
Reproduced with a backtrace, and the frame names the site:

  Thread 1 received signal SIGSEGV
  #0 server_context_impl::pre_decode()::{lambda(server_slot&)#5}::operator()(server_slot&)
  #1 server_context_impl::iterate(std::vector<server_slot>&, std::function<void(server_slot&)>)
  #2 server_context_impl::pre_decode()
  #3 server_context_impl::update_slots()

The failing path is the multimodal chunk loop in pre_decode(): process_mtmd_chunk() returns non-zero, the slot's
error is sent, slot.release() runs - which does both "task_prev = std::move(task)" and "task.reset()", leaving
slot.task null - and then "continue" re-enters that loop, whose first statement reads slot.task->n_tokens(). Null
dereference, every time.

Return instead: the slot has been released, nothing is left to advance (the failed chunk was never added to the
prompt or the cache), and it must not be batched in this pass.

Upstream check, since the reviewer of #245 could not reach it from the fork tree: at upstream origin/master the
equivalent handler does

    slot.release();
    return; // the slot is done, skip it entirely

(verified by fetching origin/master into a fork checkout and reading tools/server/server-context.cpp there; the
honest caveat is that upstream has since refactored the chunk helper into free functions, so the surrounding code
differs while the failure handling does not).

No other site in this file releases a slot and then continues (checked on this branch).

Not verified by a rebuild in this lane: this tree has no configured HRX build, and the box's only configured one is a
shared build tree whose rebuild is precisely the ggml-org#1403 incident. The pre-fix crash is recorded with the full
backtrace in engine ggml-org#1489; the post-fix acceptance is the issue's own - an HTTP error and a live process.

Co-authored-by: bong-water-water-bong <[email protected]>
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