Files
baji-vc/docs/STRUCTURED_REPLY_072.md
T

39 lines
6.7 KiB
Markdown

# Gateway 0.7.2 structured reply repair
The 0.5.1 report received on 2026-10-12 at 11:47:40 +08:00 retained five actual applied fallbacks: turns 22/23/25/27/33, all `non_json/plain_text/stop`. Those were usable plain-text answers without an emotion envelope, not model-selected neutral or reported token truncation. All five used yangmi_fiction. Its old format rules competed with the system's JSON request despite a preceding override. That competition was present, but was not proven to be the reason the model ignored the format. No actual user reply/prompt/audio was accessed for the audit.
## Minimal change
- Public Yangmi/Lvbu lore format sentences now explicitly constrain only the spoken reply field; outer format follows the round's format contract. Character style, facts and safety rules are unchanged.
- One system, one LLM request and a 160-token budget remain. TTS voice/parameters, ASR, reply-only history/speech, parser recovery, diagnostic reasons, turn fencing and Android presentation are unchanged.
- `LAN_LLM_STRUCTURED_OUTPUT` accepts `prompt` or `json_schema`, rejecting unknown modes. Only the exact verified local URL/model/thinking=false tuple defaults to schema when unset. Arbitrary aliases or custom Qwen endpoints do not imply support.
- Schema uses object/properties/required/additionalProperties=false, reply string, emotion enum neutral/happy/angry/sad and integer intensity enum 0/1/2. The parser still enforces neutral0 and other emotions at intensity1/2. There is no extra inference retry for malformed output or unsupported schema.
- Doubao configuration/Authorization loading and provider-specific kwargs remain supported. Its schema capability is not verified; use prompt mode when switching. Do not carry an explicit Qwen schema setting to an unverified provider.
- Gateway health version is 0.7.2 and health/hello plus finite metadata expose format mode. Android remains 0.5.1/code9 and needs no rebuild or reinstall.
## Actual endpoint compatibility
Read-only inspection of the running SGLang reported version `0.0.0.dev0+qwen38.27b.g561c8f3`, xgrammar backend, response_format/json_schema request types, sampling-schema forwarding and compile_json_schema implementation (xgrammar0.2.1).
Before enabling the provider behavior, one public short greeting was sent with the exact minimal schema and stream=true under the active persona. Actual HTTP200, SSE [DONE], strict_json/model neutral0, finishstop and six reply characters passed at max_tokens160. First content: 915.99ms; completed envelope: 1916.29ms; wait after first content: 1000.30ms. Usage was absent, not zero tokens. This validates the concrete schema/stream/thinkingfalse combination once; it is not a broad stability or latency guarantee.
`scripts/probe-llm-schema.py` is bounded to one or two public samples and records finite enums/counts/timing only. Running it sends real model requests; it is not part of model-free regression. After deployment it asserts the provider actually built the expected schema request. `scripts/probe-reply-emotion.py` exercises one authorized existing public-audio round, asserts live schema mode/model output, reply-only single TTS and emotion-before-PCM/drained acknowledgement. PCM/drained do not prove phone audibility. The larger historical `check-reply-structure.py` also contacts saved Doubao; it is not required for this repair and is not run automatically.
## Deployment and rollback
Canonical source remains gateway/. SOURCE_MANIFEST records previous deployed baseline hashes and new source hashes. Deployment tests a temporary source copy using the existing venv and read-only authorized Silero artifact, checks source/unit/environment hashes and idle state repeatedly, backs up all source/tests/public lore/modes plus private unit/env loading relationships on the server, then restarts only lan-voice-gateway.service. Private environment values and credentials are not copied to this repository or printed.
On failed restart, automatic rollback refuses intervening source edits; for an operator-requested rollback, use `python3 scripts/rollback-gateway-source.py` with the local ignored record of that exact deployment. It checks deployed hashes, busy state and unchanged unit/private environment before restoring original files/modes and restarting only gateway. `LAN_LLM_STRUCTURED_OUTPUT=prompt` can disable schema in a separately approved configuration change; this release does not modify private env files.
Full source/unit/client regression and post-deployment numeric results are recorded in ignored logs/structure-output-fix/ and logs/voice-investigation/. User conversation/LLM envelopes, prompt, keys, audio and raw face data are excluded from these records and Git. Finite public samples cannot establish that the five actual user conversations are fixed; user phone acceptance remains outstanding.
## Completed validation
The isolated full gateway suite passed 73 tests using the existing venv and checksum-verified read-only Silero artifact (1.039s during deployment). Client coordinator/playback/capture/protocol, expression rules and camera permission lifecycle regressions passed with device/transport doubles; no Android source was changed or APK rebuilt.
After deployment, two public short text inputs under the active persona returned HTTP200, SSE [DONE], strict_json/model happy1 and finishstop at max_tokens160. First content was 343.84/322.62ms; full structure completed at 1964.95/2627.62ms; structure wait was 1621.11/2305.00ms. These checks validate formatting on finite samples, not the appropriateness of emotion for user conversation or a forced emotion distribution.
One existing public audio sample (3.36s input) completed real ASR→Qwen→VoxCPM2→PCM with one reply.emotion happy1/model/none/strict_json/stop before the first PCM. TTS used exactly one parsed-body input; 152 frames/291840 bytes (3.04s audio), nonzero RMS1807.56, drained acknowledged. A synthetic whitelisted face cue was snapshotted and invalid control survived; this was not a real camera observation. ASR28.76ms; LLM first content376.38ms; full reply2795.37ms; structure wait2418.99ms; TTS first PCM199.55ms; capture end to first PCM3045.49ms. Structured waiting is nonzero and significant; there is no latency-free claim or isolated before/after benchmark. Usage remained absent.
Deployment was idle and hash-fenced, restarted only gateway, and reverified all deployed hashes plus unchanged unit/private env relationships and Qwen configuration. Backup: `/home/gorios-spark-2/lan-voice/.runtime/backups/voice-gateway-20261012-121534`. The manifest retains the pre-repair baseline separately and advances its live deployment fence to the verified deployed hashes. Doubao schema inference, long-session stability, real-phone playback and the user's five previous conversations were not retested.