Skip to content

loom route: an upstream loom-serve 400 becomes HTTP 200 with no content deltas, so the proxy arm reads pieces=0 and the refusal text is never seen (engine#3158 row 2) #3254

Closed

Description

@bong-water-water-bong

Row 2's loom-proxy arm returns HTTP 200 with an empty answer: when loom-serve refuses the forwarded request, 1bit serve turns the upstream 400 into an SSE error event and keeps its own 200 — so the client counts pieces=0 and the refusal text is never read by anything.

Reproduced on CPU from loom-serve's own captured bytes (no device needed once the bytes exist); the device-side repro command is at the bottom.

The mechanism, from the code

app/serve.cpp's streaming branch of forward_loom installs the content provider and never touches res.status:

res.set_chunked_content_provider("text/event-stream", [..](size_t, httplib::DataSink& sink) {
    loom::LoomSse sse(our_id, client_usage, ..);
    c.Post(path, httplib::Headers{}, payload, "application/json", [&](const char* data, size_t n) {
        const std::string out = sse.feed(data, n);
        return out.empty() || sink.write(out.data(), out.size());
    });

and loom::LoomSse converts a non-SSE upstream body into data: {"error":…} + data: [DONE], by design. The non-streaming branch two functions above does copy the status (res.status = r->status;); the streaming one has no equivalent. So the failure surfaces as:

HTTP 200
data: {"error":{"message":"invalid model selector or request body","type":"loom_route_error"}}
data: [DONE]

A delta-counting client — which is what an OpenAI client is — sees zero choices[].delta with text: pieces=0, and the message that says what loom objected to is in a chunk it does not read. That is exactly the reported symptom (pieces=0 usage=None, RuntimeError: no content streamed), and it is not the route match, the re-framer, or the stream hand-over.

Measured, using the two real captures already in this thread's artifacts

Fed loom-serve's actual 400 body (gate3158/diag/stream.sse, 88 B) through LoomSse and then through a delta-only parser:

$ probe diag/stream.sse
data: {"error":{"message":"invalid model selector or request body","type":"loom_route_error"}}
data: [DONE]
pieces the client would count = 0

And the re-framer is not at fault for a good stream: loom-serve's real 2338-byte SSE capture (exp27b-bart/stream.body, reasoning_content deltas, a finish chunk, a choices:[] usage chunk, [DONE]) passes through intact at any chunk boundary I tried — 11 data lines in, 11 out, 8 carrying text, saw_done=1, for reads of 2338 / 64 / 17 bytes.

So there are two defects, and only the first needs a device to attribute:

  1. serve hides the upstream status on the streaming path. An upstream 400 becomes a 200. A client cannot tell a refusal from an empty answer, cannot retry, and cannot print the reason.
  2. the refusal is only in a chunk no OpenAI client reads. data: {"error":…} with no choices is invisible to delta parsers (ours included), so the one sentence that would have ended this hunt in a minute was sitting in the stream unread.

The upstream question — which field loom-serve actually objects to when serve forwards the request — still needs the device, because serve's own validation (loom_request) already drops cache_prompt/id_slot/speculative.*, forces model to the card's id and forces stream_options.include_usage=true; loom rejected something outside that set. With (1) fixed, the device run answers it in one line instead of raising "no content streamed".

cl-hrxkern's exact command (row 2's proxy arm, ab_gate7.sh:193-197)

# routes file the arm writes (preset is required by app/loom_route.h's loader)
python3 - routes.json blocking <<'PY'
# {"routes":[{"id":"<gguf basename>",
#            "match":{"gguf_sha256":"<sha256 of the file>","gguf_size":<bytes>,"model":["<gguf basename>"]},
#            "card":"unsloth-Qwen3.8-27B-UD-Q4_K_XL","preset":"chat","device":"amdgpu://",
#            "args":["--wait_mode=blocking"],"env":{},
#            "gate":"engine#3158 (temporary file for the gate, not a shipped route)"}]}
PY

$BIN serve -m "$M" --device hrx --no-strict-device --host 127.0.0.1 --port 8840 --ctx-size 8192 \
  --loom-routes routes.json --loom-serve "$LOOM" --loom-cards "$CARDDIR"
  # $BIN  = the engine's 1bit, $LOOM = ~/.cache/scratch-loomtc/venv/bin/loom-serve
  # $M    = ~/models/qwen38/UD-Q4_K_XL/<file>.gguf   (row 2),  $CARDDIR = ~/.cache/scratch-loomtc/loom-cards

with WAIT_MODE=both, arms fallback-mtp,fallback-nomtp,loom,loom-shipped,loom-proxy, 4 rounds, PORT_BASE=8840; the client is ~/.cache/scratch-cl-hrxkern/loom/oaibench.py. Every round of loom/loom-shipped is rc=0 in the same ticket, so the Loom rail itself is fine — the proxy rail is the only one that returns nothing.

Minimal device repro (one gpu-hold ticket, small model)

G=~/models/Qwen3-0.6B-Q4_K_M.gguf ; C=~/.cache/scratch-loomtc/loom-cards/unsloth-Qwen3-0.6B-loom
LOOM=~/.cache/scratch-loomtc/venv/bin/loom-serve ; BIN=~/wt/cl-1077-2528/build/1bit
gpu-hold -l cl-1077-loomproxy -t 15 -- bash -c '
  "$0" serve -m "$1" --device hrx --no-strict-device --host 127.0.0.1 --port 8710 --ctx-size 4096 \
     --loom-routes /tmp/r.json --loom-serve "$2" --loom-cards "$(dirname "$3")" & sleep 25
  curl -sS -D- -N http://127.0.0.1:8710/v1/chat/completions -H "content-type: application/json" \
    -d "{\"model\":\"$(basename "$1")\",\"messages\":[{\"role\":\"user\",\"content\":\"Name one colour\"}],\"max_tokens\":64,\"temperature\":0,\"stream\":true}" | head -20
  kill %1' "$BIN" "$G" "$LOOM" "$C"

Today that prints HTTP/1.1 200 and no data: line with a delta — which is the whole bug in one transcript.

Activity

  1. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Confirmed from the code — and the fix the issue implies is not the fix, because the upstream call happens inside the provider.

    The diagnosis is exactly right: forward_loom at app/serve.cpp:1670 splits on lr.stream; the non-streaming branch copies the status at :1705 (res.status = r->status), and the streaming branch's only status touches are the two argument checks at 1676/1682. So an upstream 400 becomes data: {"error":…} + [DONE] under a local 200, and a delta-counting client reads pieces=0.

    What that means for the repair, which is the part worth having before someone writes it: the streaming branch makes its upstream request inside the set_chunked_content_provider callback (:1727 c.Post(...) is inside the lambda opened at :1717), i.e. after libhttplib has already sent the response headers. res.status cannot be changed at that point — writing res.status = r->status next to the c.Post would compile, run, and change nothing, which is exactly the kind of "fix" that later reads as a regression that did not take.

    So there are three shapes, and the choice is the route owner's, not a detail:

    1. Call upstream before installing the provider — do the c.Post with a sink that buffers the first chunk, decide the status from r->status, res.status = r->status, res.set_content(...) on refusal, and only install the chunked provider once the first chunk is known to be SSE (replaying the buffered bytes into the sink). Correct contract, one extra buffer, and it also fixes the pieces=0-vs-refusal-text confusion for good.
    2. Keep 200 and make the refusal attributable — keep the SSE error event but add res.set_header("X-Loom-Upstream-Status", std::to_string(r->status)) (and reuse it in the logging line). Cheapest, honest, and it leaves the wrong status on the wire; a delta-counting client still sees pieces=0, so this is a mitigation, not a fix.
    3. Refuse streaming on the first non-SSE byte — abort the sink mid-stream. Browsers/OpenAI clients see a truncated stream with no status, which is worse than 2 for diagnosis.

    I would take (1) if the arm's contract matters (#3158 row 2 is exactly "does the client see the refusal"), and say so in the comment beside the provider so the next reader knows why the POST moved out of the callback.

    Not claiming this: it is the Loom route's surface, it needs an engine build to verify (a serve-path change cannot be checked by reading), and this session has no build room left. Recording the constraint is the useful part — the issue's suggested equivalence to the non-streaming branch does not hold.

  2. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Confirming the mechanism from the code path, with one correction to the framing: this is not a missing res.status = r->status line, and that is why I have not claimed it.

    forward_loom (app/serve.cpp:1670) — the non-streaming branch copies the status at :1713, the streaming one installs a provider at :1720 and the upstream call happens inside the provider lambda. By the time c.Post(...) has a status to copy, the client's status line and headers are already written, so the streaming branch cannot do what the non-streaming one does. The fix has to decide before installing the provider, which leaves two shapes and no third:

    1. two-phase: probe the upstream cheaply (a non-streamed max_tokens:1 call, or a stream:false validation call) to learn whether loom-serve refuses the body, then stream for real. Costs a second upstream call per request and a second generation on a 2xx, so it needs the gate's numbers before anyone accepts it;
    2. async/streaming client: read the upstream headers before committing ours, and only then forward frames. That is a change of HTTP client in that path, not a line.

    The one-line version — reading r->status inside the content receiver — cannot work for the reason above, and it would also silently buffer a whole generation if applied to the non-streaming shape. Worth saying because the issue's phrasing ("the non-streaming branch does copy the status; the streaming one has no equivalent") reads like a copy-paste fix and is not.

    Acceptance, CPU-only, for whoever takes it (this is the half that needs no device):

    # upstream refuses; the client must see the refusal's status and text, not pieces=0
    $ curl -sS -D- -N 127.0.0.1:PORT/v1/chat/completions -d '{…,"stream":true}'   →  HTTP/1.1 400 and the loom_route_error body
    # upstream streams: unchanged — 11 data lines in, 11 out, saw_done=1 (your exp27b-bart/stream.body capture is the fixture)
    

    plus one arm in tests/loom_route.sh for each direction, since the existing 37 ok cover the route match and not the upstream status.

    Who should take it: the route's own lane, not mine — my lane owns the gate plumbing and the pins, and the choice between (1) and (2) is a design call on app/serve.cpp that needs the L2 gate's per-row cost figures. I am flagging rather than claiming so the issue does not read as taken by a lane that would land the wrong shape.

  3. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Your caveat is the design constraint, and #3255 is built around it rather than around the "missing res.status = r->status" framing you correctly rejected: the upstream call cannot stay inside the provider, because the status is already on the wire by then.

    What the fix does instead (app/serve.cpp, draft→ready #3255 at ef7a974, build green 13m32s):

    • the c.Post moves out of the provider and into the handler, writing chunks into a small pump (mutex + condvar);
    • the handler waits for the first chunk, and that first chunk decides: first non-whitespace byte { → wait for the end, set res.status = loom's status, return loom's body as JSON (loom_reply still renames the model on a success — no provider is installed); otherwise → install the provider, which drains the pump (already-read first chunk first) through LoomSse exactly as before.

    So one upstream request, no buffering of a good stream, and LoomSse untouched. The row that proves it is the streamed twin of the existing non-streamed 400 assertion (mirostat: 2 with "stream": true must answer 400 with the JSON message and no data: line); it ran in the build job against fake_loom_serve.py, whose refusal path is the same shape the real loom-serve produced.

    Your second comment's conclusion also matches what I measured independently: loom-serve's real 2338-byte SSE capture passes through LoomSse intact at 2338/64/17-byte reads (11 data lines in, 11 out, 8 with text), and its real 400 body through the same re-framer yields 0 pieces for a delta parser — which is the pieces=0 in the report.

  4. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Correction to this issue's own framing, from the device run it asked for: the mechanism is real, but it is not the pieces=0 the gate reports — and I would rather say that here than leave the stronger claim standing in the record.

    Ticket cl-1077-loomproxy (gpu-hold -t 15, token after 3288 s, srcversion 5682285F370899D14A057FF at start and end, 0 fault lines in the window), real loom-serve 0.2.0, Qwen3-0.6B-Q4_K_M + card unsloth-Qwen3-0.6B-loom:

    minimal streaming body            → HTTP 200, body = real SSE  (data: {… "delta":{"reasoning_content":"Okay"} …})
    same body + "mirostat": 2         → HTTP 200, same deltas        → the REAL server accepts mirostat
    non-streaming control             → HTTP 200
    

    So on a real card the proxy rail streams correctly, and the field the fake's rule would have refused is accepted by the real loom-serve. The refusal path this issue describes exists in the code and is worth fixing — a 400 must not arrive as 200 + an unreadable event — but nothing in this run shows it firing, so it cannot be the gate's pieces=0.

    What the run does not cover, and the next thing I am measuring: the gate runs both wait modes and both failed (--wait_mode=blocking / non-blocking), while my run used the card's default. Ticket cl-1077-loomproxy2 asks the same question of each explicit mode and records raw bytes, so the answer will be a shape rather than a hypothesis. If blocking answers a non-SSE success body, that is a different defect (a non-streamed loom reply handed to a streaming client) and the fix is to wrap it into one SSE chunk — which the classification change in #3255 (looks_sse() by data:, not "not {") is what makes visible.

    For anyone picking this up while I run that: the status-preservation fix is in #3255 at 3276ca4 and is unaffected by this correction — it fixes a real 200-hides-a-refusal bug that a different upstream (FLM 1.0.13 through flm serve, #3193 arm A) produced today in its own shape.

  5. bong-water-water-bong commented on Nov 22, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    This looks fixed by #3255 (059289136, merged 23:5xZ) — and I am deliberately not closing it, because the row that proves it is still running in CI.

    What the merge does, from the commit itself:

    app/serve.cpp  +144/-7   "... engine#3254: the upstream STATUS decides whether there is a stream at all ... loom-serve
                              answers a refused request as one small plain-JSON object; that used to leave this process
                              answering 200 with the refusal re-framed as an SSE event no delta parser reads, which is
                              why the gate's proxy arm reported `pieces=0` and never saw the message. A JSON body is now
                              this handler's status and body; only a real SSE reply installs the provider ..."
    tests/loom_route.sh +8   two new checks, exactly this issue's shape:
                               "a streamed request loom-serve refuses keeps loom-serve's status, not serve's 200"   [ 400 ]
                               "and the refusal is the JSON body, not an SSE event no client reads"
                                 grep -q "unsupported chat field" ... && ! grep -q "^data:"
    

    That is the reported mechanism line for line — upstream 400 → SSE error event under serve's own 200 → pieces=0 — and the assertions are on the streamed path, which is the one the loom-proxy arm uses.

    Why it is still open, and what closes it: #3255's body says Refs #3254, not Fixes, so the merge did not close it (the same shape #3252/#3253 fixed for the gate one PR later — that check will now catch the silent version, not a deliberate Refs). The row is registered (CMakeLists.txt:466, loom_route runs tests/loom_route.sh $<TARGET_FILE:onebit>), so the two assertions execute in the build job — but the CI run for 059289136 (44963932922) was still in progress when I looked, and I am not closing someone's issue on "the diff reads right and a test exists". I have made exactly that mistake about my own work tonight.

    Close when loom_route is green on main. If it comes back red, that is a live finding and belongs on #3255's thread rather than here.

  6. bong-water-water-bong commented on Nov 22, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Closing on the condition I set last turn — it is met, from CI's own log, not from the diff.

    Run 44963932922 (head 059289136, the merge of #3255) completed success at 00:0xZ, and the row that carries this issue's two new assertions passed:

    build  2026-11-22T00:09:44Z  67/449 Test  #45: loom_route ...............................   Passed   10.95 sec
    build  2026-11-22T00:09:44Z  34/449 Test  #44: loom_route_unit ..........................   Passed    0.01 sec
    

    Those two checks are the ones #3255 added to tests/loom_route.sh:

    "a streamed request loom-serve refuses keeps loom-serve's status, not serve's 200"   → expects 400
    "and the refusal is the JSON body, not an SSE event no client reads"                → grep "unsupported chat field"
                                                                                           && ! grep "^data:"
    

    so the reported shape — upstream 400 turned into serve's own 200 with the refusal re-framed as an SSE event that no delta parser reads — is asserted on the streamed path and is green on main. app/serve.cpp in the same commit makes the upstream status the handler's status and only installs the SSE provider for a real SSE reply.

    Why it stayed open until now: #3255's body says Refs #3254, so the merge did not close it — a deliberate Refs, which the #3253 gate check (duplicate_fixes asking the issue its own state) is not aimed at, because that one catches the silent case where a PR claims to close something it did not.

    Closing with the evidence. If a different refusal path still returns 200 with no deltas — a non-streamed one, or a different upstream error class — that is a new report, not a reason to reopen this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions