interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

ollm serve: POST /v1/completions raw-prompt route (DRA-290)

open 124c6161c908fbd9 #76 · opened 2026-11-07 02:07 UTC

Imported from GitHub aien-dev/aien-train#76, by drakestapleton

Base 9d373fc497f2aeae303ff91f5cc43b06e327f878 · Head 9edd881cd7d7338c8722fda95b09e656b5c96b36

drakestapleton wrote on 2026-11-07 02:07 UTC

Stacked on #72 (feat/ollm-serve-parity). DRA-290 (Omega Node): a raw-prompt route so the Node's edit→verify→review workflow can drive the own Omega model without the interim chat template.

Change

  • native/omegallm/serve.om: POST /v1/completions. prompt (non-empty string) is the whole template: context = token 0 + encoding of prompt (no role lines, no assistant: ). Same scalar options as chat (max_tokens, temperature, top_p, top_k, seed, stop, n=1). Response text_completion, id cmpl-ollm-N, choices[0].text, finish stop/length, usage. 400 invalid_request: stream true (code 27), messages/tools/tool_choice present (28), prompt missing/non-string/empty (26); tplmax and context_length_exceeded as on chat. Busy 503 and client-left 499 shared with chat. 404 text lists the route. Route flag sv 37 set in svroute; svparse→svcprm, svfull→svcfull, svid prefix.
  • tests/omegallm/serve-check.py: cmpl_* (greedy parity with ollm sample CK 7 8 0 PROMPT MERGES, control that the chat template gives different text, top_p 0 greedy, each refusal, tplmax, context, 405, 404 lists route) and t_cmpl_* on the test server (scripted output, busy 503, disconnect frees slot + 499 log line finish 4 with completion tokens < max).
  • docs/omegallm/README.md: route documented.

Status

IMPLEMENTED, EXERCISED (host CPU, private netns, round40 checkpoint). Not QUALIFIED for the Node workflow; not MERGED; not DEPLOYED.

Build

~/work/omega-node-run.sh sh -c 'CORE=$(taskset -pc $$ | sed "s/.*: //;s/[-,].*//"); CORE=$CORE OMC=$HOME/work/omega-node-e5b3/seed/out/omc OUT=$HOME/work/omega-node-ollm sh tests/omegallm/build.sh'

omc e5b32567. ollm sha256 f99fce9fe914f51b708af5b39c8f07856bdcc6f4523dd43fa457f0d26aaa4745, source (ollm.om) sha256 3f304adde3378e4a79f5c3411feb4cb8b48cd3d56ea1338064b0a563f34d6694.

Referee run

E=~/work/omega-node-evidence-serve-20261107T020240Z
~/work/omega-node-run.sh bwrap --dev-bind / / --unshare-net -- sh -c "CORES=\$(taskset -pc \$\$ | sed 's/.*: //') OLLM=$HOME/work/omega-node-ollm/ollm CK=$HOME/.local/share/omega-tool-model/round40/model.ck MERGES=$HOME/.local/share/omega-tool-model/round40/merges.bin OUT=$E/check PORT=18294 TPORT=18295 sh tests/omegallm/serve-check.sh"

Observed ($E/check/referee.txt):

PASS cmpl_greedy_parity 200 ... "text":"Frankie was a very happy","finish_reason":"length" ...
PASS cmpl_no_chat_template_control chat_template='"I\'m going to take you' raw='Frankie was a very happy'
PASS cmpl_refuse_stream 400 invalid_request 'stream is not supported on /v1/completions: send stream false or leave it out'
PASS cmpl_refuse_context 400 context_length_exceeded 'prompt is 2445 tokens including the start token; ...'
PASS t_cmpl_busy_503 health={'status': 'ok', 'in_flight': 1, 'busy': True} 503 server_busy ...
PASS t_cmpl_disconnect_logged [['C', '499', '17', '3', '4', '1205'], ['C', '499', '2', '3', '4', '1206']]
SUMMARY pass=118 fail=0
bind_loopback_only 1 ...
SERVE_CHECK PASS

allen_prompt_context ran and passed (no NOT_RUN lines).

Negative control

Mutant (scratch copy /tmp/on-mut, not committed): svcprm drops the stream refusal and appends assistant: after the prompt (diff in $E/negctl/mutant.diff). Built with the same build.sh to /tmp/on-mut/out (BUILD_OK 74d9c2f8…), served on 18296 inside bwrap --unshare-net, refereed with the /v1/completions subset of serve-check.py ($E/negctl/mini.py):

FAIL cmpl_greedy_parity 200 ... "text":"\"I'm going to get you" ...
FAIL cmpl_top_p0_is_greedy ...
FAIL cmpl_refuse_stream 200 None "JSONDecodeError(...)"
SUMMARY pass=14 fail=3

aien-spark reviewed (COMMENTED) on 2026-11-07 03:55 UTC

COMMENT, not an approval. Head 9edd881cd7d7. Reviewer hardware/runtime execution NOT_RUN; the reported host-CPU exercise is author evidence, not independent qualification.

Verdict

COMMENT: no blocking defect identified in this raw-prompt route delta. The PR remains a draft stacked on #72, not a merge recommendation or approval of the entire serving stack.

What I read at this head

  • First Hermes review: live issue comments, review records and inline comments were empty; no unchanged reviewed head to skip.
  • Exact stacked comparison 9d373fc497f2aeae303ff91f5cc43b06e327f878...9edd881cd7d7338c8722fda95b09e656b5c96b36, all 3 changed paths. The fetched compare's file inventory matched the PR inventory.
  • native/omegallm/serve.om:1-2592, including route dispatch at 2400-2429, reset/parse at 1512-1602, prompt copy at 944-957, context preparation at 2303-2323, completion response at 694-717, request ID at 2273-2285 and generation/side-request handling at 1663-1709 and 2112-2257.
  • tests/omegallm/serve-check.py:1-569, particularly the new completions cases at 352-396 and 533-565 and the changed existing disconnect assertion at 517. docs/omegallm/README.md:145-225, including every changed documentation hunk.
  • Supporting build contract tests/omegallm/build.sh:1-163 and native/omegallm/.crumb. The root .crumb fetch was absent at this revision; it did not prevent reading the touched source or the build contract.
  • Compiler source pinned by this build, rather than current omega-mv main: e5b32567a7aff3ce594e3254a622a846a6cd190b, seed/omc/omc.om:3814-3889,3974-4109 for part-span checks, numeric conversion, array loads and typed call arguments. The unchanged build requires compiler binary SHA-256 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f and pins its vendored network/JSON units. No compiler or build was executed.
  • Relied-on execution narrative: this PR's body only, including the author run summary and negative-control description. No separate comments supplied additional execution evidence. #72 is the stack boundary, not an independently reviewed dependency in this review.

Findings by concern

Raw prompt: the new branch bypasses chat-template assembly. native/omegallm/serve.om:1556-1558,1576-1602 rejects stream true and chat-only fields, checks for a non-empty string and copies it through the existing bounded string path. svreset clears the template length; svprep then adds the start token and encodes that prompt. [INFERENCE] No role text or assistant prefix enters the new route along this path.

Response selection and request state: the route is reset explicitly. native/omegallm/serve.om:2402-2412 sets slot 37 for each POST route; 1512-1525 does not overwrite that route selection. 695-710 emits the plain text completion object and shared usage; 2275-2285 selects its completion ID. The raw branch disables tool detection at 1596-1597, so tool-looking output remains text. The side-request path does not route a second completion through the active request's route state.

Evidence coverage: useful controls, with remaining route-specific cases. tests/omegallm/serve-check.py:365-395 compares against the same binary's raw CLI sample, includes a chat-template difference control, tests refusals and checks route errors. 533-565 checks forced text, busy admission and disconnect cleanup. These are protocol checks, not a model-quality or Node-workflow qualification. Non-blocking follow-up: add raw-route sampled-temperature/seed parity, stop-string behavior, escaped or multibyte prompt bytes, and a chat request immediately after a raw completion on the same server. Existing shared helpers reduce the delta risk, but the added raw-route cases do not directly cover those boundaries.

Evidence and limits

  • IMPLEMENTED: route, response, parser branch, tests and documentation exist at the exact head.
  • Author EXERCISED: the body reports SUMMARY pass=118 fail=0, loopback-only binding, no NOT_RUN lines and a two-change mutant yielding three expected failures, on host CPU in a private network namespace. The body names built source/binary hashes and private evidence paths; this review did not retrieve those external logs or independently tie the composed-source hash to a rebuild at this head. These remain author-reported results.
  • Live CI: the exact-head check-runs list is empty; pr checks 76 reports no checks. There is no green CI result to claim.
  • Reviewer read-only inventory and head checks passed. No PR code, Python referee, compiler, model, network listener, GPU, server or full suite was run. Reviewer runtime/hardware NOT_RUN; QUALIFIED not established; live Node integration and deployment remain NOT_RUN.

VERDICT aien-dev/aien-train#76 head=9edd881cd7d7338c8722fda95b09e656b5c96b36 verdict=COMMENT model=gpt-6-astra provider=openai-codex reasoning=medium session=local-497f78483f6acb0308504e402fea50328dd487fa167bab8bdb244d2de82960eb findings=0 — Hermes

Apply it

git checkout -b patch-124c6161c908fbd9 9d373fc497f2aeae303ff91f5cc43b06e327f878
curl -fsSL https://interplane.io/drakestapleton/aien-train/patches/124c6161c908fbd9.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/aien-train
76
9edd881cd7d7338c8722fda95b09e656b5c96b36
{"kind":"github-import","owner":"aien-dev","repo":"aien-train","number":76,"url":"https://github.com/aien-dev/aien-train/pull/76","export_sha256":"e2d49089563cb3d01f7a323b1228844868dc3e2c89531906e1b60f6b775ad91a","imported_utc":"2026-11-18T16:40:28Z"}

Changes

diff --git a/docs/omegallm/README.md b/docs/omegallm/README.md
index 4d18692..9f08acb 100644
--- a/docs/omegallm/README.md
+++ b/docs/omegallm/README.md
@@ -200,6 +200,15 @@ connections before each token); without it they are 400.
   A stream holds back a possible marker and sends the calls in one delta chunk. Role `tool`
   messages are rendered like any other role. Whether the model emits such blocks is a model
   matter; the checks script the output with `ollm_test_output`.
+- `POST /v1/completions` (raw prompt, for the Omega Node edit→verify→review workflow): `prompt`
+  (a non-empty string) is the whole template: the context is token 0 plus the prompt's encoding,
+  with no role lines and no `assistant: ` prefix, so the same SEED and TEMPMILLI give
+  `ollm sample CK SEED N TEMPMILLI PROMPT MERGES`'s bytes. The scalar members are chat's
+  (`max_tokens`, `temperature`, `seed`, `top_k`, `top_p`, `stop`, `n` = 1). JSON only:
+  `{"id":"cmpl-ollm-N","object":"text_completion","created":..,"model":"ollm","choices":[{"index":0,"text":..,"finish_reason":"stop"|"length"}],"usage":{..}}`.
+  400 `invalid_request` for `stream` true, for `messages`, `tools` or `tool_choice` present, and
+  for a missing, non-string or empty `prompt`; `tplmax` and `context_length_exceeded` apply as on
+  chat. Busy 503, client-left 499 and the log line are shared with chat.
 - Refusals are JSON `{"error":{...}}`: 400 (`invalid_json`, `invalid_request`,
   `context_length_exceeded`), 404, 405, 503 `server_busy`, and 413 `request_too_large` for a body
   over 983040 bytes (refused at the head) or over 65532 JSON tokens (the JSON parser's tape).
@@ -207,9 +216,9 @@ connections before each token); without it they are 400.
   (finish 0 none, 1 stop, 2 length, 3 tool_calls, 4 client left).
 
 `tests/omegallm/serve-check.sh` starts two servers under taskset/nice/bwrap (defaults on PORT,
-`tplmax=4000 test=1` on TPORT), referees them with `serve-check.py` (96 checks; the content oracle
-is the same binary's `sample`, decoded with Python's `errors="replace"`; the 499 log line is read
-from `server-test.log` via `SERVE_TLOG`) and stops the PIDs it started. The checks added since
+`tplmax=4000 test=1` on TPORT), referees them with `serve-check.py` (the content oracle
+is the same binary's `sample`, decoded with Python's `errors="replace"`; the 499 log lines are read
+from `server-test.log` via `SERVE_TLOG`; `cmpl_*`/`t_cmpl_*` cover `/v1/completions`) and stops the PIDs it started. The checks added since
 DRA-119's first 27 come with control checks (`*_control`, `*_is_sample`,
 `sample_differs_from_greedy`, `t_ctl_*`, `t_forced_plain`): the same request with one input
 changed, expecting the other outcome. A refusal (`refuse_*`) is controlled by the accepted
diff --git a/native/omegallm/serve.om b/native/omegallm/serve.om
index d3fa4f0..40be7d4 100644
--- a/native/omegallm/serve.om
+++ b/native/omegallm/serve.om
@@ -69,6 +69,10 @@ text svtctyp "Content-Type"
 text svphlth "/health"
 text svpmods "/v1/models"
 text svpchat "/v1/chat/completions"
+text svpcomp "/v1/completions"
+text skprompt "prompt"
+text svtcomp "text_completion"
+text svcidp "cmpl-ollm-"
 text svmget "GET"
 text svmpost "POST"
 text svthlth "{\"status\":\"ok\",\"in_flight\":0,\"busy\":false}"
@@ -164,7 +168,7 @@ text sem9 "seed must be an unsigned integer"
 text sem10 "stream must be true or false"
 text sem12 "only n = 1 is supported"
 text sem13 "the request body is over 983040 bytes"
-text sem14 "no such path; routes: GET /health, GET /v1/models, POST /v1/chat/completions"
+text sem14 "no such path; routes: GET /health, GET /v1/models, POST /v1/chat/completions, POST /v1/completions"
 text sem15 "method not allowed on this path"
 text sem16 "response construction failed"
 text sem17 "message content parts must be {\"type\":\"text\",\"text\":string}; image_url, input_audio, file and other part types are not supported"
@@ -176,6 +180,9 @@ text sem22 "tool_choice must be \"none\", \"auto\", \"required\" or a {\"type\":
 text sem23 "tool_calls must be an array of {\"function\":{\"name\":string,\"arguments\":string or object}} objects"
 text sem24 "ollm_test_output (a string of at most 16384 bytes) and ollm_test_delay_ms (0 to 10000) need a server started with test=1"
 text sem25 "the request body has over 65532 JSON tokens (values, keys and closers), the JSON parser's limit"
+text sem26 "prompt must be a non-empty string"
+text sem27 "stream is not supported on /v1/completions: send stream false or leave it out"
+text sem28 "messages, tools and tool_choice belong to /v1/chat/completions; /v1/completions takes prompt"
 text sem11a "prompt is "
 text sem11b " tokens including the start token; the context window is "
 text sem11c " tokens, so no room is left for output"
@@ -540,6 +547,15 @@ end
 if eq e 25
 ret svmcat wb p z sem25
 end
+if eq e 26
+ret svmcat wb p z sem26
+end
+if eq e 27
+ret svmcat wb p z sem27
+end
+if eq e 28
+ret svmcat wb p z sem28
+end
 ret p
 end
 
@@ -675,8 +691,30 @@ end
 js_warre ob
 end
 
-note svfull: the chat.completion object (stream false)
+note svcfull: the text_completion object of /v1/completions
+fn svcfull ob edit uchar 409600 wb edit uchar 1073664 sv edit ulong 64 to long
+svhead ob wb sv svtcomp
+svwt ob skchoi
+js_warr ob
+js_wobj ob
+svwt ob skidx
+js_wulong ob 0
+svwt ob sktext
+js_wsbuf ob wb 8192 get sv 13
+svwt ob skfin
+svfr ob sv
+js_wobje ob
+js_warre ob
+svusage ob sv
+js_wobje ob
+ret js_wdone ob
+end
+
+note svfull: the chat.completion object (stream false), or svcfull on /v1/completions
 fn svfull ob edit uchar 409600 wb edit uchar 1073664 sv edit ulong 64 bd edit uchar 983040 to long
+if eq get sv 37 1
+ret svcfull ob wb sv
+end
 svhead ob wb sv svcc
 svwt ob skchoi
 js_warr ob
@@ -1515,6 +1553,9 @@ ret e
 end
 k = js_mnext tp k
 end
+if eq get sv 37 1
+ret svcprm bd tp wb sv
+end
 ma = svmem bd tp 0 skmsgs
 if eq ma jsnone
 ret 3
@@ -1529,6 +1570,37 @@ end
 ret svmsgs bd tp ma wb sv
 end
 
+note svcprm: a /v1/completions body after its scalars: prompt (a non-empty string) is the whole
+note template, with no role lines and no assistant prefix; stream true, messages, tools and
+note tool_choice are refused; 0 or an error code
+fn svcprm bd edit uchar 983040 tp edit uint 262144 wb edit uchar 1073664 sv edit ulong 64 to ulong
+if eq get sv 0 1
+ret 27
+end
+if ne svmem bd tp 0 skmsgs jsnone
+ret 28
+end
+if ne svmem bd tp 0 sktools jsnone
+ret 28
+end
+if ne svmem bd tp 0 sktchoi jsnone
+ret 28
+end
+pr = svmem bd tp 0 skprompt
+if eq pr jsnone
+ret 26
+end
+if or ne js_type tp pr 6 eq js_slen tp pr 0
+ret 26
+end
+put sv 30 0
+put sv 31 0
+if not svpstr bd tp pr wb sv
+ret 6
+end
+ret 0
+end
+
 note ======== encoding
 
 note svemit: token t, the m-th of an encoding: md 0 onto the context, md 1 into the forced tokens
@@ -2198,10 +2270,16 @@ end
 
 note ======== serving
 
-note svid: response id chatcmpl-ollm-<request count> into wb[82176 ..), its length into sv15
+note svid: response id chatcmpl-ollm-<request count> (cmpl-ollm- on /v1/completions) into
+note wb[82176 ..), its length into sv15
 fn svid wb edit uchar 1073664 sv edit ulong 64 to void
 put sv 9 add get sv 9 1
-p = svmcat wb 82176 82240 svidp
+p = ulong 82176
+if eq get sv 37 1
+p = svmcat wb p 82240 svcidp
+else
+p = svmcat wb p 82240 svidp
+end
 p = svmdec wb p 82240 get sv 9
 put sv 15 sub p 82176
 end
@@ -2323,6 +2401,14 @@ fn svroute cs edit ulong 320 io edit uchar 131072 bd edit uchar 983040 wb edit u
 svbeg sv
 if hispath cs io svpchat
 if hismeth cs io svmpost
+put sv 37 0
+ret svchat cs io bd wb sv
+end
+ret svend cs io wb sv 15 405
+end
+if hispath cs io svpcomp
+if hismeth cs io svmpost
+put sv 37 1
 ret svchat cs io bd wb sv
 end
 ret svend cs io wb sv 15 405
diff --git a/tests/omegallm/serve-check.py b/tests/omegallm/serve-check.py
index 00583f0..04d8d2e 100755
--- a/tests/omegallm/serve-check.py
+++ b/tests/omegallm/serve-check.py
@@ -348,6 +348,53 @@ check("silent_conn_closed_10s", eof == b"" and 8 < dts < 20, f"recv={eof!r} afte
 st, ct, out, _ = call("GET", "/health")
 check("alive_after_negatives", st == 200, f"{st}")
 
+
+# --- POST /v1/completions: prompt is the whole template (start token + prompt, no role lines) ---
+def cpost(body, port=None, raw=None):
+    st, ct, out, _ = call("POST", "/v1/completions", body, raw=raw, port=port)
+    j = json.loads(out) if st == 200 else {}
+    return st, j, out
+
+
+def crefused(body, word, port=None, raw=None, code_want="invalid_request"):
+    st, ct, out, _ = call("POST", "/v1/completions", body, raw=raw, port=port)
+    code, msg, typ = err_code(out)
+    return st == 400 and code == code_want and word in msg, f"{st} {code} {msg!r}"
+
+
+cprompt = "fn main to long\n"
+cwant = oracle_tpl(cprompt, 7, 8, 0)
+st, j, out = cpost({"model": "ollm", "prompt": cprompt, "max_tokens": 8, "temperature": 0, "seed": 7})
+ch = (j.get("choices") or [{}])[0]
+u = j.get("usage", {})
+check("cmpl_greedy_parity", st == 200 and j.get("object") == "text_completion" and j.get("id", "").startswith("cmpl-ollm-")
+      and ch.get("index") == 0 and ch.get("finish_reason") in ("stop", "length") and ch.get("text") == cwant
+      and "message" not in ch and u.get("total_tokens") == u.get("prompt_tokens", 0) + u.get("completion_tokens", 0)
+      and 1 <= u.get("completion_tokens", 0) <= 8, f"{st} {out[:240]!r} oracle={cwant!r}")
+chatw = oracle_tpl("user: " + cprompt + "\nassistant: ", 7, 8, 0)
+check("cmpl_no_chat_template_control", chatw != cwant, f"chat_template={chatw!r} raw={cwant!r}")
+st, j, out = cpost({"prompt": cprompt, "max_tokens": 8, "top_p": 0, "temperature": 0.8, "seed": 7})
+check("cmpl_top_p0_is_greedy", st == 200 and (j.get("choices") or [{}])[0].get("text") == cwant, f"{out[:200]!r}")
+cb = {"prompt": cprompt, "max_tokens": 4}
+for name, body, word in (("cmpl_refuse_stream", dict(cb, stream=True), "stream is not supported on /v1/completions"),
+                         ("cmpl_refuse_messages", dict(cb, messages=msgs), "takes prompt"),
+                         ("cmpl_refuse_tools", dict(cb, tools=tools), "takes prompt"),
+                         ("cmpl_refuse_tool_choice", dict(cb, tool_choice="none"), "takes prompt"),
+                         ("cmpl_refuse_no_prompt", {"max_tokens": 4}, "prompt must be a non-empty string"),
+                         ("cmpl_refuse_prompt_number", dict(cb, prompt=5), "prompt must be a non-empty string"),
+                         ("cmpl_refuse_prompt_array", dict(cb, prompt=["a"]), "prompt must be a non-empty string"),
+                         ("cmpl_refuse_prompt_empty", dict(cb, prompt=""), "prompt must be a non-empty string"),
+                         ("cmpl_refuse_n2", dict(cb, n=2), "n = 1"),
+                         ("cmpl_refuse_prompt_bytes", dict(cb, prompt="x" * 66000), "over 65536 bytes")):
+    check(name, *crefused(body, word))
+check("cmpl_refuse_context", *crefused({"prompt": long_text, "max_tokens": 4}, "context window is 256", code_want="context_length_exceeded"))
+st, ct, out, _ = call("GET", "/v1/completions")
+check("cmpl_refuse_405", st == 405 and err_code(out)[0] == "method_not_allowed", f"{st} {out!r}")
+st, ct, out, _ = call("GET", "/v1/nope")
+check("refuse_404_lists_completions", st == 404 and "POST /v1/completions" in err_code(out)[1], f"{st} {out!r}")
+st, ct, out, _ = call("GET", "/health")
+check("alive_after_cmpl", st == 200, f"{st}")
+
 # --- second server: tplmax=4000 test=1 (scripted output: protocol checks, not model checks) ----
 if TPORT:
     st, ct, out, _ = call("GET", "/health", port=TPORT)
@@ -467,7 +514,7 @@ if TPORT:
     if TLOG:
         with open(TLOG) as f:
             lines = [l.split() for l in f if l.startswith("C 499 ")]
-        check("t_disconnect_logged", len(lines) == 1 and lines[0][4] == "4", f"{lines}")
+        check("t_disconnect_logged", len(lines) >= 1 and lines[0][4] == "4", f"{lines}")
     else:
         print("NOT_RUN t_disconnect_logged SERVE_TLOG unset", flush=True)
     box = {}
@@ -483,6 +530,40 @@ if TPORT:
     st, ch, out = post(base, port=TPORT)
     check("t_idle_not_busy_control", st == 200 and ch["message"]["content"] == greedy, f"{out[:200]!r}")
 
+    # /v1/completions on the test server: scripted output, busy 503, and a client that leaves
+    cslow = {"prompt": "x", "max_tokens": 200, "temperature": 0, "ollm_test_output": slow, "ollm_test_delay_ms": 300}
+    st, j, out = cpost(dict(cslow, ollm_test_delay_ms=0), port=TPORT)
+    check("t_cmpl_forced", st == 200 and j["choices"][0]["text"] == slow and j["choices"][0]["finish_reason"] == "stop", f"{out[:200]!r}")
+    box = {}
+    th = threading.Thread(target=lambda: box.update(r=cpost(cslow, port=TPORT)))
+    th.start()
+    time.sleep(1.5)
+    st, ct, out, _ = call("GET", "/health", port=TPORT)
+    hb = json.loads(out) if st == 200 else {}
+    st5, ct, out5, _ = call("POST", "/v1/completions", cb, port=TPORT)
+    ra = LAST[threading.get_ident()].get("retry-after")
+    code, msg, typ = err_code(out5)
+    th.join()
+    stb, jb, outb = box.get("r", (0, {}, b""))
+    check("t_cmpl_busy_503", hb.get("busy") is True and st5 == 503 and code == "server_busy" and ra == "1", f"health={hb} {st5} {code} {msg!r}")
+    check("t_cmpl_busy_whole", stb == 200 and (jb.get("choices") or [{}])[0].get("text") == slow, f"{outb[:200]!r}")
+    body = json.dumps(cslow).encode()
+    gone = socket.create_connection((HOST, TPORT), timeout=30)
+    gone.sendall(b"POST /v1/completions HTTP/1.1\r\nHost: x\r\nContent-Type: application/json\r\nContent-Length: "
+                 + str(len(body)).encode() + b"\r\n\r\n" + body)
+    time.sleep(1.0)
+    gone.close()
+    time.sleep(1.0)
+    st, ct, out, _ = call("GET", "/health", port=TPORT)
+    hg = json.loads(out) if st == 200 else {}
+    check("t_cmpl_disconnect_frees_slot", hg == {"status": "ok", "in_flight": 0, "busy": False}, f"{st} {out!r}")
+    if TLOG:
+        with open(TLOG) as f:
+            lines = [l.split() for l in f if l.startswith("C 499 ")]
+        check("t_cmpl_disconnect_logged", len(lines) == 2 and lines[1][4] == "4" and int(lines[1][3]) < 200, f"{lines}")
+    else:
+        print("NOT_RUN t_cmpl_disconnect_logged SERVE_TLOG unset", flush=True)
+
 fails = results.count(False)
 print(f"SUMMARY pass={results.count(True)} fail={fails}", flush=True)
 sys.exit(1 if fails else 0)