@vellumai/assistant 0.11.6-dev.202608261801.b683b42 → 0.11.6-dev.202608261844.52da3d2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +26 -14
- package/docs/stt-provider-onboarding.md +8 -4
- package/package.json +1 -1
- package/src/__tests__/llm-resolver.test.ts +54 -0
- package/src/__tests__/managed-speech-defaults.test.ts +64 -0
- package/src/__tests__/media-stream-stt-session.test.ts +2 -0
- package/src/__tests__/schedule-retry.test.ts +177 -4
- package/src/__tests__/scheduler-reuse-conversation.test.ts +6 -6
- package/src/calls/__tests__/telephony-synthesis-language.test.ts +81 -0
- package/src/calls/__tests__/voice-session-bridge.test.ts +20 -0
- package/src/calls/media-stream-stt-session.ts +2 -1
- package/src/calls/telephony-synthesis-language.ts +13 -5
- package/src/calls/voice-session-bridge.ts +6 -4
- package/src/config/bundled-skills/media-processing/services/audio-transcribe.ts +3 -1
- package/src/config/bundled-skills/media-processing/services/preprocess.ts +1 -1
- package/src/config/bundled-skills/phone-calls/SKILL.md +1 -1
- package/src/config/bundled-skills/phone-calls/references/CONFIG.md +16 -15
- package/src/config/bundled-skills/phone-calls/references/TROUBLESHOOTING.md +2 -1
- package/src/config/bundled-skills/transcribe/tools/transcribe-media.ts +1 -1
- package/src/config/llm-resolver.ts +24 -0
- package/src/config/managed-speech-defaults.ts +75 -18
- package/src/config/schemas/__tests__/stt.test.ts +94 -0
- package/src/config/schemas/stt.ts +99 -0
- package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +42 -0
- package/src/live-voice/live-voice-credential-preflight.ts +5 -1
- package/src/live-voice/live-voice-session.ts +13 -3
- package/src/notifications/__tests__/activity-failed-dedupe.test.ts +161 -0
- package/src/notifications/activity-failed-dedupe.ts +95 -0
- package/src/plugin-api/transcription-session.ts +1 -1
- package/src/providers/speech-to-text/__tests__/resolve.test.ts +197 -0
- package/src/providers/speech-to-text/provider-catalog.ts +15 -1
- package/src/providers/speech-to-text/resolve.ts +55 -12
- package/src/runtime/__tests__/background-job-runner.test.ts +61 -3
- package/src/runtime/background-job-runner.ts +37 -9
- package/src/runtime/http-server.ts +12 -4
- package/src/runtime/routes/inbound-stages/transcribe-audio.ts +1 -1
- package/src/runtime/routes/stt-routes.ts +7 -4
- package/src/runtime/routes/watch-routes.ts +9 -5
- package/src/schedule/retry-policy.ts +8 -8
- package/src/schedule/schedule-recovery.ts +0 -1
- package/src/schedule/scheduler.ts +83 -15
- package/src/stt/__tests__/roles.test.ts +152 -0
- package/src/stt/roles.ts +180 -0
- package/src/stt/stt-stream-session.ts +3 -2
package/ARCHITECTURE.md
CHANGED
|
@@ -577,17 +577,29 @@ All guardian decisions for voice access requests flow through:
|
|
|
577
577
|
|
|
578
578
|
Audio-to-text conversion occurs in six distinct runtime boundaries, each with its own provider model and adapter layer. The `services.stt` config block is the single source of truth for STT provider selection across assistant, client, live voice, and telephony boundaries.
|
|
579
579
|
|
|
580
|
+
**Per-consumer roles:** `services.stt.provider` (plus that provider's `services.stt.providers.<id>.model` family) is the global selection. `services.stt.roles.<role>` overrides it for one consumer, naming a `{provider, model?}` pair; an unset role falls back to the global. Roles exist because capability is per boundary while the global is not: the Flux family streams but has no batch endpoint, so a global set to it breaks file transcription and telephony at the same moment it improves live voice. A role names the consumer rather than the boundary, because one telephony call resolves a streaming transcriber and a batch fallback within the same session.
|
|
581
|
+
|
|
582
|
+
| Role | Consumers | Boundaries required |
|
|
583
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
|
|
584
|
+
| `liveVoice` | `src/live-voice/live-voice-session.ts`, `src/live-voice/live-voice-credential-preflight.ts` | streaming |
|
|
585
|
+
| `telephony` | `src/calls/media-stream-stt-session.ts` (streaming dial and batch fallback) | streaming + batch + telephony |
|
|
586
|
+
| `dictation` | `/v1/stt/stream` (`src/runtime/http-server.ts`), `POST /v1/stt/transcribe`, `src/plugin-api/transcription-session.ts` | streaming + batch |
|
|
587
|
+
| `watch` | `/v1/watch/stream` (`src/runtime/routes/watch-routes.ts`) | streaming |
|
|
588
|
+
| `batch` | inbound audio (`routes/inbound-stages/transcribe-audio.ts`), `POST /v1/stt/transcribe-file`, media-processing/transcribe skills | batch |
|
|
589
|
+
|
|
590
|
+
Roles are defined in `src/stt/roles.ts`: `STT_ROLE_REQUIREMENTS` declares each role's boundaries, `sttSelectionForRole()`/`sttCatalogKeyForRole()` perform the lookup, and `sttRoleCapabilityGap()` states why a pair cannot serve a role. Selection is resolved inside `resolveBatchTranscriber()`/`resolveStreamingTranscriber()`, so a caller passes `role` and nothing else. Capability is checked against the **resolved catalog row** (`sttCatalogKeyFor(provider, model)`), not the bare provider id, since `deepgram` batches and `deepgram` running `flux` does not. Validation is fail-closed: `services.stt.roles` rejects an incapable pair at config parse time rather than substituting a working provider at dial time. Telephony and live-voice preflight, the dictation session label, and the telephony language pin all read their own role, so what preflight judges is what the session dials.
|
|
591
|
+
|
|
580
592
|
**Provider catalog model:** The daemon's canonical provider catalog (`src/providers/speech-to-text/provider-catalog.ts`) is the single source of truth for all STT provider metadata — credential mappings, supported boundaries, telephony mode, conversation streaming mode, and client-facing display metadata (names, hints, setup mode, credentials guide). Native clients fetch provider metadata at launch via `GET /v1/stt/providers`. To add a new provider, follow the checklist in `docs/stt-provider-onboarding.md`.
|
|
581
593
|
|
|
582
594
|
**Boundary overview:**
|
|
583
595
|
|
|
584
|
-
| Boundary | Runtime | Provider (current)
|
|
585
|
-
| ---------------------------- | --------------------------------------------------- |
|
|
586
|
-
| **Telephony (media-stream)** | Daemon process (Twilio Media Streams WebSocket) |
|
|
587
|
-
| **Daemon batch** | Daemon process (REST API to provider) |
|
|
588
|
-
| **Conversation streaming** | Daemon process (WebSocket-based) |
|
|
589
|
-
| **Live voice channel** | Assistant process (gateway-authenticated WebSocket) |
|
|
590
|
-
| **Client service-first** | Web/Electron via gateway → daemon |
|
|
596
|
+
| Boundary | Runtime | Provider (current) | Adapter module | Caller |
|
|
597
|
+
| ---------------------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
|
|
598
|
+
| **Telephony (media-stream)** | Daemon process (Twilio Media Streams WebSocket) | `telephony` role, else `services.stt.provider` | `src/calls/media-stream-stt-session.ts`, `src/providers/speech-to-text/resolve.ts`, streaming provider adapters | `src/calls/media-stream-server.ts` |
|
|
599
|
+
| **Daemon batch** | Daemon process (REST API to provider) | `batch` role, else `services.stt.provider` | `src/stt/daemon-batch-transcriber.ts` | `src/runtime/routes/inbound-stages/transcribe-audio.ts` |
|
|
600
|
+
| **Conversation streaming** | Daemon process (WebSocket-based) | `dictation` role, else `services.stt.provider` | `src/stt/stt-stream-session.ts`, `src/providers/speech-to-text/deepgram-realtime.ts`, `src/providers/speech-to-text/google-gemini-live-stream.ts`, `src/providers/speech-to-text/openai-whisper-stream.ts`, `src/providers/speech-to-text/xai-realtime.ts` | Web/Electron dictation client via gateway WS proxy |
|
|
601
|
+
| **Live voice channel** | Assistant process (gateway-authenticated WebSocket) | `liveVoice` role, else `services.stt.provider` | `src/runtime/http-server.ts`, `src/live-voice/live-voice-session-manager.ts`, `src/live-voice/live-voice-session.ts`, `src/providers/speech-to-text/resolve.ts`, streaming provider adapters | Web/Electron live voice client via `/v1/live-voice` |
|
|
602
|
+
| **Client service-first** | Web/Electron via gateway → daemon | `dictation` (transcribe) / `batch` (transcribe-file) role, else `services.stt.provider` | `src/runtime/routes/stt-routes.ts` | Web/Electron dictation and voice clients |
|
|
591
603
|
|
|
592
604
|
**Telephony boundary (media-stream):**
|
|
593
605
|
|
|
@@ -595,8 +607,8 @@ Every phone call connects over Twilio Media Streams: the voice webhook emits `<C
|
|
|
595
607
|
|
|
596
608
|
Transcription mode is selected once per session in `media-stream-stt-session.ts`:
|
|
597
609
|
|
|
598
|
-
- **Streaming** (default)
|
|
599
|
-
- **Batch fallback
|
|
610
|
+
- **Streaming** (default): when `calls.voice.telephonyStreaming` is enabled and the `telephony` role resolves a streaming transcriber (`resolveStreamingTranscriber({ role: "telephony" })`), inbound audio is decoded (mu-law → PCM16, resampled 8 kHz → 16 kHz) and fed to the provider's realtime adapter. Replies trigger only on utterance-boundary finals (for Deepgram, `speech_final`/`UtteranceEnd`, never mid-sentence `is_final` segments), and barge-in fires from local energy VAD, never from transcriber partials.
|
|
611
|
+
- **Batch fallback**: otherwise the session segments turns with the energy-based `MediaTurnDetector` and transcribes each completed turn via the same role's batch API. Both halves of a call read the `telephony` role, which is why a role names its consumer rather than a boundary.
|
|
600
612
|
|
|
601
613
|
A credential preflight (`resolveTelephonyCredentialReadiness()` in `src/calls/telephony-credential-preflight.ts`) gates every call: it requires a credentialed, telephony-capable STT provider **and** a media-stream-playable TTS provider (the configured one or a credentialed playable fallback). Inbound calls that fail the preflight receive `<Say>` setup-required copy plus `<Hangup/>` instead of a doomed stream; outbound placement fails before dialing via `preflightVoiceIngress()` with the same user-facing message.
|
|
602
614
|
|
|
@@ -632,7 +644,7 @@ To add a new daemon batch STT provider, follow the full checklist in `docs/stt-p
|
|
|
632
644
|
|
|
633
645
|
**Conversation streaming boundary:**
|
|
634
646
|
|
|
635
|
-
Real-time conversation chat message capture on macOS uses a WebSocket-based streaming STT path. When the
|
|
647
|
+
Real-time conversation chat message capture on macOS uses a WebSocket-based streaming STT path. When the provider the `dictation` role resolves to supports conversation streaming (determined by the `conversationStreamingMode` field in the provider catalog), native clients open a WebSocket session through the gateway to the daemon's `/v1/stt/stream` endpoint. The daemon resolves a `StreamingTranscriber` for that provider and streams partial/final transcript events back to the client in real time.
|
|
636
648
|
|
|
637
649
|
Each provider that advertises a conversation streaming mode in the catalog ships an adapter implementing the `StreamingTranscriber` interface from `src/stt/types.ts`. The catalog (`src/providers/speech-to-text/provider-catalog.ts`) is the source of truth for which providers are streaming-capable; `resolveStreamingTranscriber()` maps each to its adapter:
|
|
638
650
|
|
|
@@ -653,8 +665,8 @@ Each provider that advertises a conversation streaming mode in the catalog ships
|
|
|
653
665
|
|
|
654
666
|
**Session lifecycle (daemon side):**
|
|
655
667
|
|
|
656
|
-
1. Client opens a WebSocket to `/v1/stt/stream` with required query parameter `mimeType` and optional `provider` and `sampleRate`. The `provider` parameter is optional compatibility metadata
|
|
657
|
-
2. `SttStreamSession` (in `src/stt/stt-stream-session.ts`) resolves a `StreamingTranscriber` via `resolveStreamingTranscriber()` from `src/providers/speech-to-text/resolve.ts`, using the
|
|
668
|
+
1. Client opens a WebSocket to `/v1/stt/stream` with required query parameter `mimeType` and optional `provider` and `sampleRate`. The `provider` parameter is optional compatibility metadata: the runtime is config-authoritative and always resolves the streaming transcriber from the `dictation` role (`services.stt.roles.dictation`, else `services.stt.provider`). When a requested provider disagrees with the one that role resolves to, the runtime logs a mismatch warning.
|
|
669
|
+
2. `SttStreamSession` (in `src/stt/stt-stream-session.ts`) resolves a `StreamingTranscriber` via `resolveStreamingTranscriber()` from `src/providers/speech-to-text/resolve.ts`, using the dictation role's provider (not the requested one).
|
|
658
670
|
3. The transcriber's `start()` method opens the provider session.
|
|
659
671
|
4. A `ready` event (with `provider` field) is sent to the client, signaling that audio frames are accepted.
|
|
660
672
|
5. Client sends `audio` frames (binary WebSocket frames or base64-encoded JSON) and a `stop` event when recording ends.
|
|
@@ -725,7 +737,7 @@ V1 is local/gateway-scoped. Managed/cloud WebSocket proxy support, cross-region
|
|
|
725
737
|
|
|
726
738
|
**Client service-first boundary:**
|
|
727
739
|
|
|
728
|
-
All product-facing dictation and voice-streaming paths use a service-first STT strategy. Clients record audio, encode it to WAV, and POST it through the gateway to the daemon's `POST /v1/stt/transcribe` endpoint. The daemon resolves the
|
|
740
|
+
All product-facing dictation and voice-streaming paths use a service-first STT strategy. Clients record audio, encode it to WAV, and POST it through the gateway to the daemon's `POST /v1/stt/transcribe` endpoint. The daemon resolves the `dictation` role's provider through `resolveBatchTranscriber()` and returns the transcribed text. `POST /v1/stt/transcribe-file` resolves the `batch` role the same way.
|
|
729
741
|
|
|
730
742
|
- The client receives a typed result distinguishing success from `notConfigured`, `serviceUnavailable`, and `error`, so callers can deterministically trigger their fallback path.
|
|
731
743
|
- The gateway proxies the request via assistant-scoped path rewriting: `/v1/assistants/:id/stt/transcribe` is rewritten to `/v1/stt/transcribe` on the daemon.
|
|
@@ -735,7 +747,7 @@ The web client implements these flows in `clients/web/src/domains/chat/voice/`:
|
|
|
735
747
|
|
|
736
748
|
**Cross-boundary notes:**
|
|
737
749
|
|
|
738
|
-
- The `services.stt` config block is the single source of truth for STT provider selection across the daemon batch boundary, the conversation streaming boundary, the client service-first boundary, and the telephony boundary. The batch and streaming resolvers (`resolveBatchTranscriber()`, `resolveStreamingTranscriber()`) both read
|
|
750
|
+
- The `services.stt` config block is the single source of truth for STT provider selection across the daemon batch boundary, the conversation streaming boundary, the client service-first boundary, and the telephony boundary. The batch and streaming resolvers (`resolveBatchTranscriber()`, `resolveStreamingTranscriber()`) both read it, taking the caller's `role` override (`services.stt.roles.<role>`) when one is set and the global `services.stt.provider` otherwise, and resolve credentials through the same catalog; the telephony boundary's media-stream STT session uses these same resolvers, selecting streaming vs batch transcription via `resolveStreamingTranscriber()`/`resolveBatchTranscriber()` under the `calls.voice.telephonyStreaming` flag, gated by `resolveTelephonySttCapability()`, while call placement/TwiML is gated by `resolveTelephonyCredentialReadiness()`. The daemon provider catalog (`src/providers/speech-to-text/provider-catalog.ts`) is the authoritative registry of supported providers. Native clients fetch display metadata via `GET /v1/stt/providers`.
|
|
739
751
|
- **Spoken language** is a second axis on the same block: `services.stt.language` is read by `resolveStreamingTranscriber()` and `resolveBatchTranscriber()` and forwarded to the adapters that accept one (Deepgram, xAI, and the managed relay, which passes it to Deepgram server-side). Callers may override it per streaming session, but none need to: reading it in the resolvers means every boundary inherits the setting. Gemini and Whisper take no language option and auto-detect natively, so they ignore it. Leaving it unset is **not** auto-detection on Deepgram or the managed relay: Deepgram's default is English, so non-English speech transcribes as English-sounding nonsense. `"multi"` selects nova-3 code-switching across English, Spanish, French, German, Hindi, Russian, Portuguese, Japanese, Italian, and Dutch, the mode to use when a speaker mixes languages inside one utterance. BYOK Deepgram pins `model=nova-3` for **any** explicitly configured language, not just `"multi"`: the curated roster is verified against nova-3 (the default nova-2 supports only a subset, and rejects `"multi"` outright), and `deepgramLanguageOptions()` owns the model+language pairing so every call site inherits the rule; leaving the language unset keeps the adapter default model with no language param. `"multi"` is never forwarded to xAI (it is not a BCP-47 code; xAI auto-handles multilingual audio). The managed relay pins nova-3 and allowlists `language`, so streaming needs no platform-side change; managed **batch** goes through the platform speech proxy, which accepts no language parameter, so forwarding it there is deferred pending a platform-side change.
|
|
740
752
|
- Conversation streaming does not replace the client service-first batch path. When streaming is available, it runs concurrently during recording and provides real-time partials and finals. The batch path remains the fallback for providers that do not support streaming, when streaming fails mid-session, or when streaming produces no final transcript.
|
|
741
753
|
- Credential mapping is catalog-driven: `provider-secret-catalog.ts` derives STT API-key provider names from the daemon catalog via `listCredentialProviderNames()`, deduplicating against the LLM/search provider list. Adding a provider to the catalog automatically includes its credential name in `API_KEY_PROVIDERS`.
|
|
@@ -29,7 +29,7 @@ This ensures the exhaustive switch in `daemon-batch-transcriber.ts` produces a c
|
|
|
29
29
|
|
|
30
30
|
- Append the new provider ID string to the `VALID_STT_PROVIDERS` tuple.
|
|
31
31
|
|
|
32
|
-
The `services.stt.providers` map uses a sparse `z.record(z.string(), ...)` schema, so adding a new provider does **not** require a workspace migration to seed a `services.stt.providers.<id>` entry. Users only need to set `services.stt.provider` to the new ID and supply credentials.
|
|
32
|
+
The `services.stt.providers` map uses a sparse `z.record(z.string(), ...)` schema, so adding a new provider does **not** require a workspace migration to seed a `services.stt.providers.<id>` entry. Users only need to set `services.stt.provider` (or a single consumer's `services.stt.roles.<role>`, see step 7) to the new ID and supply credentials.
|
|
33
33
|
|
|
34
34
|
**Language handling.** `services.stt.language` is resolved centrally in `resolveStreamingTranscriber()` (and in `resolveBatchTranscriber()` for the daemon-batch boundary), so a new adapter inherits it for free: accept a `language` option in the adapter's constructor and forward it to the provider. If the provider auto-detects natively and has no language parameter (as Gemini and Whisper do), accept nothing and let the resolver's value be ignored; document that choice in the adapter, because "no language param" means auto-detect for some providers and _English_ for others (Deepgram), and that difference is an easy source of silent wrong-language transcription. A provider that supports both batch and streaming must forward the language on **both** paths, not just the streaming one.
|
|
35
35
|
|
|
@@ -84,12 +84,16 @@ Clients derive shared-vs-exclusive key behavior from the catalog automatically:
|
|
|
84
84
|
|
|
85
85
|
## 7. Verify unified STT architecture
|
|
86
86
|
|
|
87
|
-
`services.stt
|
|
87
|
+
The `services.stt` block is the single source of truth for all STT routing, including telephony. There is no separate telephony STT config path.
|
|
88
|
+
|
|
89
|
+
Routing has two levels. `services.stt.provider`, plus that provider's `services.stt.providers.<id>.model` family, is the global selection every consumer falls back to. `services.stt.roles.<role>` overrides it for one consumer, naming a `{provider, model?}` pair. The roles are `liveVoice`, `telephony`, `dictation`, `watch` and `batch`; `src/stt/roles.ts` maps each to the boundaries its call sites resolve on, and `ARCHITECTURE.md` lists the consumers per role. A new provider needs no per-role registration: a role may name any provider in the catalog whose row covers the boundaries that role requires.
|
|
88
90
|
|
|
89
91
|
Before submitting the PR, verify that:
|
|
90
92
|
|
|
91
|
-
1. **No stale config references
|
|
93
|
+
1. **No stale config references**: grep for any references to a separate telephony transcription config. Telephony transcription runs daemon-side over the Twilio media-stream transport (`src/calls/media-stream-stt-session.ts`), which resolves through `resolveStreamingTranscriber()`/`resolveBatchTranscriber()` under the `telephony` role like every other boundary resolves under its own.
|
|
92
94
|
|
|
93
95
|
2. **Provider catalog telephony metadata** — the new provider's catalog entry (step 1) declares `telephonyMode` and `supportedBoundaries`; these are the single source of truth for the telephony capability check (`resolveTelephonySttCapability()`) and for streaming-vs-batch mode selection in the media-stream STT session. No per-provider routing maps exist.
|
|
94
96
|
|
|
95
|
-
3. **
|
|
97
|
+
3. **Role capability follows the catalog row**: `sttRoleCapabilityGap()` reads `supportedBoundaries` and `telephonyMode` from the row the pair resolves to (`sttCatalogKeyFor(provider, model)`), so a model family that drops a boundary must be its own catalog row. Get the row right and config validation rejects incapable role pairs on its own; nothing per-role needs writing.
|
|
98
|
+
|
|
99
|
+
4. **No duplicate wiring**: a provider should appear only once in `services.stt`. The telephony layer consumes the same catalog, and a role selects from it; there is no second registration step for telephony or for any role.
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
resolveCallSiteConfigWithProfile,
|
|
10
10
|
resolveDefaultProfileKey,
|
|
11
11
|
resolveEffectiveProfileKey,
|
|
12
|
+
resolveSingleRouteProfileKey,
|
|
12
13
|
} from "../config/llm-resolver.js";
|
|
13
14
|
import { type LLMCallSite, LLMSchema } from "../config/schemas/llm.js";
|
|
14
15
|
import { resolveModelIntent } from "../providers/model-intents.js";
|
|
@@ -889,6 +890,59 @@ describe("mix profiles", () => {
|
|
|
889
890
|
);
|
|
890
891
|
});
|
|
891
892
|
|
|
893
|
+
test("resolveSingleRouteProfileKey names standard winners and refuses mixes", () => {
|
|
894
|
+
// The mix's arm is picked per conversation and can differ from any
|
|
895
|
+
// post-hoc recomputation, so the outer mix key must never be used as a
|
|
896
|
+
// single-route attribution scope.
|
|
897
|
+
expect(resolveSingleRouteProfileKey("mainAgent", mixLlm)).toBeUndefined();
|
|
898
|
+
expect(
|
|
899
|
+
resolveSingleRouteProfileKey("mainAgent", mixLlm, {
|
|
900
|
+
overrideProfile: "a",
|
|
901
|
+
}),
|
|
902
|
+
).toBe("a");
|
|
903
|
+
// An unusable override falls through to the active mix, which still
|
|
904
|
+
// refuses to name a route.
|
|
905
|
+
expect(
|
|
906
|
+
resolveSingleRouteProfileKey("mainAgent", mixLlm, {
|
|
907
|
+
overrideProfile: "no-such-profile",
|
|
908
|
+
}),
|
|
909
|
+
).toBeUndefined();
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
test("resolveSingleRouteProfileKey honors the dispatch resolvability predicate", () => {
|
|
913
|
+
// A pin whose provider dispatch cannot resolve (e.g. a force-deleted
|
|
914
|
+
// connection) must not be claimed as a scope: selection falls through to
|
|
915
|
+
// the active mix exactly as dispatch does, which then refuses to name a
|
|
916
|
+
// route. Without the predicate the stale pin still wins the chain, which
|
|
917
|
+
// is why scope callers must pass dispatch's predicate.
|
|
918
|
+
const staleLlm = LLMSchema.parse({
|
|
919
|
+
profiles: {
|
|
920
|
+
a: { provider: "anthropic", model: "model-a" },
|
|
921
|
+
b: { provider: "anthropic", model: "model-b" },
|
|
922
|
+
stale: { provider: "openai", model: "model-s" },
|
|
923
|
+
ab: {
|
|
924
|
+
mix: [
|
|
925
|
+
{ profile: "a", weight: 1 },
|
|
926
|
+
{ profile: "b", weight: 1 },
|
|
927
|
+
],
|
|
928
|
+
},
|
|
929
|
+
},
|
|
930
|
+
activeProfile: "ab",
|
|
931
|
+
});
|
|
932
|
+
const openaiForceDeleted = (provider: string) => provider !== "openai";
|
|
933
|
+
expect(
|
|
934
|
+
resolveSingleRouteProfileKey("mainAgent", staleLlm, {
|
|
935
|
+
overrideProfile: "stale",
|
|
936
|
+
isResolvableProvider: openaiForceDeleted,
|
|
937
|
+
}),
|
|
938
|
+
).toBeUndefined();
|
|
939
|
+
expect(
|
|
940
|
+
resolveSingleRouteProfileKey("mainAgent", staleLlm, {
|
|
941
|
+
overrideProfile: "stale",
|
|
942
|
+
}),
|
|
943
|
+
).toBe("stale");
|
|
944
|
+
});
|
|
945
|
+
|
|
892
946
|
test("all dereference spots in a turn agree for the same seed", () => {
|
|
893
947
|
// mainAgent (mix as activeProfile) and a non-main call site resolving the
|
|
894
948
|
// same mix as its call-site profile must pick the same arm when given the
|
|
@@ -27,6 +27,7 @@ mock.module("../calls/telephony-tts-capability.js", () => ({
|
|
|
27
27
|
|
|
28
28
|
import { getConfig, invalidateConfigCache } from "../config/loader.js";
|
|
29
29
|
import { maybeDefaultSpeechToManaged } from "../config/managed-speech-defaults.js";
|
|
30
|
+
import { sttCatalogKeyForRole } from "../stt/roles.js";
|
|
30
31
|
|
|
31
32
|
const WORKSPACE_DIR = process.env.VELLUM_WORKSPACE_DIR!;
|
|
32
33
|
const CONFIG_PATH = join(WORKSPACE_DIR, "config.json");
|
|
@@ -115,6 +116,69 @@ describe("maybeDefaultSpeechToManaged", () => {
|
|
|
115
116
|
});
|
|
116
117
|
});
|
|
117
118
|
|
|
119
|
+
test("a narrowing stand-in is written to the live-voice role, not the global", async () => {
|
|
120
|
+
// BYOK Flux with no key: the stand-in preserves turn detection, so it is
|
|
121
|
+
// vellum-flux, which streams and nothing else. Writing that globally is
|
|
122
|
+
// how batch transcription and telephony disappear for a managed user.
|
|
123
|
+
mockManagedSpeechAvailable = true;
|
|
124
|
+
writeConfig({
|
|
125
|
+
services: {
|
|
126
|
+
stt: {
|
|
127
|
+
provider: "deepgram",
|
|
128
|
+
providers: { deepgram: { model: "flux" } },
|
|
129
|
+
},
|
|
130
|
+
tts: { provider: "vellum" },
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
await maybeDefaultSpeechToManaged();
|
|
135
|
+
|
|
136
|
+
const stt = (readConfig().services as any).stt;
|
|
137
|
+
expect(stt.roles.liveVoice).toEqual({ provider: "vellum", model: "flux" });
|
|
138
|
+
// The other consumers land on the stand-in's base, which serves them all.
|
|
139
|
+
expect(stt.provider).toBe("vellum");
|
|
140
|
+
expect(stt.providers.vellum.model).toBe("nova-3");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("the role write leaves batch and telephony on a provider that answers", async () => {
|
|
144
|
+
mockManagedSpeechAvailable = true;
|
|
145
|
+
writeConfig({
|
|
146
|
+
services: {
|
|
147
|
+
stt: {
|
|
148
|
+
provider: "deepgram",
|
|
149
|
+
providers: { deepgram: { model: "flux" } },
|
|
150
|
+
},
|
|
151
|
+
tts: { provider: "vellum" },
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
await maybeDefaultSpeechToManaged();
|
|
156
|
+
|
|
157
|
+
invalidateConfigCache();
|
|
158
|
+
const stt = getConfig().services.stt;
|
|
159
|
+
expect(sttCatalogKeyForRole(stt, "liveVoice")).toBe("vellum-flux");
|
|
160
|
+
expect(sttCatalogKeyForRole(stt, "batch")).toBe("vellum");
|
|
161
|
+
expect(sttCatalogKeyForRole(stt, "telephony")).toBe("vellum");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("a capability-preserving stand-in still writes the global provider", async () => {
|
|
165
|
+
// Plain deepgram has no turn detection, so the stand-in is plain vellum,
|
|
166
|
+
// which serves every role. That one belongs on the global, not a role.
|
|
167
|
+
mockManagedSpeechAvailable = true;
|
|
168
|
+
writeConfig({
|
|
169
|
+
services: {
|
|
170
|
+
stt: { provider: "deepgram" },
|
|
171
|
+
tts: { provider: "vellum" },
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
await maybeDefaultSpeechToManaged();
|
|
176
|
+
|
|
177
|
+
const stt = (readConfig().services as any).stt;
|
|
178
|
+
expect(stt.provider).toBe("vellum");
|
|
179
|
+
expect(stt.roles).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
|
|
118
182
|
test("never repoints an explicit BYOK provider with resolving credentials", async () => {
|
|
119
183
|
mockManagedSpeechAvailable = true;
|
|
120
184
|
mockSttKeyResolves = true;
|
|
@@ -774,6 +774,7 @@ describe("MediaStreamSttSession", () => {
|
|
|
774
774
|
|
|
775
775
|
expect(resolveStreamingTranscriber).toHaveBeenCalledTimes(1);
|
|
776
776
|
expect(resolveStreamingTranscriber).toHaveBeenCalledWith({
|
|
777
|
+
role: "telephony",
|
|
777
778
|
sampleRate: 16_000,
|
|
778
779
|
utteranceBoundaryFinals: true,
|
|
779
780
|
utteranceEndMs: 1000,
|
|
@@ -787,6 +788,7 @@ describe("MediaStreamSttSession", () => {
|
|
|
787
788
|
const { session } = await startStreamingSession();
|
|
788
789
|
|
|
789
790
|
expect(resolveStreamingTranscriber).toHaveBeenCalledWith({
|
|
791
|
+
role: "telephony",
|
|
790
792
|
sampleRate: 16_000,
|
|
791
793
|
utteranceBoundaryFinals: true,
|
|
792
794
|
utteranceEndMs: 2500,
|
|
@@ -10,12 +10,23 @@ import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
|
10
10
|
let injectedProcessMessageForRunner:
|
|
11
11
|
| ((conversationId: string, message: string) => Promise<unknown>)
|
|
12
12
|
| null = null;
|
|
13
|
+
// Options of every mocked `runBackgroundJob` call, for asserting what the
|
|
14
|
+
// scheduler asked of the runner (e.g. that per-attempt failure emissions are
|
|
15
|
+
// suppressed in favor of the retries-exhausted alert).
|
|
16
|
+
const runnerCalls: Array<Record<string, unknown>> = [];
|
|
17
|
+
// When set, a failing mocked run reports this classification instead of the
|
|
18
|
+
// default generic exception, letting a test drive the cause-keyed alert path.
|
|
19
|
+
let runnerFailureClassification: {
|
|
20
|
+
errorKind: "timeout" | "model_provider" | "exception";
|
|
21
|
+
failureCode?: string;
|
|
22
|
+
} | null = null;
|
|
13
23
|
mock.module("../runtime/background-job-runner.js", () => ({
|
|
14
24
|
runBackgroundJob: async (opts: {
|
|
15
25
|
jobName: string;
|
|
16
26
|
prompt: string;
|
|
17
27
|
onConversationCreated?: (conversationId: string) => void;
|
|
18
28
|
}) => {
|
|
29
|
+
runnerCalls.push(opts as unknown as Record<string, unknown>);
|
|
19
30
|
const conversationId = `mock-conv-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
20
31
|
opts.onConversationCreated?.(conversationId);
|
|
21
32
|
try {
|
|
@@ -29,7 +40,7 @@ mock.module("../runtime/background-job-runner.js", () => ({
|
|
|
29
40
|
conversationId,
|
|
30
41
|
ok: false,
|
|
31
42
|
error,
|
|
32
|
-
errorKind: "exception" as const,
|
|
43
|
+
...(runnerFailureClassification ?? { errorKind: "exception" as const }),
|
|
33
44
|
};
|
|
34
45
|
}
|
|
35
46
|
},
|
|
@@ -466,6 +477,171 @@ describe("scheduler retry integration", () => {
|
|
|
466
477
|
});
|
|
467
478
|
});
|
|
468
479
|
|
|
480
|
+
// ── Execute-mode failure notifications ────────────────────────────────
|
|
481
|
+
|
|
482
|
+
describe("execute-mode failure notifications", () => {
|
|
483
|
+
let scheduler: SchedulerHandle;
|
|
484
|
+
|
|
485
|
+
beforeEach(() => {
|
|
486
|
+
emitNotificationSignalImpl = async () => {};
|
|
487
|
+
runnerCalls.length = 0;
|
|
488
|
+
runnerFailureClassification = null;
|
|
489
|
+
const db = getDb();
|
|
490
|
+
db.run("DELETE FROM cron_runs");
|
|
491
|
+
db.run("DELETE FROM cron_jobs");
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
afterEach(() => {
|
|
495
|
+
scheduler?.stop();
|
|
496
|
+
runnerFailureClassification = null;
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
test("a failing schedule alerts once, at exhaustion, keyed on the failure cause", async () => {
|
|
500
|
+
const emitted: Array<Record<string, unknown>> = [];
|
|
501
|
+
emitNotificationSignalImpl = async (payload) => {
|
|
502
|
+
emitted.push(payload as Record<string, unknown>);
|
|
503
|
+
};
|
|
504
|
+
runnerFailureClassification = {
|
|
505
|
+
errorKind: "model_provider",
|
|
506
|
+
failureCode: "PROVIDER_BILLING",
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
const schedule = await createSchedule({
|
|
510
|
+
name: "Billing victim",
|
|
511
|
+
cronExpression: "0 * * * *",
|
|
512
|
+
message: "do work",
|
|
513
|
+
syntax: "cron",
|
|
514
|
+
maxRetries: 1,
|
|
515
|
+
retryBackoffMs: 1000,
|
|
516
|
+
});
|
|
517
|
+
forceScheduleDue(schedule.id);
|
|
518
|
+
|
|
519
|
+
scheduler = startScheduler(async () => {
|
|
520
|
+
throw new Error("PROVIDER_BILLING: Agent turn failed.");
|
|
521
|
+
});
|
|
522
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
523
|
+
|
|
524
|
+
// First failure: a retry is pending, so nothing is user-visible yet, and
|
|
525
|
+
// the scheduler told the runner to keep its per-attempt emission quiet.
|
|
526
|
+
expect(emitted).toHaveLength(0);
|
|
527
|
+
expect(runnerCalls.length).toBeGreaterThanOrEqual(1);
|
|
528
|
+
for (const call of runnerCalls) {
|
|
529
|
+
expect(call.suppressFailureNotifications).toBe(true);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// Second failure exhausts retries (maxRetries: 1) and fires the single
|
|
533
|
+
// alert, deduped on the classified cause rather than the schedule.
|
|
534
|
+
forceScheduleDue(schedule.id);
|
|
535
|
+
await scheduler.runOnce();
|
|
536
|
+
scheduler.stop();
|
|
537
|
+
|
|
538
|
+
expect(emitted).toHaveLength(1);
|
|
539
|
+
const alert = emitted[0];
|
|
540
|
+
expect(alert.sourceEventName).toBe("activity.failed");
|
|
541
|
+
expect(alert.sourceContextId).toBe(schedule.id);
|
|
542
|
+
// Schedules snapshot a concrete inference profile at creation, and that
|
|
543
|
+
// profile is the alert's provider scope.
|
|
544
|
+
const scope = schedule.inferenceProfile;
|
|
545
|
+
expect(scope).toBeTruthy();
|
|
546
|
+
expect(alert.dedupeKey).toMatch(
|
|
547
|
+
new RegExp(
|
|
548
|
+
`^activity-failed:cause:PROVIDER_BILLING:${scope}:\\d{4}-\\d{2}-\\d{2}$`,
|
|
549
|
+
),
|
|
550
|
+
);
|
|
551
|
+
expect(alert.contextPayload).toMatchObject({
|
|
552
|
+
jobName: "schedule:Billing victim",
|
|
553
|
+
errorKind: "model_provider",
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
test("schedules on different profiles alert separately for the same cause", async () => {
|
|
558
|
+
// Two provider connections can fail for the same class of reason with
|
|
559
|
+
// different remedies; schedule A's alert must not suppress schedule B's.
|
|
560
|
+
const emitted: Array<Record<string, unknown>> = [];
|
|
561
|
+
emitNotificationSignalImpl = async (payload) => {
|
|
562
|
+
emitted.push(payload as Record<string, unknown>);
|
|
563
|
+
};
|
|
564
|
+
runnerFailureClassification = {
|
|
565
|
+
errorKind: "model_provider",
|
|
566
|
+
failureCode: "PROVIDER_INVALID_KEY",
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
const scheduleA = await createSchedule({
|
|
570
|
+
name: "Profile A victim",
|
|
571
|
+
cronExpression: "0 * * * *",
|
|
572
|
+
message: "do work",
|
|
573
|
+
syntax: "cron",
|
|
574
|
+
maxRetries: 1,
|
|
575
|
+
retryBackoffMs: 1000,
|
|
576
|
+
inferenceProfile: "cost-optimized",
|
|
577
|
+
});
|
|
578
|
+
const scheduleB = await createSchedule({
|
|
579
|
+
name: "Profile B victim",
|
|
580
|
+
cronExpression: "0 * * * *",
|
|
581
|
+
message: "do work",
|
|
582
|
+
syntax: "cron",
|
|
583
|
+
maxRetries: 1,
|
|
584
|
+
retryBackoffMs: 1000,
|
|
585
|
+
inferenceProfile: "balanced",
|
|
586
|
+
});
|
|
587
|
+
forceScheduleDue(scheduleA.id);
|
|
588
|
+
forceScheduleDue(scheduleB.id);
|
|
589
|
+
|
|
590
|
+
scheduler = startScheduler(async () => {
|
|
591
|
+
throw new Error("provider rejected the key");
|
|
592
|
+
});
|
|
593
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
594
|
+
forceScheduleDue(scheduleA.id);
|
|
595
|
+
forceScheduleDue(scheduleB.id);
|
|
596
|
+
await scheduler.runOnce();
|
|
597
|
+
scheduler.stop();
|
|
598
|
+
|
|
599
|
+
expect(emitted).toHaveLength(2);
|
|
600
|
+
const keys = emitted.map((signal) => signal.dedupeKey as string).sort();
|
|
601
|
+
expect(keys[0]).toMatch(
|
|
602
|
+
/^activity-failed:cause:PROVIDER_INVALID_KEY:balanced:\d{4}-\d{2}-\d{2}$/,
|
|
603
|
+
);
|
|
604
|
+
expect(keys[1]).toMatch(
|
|
605
|
+
/^activity-failed:cause:PROVIDER_INVALID_KEY:cost-optimized:\d{4}-\d{2}-\d{2}$/,
|
|
606
|
+
);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
test("a cause-less failure keys the exhaustion alert per schedule", async () => {
|
|
610
|
+
const emitted: Array<Record<string, unknown>> = [];
|
|
611
|
+
emitNotificationSignalImpl = async (payload) => {
|
|
612
|
+
emitted.push(payload as Record<string, unknown>);
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
const schedule = await createSchedule({
|
|
616
|
+
name: "Crashing job",
|
|
617
|
+
cronExpression: "0 * * * *",
|
|
618
|
+
message: "do work",
|
|
619
|
+
syntax: "cron",
|
|
620
|
+
maxRetries: 1,
|
|
621
|
+
retryBackoffMs: 1000,
|
|
622
|
+
});
|
|
623
|
+
forceScheduleDue(schedule.id);
|
|
624
|
+
|
|
625
|
+
scheduler = startScheduler(async () => {
|
|
626
|
+
throw new Error("boom");
|
|
627
|
+
});
|
|
628
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
629
|
+
forceScheduleDue(schedule.id);
|
|
630
|
+
await scheduler.runOnce();
|
|
631
|
+
scheduler.stop();
|
|
632
|
+
|
|
633
|
+
expect(emitted).toHaveLength(1);
|
|
634
|
+
expect(emitted[0].dedupeKey).toMatch(
|
|
635
|
+
new RegExp(
|
|
636
|
+
`^activity-failed:schedule:${schedule.id}:\\d{4}-\\d{2}-\\d{2}$`,
|
|
637
|
+
),
|
|
638
|
+
);
|
|
639
|
+
expect(emitted[0].contextPayload).toMatchObject({
|
|
640
|
+
errorKind: "exception",
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
|
|
469
645
|
// ── Crash recovery ────────────────────────────────────────────────────
|
|
470
646
|
|
|
471
647
|
describe("crash recovery", () => {
|
|
@@ -667,7 +843,6 @@ describe("scheduler-recovery equivalence", () => {
|
|
|
667
843
|
await applyRetryDecision({
|
|
668
844
|
job: jobB,
|
|
669
845
|
isOneShot: false,
|
|
670
|
-
errorMsg: "fail",
|
|
671
846
|
decision,
|
|
672
847
|
scheduleRetry,
|
|
673
848
|
failOneShotPermanently: () => {},
|
|
@@ -747,7 +922,6 @@ describe("scheduler-recovery equivalence", () => {
|
|
|
747
922
|
await applyRetryDecision({
|
|
748
923
|
job: jobB1,
|
|
749
924
|
isOneShot: true,
|
|
750
|
-
errorMsg: "fail",
|
|
751
925
|
decision: decision1,
|
|
752
926
|
scheduleRetry,
|
|
753
927
|
failOneShotPermanently: (id: string) => {
|
|
@@ -774,7 +948,6 @@ describe("scheduler-recovery equivalence", () => {
|
|
|
774
948
|
await applyRetryDecision({
|
|
775
949
|
job: jobB2,
|
|
776
950
|
isOneShot: true,
|
|
777
|
-
errorMsg: "fail",
|
|
778
951
|
decision: decision2,
|
|
779
952
|
scheduleRetry,
|
|
780
953
|
failOneShotPermanently: (id: string) => {
|
|
@@ -456,7 +456,7 @@ describe("scheduler talk-mode runner option propagation", () => {
|
|
|
456
456
|
runBackgroundJobBootstrapFails = false;
|
|
457
457
|
});
|
|
458
458
|
|
|
459
|
-
test("talk-mode propagates conversationType=scheduled
|
|
459
|
+
test("talk-mode propagates conversationType=scheduled and scheduleJobId", async () => {
|
|
460
460
|
const rruleExpr = buildEveryMinuteRrule();
|
|
461
461
|
const schedule = await createSchedule({
|
|
462
462
|
name: "Quiet Talk Mode",
|
|
@@ -475,10 +475,12 @@ describe("scheduler talk-mode runner option propagation", () => {
|
|
|
475
475
|
expect(opts.conversationType).toBe("scheduled");
|
|
476
476
|
expect(opts.scheduleJobId).toBe(schedule.id);
|
|
477
477
|
expect(opts.groupId).toBe("system:scheduled");
|
|
478
|
-
expect(opts.suppressFailureNotifications).toBe(true);
|
|
479
478
|
});
|
|
480
479
|
|
|
481
|
-
test("talk-mode
|
|
480
|
+
test("talk-mode always suppresses the runner's per-attempt failure emission", async () => {
|
|
481
|
+
// The retry policy owns the single user-facing alert for a failing
|
|
482
|
+
// schedule (fired once, at exhaustion), so the runner must stay quiet
|
|
483
|
+
// per attempt whether or not the schedule itself is quiet.
|
|
482
484
|
const rruleExpr = buildEveryMinuteRrule();
|
|
483
485
|
const schedule = await createSchedule({
|
|
484
486
|
name: "Loud Talk Mode",
|
|
@@ -493,9 +495,7 @@ describe("scheduler talk-mode runner option propagation", () => {
|
|
|
493
495
|
await runDueSchedulesOnce();
|
|
494
496
|
|
|
495
497
|
expect(runBackgroundJobOptions).toHaveLength(1);
|
|
496
|
-
expect(runBackgroundJobOptions[0]!.suppressFailureNotifications).toBe(
|
|
497
|
-
false,
|
|
498
|
-
);
|
|
498
|
+
expect(runBackgroundJobOptions[0]!.suppressFailureNotifications).toBe(true);
|
|
499
499
|
});
|
|
500
500
|
|
|
501
501
|
test("talk-mode bootstrap failure writes sentinel conversationId, not empty string", async () => {
|