Skip to content

speech: openai_audio, a cmd worker for any OpenAI-compatible audio server - #154

Merged
jayleaton merged 4 commits into
jayleaton:mainfrom
smfworks:amd-split/2-openai-audio
Nov 17, 2026
Merged

jayleaton merged 4 commits into
jayleaton:mainfrom
smfworks:amd-split/2-openai-audio

Conversation

@smfworks

@smfworks smfworks commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Part 2 of 5 (split from #152).

A generic cmd worker that serves speech and transcription through any OpenAI-compatible audio server. Independent of the AMD work.

From the review of #152:

  • Transcription forwards temperature, language and prompt to the server; a server's own refusal comes back as a 400 (no more silent temperature 0).
  • Timestamps are explicit. The tool option timestamps lists what the server supports (default []). A listed granularity requests verbose_json with timestamp_granularities[]. An unlisted word request is refused with a 400 before the server is called; an unlisted segment request returns the whole clip as one segment. A declared granularity missing from the reply is a server error, never a silent success.
  • Bad temperature or timestamps values return a 400.

tools/speech/openai_audio/test_worker.py: 23 checks (was 8) against a fake server that records the form fields it received. CI runs it.

Checks run locally: zig build test, zig build test-unit (26/26), audio 23/23, syntax, git diff --check.

…rver

tools/speech/openai_audio/worker.py serves speech (POST /v1/audio/speech, raw PCM
streamed into speech.wav) and transcription (POST /v1/audio/transcriptions ->
transcript.json) through a model's own server, which it starts from options.server
({port}, {id}, {weights}) and stops on exit, as openai_server does for chat; or an
existing options.url. Standard library only. Server 4xx -> invalid_request_error,
503/unreachable -> service_unavailable; 64-bit seeds are folded to 32 bits.
test_worker.py runs it against a fake server (no GPU).
Review of 944f585: transcription replaced the requested temperature with 0 and
ignored timestamp granularity, so temperature=0.7 with timestamps=word succeeded
with no words.

- temperature, language and prompt go to the server as asked. A server that cannot
  honour one refuses it, and the caller gets that 400 with the server's reason
  (Gufo's Qwen3-ASR: "supports temperature 0 only").
- options.timestamps lists the granularities the server returns ([] by default).
  A request for a listed one asks for verbose_json with that
  timestamp_granularities[] (word also asks for segment when listed), and a reply
  without them is a server_error, never a transcript missing what was asked.
- word not listed is refused (invalid_request_error) before the server is asked.
  segment not listed keeps the whole clip as one segment, since the daemon asks for
  segments for every verbose_json, srt and vtt reply.

The fake server now records each request's form fields: 23 checks (was 8),
covering forwarding, refusals and both timestamp configurations. CI runs them.

@jayleaton jayleaton left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the transcription options and adding the request-recording tests. Temperature, language and prompt are now forwarded, unsupported word timestamps are refused, and all 23 tests pass.

Blocking: tools/speech/openai_audio/worker.py:147. start_new_session=True puts the model server outside the worker's process group. The daemon's abort and timeout path SIGKILLs the worker's group, so Python's cleanup never runs. The server can survive, still holding GPU memory, while the scheduler thinks the tool is unloaded. Please make the server's lifetime follow the daemon's kill scope, including Gufo container teardown, and add a fake-server regression test that SIGKILLs the worker mid-generation.

Nit: worker.py:235. A seed of 0 is valid, but the truthiness check drops it. Please forward it when send_seed is enabled, and test that the server receives 0.

The model's server no longer gets a session of its own (start_new_session):
it stays in the worker's process group, so the daemon's SIGKILL of that group
on abort or timeout takes it down too, and PR_SET_PDEATHSIG (SIGTERM) covers
the worker dying alone. Before, a hard kill left the server, and a Gufo
container behind it, holding the GPU. An unload now signals the server and
every process below it (/proc children) instead of its group.

Seed 0 was dropped by a truthiness check: a request's seed is sent whenever it
has one and send_seed is on.

Tests: SIGKILL of the worker's group mid-generation, the server is gone
(fails on the old worker: the server outlived it); the server receives seed 0;
no seed, none sent; send_seed false, none sent.
@smfworks

Copy link
Copy Markdown
Contributor Author

Review fixes pushed (eaca3c0, new commit, no force-push):

  • worker.py:147 detached server (blocking): fixed in eaca3c0. start_new_session is gone, so the server stays in the worker's process group and dies when the daemon kills the group. A PR_SET_PDEATHSIG preexec covers the case where only the worker dies, and stop() signals the whole process tree. New test: SIGKILL the group while a fake server is mid-generation, then assert the server is gone. The old worker fails this test.
  • seed 0 dropped: fixed in eaca3c0. The seed is sent whenever it is not None. New tests check that the server receives 0, that seed 5 is forwarded, that no seed is sent when none is given, and that nothing is sent when send_seed is false.

— SMF Works

@jayleaton jayleaton left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Randy's round-2 review found nothing left to fix. Seed 0 is now forwarded, and the server dies with the worker in both the group-SIGKILL and the worker-only SIGKILL cases. Thanks!

@jayleaton
jayleaton merged commit f902361 into jayleaton:main Nov 17, 2026
4 checks passed
smfworks added a commit to smfworks/localrouter that referenced this pull request Nov 18, 2026
smfworks added a commit to smfworks/localrouter that referenced this pull request Nov 18, 2026
smfworks added a commit to smfworks/localrouter that referenced this pull request Nov 18, 2026
smfworks added a commit to smfworks/localrouter that referenced this pull request Nov 18, 2026
…split/5-minimax-workflows

ci.yml: keep this branch's steps.
smfworks added a commit to smfworks/localrouter that referenced this pull request Nov 18, 2026
…amd-split/5-minimax-workflows

# Conflicts:
#	.github/workflows/ci.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants