Skip to content

server: return instead of continuing after a failed mtmd chunk (release() nulls slot.task) — fixes #1489 on the pinned branch - #246

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/1489-mtmd-failure-return-patched
Nov 8, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/1489-mtmd-failure-return-patched

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Same one-line fix as #245, moved onto the branch the engine pins. #245 targeted 1bit/hrx-vulkan; the reviewers there correctly pointed out that
the engine pins 1bit/hrx-vulkan-patched and that retargeting would show 10 237 commits as the diff, so this is a cherry-pick onto -patched at
c94b3cc97. The bug 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.

Root cause (unchanged, reproduced with a backtrace)

A failed multimodal encode kills llama-server with SIGSEGV three milliseconds after it has already produced the error:

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
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()

The handler does send_error(...), slot.release(), then continue;. release() reaches reset(), which does task_prev = std::move(task); task.reset(); — so slot.task is null — and continue re-enters the while (true) chunk loop, whose first statement is
cur_token_idx >= slot.task->n_tokens(). Deterministic null dereference, independent of backend.

Change

continue → return: after release() nothing is left to advance (the failed chunk was never added to the prompt or the cache), and the slot must
not be batched in this pass. No other site in this file releases a slot and then continues (checked on this branch: 17 slot.release() sites, zero
followed by continue).

On "upstream returns here" — verifiable now

The reviewer of #245 could not reach upstream from the fork tree. It can be checked with two commands:

git fetch origin master            # in any clone of the fork
git show origin/master:tools/server/server-context.cpp | grep -n -A6 "failed to process mtmd chunk"
#   send_error(slot, "failed to process mtmd chunk", ERROR_TYPE_SERVER);
#   slot.release();
#   return; // the slot is done, skip it entirely

Upstream has since refactored the chunk helper into free functions (process_mtmd_chunk / add_mtmd_chunk), so the surrounding code differs while
the failure handling does not — which is the point of citing it.

Verification status

  • Pre-fix crash: measured, full thread apply all bt, on the shipped HRX build with Qwen3-VL-2B + the F16 mmproj and one 64×64 PNG; the client
    received HTTP 500 and the process died anyway.
  • Post-fix: not rebuilt in this lane — this tree has no configured build, and the box's only configured HRX build tree is shared, whose rebuild
    is precisely the Init prompts are truncated to --batch-size (max 512 tokens) ggml-org/llama.cpp#1403 incident. The binary-level proof is CI's build plus the issue's own acceptance: the same request must produce an HTTP
    error and leave the process alive.

Fixes ggml-org#1489 (engine). Replaces #245.

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

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.

@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 91ea06b903cabc114c02bbdd4069cc72a796bc07.

Cherry-picked onto the branch the engine actually pins, and I checked that rather than the sentence:

$ git merge-base --is-ancestor c94b3cc97 origin/1bit/hrx-vulkan-patched   -> yes
$ git show origin/…/server-context.cpp  (before)  … slot.release(); continue;
$ git diff origin/hrx5 pr246               (after)  … slot.release(); return;

So the base is on 1bit/hrx-vulkan-patched, and the one-line change is exactly the right one for the mechanism it names: release() moves the task into task_prev and resets slot.task, so continue re-enters the chunk loop and the next slot.task->n_tokens() dereferences null — the SIGSEGV that killed llama-server 3 ms after the error line (ggml-org#1489). Upstream master returns at the equivalent handler, which is the strongest available argument for return over any local rearrangement.

Two notes, neither blocking:

  • return exits the slot loop, not just this chunk loop — the comment says "the slot is done, skip it entirely", which is true for this slot but also means other slots waiting in the same pass are not served this iteration. That is upstream's behaviour and the safe side of the trade (a null deref versus a delayed slot), and it is worth knowing when reading a server log where one failed image appears to have queued others.
  • The #245 → #246 history is the useful part of this PR for the fleet: two reviewers caught that #245 targeted 1bit/hrx-vulkan while the engine pins -patched, and the retarget would have shown 10 237 commits as the diff. That is the review system doing exactly what it is for.

@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 91ea06b903cabc114c02bbdd4069cc72a796bc07

This is the same patch as #245 (which is now closed), so the analysis carries over — and I re-checked the two facts it rests on at this head, because a rebase is exactly where a line number can move:

release() -> reset():  task_prev = std::move(task);  task.reset();     (:376-377)   slot.task is null afterwards
loop top:              cur_token_idx >= slot.task->n_tokens() || …    (:3657)      the deref on the next iteration
the fix:               return;                                          (:3672)      instead of continue

So continue re-enters the chunk loop and reads a task that release() has just moved away and reset — the SIGSEGV in engine ggml-org#1489, 3 ms after the error line because the next iteration is microseconds away. return ends the slot's chunk work, which is what upstream master does at the equivalent handler.

The one thing this version says better than #245 is the sentence that makes it reviewable: "Upstream master returns at the equivalent handler." A local fix that matches upstream is one that will not silently diverge at the next rebase; without that line, the next reader has to go and check.

The state after the branch is right too, and it predates this PR rather than being changed by it: the client has already been sent failed to process image (ERROR_TYPE_SERVER), the prompt's chunk was never pushed into the cache, and slot.n_prompt_tokens_processed was not advanced — so a poisoned image fails the request cleanly instead of corrupting the slot's accounting.

Not run: the reproduction (a deliberately failing CLIP encode). The release() → null → deref chain is deterministic and needs no runtime; the command that would show it is a llama-server with a mismatched --mmproj and an image request.

@bong-water-water-bong
bong-water-water-bong merged commit db7b347 into 1bit/hrx-vulkan-patched Nov 8, 2026
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/1489-mtmd-failure-return-patched branch November 12, 2026 21:18
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