Skip to content

feat(server): filter speech delivery controls with an opt-in allowlist - #1152

Closed
plotarmordev wants to merge 1 commit into
ashhart:mainfrom
plotarmordev:feat/allowed-controls
Closed

plotarmordev wants to merge 1 commit into
ashhart:mainfrom
plotarmordev:feat/allowed-controls

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

Adds serve --allowed-controls LIST, an opt-in filter for bracketed delivery controls in the input of POST /v1/audio/speech. It runs before input validation, tokenization and prompt-derived seeding. Without the flag the input is passed through unchanged, and no copy is made.

The filter rules:

  • LIST is comma-separated, UTF-8, has no square brackets, and is open vocabulary, so novel names such as gentle robot are accepted. Names, and the text inside brackets, are compared after NFC normalization, lowercasing, whitespace folding and removal of trailing !?.….
  • Listed controls are kept and rewritten in their normalized form. For example, with gentle robot listed, [Gentle Robot!] becomes [gentle robot].
  • An unlisted bracket is removed only when every word in it (split on spaces, commas and hyphens) is in the built-in vocabulary, drama_cues.txt, and at least one word is a cue rather than a modifier. [sad] and [softly, whispering] are removed this way; [Pleased!] is kept, because pleased is not in the vocabulary. An empty LIST removes every recognized control.
  • drama_cues.txt lists only words used in tags in Fish Audio's public Drama 3 and Emotion Control docs, the Drama 3 model card and the Drama 3 technical report, and names those sources.
  • Unknown and contextual brackets are kept as written. That covers [someone], notes such as [see note 3], and indexes such as x[i]. It also covers a bracket attached to a preceding letter, digit, _, backtick or index (你好[sighs], m[1][sighs]); Markdown links [text](url); unclosed brackets; brackets longer than 120 bytes; and brackets nested inside a kept bracket.
  • The scoped tags <whisper>, <emphasis>, <soft>, <fast>, <slow>, <stress> and <forceful> are removed case-insensitively, including inside kept brackets, and their enclosed text stays. Other angle-bracket text stays.
  • When a control is removed, only one of the whitespace runs around it is kept: the one with more line breaks, or the preceding one on a tie. If only whitespace precedes the control, the whitespace on both sides is dropped. An input that becomes empty is refused by the existing speech validation.

This is a lexical filter. It is not a prompt-injection or content-safety policy. Chat, completions and drama3-generate are unaffected. docs/speech-controls.md documents the flag and cites the public sources for its examples.

This is independent of #1119, #1120, #1134 and #1135 and can be reviewed in any order.

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: aa6bdaaa6b5cb507bb7b9d4456f4ef9ebd9cec7e on d1018b318fb51981c4a18f12e40269a4d3ee9713. aarch64 Linux CPU host with Zig 0.17.0. No checkpoint, MLX, PyTorch or GPU was used.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: no GPU receipt applies. The change only rewrites the request text before validation and tokenization, which is equivalent to a client sending the filtered text. With the flag omitted, a test checks that the input comes back as the same pointer, without allocating. No model, sampling, codec, scheduler or kernel code changes. Behaviour is pinned by synthetic golden cases: 30 invented input/output pairs in drama_allow_golden_test.zig.
  • Decode speed before and after, from tools/bench_openai.py: n/a; decoding is unchanged.
  • Prompt speed before and after: the cold first request's ttft_s from tools/bench_cache.py --require-cold on a long prompt, or "n/a" with the reason when the change cannot reach prompt processing: n/a. The filter runs on request text before tokenization, and prompt processing is unchanged.
  • Tests run, with pass, fail and skip counts: the counts below are from 506ef593, with no cached test results and no reruns.
    • zig fmt --check build.zig zig: clean.
    • zig build test -j8 --summary all: 211/211 steps; 2965/2979 tests passed, 0 failed, 14 skipped. The server suite passed 512/512.
    • CUDA_VISIBLE_DEVICES= zig build test-cuda-host -j8 --summary all: 129/129 steps; 2184/2189 tests passed, 0 failed, 5 skipped.
    • CUDA_VISIBLE_DEVICES= zig build test-kernel-contract -j8 --summary all: 11/11 steps; 65/65 tests passed.
    • CUDA_VISIBLE_DEVICES= zig build test-golden -j8 --summary all: 5/5 steps. Server cases: 306/319 equal with 13 known differences. Security cases: 26/26 equal. 0 unexpected differences.
    • The last two commits change only drama_cues.txt, docs/speech-controls.md and drama_allow_golden_test.zig. 8cf0ae2e keeps only publicly sourced cue words; aa6bdaaa lists two of them in the golden policy, with every expected output printed from the filter. At aa6bdaaa, zig fmt --check build.zig zig is clean and zig build test -j8 --summary all succeeds: 211/211 steps, 0 failed.
  • Not run, and why: GPU and Metal runs, because nothing they execute changes. The new tests were not run against the base, where drama_allow.zig and the flag do not exist.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt.
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

--allowed-controls keeps listed delivery controls in a normalized form and strips other cue-only brackets before speech input validation; contextual and unknown brackets stay as written. The built-in cue word list holds only words from tags in Fish Audio's public sources.
@ashhart

ashhart commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Thanks @plotarmordev for keeping the filter strictly opt-in, with the no-flag path returning the same pointer without allocating, and for pinning the rules down with 30 golden cases. We are carrying this onto current main ourselves, kept as yours (only CHANGELOG.md conflicts), and a separate commit of ours will make a kept bracket that is attached or longer than 120 bytes protect what is nested in it, as docs/speech-controls.md:33-35 already says (today x[note [sighs] tail] becomes x[note tail] with --allowed-controls ''), add golden cases for both, and shorten the 159-column comment at zig/src/server/drama_cues.txt:3. One choice is yours: the shielding path allocates one usize per input byte (zig/src/server/drama_allow.zig:95-97) before the 4096-character check at zig/src/server/speech.zig:101, so a request near the 32 MiB body limit can cost about 256 MiB before it is refused; would you rather the limit apply to the text as sent, checked before the filter runs, or stay on the filtered text with a separate cap on the raw input, and if so, what cap? We will add an oversized-input test under a counting allocator to match your answer. Then it goes to the device runs on a GB10 and on Metal, comparing output without the flag against main and filtered requests against the same filtered text sent without the flag, and lands. You need not rebase this or #1160, #1161 and #1162, which pick up these fixes through it; if you are in the middle of a change on any of them, please tell us so we do not collide.

- Synthema, Ash's AI Assistant.

@plotarmordev

Copy link
Copy Markdown
Contributor Author

Thanks for catching this. Please apply the limit to the text as sent, checked before the filter runs, with no second cap. The order would be: the UTF-8 check and the 4096-character count on the raw input, then the filter, then the empty check on the filtered text, so a request made only of dropped controls still gets input must be a non-empty string.

Why this one:

  • Whether a request is accepted no longer depends on the server's --allowed-controls list: the same input is accepted or refused with and without the flag. Without the flag nothing changes from main, since the filter returns the input unchanged there.
  • The filter's work and allocations are bounded by the existing limit: at most 4096 code points, so at most 16 KiB of input and a 128 KiB bracket table, instead of growing with the body size.
  • A separate raw cap would be a second number to document and choose without a measurement behind it.

The cost is that an input over 4096 characters as sent is refused even when filtering would bring it under; that request is already refused without the flag, so we think it is the expected answer. The redraw filter in #1160 runs on the text that passed this check, so the same bound covers a nonempty --silence-redraw-controls list.

ashhart added a commit that referenced this pull request Oct 24, 2026
…the scan bound shield what they nest

- zig/src/server/drama_allow.zig: a declined opener (attached, or with no ']' within 120 bytes) with a matching close shields its contents, as docs/speech-controls.md says, so with an empty list x[note [sighs] tail] stays whole.
- zig/src/server/drama_allow_golden_test.zig: golden cases for attached and overlong nesting, kept byte for byte; the 30 existing cases are unchanged.
- zig/src/server/drama_cues.txt: the source comment is one line within 120 columns; the vocabulary is unchanged.
@ashhart

ashhart commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Landed on main as 238653a with a maintainer fix-up (04e203d), thank you @plotarmordev. Speech delivery controls can be filtered with an opt-in allowlist. On a GB10, the default Drama output stayed byte-identical to main on six inputs with these options off, repeats were 6/6 equal, and concurrent equalled solo. The speech, Drama, server and golden host suites pass on current main.

- Synthema, Ash's AI Assistant.

@ashhart ashhart closed this Oct 24, 2026
@ashhart

ashhart commented Oct 24, 2026

Copy link
Copy Markdown
Owner

This shipped in TensorFold 1.1.4: https://github.com/ashhart/TensorFold/releases/tag/v1.1.4

Thank you @plotarmordev for the contribution.

- Synthema, Ash's AI Assistant.

@ashhart ashhart added the landed Landed on main by the maintainers; the commits keep the contributor's authorship label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

landed Landed on main by the maintainers; the commits keep the contributor's authorship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants