Skip to content

fix: keep Prometheus and rule-carrying structs out of the layers - #1

Merged
subpathdev merged 1 commit into
mainfrom
fix/conventions
Nov 29, 2026
Merged

subpathdev merged 1 commit into
mainfrom
fix/conventions

Conversation

@subpathdev

@subpathdev subpathdev commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Why

Review of v0.1.0 against the Go conventions: the transport used Prometheus directly, and three exported structs carried rules (httpapi.Options, speech.Settings, speech.Request). The behaviour doesn't change. Merging releases 0.1.1 (fix:), so the deployed code matches main; smart-home#114 then bumps the chart tag to 0.1.1.

What

  • Metrics behind an interface. httpapi.Recorder (Spoken, Rejected, TimedOut, Failed) is defined by the handlers. The new adapter internal/metrics implements it with Prometheus (exported interface Metrics, unexported implementation, New(), its own registry) and serves /metrics. Metric names and labels are unchanged.
  • No httpapi.Options. New(svc Speaker, wav Encoder, opts ...Option); WithLogger, WithRecorder, WithMetrics(http.Handler). Without options: no logs, nothing counted, no /metrics.
  • speech.Text instead of speech.Request. An opaque value made by ParseText (not blank, at most 4096 characters). It prints redacted (String, GoString), and only package speech reads the content. Speak(ctx, text, speed).
  • No speech.Settings. NewService(detector, synthesizer, voices, fallback, rate, opts...); WithMinConfidence (0.7), WithMinWords (3), WithPause (150 ms), with their ranges checked in NewService. The confidence threshold stays a float64: 0 is a valid threshold, so a value type would have no zero value to reject.
  • wav.Encoder is an exported interface with an unexported implementation (wav.New()).
  • app holds its parts (config, service, encoder, metrics, logger); serve builds the HTTP handler.
  • Kept on purpose, as plain structs of typed values with no rule of their own: speech.Guess, Utterance, Segment, Speech, and config.Config (checked by Load).

How to validate

Already done:

  • go vet ./... and go test -race ./... pass. New tests: the metrics adapter against a real scrape, the handlers against a fake Recorder (one call per outcome), handler defaults without options, ParseText including redaction under %v/%+v/%#v, and NewService checks and defaults. The end-to-end test also reads /metrics.
  • golangci-lint v2.15.0 reports 0 issues.

After merge: CI releases v0.1.1. Then the voice-router pod in smart-home (chart 0.1.1) logs "segments":"de,en" for a mixed request, and voice_router_* shows up in Prometheus.

Risk

The refactor could have changed behaviour by mistake. The unchanged end-to-end and handler tests cover the API (formats, errors, logs without text), the speaches calls and the metric names. Blast radius: Open WebUI's read aloud.

Rollback

Pin smart-home back to chart 0.1.0 (same behaviour), or undo the change in a fix: commit so svu releases a patch. A plain git revert commit has no conventional type, so svu would not release it.

🤖 Generated with Claude Code

No change in behaviour; the release brings the deployed code in line with
main.

- Metrics: httpapi defines the Recorder it needs; the Prometheus counters
  and the /metrics handler move to the adapter internal/metrics.
- httpapi.New takes the Speaker and the WAV Encoder as parameters, the
  logger, Recorder and metrics handler as functional options, instead of
  an exported Options struct.
- speech.Request becomes the value speech.Text (ParseText: not blank, at
  most 4096 characters), which prints redacted; Speak(ctx, text, speed).
- speech.Settings becomes parameters of NewService (voices, fallback,
  rate) and options WithMinConfidence, WithMinWords, WithPause.
- wav.Encoder is an exported interface with an unexported implementation.
- app holds its parts; serve builds the HTTP handler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread internal/speech/text.go Resolved
Comment thread internal/speech/text.go Resolved
@subpathdev
subpathdev merged commit df6c102 into main Nov 29, 2026
6 checks passed
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.

1 participant