fix(messaging): transcribe voice notes on the model-owning side of the boundary

The Messaging Service built the voice-transcription client in-process
from [models].transcription and [providers.*], which the messaging
boundary PRD reserves to the process that owns the model runtime and its
provider credentials. The deletion gate only measured linked packages,
so the PRD violation shipped green: config reads are not imports.

Move the capability across the boundary:

- archiemessaging no longer reads [models] or [providers], builds no
  transcription client, and drops the ResolvedConfig.Transcriber field.
- telegram classifies a voice note as messaging.MediaTypeVoice and stops
  transcribing; it carries the attachment bytes and its note to the turn,
  which is all a frontend without the credential can do.
- archied builds the transcriber beside the chat runtime from its own
  model-role configuration (setupTranscriber) and gives it to every
  gateway TurnRunner.
- the turn runner transcribes a speech attachment before recording the
  inbound message, so stored history and the model context carry the
  transcript; a nil/failed/empty transcription keeps the frontend note.
- messaging.TranscribedMessageText renders the transcript into the text a
  frontend built from its media note, preserving the sender's caption.

Red first: TestTurnRunnerTranscribesSpeechOnTheModelOwningSide failed at
'Transcribe calls = 0, want 1' with the transcription call disabled.
This commit is contained in:
sam committed 2026-10-02 11:12:59 +10:00
1 parent 3a65fd2ee1
commit a8ea4e0656
15 files changed
+430 -215

No files matched your search

+31
View File
@@ -41,6 +41,7 @@ import (
"github.com/samcharles93/archie-core/internal/domain/health"
"github.com/samcharles93/archie-core/internal/domain/identity"
domainmemory "github.com/samcharles93/archie-core/internal/domain/memory"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/domain/scheduling"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/workflow"
@@ -61,6 +62,7 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/infrastructure/taskactions"
"github.com/samcharles93/archie-core/internal/infrastructure/toolbuilder"
"github.com/samcharles93/archie-core/internal/infrastructure/transcription"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/plugin"
"github.com/samcharles93/archie-core/internal/plugin/pluginextract"
@@ -254,6 +256,15 @@ type boot struct {
// unrelated call.
embeddings domainembedding.Client
// transcriber is the optional voice-transcription capability. It is built
// beside the chat runtime from this process's own [models]/[providers],
// which is the model-owning side of the Messaging boundary: a channel
// frontend carries a voice note's bytes across the inbound wire, and this
// process turns them into text before the turn is recorded. Nil when no
// role is configured or the provider credential did not resolve; a turn
// then keeps the frontend's media note rather than failing.
transcriber messaging.Transcriber
toolReg *tools.Registry
chatModels *chatModelManager
personas *gateway.PersonaRegistry
@@ -872,6 +883,26 @@ func (b *boot) setupEmbeddings(cfg config.Config, log *slog.Logger) {
}
}
// setupTranscriber builds the optional voice-transcription capability. It is
// the model-owning side of the Messaging Service boundary: the channel
// frontend carries a voice note's audio bytes across the inbound wire but
// holds no provider credential, so this process turns them into text before
// the turn's message is recorded. Like setupEmbeddings, a client is wired only
// when models["transcription"] names a provider/model and that provider's
// credential resolves; a configured-but-unusable role is logged so the
// degradation is visible, while a role never configured is silent.
func (b *boot) setupTranscriber(cfg config.Config, log *slog.Logger) {
client, ok := transcription.New(cfg.Models, cfg.Providers, transcription.Options{
ResolveSecret: b.secrets.Resolve,
})
if ok {
b.transcriber = client
log.Info("voice transcription enabled", "role", transcription.Role)
} else if cfg.Models[transcription.Role] != "" {
log.Warn("voice transcription configured but unavailable; capability disabled", "role", transcription.Role)
}
}
// setupLLMAndChat wires the runtime, tool registry, model management,
// personas and the dashboard's chat service.
func (b *boot) setupLLMAndChat(ctx context.Context) error {
+8
View File
@@ -14,6 +14,7 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/daemon"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/installtype"
@@ -63,6 +64,12 @@ type chatSetup struct {
// process makes, which the /status health source reads back. Nil disables
// recording (the recorder's methods tolerate that rather than panicking).
ProviderOutcomes *providerOutcomeRecorder
// Transcriber is the voice-transcription capability built by
// setupChatRuntime from this process's own [models]/[providers]. Every turn
// runner carries it so a speech attachment is transcribed before its
// message is recorded. Nil disables the capability (no role configured, or
// the provider credential did not resolve), leaving the frontend's note.
Transcriber messaging.Transcriber
}
// daemonRunningVersions reports the component versions this process can
@@ -190,6 +197,7 @@ func newChatTurnRunner(
MemoryEngine: s.MemoryEngine,
MemoryWriter: s.MemoryWriter,
UserIdentity: userIdentityResolver(),
Transcriber: s.Transcriber,
Log: s.Log,
})
if err := runner.Recover(ctx); err != nil && s.Log != nil {
+8
View File
@@ -25,6 +25,11 @@ func (b *boot) setupChatRuntime(ctx context.Context, cfg config.Config) error {
// non-command message processing.
providers := executionProviders(cfg)
b.setLLM(agentexec.NewRuntime(providers))
// Transcription is a model-role capability, like the chat models it sits
// beside: it is built here, on the model-owning side, from this process's
// own [models]/[providers]. The Messaging Service carries a voice note's
// bytes to the Gateway and never holds the credential.
b.setupTranscriber(cfg, b.log)
b.toolReg = tools.NewRegistry()
chatModels := newChatModelManager(cfg.Models, cfg.Chat.Models)
catalog, catalogModels := b.catalogState()
@@ -142,6 +147,9 @@ func (b *boot) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskActor
Bus: b.bus, Log: b.log,
MemoryEngine: b.memoryStore(),
MemoryWriter: b.memoryWriter(),
// The transcription capability is built beside the chat runtime, from
// the model-role configuration only this process reads.
Transcriber: b.transcriber,
// The Gateway executes the web chat's turns, so it is the process
// that must record their outcomes for /status.
ProviderOutcomes: b.providerOutcomes,
+39
View File
@@ -0,0 +1,39 @@
package archied
import (
"log/slog"
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/infrastructure/transcription"
"github.com/samcharles93/archie-core/internal/secret"
)
// TestSetupTranscriberBuildsOnTheModelOwningSide pins where the voice
// capability is constructed: beside the chat runtime, from the process's own
// [models].transcription and [providers.*]. The Messaging Service carries the
// audio bytes across the inbound wire but no longer builds this client.
func TestSetupTranscriberBuildsOnTheModelOwningSide(t *testing.T) {
log := slog.New(slog.DiscardHandler)
t.Run("configured role wires a transcriber", func(t *testing.T) {
b := &boot{secrets: secret.NewRegistry()}
b.setupTranscriber(config.Config{
Models: map[string]string{transcription.Role: "local/whisper-large-v3"},
Providers: map[string]config.Provider{
"local": {Class: "openai-compatible", BaseURL: "http://127.0.0.1:8080/v1"},
},
}, log)
if b.transcriber == nil {
t.Fatal("transcriber = nil, want a client built from [models].transcription")
}
})
t.Run("absent role degrades to nil", func(t *testing.T) {
b := &boot{secrets: secret.NewRegistry()}
b.setupTranscriber(config.Config{}, log)
if b.transcriber != nil {
t.Fatalf("transcriber = %v, want nil when no role is configured", b.transcriber)
}
})
}
-1
View File
@@ -82,7 +82,6 @@ func compose(ctx context.Context, d deps) (*Service, error) {
}
tg := telegram.New(d.Config.TelegramToken, d.Config.Telegram.AllowedUserIDs, d.Log)
tg.Settings = d.Settings
tg.Transcriber = d.Config.Transcriber
configureTelegram(ctx, tg, d.Config, d.Chat, d.Log)
if err := srv.add("telegram", tg, telegramValidateConfigMap(d.Config.Telegram)); err != nil {
return nil, err
-29
View File
@@ -8,9 +8,7 @@ import (
"os"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/transcription"
"github.com/samcharles93/archie-core/internal/secret"
)
@@ -32,11 +30,6 @@ type ResolvedConfig struct {
BotUser string
HealthURL string
ShowToolCalls bool
// Transcriber is the optional voice-transcription capability. Nil means it
// is not configured (or its provider did not resolve), and a voice note
// keeps its media note. Constructed from [models].transcription and the
// matching [providers.*] entry.
Transcriber messaging.Transcriber
}
type projection struct {
@@ -50,8 +43,6 @@ type projection struct {
botUser string
healthURL string
showToolCalls bool
models map[string]string
providers map[string]config.Provider
}
// Resolve loads the configuration, extracts the messaging projection, resolves
@@ -101,7 +92,6 @@ func Resolve(o Options, log *slog.Logger) (ResolvedConfig, error) {
BotUser: proj.botUser,
HealthURL: proj.healthURL,
ShowToolCalls: proj.showToolCalls,
Transcriber: setupTranscriber(proj, secrets, log),
}, nil
}
@@ -131,8 +121,6 @@ func project(cfg config.Config) projection {
botUser: cfg.BotUser,
healthURL: cfg.Health.URL(),
showToolCalls: cfg.Chat.ShowToolCalls,
models: cfg.Models,
providers: cfg.Providers,
}
}
@@ -177,20 +165,3 @@ func resolveWebhookSecret(route config.WebhookRoute, secrets *secret.Registry) (
}
return "", nil
}
// setupTranscriber builds the optional voice-transcription capability. A
// client is wired only when [models].transcription names a provider/model and
// that provider's credential resolves; a configured-but-unusable role is
// logged so the degradation is visible, while a role that was never
// configured is silent (mirrors archied's setupEmbeddings).
func setupTranscriber(proj projection, secrets *secret.Registry, log *slog.Logger) messaging.Transcriber {
client, ok := transcription.New(proj.models, proj.providers, transcription.Options{ResolveSecret: secrets.Resolve})
if ok {
log.Info("voice transcription enabled", "role", transcription.Role)
return client
}
if proj.models[transcription.Role] != "" {
log.Warn("voice transcription configured but unavailable; capability disabled", "role", transcription.Role)
}
return nil
}
@@ -72,70 +72,6 @@ allowed_user_ids = [12345]
}
}
func TestResolveBuildsTranscriberFromModelRole(t *testing.T) {
write := func(t *testing.T, extra string) string {
t.Helper()
tmp := t.TempDir()
path := filepath.Join(tmp, "config.toml")
content := `
bot_user = "testbot"
[services.gateway]
target = "127.0.0.1:8999"
` + extra
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
t.Fatal(err)
}
return path
}
t.Run("configured role wires a transcriber", func(t *testing.T) {
path := write(t, `
[models]
transcription = "local/whisper-large-v3"
[providers.local]
class = "openai-compatible"
base_url = "http://127.0.0.1:8080/v1"
`)
resolved, err := Resolve(Options{Config: path}, slog.Default())
if err != nil {
t.Fatalf("Resolve: %v", err)
}
if resolved.Transcriber == nil {
t.Error("Transcriber = nil, want a client built from [models].transcription")
}
})
t.Run("absent role degrades to nil", func(t *testing.T) {
resolved, err := Resolve(Options{Config: write(t, "")}, slog.Default())
if err != nil {
t.Fatalf("Resolve: %v", err)
}
if resolved.Transcriber != nil {
t.Errorf("Transcriber = %v, want nil when no role is configured", resolved.Transcriber)
}
})
t.Run("configured but unusable role degrades to nil", func(t *testing.T) {
path := write(t, `
[models]
transcription = "openai/whisper-1"
[providers.openai]
class = "openai"
api_key_env = "TRANSCRIPTION_TEST_UNSET_KEY"
`)
resolved, err := Resolve(Options{Config: path}, slog.Default())
if err != nil {
t.Fatalf("Resolve: %v", err)
}
if resolved.Transcriber != nil {
t.Errorf("Transcriber = %v, want nil when the credential is missing", resolved.Transcriber)
}
})
}
func TestServiceStartAndStop(t *testing.T) {
d := deps{
Config: ResolvedConfig{