feat(settings): profiles write path + Test Connection (#136)

Profiles S3 over the S2 shell: every Settings change now persists.

Model/effort writes ride the engine's own CLI — `hermes -p <profile>
config set/unset` for model.provider / model.default /
model.reasoning_effort / model.base_url (zai endpoint family written
LAST: setting model.provider clears a stale base_url, live-probed;
unset-when-absent is idempotent success). Provider keys upsert
VAR=value into ALL THREE profiles' .env — a key entered before any
surface is on its provider still persists and pre-lands for any later
switch (maintainer ruling 2026-10-28; no switch re-fire). 0600,
foreign lines preserved byte-for-byte, line-broken values refused at
the shared sink (env-file injection guard), NSLock serializes the
read-upsert-write across concurrent provider writes.

Hydration reads model blocks and keys back at pane open — a restart
neither blanks the key fields nor refuses Test Connection; an edit
made mid-read owns the truth (no stomp), and a custom z.ai base_url
seeds the endpoint field instead of being clobbered to a family
default. Per-target writes coalesce AND chain past the debounce
guard: cancellation can't stop a past-the-guard CLI write, so the
newer write queues — the last edit is always the last write to land
(finish-audit race fix, pinned).

Test Connection = two-step probe (GET /models, then a minimal
streaming chat) with honest decode per the factsheet: zai 1113 →
wrong key type, 401s → auth failed (Anthropic request_id),
finish=length → starved, empty 200 → request failed, errors riding a
2xx decoded as the provider error.

Live-probed wire corrections (dogfood, 2026-10-28): Content-Type
application/json on every request — URLSession defaults to
form-urlencoded and providers diverge (zai 200+envelope, OpenAI 400,
Anthropic tolerates); OpenAI speaks the Responses API (/responses,
input + max_output_tokens, flagship gpt-6.1-sol); probe token cap 512
(64 starved reasoning models into "no content"); OpenAI's
"error": null event snapshots don't decode as failures.

Finish-audit (ponytail + security + general reviewers): write-ordering
race + .env lost update + hydrate stomp + custom-endpoint clobber
fixed and pinned (one-shot hold / latched read knobs in the test
double); ~30 lines of dead flexibility cut (keyType protocol param,
works(reply:) payload, unused timeout knob, double JSON round trips).

Suite 468/468 xcresult-verified; swiftlint clean; factsheet §6
correction logged. Closes #136
This commit is contained in:
AlexKucera committed 2026-10-27 18:32:30 +01:00
1 parent 42a27cc8a3
commit 5ad605eb3c
20 files changed
+1983 -161

No files matched your search

+20
View File
@@ -304,3 +304,23 @@ silent latency hole; TTFT fires on first content.
- Live probes 2026-10-23: /models ×4, cross-family chat calls, thinking-disable, effort enum,
budget starvation, stream cadence ×2 families, typed-tool streaming ×3 providers, bad-key
errors ×4 endpoints, Anthropic adaptive/effort/forced-tool probes, OpenAI tools×effort clash.
## 6. Correction 2026-10-28 (Museion #136 dogfood, live-probed)
- **Content-Type is load-bearing.** Without `Content-Type: application/json`,
URLSession defaults the request to `x-www-form-urlencoded` — z.ai answers
**HTTP 200** with `{"error":{"code":"500","message":"Content type
'application/x-www-form-urlencoded;charset=UTF-8' not supported"}}` (an error
envelope riding a 200), OpenAI can't parse the body ("you must provide a
model parameter"). The original curl probes worked because they passed the
header explicitly; the app (URLSession) did not. Anthropic tolerated the
omission.
- **OpenAI chat probes must speak the RESPONSES API** (`POST /v1/responses`,
`{"model","input"}`, `max_output_tokens`; flagship `gpt-6.1-sol`) —
chat-completions is the retired path for current models (maintainer
correction; §3.1/§3.3 above describe the older wire).
- **§4's "max_tokens ≈ 64" starves reasoning models.** Live tail on
glm-5.3 + `reasoning_effort:"low"` + `max_tokens:64`: all 64 tokens burned
as reasoning (`reasoning_tokens:64/64`), `finish_reason:"length"`, empty
content — the probe can never produce text at that cap. Museion's probe
uses 512.