Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions .engineering/security-exceptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
"exceptions": [
{
"id": "PYSEC-2026-2447",
"aliases": ["CVE-2025-69872", "GHSA-w8v5-vhqr-4h9v"],
"aliases": [
"CVE-2025-69872",
"GHSA-w8v5-vhqr-4h9v"
],
"package": "diskcache",
"affected_version": "5.6.3",
"owner": "repository engineering",
"review_by": "2026-09-30",
"expires_on": "2026-11-15",
"reason": "diskcache is a transitive llama-cpp-python dependency and no fixed upstream release is currently available",
"reachability": "Local LLM Server does not instantiate llama-cpp-python disk-cache APIs or enable disk prompt caching; repository search has no LlamaDiskCache/set_cache/cache_type wiring",
"review_by": "2026-11-19",
"expires_on": "2026-11-26",
"reason": "Time-boxed exception for unfixed diskcache 5.6.3 (CVE-2025-69872 / PYSEC-2026-2447), transitive through llama-cpp-python. Re-reviewed 2026-11-19 against GitHub/OSV and PyPI: upstream still has no fixed release; active security audit and 7-day expiry retained. Do not extend again without repository security review.",
"reachability": "Repository code search 2026-11-19 found zero LlamaDiskCache / set_cache( usages, zero direct diskcache import usages; only the security exception file mentions diskcache. llama_server cache_type settings are llama.cpp KV cache flags, not python-diskcache. Vulnerability requires attacker-controlled cache files followed by unsafe unpickling; this product does not expose diskcache reading.",
"compensating_controls": [
"model/runtime state remains local-only by default",
"no product API enables llama-cpp-python disk cache",
"security audit remains scheduled weekly so an upstream fixed release is detected",
"exception expires automatically through repository validation"
"No LlamaDiskCache / set_cache( or direct diskcache APIs exposed in repository runtime code (GitHub code search verified 2026-11-19)",
"Korgis local-first runtime does not expose a disk cache directory for untrusted write access",
"Dependency security audit is preserved with exactly this named exception, never disabled",
"Exception expires within seven days (2026-11-26); remove on upstream fix or on new reachable usage"
],
"remediation": "remove the exception and update the lock as soon as a fixed diskcache release or a llama-cpp-python release without the vulnerable dependency is available"
}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ jobs:
name: Playwright E2E
needs: [scope, guards, reuse]
if: always() && needs.guards.result == 'success' && contains(needs.scope.outputs.required_gates, 'browser-e2e') && needs.reuse.outputs.reused != 'true'
runs-on: ubuntu-latest
# Playwright's pinned Chromium supports Ubuntu 24.04; ubuntu-latest moved to 26.04.
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with: {ref: "${{ needs.scope.outputs.head_sha }}"}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,4 @@ Contributors work from `dev` and follow [`AGENTS.md`](AGENTS.md). Canonical setu
See [`LICENSE`](LICENSE).

Built by [Daniele Moltisanti](https://daniele21.github.io/) as the reusable execution layer of a broader Local AI effort: control the runtime, measure the result, then decide Local, Hybrid or Cloud.
See also [FLUX.3 Image Klein local GGUF setup](docs/flux3-image-klein-q5km.md) and [Qwen Turbo reference editing](docs/qwen-21-turbo-image-edit.md).
11 changes: 9 additions & 2 deletions docs/current-state.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Current State

Status: active
Last reviewed: 2026-09-28
Last reviewed: 2026-11-19

Local LLM Server is a local-first multi-backend **runtime control plane for local AI applications**, with Local LLM Studio as its browser control plane. Hosted CI proves deterministic software contracts; hardware- and human-dependent claims require matching real evidence.

Expand All @@ -12,7 +12,7 @@ Local LLM Server is a local-first multi-backend **runtime control plane for loca
- Repository-side L2 acceptance: `d528b6c5b676e705e7ccf24800929da6d5534203`.
- Representative Apple Silicon evidence is accepted for TH-E1, EV-3, HE-2, RES-2 and RRG-5.
- Bounded manual accessibility and representative-user usability evidence is accepted for tested source `a29e77c1ce4e65294440cfe4fc47e33c92173096`.
- Full L2 evidence is complete; the current action is final FULL publication preflight and promotion to `main`.
- The August L2 evidence covers its reviewed source; it must not be extended to newly integrated November image-generation engines without matching test and representative-device evidence.

## Accepted deterministic surface

Expand Down Expand Up @@ -55,6 +55,13 @@ All required checks/journeys are acceptance-ready with no blocking finding. No r
thermal and reclamation remain unproven.
See `docs/workstreams/qwen-image-2-1.md`.

## November 2026 image runtime reconciliation

- The dedicated main-compatibility integration is tracked in [PR #290](https://github.com/daniele21/korgis/pull/290), including separate Qwen Image 2.1 Turbo and FLUX.3 Image Klein Q5_K_M native model profiles. The Experiments Playground implementation is on main via [PR #136](https://github.com/daniele21/experiments/pull/136).
- FLUX reuses the Q5_K_M transformer directly from the local LM Studio directory. Its Qwen3-VL-4B encoder and FLUX.2 VAE are independent required artifacts. Native image generation on representative macOS hardware is **not yet verified**.
- Qwen Turbo edit mode remains opt-in. Memory estimates for both profiles are provisional; a first real 512px smoke, latency and unified-memory/swap evidence are required before production acceptance. No automatic memory-protection bypass is introduced.
- CI and source checks are ongoing on the integration branch. A historical green test does not prove FLUX model startup, image quality, image editing or commercial suitability; checksum/license review remain open.

## Durable references

- `docs/architecture.md`
Expand Down
118 changes: 118 additions & 0 deletions docs/flux3-image-klein-q5km.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# FLUX.3 Image Klein Q5_K_M · LM Studio integration (experimental)

**Status:** native Korgis registry/loader integrated. Unit tests do not prove
the user's actual Mac binary can generate FLUX.3 images; first image E2E and
resource calibration are mandatory before marking production-ready.

## Components (distilled, 16-step, CFG 1.0)

FLUX.3 **Image** Klein is not FLUX.2 Klein or FLUX.3 Klein **Base**.
The Q5_K_M GGUF is the **diffusion transformer only**, not a complete
standalone model. [Unsloth](https://huggingface.co/unsloth/flux-3-image-klein-GGUF)
and [stable-diffusion.cpp](https://github.com/leejet/stable-diffusion.cpp/blob/master/docs/models/flux3.md)
specify a separate **Qwen3-VL-4B-Instruct text encoder** and **FLUX.2 VAE**.

1. Diffusion GGUF: **existing**, no copy or automatic download:
`$HOME/.lmstudio/models/unsloth/flux-3-image-klein-GGUF/flux-3-image-klein-Q5_K_M.gguf`
(Unsloth Q5_K_M; approximately 4.22 decimal GB).
2. Text encoder: `unsloth/Qwen3-VL-4B-Instruct-GGUF`,
`Qwen3-VL-4B-Instruct-Q4_K_M.gguf`, managed target
`~/.local-llm/models/flux-3-image-klein-gguf-q5km/text_encoder/Qwen3-VL-4B-Instruct-Q4_K_M.gguf`.
Registry revision `cc8371d67a57fc6ae05fc5a9c2df763914928539`.
3. VAE: `unsloth/flux-3-image-klein`, `ae.safetensors`, managed target
`~/.local-llm/models/flux-3-image-klein-gguf-q5km/vae/ae.safetensors`.
**Its upstream SHA256/revision are not yet locked**, so do not treat this
provisional source entry as immutable-provenance evidence.

Both auxiliary components must be present to start image inference. The
registry path is resolved relative to **the current user's home**, not a
hard-coded Mac account. If the LM Studio GGUF is absent, Korgis rejects it
without downloading it somewhere else. The original GGUF is validated for
regular file, a plausible minimum byte size, and the `GGUF` header, but
this is *not yet full artifact integrity verification*.

## Start on a Mac with LM Studio weights already installed

```bash
cd ~/Projects/experiments/korgis
git fetch origin
git switch feat/flux3-klein-q5km-lmstudio-20261119
git pull --ff-only

# Check the local transformer is present; no model inference runs here.
ls -lh "$HOME/.lmstudio/models/unsloth/flux-3-image-klein-GGUF/flux-3-image-klein-Q5_K_M.gguf"

# First run: Korgis may download the separate 4B encoder and VAE to its
# own managed bundle. It never re-downloads the existing LM Studio GGUF.
uv run --frozen local-llm serve \
--model flux-3-image-klein-gguf-q5km \
--host 127.0.0.1 --port 1235 \
--sd-server-bin "$HOME/.local-llm/tools/sdcpp-b43af40461cc64c89cac3b621019f8914f50dd9c/build/bin/sd-server"
```

For a strictly offline run *after* the two auxiliary artifacts exist, add
`--no-download` to the command. If they are not installed, the error will
show the exact missing managed path. Source repository downloads could be
gated or unavailable; use an approved Hugging Face client to fetch those two
files explicitly if Korgis cannot obtain them. The pinned native
stable-diffusion.cpp build must include FLUX.3 (upstream support introduced
October 2026). A filename or revision alone does not establish binary support.

Check `curl -fsS http://127.0.0.1:1235/v1/models` for
`flux-3-image-klein-gguf-q5km`. Then run one **small** generation:

```bash
curl -fsS http://127.0.0.1:1235/v1/images/generations \
-H 'Content-Type: application/json' \
-d '{"model":"flux-3-image-klein-gguf-q5km",
"prompt":"A single emerald-green mug on a white desk, morning window light",
"size":"512x512","n":1,"seed":43,"num_inference_steps":16,
"output_format":"png","guidance_scale":1.0}' \
> flux3-response.json

python3 - <<'PY'
import base64, json
from pathlib import Path
data = json.loads(Path("flux3-response.json").read_text())
Path("flux3-test.png").write_bytes(base64.b64decode(data["data"][0]["b64_json"]))
print("Saved flux3-test.png")
PY
open flux3-test.png
```

Check that the output is coherent, the backend actually uses the GGUF and
**Qwen3-VL-4B + FLUX.2 VAE** rather than Qwen Image weights, and record
elapsed time, process RSS/unified-memory pressure and swap I/O. The
configured `disk_backed_image` estimate is **9 GiB provisional**; it is
not a benchmarked peak or a license to turn off host protections.

## Experiments comparison

Check out Experiments branch
`feat/imagegen-flux3-klein-q5km-20261119`. In the Image Generation
Playground select **FLUX.3 Image Klein GGUF Q5_K_M**, or pick it as an
additional arm in **Compare models**. To generate a FLUX vs Gemini vs GPT
comparison, start FLUX in Korgis and configure server-side cloud API keys.
You can also compare FLUX with Qwen if *both* are loaded and host memory
permits. The default `serve --model` starts only one local runtime;
`--models` can start multiple but may exceed available RAM on a 32 GiB Mac.
Avoid automatically forcing simultaneous residency.

The existing benchmark `smoke`, `budget`, and `robust` suites can
compare the new model using the catalog key. The FLUX Kommunity License
has noncommercial/commercial-output conditions; review it before customer
use. No auto-download of the 9B prompt upsampler is attempted. Unlike the
BFL reference pipeline, Korgis feeds the **literal prompt as entered**,
so prompt-upsampled BFL service examples are not identical to this setup.

### Acceptance checklist

- [x] Registered distinct model and 16-step preset, without altering Qwen
- [x] Deterministic path resolution and local-only GGUF startup checks
- [x] Separate encoder/VAE dependencies, per-model metadata and benchmark arm
- [ ] CI test verification and complete native Mac startup
- [ ] 512px generation at seed 43 with correct 16-step sampling
- [ ] Measured RSS, unified-memory pressure, swap and runtime latency
- [ ] Validate outputs at 768/1024 before quality comparisons
- [ ] Lock the upstream VAE revision/checksum and local GGUF digest
- [ ] Validate native image editing separately; it is not enabled by this PR
147 changes: 147 additions & 0 deletions docs/qwen-21-turbo-image-edit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Qwen Image 2.1 Turbo: resource-safe reference editing (draft)

**Status: integration foundation implemented, native edit with vision projector not yet proven E2E.** Keep this separate from existing text-to-image and from Experiments benchmarks. Do not merge based on API unit tests alone.

## Why this design

The pinned `stable-diffusion.cpp` commit
[`b43af40461cc64c89cac3b621019f8914f50dd9c`](https://github.com/leejet/stable-diffusion.cpp/tree/b43af40461cc64c89cac3b621019f8914f50dd9c)
already supports reference images through its asynchronous `/sdcpp/v1/img_gen`
(`ref_images` field). It also has `/v1/images/edits` and SDAPI `img2img`,
but using the already integrated native async-job API reuses the current
submission, polling, timeout and cancellation machinery and avoids a second
inference engine. This first release does not expose arbitrary native options,
init-image strength or masks before validating their behavior with Qwen Turbo.

Qwen Image 2.1 + a GGUF Qwen3-VL-8B text encoder **requires the matching
vision projector**. The [upstream model guide](https://github.com/leejet/stable-diffusion.cpp/blob/b43af40461cc64c89cac3b621019f8914f50dd9c/docs/qwen_image_2.1.md)
specifies `--llm_vision` for reference editing.

Other designs studied:
- **InvokeAI:** model cache has RAM/VRAM limits, lock-based access, and controlled
model offload/eviction; Korgis retains its own central ResourceManager and
serializes inference through the existing runtime lease.
- **Diffusers:** CPU, group and disk offloading all trade memory for latency.
For this Mac/Metal GGUF use case Korgis retains `diffusion=disk,te=cpu,vae=cpu`,
`--disable-prefetch` and tiled VAE rather than adding a PyTorch runtime.
- **ComfyUI:** flexible image workflows are useful as a quality/reference oracle,
but do not justify adding a DAG runtime or second weights manager to Korgis.

## Opt-in model and resource contract

The original three local files remain the text-to-image bundle: diffusion,
text encoder and VAE. A fourth **optional** artifact is registered separately:

- Repo: `unsloth/Qwen3-VL-8B-Instruct-GGUF`
- Immutable revision: `174e4a339d8aceef41c87fda9f732c042d49e50b`
- Filename: `mmproj-BF16.gguf` (~1.16 GB on disk)
- SHA256: `6516bb64bae1503a0fcd7ec9fa39655f8c481580be0a0a066397941d9761c9f4`
- Local target: `~/.local-llm/models/qwen-image-2.1-turbo-gguf-q4km/text_encoder/mmproj-BF16.gguf`

Projector metadata is not part of the text-to-image completeness gate. Without
the explicit editing flag the projector is not opened, verified or downloaded.
With the flag, Korgis verifies the full SHA256 and launches its existing native
server with `--llm_vision`. `--no-download` fails if the projector is missing;
the app does not silently download model assets in offline mode.

Existing Turbo T2I uses an **8 GiB provisional** resident estimate. Edit mode
adds **2 GiB provisional** for projector and vision activations, yielding a
**10 GiB effective resident estimate** on the same memory ledger. The existing
disk-backed profile uses a 1.25× reserve factor and up to 3 GiB OS reserve:
for a 32 GiB Mac an editing startup therefore needs roughly **15.5 GiB
reclaimable memory**, before optional concurrent load. This bound is *not*
proven adequate until a real edit is profiled. Existing swap usage is never
added to available RAM. The API rejects new editing work when host pressure
is elevated or unknown, both before and after acquisition of the runtime lease.

## First API slice

`POST /v1/images/edits`, multipart form:
- `image`: exactly one PNG file (max 8 MiB, up to 1 megapixel source pixels).
- `prompt`: text editing instruction.
- `model`: resident model key, optional.
- `size`: `WIDTHxHEIGHT`, optional; default source dimensions.
- `seed`, `num_inference_steps`: optional, validated against 8-step Turbo cap.
- `n`: must be 1.

First-release image output is capped at 1 megapixel and dimensions must be
multiples of 32. Input data is validated using PNG signature, IHDR,
dimensions and IHDR checksum before encoding to base64 and sending `ref_images`
to the private native server. No remote image URL, arbitrary filesystem path,
multiple reference images, mask, or unvalidated native parameters are accepted.
Korgis does not intentionally persist the uploaded image (the multipart
library may spool larger bodies to temporary local files); raw images are not
logged. Output is OpenAI-shaped `data[0].b64_json`; metadata includes source
SHA256, original dimensions, generation and local runtime evidence.

**This is not a network-hardened multi-user upload service.** Use loopback
binding, avoid untrusted remote clients, and do not publish the API publicly
without transport-level size limits/authentication and further input fuzzing.

## Manual test when projector is installed

First verify free disk space, the file and SHA256. Explicit download is needed
only for this editing variant, not for normal text-to-image:

```bash
mkdir -p "$HOME/.local-llm/models/qwen-image-2.1-turbo-gguf-q4km/text_encoder"
# Download from the pinned Hugging Face revision above using an approved
# network-enabled tool, then verify its SHA256:
shasum -a 256 "$HOME/.local-llm/models/qwen-image-2.1-turbo-gguf-q4km/text_encoder/mmproj-BF16.gguf"
```

Run the *edit foundation branch* of Korgis (not the stable T2I branch):
```bash
uv run --frozen local-llm serve \
--model qwen-image-2.1-turbo-gguf-q4km \
--image-editing-enabled \
--host 127.0.0.1 --port 1235 \
--sd-server-bin "$HOME/.local-llm/tools/sdcpp-b43af40461cc64c89cac3b621019f8914f50dd9c/build/bin/sd-server" \
--no-download
```

When resident startup and memory admission succeed, submit a local 512x512 PNG:

```bash
curl -fsS http://127.0.0.1:1235/v1/images/edits \
-F "model=qwen-image-2.1-turbo-gguf-q4km" \
-F "prompt=Change the ceramic mug from red to blue; keep the rest identical" \
-F "image=@/absolute/path/to/reference-512.png;type=image/png" \
-F "size=512x512" -F "seed=42" -F "num_inference_steps=8" \
> edited-response.json
python3 - <<'PY'
import base64
import json
from pathlib import Path
result = json.loads(Path("edited-response.json").read_text())
Path("edited-image.png").write_bytes(
base64.b64decode(result["data"][0]["b64_json"])
)
print(result["korgis"]["latency_ms"])
PY
```

Do **not** run production image-editing workloads on the previous T2I 8 GiB
estimate, or bypass `LOCAL_LLM_HOST_MEMORY_GUARD` after a refusal.

## Acceptance plan, in order

1. Static and isolated API/engine tests: text-to-image unchanged; opt-in
capabilities, checksum and path, command `--llm_vision`, malformed image
rejection, exact one native `ref_images` field, no input pixels logged.
2. On the Mac, check if the projector is present; if absent, do not simulate
editing success. Download and checksum it in a controlled separate step.
3. Native `sd-server` small 512px edit with exact seed and prompt. Verify
that the pinned build actually supports Qwen Turbo reference conditioning.
4. Full Korgis E2E edit on host: initial and final memory pressure, RSS,
swap-in/out, wall time, image fidelity and source/image hashes.
5. Repeat at 768 and 1024, with at least three prompts: object color change,
preserve composition, and legible text replacement. Include negative
source checks (invalid PNG, too large, missing projector, low memory).
6. Only after E2E and manual review: JPEG/WebP ingestion, multiple references,
masks, queued jobs/cancellation and separate Experiments evaluation suite.

Do not interpret a valid output PNG as successful editing: image-to-image
requires **measurable adherence to the source and instruction**, not just
successful inference. Keep the benchmark and visual review in
`daniele21/experiments`.
1 change: 1 addition & 0 deletions docs/workstreams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Do not create separate plan/progress/status files for the same workstream. Git h
## Active

- [Qwen Image 2.1 Local Generation](qwen-image-2-1.md) — first-class local image-generation capability, Diffusers runtime, API integration and validation.
- [Qwen Image 2.1 Turbo GGUF](qwen-image-2-1-turbo.md) — pinned Turbo bundle, exact native sigma schedule, Korgis E2E validation.
Loading
Loading