Skip to content

feat(serve): a chat-completions server, on the CPU and from the GPU - #32

Merged
Defilan merged 14 commits into
mainfrom
agent/i2-serve
Nov 25, 2026
Merged

Defilan merged 14 commits into
mainfrom
agent/i2-serve

Conversation

@defilan-agent

@defilan-agent defilan-agent Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What

A chat-completions server, so the engine can be used by the tools that already speak that format.

  • New crate dluth-serve: an HTTP/1.1 layer written on std::net (no new dependency), the request and response formats, a reader that cuts a reply into thinking and text, an engine that keeps its last conversation so a follow-up turn only reads what is new, and the server loop.
  • dluth serve runs it on the CPU model; dluth-cuda serve runs it on the GPU.
  • In dluth-model: conversations of several turns after the model's own template, drawing a token from the scores (temperature, top_p, seed), and generation that continues from where the model stands.
  • Routes: /v1/chat/completions (whole or streamed), /v1/models, /health.
  • DLUTH_API_KEY makes a bearer key required. It is compared in constant time and never printed.
  • Requests wait in a queue of a set length; a full queue answers 503. A request must arrive whole within one deadline.
  • Learning note 24 and a Serve section in the README.

Limits

One conversation at a time, text only, no tools, plain HTTP, one request per connection. It listens on loopback unless told otherwise.

How it was checked

  • Mac: format, lint, and the test suite with the real model.
  • GB10: format, lint, and the whole workspace's tests with the real model, including the engine against the model used directly.
  • Planted bugs 119 to 139 for the server, the engine, drawing and conversations, each caught by a test. Two survived their first run and showed thin tests (headers counted together; a listener that leaves), which were then written.
  • By hand on the GB10, loopback only: whole and streamed replies, a follow-up turn, a wrong key, a full queue.

Review

Fixed:

  • A best score that is not a finite number made drawing a token undefined. It is now the greedy choice, with a test.
  • The read deadline started again with every read, so a client sending a byte now and then could hold a place for ever. There is now one deadline for the whole request, with a test that trickles bytes.
  • Smaller: 401 bodies say authentication_error; the scheme name bearer is accepted in any case; README additions; a misleading test comment.

Declined:

  • "A stop string at the very start of a reply never stops." The expression (text.is_empty() || sink(..)) && !hit is false whenever a stop was hit. A test now pins the case.
  • "A test asserts on a string that cannot occur." The reviewer read a copy of the diff in which the model's marker had been rewritten for it; the test is right against the real file.

@Defilan
Defilan merged commit d1b1480 into main Nov 25, 2026
2 checks passed
@Defilan
Defilan deleted the agent/i2-serve branch November 25, 2026 16:42
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