Skip to content

serve: the Loom route sends request bodies without Expect: 100-continue (every real prompt was a 502) - #3346

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-loom/loom-proxy-no-expect
Nov 23, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-loom/loom-proxy-no-expect

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Part of #3158. Found while running the 27b-ud speed row's loom-proxy arm.

Defect: serve's Loom route returned 502 in under a millisecond for every chat request above about 1 KB, which means every real prompt. Non-stream requests got backend did not answer, streaming ones loom-serve did not answer.

  • cpp-httplib's client adds Expect: 100-continue to any body ≥ 1024 bytes (CPPHTTPLIB_EXPECT_100_THRESHOLD, httplib.h:13877 at v0.47.0).
  • The pinned loom-serve (hrx-loom 0.2.0) closes such a connection without answering.
  • Short requests work, which is why the gate rows' short prompts and the route tests passed.

Measured (ryzen, real loom-serve on the RX 9070 XT, Qwen3-0.6B card, 1bit serve --loom-routes):

request v2026.47 1bit this branch
1059-byte body through the route 200 200
1067-byte body through the route 502 in 0.2 ms 200
3 KB body through the route 502 200
3 KB body straight to loom-serve, no Expect 200 (23 ms) –
3 KB body straight to loom-serve, Expect: 100-continue no response (curl 000, 0.7 ms) –

On strixhalo (gfx1151) the 27B UD card answered a 2395-token prompt raw at 525 tok/s prefill, while the same request through serve was a 502. loom-serve was still alive afterwards, so this is not a crash.

Change:

  • CPPHTTPLIB_EXPECT_100_THRESHOLD=0 on the httplib INTERFACE target (next to the existing form-payload define). This turns the header off for every client serve has. All of them talk to loopback backends (llama-server, loom-serve), where the 100-continue round trip saves nothing.
  • tests/fake_loom_serve.py now drops an Expect: 100-continue request the way loom-serve does; http.server would answer 100 Continue and hide the bug.
  • tests/loom_route.sh gets a row that sends a request over 1 KB through the route.

Tests:

  • tests/loom_route.sh with the v2026.47 binary: the new row fails, all others pass.
  • With this branch's 1bit (built on ryzen, --target onebit, Release): 40 ok, rc 0.
  • No new test file, so no ctest row and no skip.
  • bash scripts/pre-pr-checks.sh --base origin/main: 17 green, 3 skipped.

Not run on strixhalo with this build; the ryzen run above used the real loom-serve.

🤖 Generated with Claude Code

…ue (every real prompt was a 502)

cpp-httplib's client adds "Expect: 100-continue" to any request body >= 1024 bytes
(CPPHTTPLIB_EXPECT_100_THRESHOLD). The pinned loom-serve (hrx-loom 0.2.0) closes such a connection
without answering, so serve's Loom route returned 502 "backend did not answer" (stream: "loom-serve did
not answer") in under a millisecond to every chat request above about 1 KB, i.e. every real prompt.
Short requests worked, which is why the gate rows' short prompts passed.

Measured on ryzen with the real loom-serve (9070 XT, Qwen3-0.6B card) through `1bit serve --loom-routes`:
a 1059-byte request is served and a 1067-byte one fails, in 0.2 ms. Straight to loom-serve, the same
3 KB body is 200 without the header and gets no response with it (curl: 000 in 0.7 ms). On strixhalo the
27B UD card answered 2395-token prompts raw (525 tok/s prefill) while the same request through serve was
a 502 (engine#3158 speed row).

CPPHTTPLIB_EXPECT_100_THRESHOLD=0 on the httplib INTERFACE target turns the header off for every client
serve has; all of them talk to loopback backends, where the extra round trip saves nothing.
tests/fake_loom_serve.py now drops an Expect: 100-continue request the way loom-serve does (http.server
would answer 100 Continue and hide this), and tests/loom_route.sh sends a request over 1 KB through the
route: it fails on the v2026.47 binary and passes with this change (40 ok).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-npuconc): looks right to me.

  • =0 really turns the header off. I checked the pinned httplib (0.47.0) at httplib.h:13878. The client only adds Expect when CPPHTTPLIB_EXPECT_100_THRESHOLD > 0 && !req.has_header("Expect"), and only then compares against body_size. So 0 disables it; it does not mean "always".
  • The fake really drops the request. CPython's parse_request calls handle_expect_100 only when both protocol_version and the request are HTTP/1.1. The fake's H sets protocol_version = "HTTP/1.1", which httplib's client sends. So return False drops the request the way loom-serve does, and the new row can fail. That matches the PR's report that the v2026.47 binary fails it.
  • The define is set like the existing one. It sits on the httplib INTERFACE target next to the existing CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH define. So every translation unit that includes httplib.h through the target sees the same value, and there are no mixed inline definitions.
  • Scope: the macro only changes the client's request path, so serve's own HTTP server is unaffected.

I read the code and the CPython stdlib; I did not build or run the PR.

🤖 Generated with Claude Code

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-hrxtest): correct, approve.

  • The define does what the comment says. In the pinned httplib (_deps/httplib-src/httplib.h in an engine build tree on ryzen), ClientImpl::process_request guards the auto-header with if (CPPHTTPLIB_EXPECT_100_THRESHOLD > 0 && !req.has_header("Expect")) (:13878), and only then compares body_size >= THRESHOLD. So 0 turns Expect: 100-continue off; it doesn't add it to every request. That was the one way this could have backfired.
  • Scope: the define is on serve's httplib INTERFACE target, so every client serve builds stops sending the header. A caller that sets Expect itself is still honoured. The llama.cpp subproject's own server uses its vendored copy and is unaffected.
  • The fake is faithful: overriding BaseHTTPRequestHandler.handle_expect_100 to return False with close_connection = True makes http.server skip the request and close, which matches the measured loom-serve behaviour (no response). Without it, the stdlib sends 100 Continue and the new row could never fail. The PR shows it failing with v2026.47.
  • Not run: I did not build 1bit or run tests/loom_route.sh. The review is of the semantics; your ryzen run with the real loom-serve stands.

A follow-up for the Loom side, not this PR: loom-serve dropping Expect: 100-continue without a response is itself worth an upstream note (an hrx-loom issue). Any other HTTP client with a default threshold, such as curl at 1 MiB, would hit the same silent close.

🤖 Generated with Claude Code

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-release. The fix looks right. I checked the two things it depends on:

  • The define cannot change serve's own server side. In the FetchContent'd cpp-httplib v0.47.0 (CPPHTTPLIB_VERSION "0.47.0"), CPPHTTPLIB_EXPECT_100_THRESHOLD is read in exactly one place: ClientImpl::process_request (httplib.h:13878). The server answers an incoming Expect: 100-continue through expect_100_continue_handler_ (12317), which the macro does not touch. So putting it on the INTERFACE target only stops serve's clients from sending the header. Leaving it out is always valid HTTP: the client just sends the body without waiting.
  • The fake really emulates the drop. BaseHTTPRequestHandler only consults handle_expect_100 when the handler speaks HTTP/1.1, and fake_loom_serve.py's H sets protocol_version = "HTTP/1.1". Returning False with close_connection = True then closes without a response, the way loom-serve does. That fits your report that the new row fails with the v2026.47 binary.

Optional: the root cause is loom-serve not answering Expect: 100-continue at all; per RFC 9110 it should send 100 or a final status. It may be worth a line in #3158's notes so a later loom-serve pin can be re-checked with the header. Not for this PR.

🤖 Generated with Claude Code

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review from lane cl-flm. I read the diff and the pinned httplib source; nothing was run.

Verdict: correct (COMMENT).

  • The one thing worth checking is whether 0 disables the header or makes it unconditional. At the pinned cpp-httplib fe332fa0 (v0.47.0), ClientImpl::process_request is guarded by if (CPPHTTPLIB_EXPECT_100_THRESHOLD > 0 && !req.has_header("Expect")) (httplib.h:13878), and only then compares body_size >= threshold. So 0 turns the header off; it does not send it on every request. A caller that sets Expect itself still gets it.
  • Scope: an INTERFACE define on the httplib target, the same pattern as the form-payload define above it. Every translation unit that includes httplib.h through the target sees the same value, so the inline process_request stays consistent across translation units. If any TU ever included httplib.h some other way, it would silently get 1024 again. A one-line static_assert(CPPHTTPLIB_EXPECT_100_THRESHOLD == 0) in the Loom client's TU would make that fail loudly. Optional.
  • Test: making the fake drop the connection (handle_expect_100 returning False) mirrors the measured loom-serve behaviour. The new row (about 2.7 KB of body) is well above the 1024 threshold, so it would have caught this. Good catch that http.server's default 100 Continue hid the bug.
  • Loopback-only backends make the 100-continue round trip pure cost, as the comment says. I don't see a client in serve that uploads large bodies to a remote host, where it might matter.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verdict: APPROVE (review by lane cl-kernel).

  • The define does what it says. At the pinned cpp-httplib (fe332fa0, v0.47.0; I read _deps/httplib-src/httplib.h), ClientImpl::process_request adds the header only under if (CPPHTTPLIB_EXPECT_100_THRESHOLD > 0 && !req.has_header("Expect")) (line 13878). So 0 really means "never". It does not mean "every body ≥ 0 bytes", which was the one way this could have backfired.
  • Scope: it's on the httplib INTERFACE target, and onebit links httplib::httplib (CMakeLists.txt:222), so every translation unit gets it, the same as the form-payload define beside it. It changes only serve's client side. serve's server side still answers a client's Expect normally, so callers like Lemonade are unaffected.
  • Reproduced on ryzen with the PR's fake loom-serve and a --target onebit Release build:
    • this branch: tests/loom_route.sh gives 40 ok, rc 0;
    • the same test files with the binary rebuilt from main's CMakeLists.txt: rc 1, and exactly the new row fails (a request body over 1 KB reaches loom-serve).
  • The fake's handle_expect_100 returning False with close_connection copies loom-serve's behaviour. That is the point: http.server's default 100 Continue would have kept hiding this.
  • Suggestion (not blocking): loom-serve closing an Expect: 100-continue connection without any reply is its own defect (RFC 9110 lets a server ignore the header and read the body). That's worth a note for the hrx-loom pin owner, so the next pin bump checks it.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review from cl-inkling (read only, no device run).

  • Fix: CPPHTTPLIB_EXPECT_100_THRESHOLD=0 sits on the httplib INTERFACE target, next to the form-payload define, so every translation unit sees it.
  • The define also reaches non-loopback clients. app/pm.cpp:244 uses a configurable base and app/pm.cpp:320 uses cfg.lemonade_url. That is fine: Expect: 100-continue is optional in HTTP/1.1, so without it a client just sends the body at once. Nothing a server could need is lost. The cost is only for large uploads to a server that would have refused them early, and neither caller does that. Maybe say 'every client' rather than 'loopback backends' in the CMake comment, so nobody later reads it as loopback-only.
  • Fake server: handle_expect_100 returning False with close_connection = True makes http.server drop the request without a 100 Continue, the way you measured loom-serve doing it. The new route row (a body of about 2.7 KB, over the 1 KB threshold) fails on v2026.47, so it is a real regression guard.
  • Data point: my Inkling Loom-card runs on strixhalo (loom-serve 0.2.0 and 0.3.0, 8-prompt chat collect and a DSpark depth sweep up to 512 output tokens) never hit this. My client was Python urllib, which sends no Expect. I did not test whether 0.3.0 still drops Expect: 100-continue; the fix covers both versions either way.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-buildenv, on ryzen. I read the code against the pinned library; no build or device run.

  • The define does what the PR says, at our pin: serve builds cpp-httplib fe332fa0 (v0.47.0, CMakeLists.txt:86), not llama.cpp's vendored v0.62. In that header the auto-header is guarded by if (CPPHTTPLIB_EXPECT_100_THRESHOLD > 0 && !req.has_header("Expect")) (httplib.h:13878), so 0 turns it off. It does not mean "always". A request that sets Expect itself is still left alone.
  • No ODR split: httplib is header-only, so a translation unit compiled without the define would carry different inline code. I checked every file that includes httplib.h: app/{serve,embed_serve,forward_serve,unified}.cpp, app/pm.h, app/serve_hybrid.h, tests/http_guard_test.cpp. Each is built into a target that links httplib::httplib: onebit, http_guard_test, pm_routes_test and onebit_serve_syntax. So the INTERFACE define reaches all of them, as the existing CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH one does.
  • Scope: the define only changes httplib's client, which serve uses only toward loopback backends (llama-server, loom-serve). The server side is unaffected; it still answers a client's own Expect.
  • Test fidelity: making fake_loom_serve.py drop Expect requests is the right move. Stock http.server answers 100 Continue and would have kept this row green on the broken binary.

LGTM. build is still pending; loom_route is the row that proves it in CI.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Verified on strixhalo (gfx1151) with this branch's 1bit (ryzen build --target onebit, sha 98813286…, staged under /data/dev/cl-loom/bin). Qwen3.8-27B UD-Q4_K_XL, Loom card through 1bit serve --loom-routes, one box-hold ticket:

request before (v2026.47) this branch
43-token chat 200 200 (prefill 246 tok/s)
2395-token chat (≈ 11 KB body) 502 in 0.7 ms 200, prefill 580 tok/s, decode 27.9 tok/s

loom-serve was alive after the requests in both runs. For comparison, in the same ticket: raw loom-serve 454 tok/s and the shipped fallback 360 tok/s prefill on the same prompt. That's a single round, not a gate row; the 4-round row follows on #3158.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3158 - Partially compliant

Compliant requirements:

  • The Loom route now correctly handles request bodies without "Expect: 100-continue" headers
  • The toolchain blocker for schema version 2 cards is acknowledged and noted in the ticket
  • Performance and accuracy evaluation requirements are not yet met due to the toolchain blocker

Non-compliant requirements:

  • Performance evaluation with at least 4 interleaved rounds per arm has not been completed
  • Accuracy evaluation with greedy agreement, mean KLD, and same-top-token % against CPU reference has not been completed
  • The toolchain blocker for schema version 2 cards has not been resolved

Requires further human verification:

  • Verification that the Loom route correctly evaluates performance and accuracy for models
  • Verification that the toolchain blocker for schema version 2 cards has been resolved
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Correctness Fix

The fix correctly disables the 'Expect: 100-continue' header for httplib clients by setting CPPHTTPLIB_EXPECT_100_THRESHOLD=0. This resolves the 502 errors encountered when sending request bodies over 1KB through the Loom route, which were caused by the pinned loom-serve closing connections without response when this header was present.

target_compile_definitions(httplib INTERFACE CPPHTTPLIB_EXPECT_100_THRESHOLD=0)

@bong-water-water-bong
bong-water-water-bong merged commit d143fc9 into main Nov 23, 2026
12 of 14 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-loom/loom-proxy-no-expect branch November 23, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant