Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs: evaluate SGLang Qwen3.8-27B recipes for CoS local serving

Adam Eivy807accf35ecb
diff --git a/docs/README.md b/docs/README.md
index cb51464f23..e472a48f97 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -34,7 +34,7 @@ Start with the [product surface map](./features/product-surfaces.md) for a compl
App management: [app-wizard](./features/app-wizard.md) · [autofixer](./features/autofixer.md) · [browser](./features/browser.md) · [error-handling](./features/error-handling.md) · [jira-sprint-manager](./features/jira-sprint-manager.md)
-Chief of Staff: [chief-of-staff](./features/chief-of-staff.md) · [cos-agent-runner](./features/cos-agent-runner.md) · [cos-enhancement](./features/cos-enhancement.md) · [agent-context](./features/agent-context.md) · [agent-skills](./features/agent-skills.md) · [memory-system](./features/memory-system.md) · [claude-ollama](./features/claude-ollama.md) · [mtplx](./features/mtplx.md) · [dflash2](./features/dflash2.md) ([DSpark vs DFlash 2](./research/2026-08-19-dspark-vs-dflash2.md)) · [qwen38-rtx3090](./features/qwen38-rtx3090.md) ([3090 bring-up](./research/2026-08-21-qwen38-rtx3090-vllm.md)) · [prompt-manager](./features/prompt-manager.md)
+Chief of Staff: [chief-of-staff](./features/chief-of-staff.md) · [cos-agent-runner](./features/cos-agent-runner.md) · [cos-enhancement](./features/cos-enhancement.md) · [agent-context](./features/agent-context.md) · [agent-skills](./features/agent-skills.md) · [memory-system](./features/memory-system.md) · [claude-ollama](./features/claude-ollama.md) · [mtplx](./features/mtplx.md) · [dflash2](./features/dflash2.md) ([DSpark vs DFlash 2](./research/2026-08-19-dspark-vs-dflash2.md)) · [qwen38-rtx3090](./features/qwen38-rtx3090.md) ([3090 bring-up](./research/2026-08-21-qwen38-rtx3090-vllm.md), [SGLang Hopper/Blackwell evaluation](./research/2026-08-21-sglang-qwen38-27b.md)) · [prompt-manager](./features/prompt-manager.md)
Identity & self: [digital-twin](./features/digital-twin.md) · [identity-system](./features/identity-system.md) · [soul-system](./features/soul-system.md) · [privacy-center](./features/privacy-center.md) · [post](./features/post.md) (insights design spike: [plans/2026-06-03](./plans/2026-06-03-cross-domain-insights-engine.md))
diff --git a/docs/features/qwen38-rtx3090.md b/docs/features/qwen38-rtx3090.md
index 5d8ceeb5da..448bd44d27 100644
--- a/docs/features/qwen38-rtx3090.md
+++ b/docs/features/qwen38-rtx3090.md
@@ -246,4 +246,8 @@ one-shot completion.
building it.
- [The 3090 bring-up record](../research/2026-08-21-qwen38-rtx3090-vllm.md) — the
measurements behind the numbers above, and how each required setting was found.
+- [SGLang Qwen3.8-27B on Hopper / Blackwell](../research/2026-08-21-sglang-qwen38-27b.md) —
+ why this 3090 container is **not** replaced by the official SGLang recipes
+ (no 3090 cell; different tool-parser spelling; Claude Code is available there
+ via native Anthropic `/v1/messages`). Follow-up issues: #4776, #4777, #4778.
- [docs/PORTS.md](../PORTS.md) — why `:18020` sits outside the 5553–5569 range.
diff --git a/docs/research/2026-08-21-sglang-qwen38-27b.md b/docs/research/2026-08-21-sglang-qwen38-27b.md
new file mode 100644
index 0000000000..af5b4323e1
--- /dev/null
+++ b/docs/research/2026-08-21-sglang-qwen38-27b.md
@@ -0,0 +1,266 @@
+# SGLang Qwen3.8-27B cookbook vs PortOS local-agent serving
+
+Date: 2026-08-21
+
+Read against the [SGLang Qwen3.8-27B cookbook](https://docs.sglang.io/cookbook/autoregressive/Qwen/Qwen3.8-27B)
+at the documented H200 / FP8 / single-node / no-speculation / low-latency /
+float32-SSM operating point
+(`hw=h200&variant=default&quant=fp8&nodes=single&spec=none&tier=low-latency&ssmDtype=float32`),
+then against how PortOS actually runs Qwen3.8-class models for CoS agents today.
+
+## Verdict
+
+**Do not replace the RTX 3090 vLLM stack, and do not add SGLang on Apple
+Silicon.** The cookbook is a verified Hopper / Blackwell recipe for a dense
+hybrid GDN vision-language model that PortOS currently cannot serve. The
+improvement is a **third CUDA path**, complementary to
+[qwen38-rtx3090](../features/qwen38-rtx3090.md) (Ampere 24 GB, frozen vLLM +
+DFlash 2) and to [MTPLX](../features/mtplx.md) / [DSpark](../features/dflash2.md)
+(Apple Silicon).
+
+The linked cell is the right **CoS default** on a card that can hold it: no extra
+draft weights, low-latency radix strategy, official `lmsysorg/sglang:qwen38-27b`
+image, tool-call and reasoning parsers already on the launch line. Two
+cookbook facts change the harness choice vs vLLM:
+
+1. SGLang registers an Anthropic `/v1/messages` endpoint on every server — Claude
+ Code talks to it with **no LiteLLM**. vLLM is OpenAI-only, which is why
+ PortOS fronts the 3090 stack with OpenCode instead.
+2. Claude Code must set `CLAUDE_CODE_ATTRIBUTION_HEADER=0` or the radix prefix
+ cache is defeated every turn. That is the 24× TTFT collapse measured on the
+ 3090 bring-up, lost.
+
+`--mamba-full-memory-ratio` is the one sizing flag the cookbook says actually
+matters on hybrid GDN models. The default `0.9` over-provisions the KV pool and
+silently clamps concurrency. CoS agent prompts are long (the 3090 bring-up used
+a 17k-token prefix); the ratio has to be derived from that length, not left at
+the default.
+
+Issues filed from this note:
+
+- [#4776](https://github.com/atomantic/PortOS/issues/4776) — SGLang local runtime
+- [#4777](https://github.com/atomantic/PortOS/issues/4777) — Claude-SGLang providers
+- [#4778](https://github.com/atomantic/PortOS/issues/4778) — Qwen parser registry
+
+They are claimable; this file is the point-in-time record, not a living guide.
+
+## What PortOS runs today
+
+| Host class | Runtime | How CoS talks to it | Speculative path |
+| --- | --- | --- | --- |
+| Apple Silicon | MTPLX (`:8000`) | OpenCode wrappers | native MTP |
+| Apple Silicon | llama-server (`:5568`) | OpenCode wrappers | DSpark (stock), DFlash 2 (unmerged llama.cpp) |
+| Apple Silicon | Ollama / LM Studio | Claude Ollama (Anthropic Messages) | none PortOS controls |
+| RTX 3090 24 GB (Ampere) | vLLM Docker (`:18020`) | OpenCode wrappers | DFlash 2, frozen in `syv-ai/qwen38-27b-rtx3090` |
+
+There is **no SGLang runtime**, no `sglangBacked` provider flag, and no Hopper /
+Blackwell recipe. `server/lib/localModelTuning.js` explicitly has no vLLM knobs
+because PortOS does not own that container's launch line. The same hole would
+apply to a new SGLang container unless the launch flags live in PortOS.
+
+Related open work that this note does **not** duplicate:
+
+- [#4765](https://github.com/atomantic/PortOS/issues/4765) — vLLM generation
+ controls silently dropped (`THINKING_STYLE` has no `vllm` key).
+- [#4766](https://github.com/atomantic/PortOS/issues/4766) — media jobs do not
+ notice the vLLM container holding the GPU.
+- [#4767](https://github.com/atomantic/PortOS/issues/4767) — guided clone /
+ build / prepare for the 3090 vLLM stack.
+
+A new SGLang path must include generation controls and GPU-exclusive refusals
+**on day one**, so those two bugs are not copied.
+
+## What the linked cookbook cell actually launches
+
+H200, `Qwen/Qwen3.8-27B-FP8`, single GPU, no speculation, low-latency, fp32 SSM.
+Base flags from the verified cell, plus the default overlays:
+
+```bash
+sglang serve \
+ --trust-remote-code \
+ --model-path Qwen/Qwen3.8-27B-FP8 \
+ --kv-cache-dtype fp8_e4m3 \
+ --mem-fraction-static 0.85 \
+ --attention-backend flashinfer \
+ --chunked-prefill-size 32768 \
+ --max-prefill-tokens 32768 \
+ --reasoning-parser qwen3 \
+ --tool-call-parser qwen3_coder \
+ --mamba-radix-cache-strategy extra_buffer \
+ --mamba-ssm-dtype float32 \
+ --host 0.0.0.0 \
+ --port 30000
+```
+
+`--mamba-full-memory-ratio` is then pinned from the calculator (see below), not
+left at `0.9`.
+
+Docker: `docker pull lmsysorg/sglang:qwen38-27b`. Unlike the 3090 vLLM image,
+this one **exists on a registry** — no local 9.5 GB build.
+
+The cookbook's supported cards for this model are H200, RTX PRO 6000 (96 GB),
+RTX 5090 (32 GB), DGX Spark, and GB300. **RTX 3090 is not a cell.** Ampere 24 GB
+stays on the vLLM container.
+
+### Architecture that drives the flags
+
+Qwen3.8-27B is a dense hybrid Gated DeltaNet **vision-language** model (64
+layers: 48 GDN + 16 full-attention GQA), served through the Qwen3-VL path. The
+checkpoint ships an in-checkpoint MTP head. Native context is 262,144 tokens
+(extensible to 1,000,000). Serving-relevant layout matches Qwen3.6-27B, so a
+recipe table for this model is reusable for that sibling.
+
+Thinking is **on by default** and disabled per request via
+`enable_thinking` / `chat_template_kwargs`. `reasoning_effort` and
+`preserve_thinking` exist. CoS coding should keep thinking **off** — same call
+as #4716 / the 3090 bring-up (`enable_thinking: false` is how tool-call format
+stays reliable).
+
+### Speculative overlays (do not make DFLASH2 the default)
+
+| Overlay | Extra weights | Fits official `qwen38-27b` tag? | CoS default? |
+| --- | --- | --- | --- |
+| none (linked cell) | no | yes | **yes** — zero extra download, verified |
+| EAGLE / MTP (`--speculative-algorithm EAGLE`, 3/1/4) | no (in-checkpoint head) | yes | optional later, when VRAM allows |
+| DSPARK (`RadixArk/Qwen3.8-27B-DSpark`) | yes | yes | no — extra sidecar, not needed for first ship |
+| DFLASH2 (`incoai/Qwen3.8-27B-DFlash2`) | yes | **no** — needs SGLang `1cf2b8c` (PR [#35496](https://github.com/sgl-project/sglang/pull/35496)) or newer | **no** |
+
+This is the opposite of the 3090 path, where DFlash 2 is the frozen container's
+reason to exist. On SGLang, DFLASH2 is newer than the pinned image and unmeasured
+on H200. Do not copy `SPEC=dflash2` across.
+
+On H200, `--attention-backend fa3` is a documented alternative to FlashInfer,
+measured slightly faster at `bs=1`. Leave FlashInfer as the default (the
+verified cell); fa3 is a tuning knob, not a recipe change.
+
+### `--mamba-full-memory-ratio`
+
+Hybrid GDN models split post-weight memory into a reserved **GDN state pool**
+(the concurrency ceiling) and a paged attention KV pool. The cookbook formula:
+
+```
+ratio = (S + D) × state_bytes / (L × kv_bytes_per_token)
+```
+
+- `S` — state slots per running request: `extra_buffer` = 5 (low-latency),
+ `extra_buffer_lazy` = 4 (high-throughput), radix off = 1.
+- `D` — speculative verify intermediates (0 with spec off; 4 for MTP 3/1/4;
+ 8 for DFLASH2 / DSPARK's default block).
+- `state_bytes` — 153.9 MB at fp32, 78.4 MB at bf16 (this model's geometry).
+- `kv_bytes_per_token` — 32.8 KB at fp8 KV, 65.5 KB at bf16.
+- `L` — average total request length (input + output).
+
+`--max-mamba-cache-size = target_concurrency × S` is the equivalent explicit
+pin. After boot, the server log's `max_running_requests` line must not be
+capped below the intended concurrency.
+
+**CoS decision:** size for **concurrency 1–2** and **L ≈ 16k–25k** (the 3090
+bring-up's 17k-token agent prefix is the measured data point), low-latency
+`extra_buffer`, spec off so `D = 0`. High-throughput `extra_buffer_lazy` is
+the wrong default for a TUI tool-loop: TTFT on a warm prefix is the number
+that matters, and the 3090 measurements already showed a 24× collapse when
+prefix cache actually hits.
+
+Do not disable radix cache on the agent recipe.
+
+### Tool / reasoning parsers — runtime-specific, silent if wrong
+
+The 3090 vLLM stack needs `--tool-call-parser qwen3_xml`. SGLang's verified
+cells all ship `--tool-call-parser qwen3_coder` and `--reasoning-parser qwen3`.
+The failure mode is identical across engines: the server starts, answers, and
+returns raw markup with no structured `tool_calls` / `tool_use` blocks, so the
+agent never edits a file. SGLang's own Anthropic tutorial says the same thing
+in so many words.
+
+This mapping must live in **one table** PortOS owns, not in three feature docs.
+vLLM's `EXTRA_ARGS` is currently only a documented `.env` line; #4767 will
+write it during guided install. SGLang must bake both parsers into the launch
+line so they cannot be omitted.
+
+### Anthropic API and Claude Code
+
+[SGLang Anthropic-compatible API](https://docs.sglang.io/docs/basic_usage/anthropic_api.md):
+
+- `/v1/messages` is on by default. No extra serve flag.
+- Anthropic SDK `base_url` is the server **root** (no `/v1` suffix). OpenAI
+ clients keep `/v1`.
+- Tool-call parser required for structured `tool_use` blocks.
+- `CLAUDE_CODE_ATTRIBUTION_HEADER=0` is **required**. Claude Code otherwise
+ prepends a per-request hash to the system prompt, which is the first token
+ to differ between turns, so the radix cache re-prefills the whole history
+ every turn. `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` does **not** remove
+ that header.
+- Claude Code needs a non-empty `ANTHROPIC_AUTH_TOKEN`; SGLang accepts any
+ value unless `--api-key` is set.
+
+This is why a Claude-SGLang provider pair is worth seeding (mirroring
+[Claude Ollama](../features/claude-ollama.md)), and why it is a **separate**
+issue from the OpenCode wrappers: the env-var contract is load-bearing and
+easy to miss.
+
+PortOS loopback convention: bind `127.0.0.1`, not the cookbook's `0.0.0.0`.
+Suggested port: **18021** (adjacent to vLLM's 18020, outside 5553–5569).
+Document in `docs/PORTS.md` when the runtime ships.
+
+### Hardware gate
+
+`getCudaCapability()` / `getCudaComputeCaps()` already exist
+(`server/lib/cudaCapability.js`). Use them:
+
+| Detected card | Path |
+| --- | --- |
+| Ampere 24 GB (RTX 3090) | existing vLLM container — **not** SGLang |
+| SM90 Hopper (H200 / H100) | SGLang H200 cell (32k prefill chunks, FlashInfer, FP8 or BF16) |
+| Blackwell 32 GB (RTX 5090) | SGLang 5090 cell: NVFP4, `--max-running-requests 1`, GDN state pool is the limit |
+| Blackwell 96 GB (RTX PRO 6000) | SGLang rtx6000 cell |
+| `darwin` | MTPLX / DSpark — refuse SGLang the way vLLM already refuses |
+| probe `unknown` | do not claim "no GPU"; say the probe failed |
+
+H200 has no FP4 tensor cores; the NVFP4 cell is correctly greyed out there.
+Do not offer NVFP4 on SM90.
+
+## What we are not doing
+
+- **Vendoring SGLang or an engine patch.** Same bar as the DFlash 2 note: point
+ at the official image and a launch line. DFLASH2 stays off the default until
+ `lmsysorg/sglang:qwen38-27b` includes PR #35496.
+- **SGLang on Apple Silicon.** The Metal backend exists upstream; the cookbook
+ cells are NVIDIA. Adding a fourth local backend on Mac was already declined
+ for `mlx-dspark`.
+- **Replacing vLLM on the 3090.** That stack is measured and the CoS tool-loop
+ works. SGLang has no 3090 cell.
+- **Auto-starting on boot.** Same exclusive-GPU rule as vLLM. The container
+ holds the card; local image/video cannot share it.
+- **Vision-agent / Qwen3-VL request bodies through the coding harness.** The
+ model is a VLM, but CoS file-editing does not send images today. Out of
+ scope until serving + tool-calling work.
+- **PD disaggregation, HiCache, HiSparse, multi-node.** Cookbook playground
+ knobs for datacenter serving, not a single-user CoS box.
+
+## What to ship
+
+Three claimable issues, decisions already made in the bodies:
+
+1. **[#4776](https://github.com/atomantic/PortOS/issues/4776) SGLang Qwen3.8-27B local runtime** — official Docker image, verified
+ H200-FP8-low-latency-no-spec launch line, OpenCode CLI/TUI presets,
+ `sglangBacked`, hardware gate, `--mamba-full-memory-ratio` derived for CoS
+ `L`, parsers baked in, never auto-start, generation controls from day one.
+2. **[#4777](https://github.com/atomantic/PortOS/issues/4777) Claude-SGLang provider pair** — Anthropic `/v1/messages` +
+ `CLAUDE_CODE_ATTRIBUTION_HEADER=0`. Blocked on #4776.
+3. **[#4778](https://github.com/atomantic/PortOS/issues/4778) Qwen-family tool/reasoning parser registry** — one table so vLLM
+ (`qwen3_xml`), SGLang (`qwen3_coder`), and a future llama.cpp path cannot
+ silently ship the wrong parser.
+
+## Sources
+
+- [SGLang Qwen3.8-27B cookbook](https://docs.sglang.io/cookbook/autoregressive/Qwen/Qwen3.8-27B) —
+ verified cells, overlays, mamba-ratio formula, install pins
+- [SGLang Anthropic-compatible API](https://docs.sglang.io/docs/basic_usage/anthropic_api.md) —
+ Claude Code env vars, attribution-header cache-break, tool-parser requirement
+- [SGLang server arguments](https://docs.sglang.io/docs/advanced_features/server_arguments.md)
+- [qwen38-rtx3090](../features/qwen38-rtx3090.md) and
+ [3090 bring-up](./2026-08-21-qwen38-rtx3090-vllm.md) — current CUDA CoS path
+- [DSpark vs DFlash 2](./2026-08-19-dspark-vs-dflash2.md) — why PortOS does not
+ vendor unmerged engine patches
+- [Qwen3.8 27B MLX on macOS](./2026-08-16-qwen38-mlx-macos.md) — Apple Silicon
+ stays on MLX / MTPLX / llama.cpp