Skip to content
104 changes: 88 additions & 16 deletions docs/status/voice-persona-evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,22 @@ check with a short sample of the intended delivery:

For each call, compare the spoken answer with the approved Workflow text.
Track progress cues separately; they aren't part of the approved answer.
After checking ordinary playback, interrupt once during synthesis and once
during playback. Make sure old audio stops, the call remains usable, and
After checking ordinary playback, ask one follow-up while playback is active,
correct one request while synthesis is pending, and interrupt one response
during playback. Make sure stale audio stops, the call remains usable, and
Discord's playback report agrees with what the caller heard.

Record the model and voice used, whether the answer matched, time to first
audible speech, playback outcome, available cost, and short listening notes.
Mark anything you couldn't observe. Hear all four personas before deciding
whether to change their voices.

Limit this first test to six MAI synthesis requests in total: four initial
answers and up to two replacement answers for the interruption checks.
Progress cues count toward the same limit, so skip a later check if a cue
uses up the remaining allowance. Do not retry requests or exceed six.
Start with one initial answer per persona, then exercise the follow-up,
correction, and interruption checks above. Aim for about six MAI synthesis
requests including progress cues, as guidance rather than a hard limit. The
operator will monitor OpenRouter spending manually. Keep the first pass short;
stop to investigate unexpected charges or repeated synthesis failures. Do not
run automated high-volume calls or retry loops.

### Choosing other models later

Expand Down Expand Up @@ -338,21 +341,90 @@ listening; do not add samples or raw provider responses to the repository.

### Remaining canary gates

- **Preflight on 2026-11-06:** The focused voice suite passed 53/53 tests with
dummy test-only Discord settings. This confirms synthetic Workflow,
transcription, synthesis, cancellation, PCM-boundary, and Discord playback
behavior; it does not confirm a real MAI response or audible Discord output.
The backend request path uses `response_format: pcm` and `provider.zdr: true`.
- **Operator decision on 2026-11-06:** The prior $1 key-cap requirement is
withdrawn for this user-led canary. The operator will monitor OpenRouter
spending manually. This does not authorize automated high-volume calls or
retry loops.
- Account-side ZDR and Safety Retention settings were not rechecked because
the OpenRouter settings page required sign-in. The request-level ZDR option
is present, but does not establish the account's Safety Retention policy.
- **Fly deployment on 2026-11-06:** The repository's `deploy.ps1` workflow
deployed revision `c78c13584d270b670e19497dec45ad89c8cd1efc` to the
canonical `footnote` app (release `v585`, image
`deployment-01M6SG295Z5XCBFCD6YAPRVYPJ`). The embedded revision matches the
deployed commit. The existing `/data/config/footnote.yaml` SHA-256 was
preserved at `1666684fc22bf9121b3923d9345dd909878e960482e5eb0540d2b10fc0a57d52`;
authentication stayed in preserve mode, and no secret values were changed.
- Fly reported one started machine, passing machine checks, and DNS
verification. `/healthz` returned 200. Startup diagnostics included four
`discord_client` ready records and no Discord startup errors. These checks
confirm bot startup, not audible Discord playback.
- The Fly backend has `OPENROUTER_API_KEY` present in its running process; the
read-only `GET /api/v1/key` check returned HTTP 200 with key metadata. The
credential value was not read or printed. All four persona bot credentials,
guild lists, and authorized-user environment variables are configured and
present in running processes. The existing per-guild and developer-only
Voice restrictions were not changed.
- No Discord call or TTS synthesis was made during deployment. The operator
will run the canary in a private voice channel with one consenting
participant, using the existing bots. No separate deployment is required.
- **First live Discord attempt (2026-11-06):** The operator reported joining
the call and speaking without hearing a response. Logs show the backend
realtime connection succeeded, then Standard transcription failed twice at
`22:59:11Z` and `22:59:29Z`. No Workflow, MAI TTS, or playback event followed.
The buffered logs omit the provider HTTP status, so the upstream failure
cause is still unknown. No speech content was added to this record.
- The handler now records only an upstream HTTP status on future
transcription failures; it does not log the provider error body or speech.
- **Diagnostic follow-up deployment (2026-11-06):** Release `v586` runs image
`registry.fly.io/footnote:deployment-01M6SJSSY5HS7QDKEBFMEJ14EX`, embedding
revision `353ad23af253f78b73c71612bb07cef5ac237930`. The machine started,
its health check passed, and `/healthz` returned 200. Startup logs again
showed four Discord clients ready and no Discord startup errors. The
production YAML hash remains
`1666684fc22bf9121b3923d9345dd909878e960482e5eb0540d2b10fc0a57d52`; auth
stayed in preserve mode and no secret values changed. No call was made after
this diagnostic release.
- **Stage-log deployment (2026-11-07):** Release `v587` runs image
`registry.fly.io/footnote:deployment-01M6VTYX9QSRGJ8JFHJBY6KVRV`; the
repository deploy process prepared its build context from revision
`62d6d6abe7bf2ef53e8d6fbf7a07894645d44947`. Fly image metadata does not
expose a source-revision label. The machine started with passing checks,
`/healthz` returned 200, and four Discord clients logged ready with no
startup errors. The production YAML hash remains
`1666684fc22bf9121b3923d9345dd909878e960482e5eb0540d2b10fc0a57d52`; auth
remained in preserve mode and no secret values were changed.
- The new scoped `info`/`warn` records trace Standard Voice input capture,
transcription status/timing, Workflow disposition/timing, MAI response
status/PCM byte count/timing, Discord handoff, and playback status/timing.
They omit speech, transcripts, provider error bodies, and user/guild IDs.
No global debug level was enabled. The latest unanswered call preceded
v587; its per-release log trace was not available in the current retained
buffer, so it remains unexplained. A separately documented v585 attempt had
two transcription failures and no following Workflow, MAI, or playback
event; its upstream status was absent. No Standard Voice attempt has been
observed after v587 yet; playback remains unverified pending the operator
retest.
- Real MAI PCM synthesis, audible playback, persona listening, end-to-end
latency, interruption, cancellation, recovery, and cost remain unverified.
- Confirm that MAI returns `audio/pcm` with nonempty, even-length 24 kHz
mono PCM16 within the 10 MiB limit. Discord resamples the audio to 48 kHz.
Synthetic tests check response type, size, and even-byte boundaries;
they cannot confirm the actual provider's sample rate or channel count.
The audition requested MP3, so real PCM output remains untested.
- Use a process-scoped OpenRouter key with a verified, non-resetting cap of
$1 or less and enough balance for six short requests. The November 5
preflight made no paid requests because it couldn't verify the active
key's cap.
- Prepare a private, non-production Discord environment. The available
checkout identified only the production Fly app, so no test deployment
or call was attempted. Keep one consenting human in the voice channel;
the caller can also be the listener.
- Verify account-side ZDR and retention settings. Speech requests set
`provider.zdr: true`, but the account settings remain operator-attested.

Rollback target before the stage-log deployment is release `v586`, image
`registry.fly.io/footnote:deployment-01M6SJSSY5HS7QDKEBFMEJ14EX`. If needed,
redeploy that image with:

```powershell
fly deploy --app footnote --image registry.fly.io/footnote:deployment-01M6SG295Z5XCBFCD6YAPRVYPJ
```

Sources: [OpenRouter TTS guide](https://openrouter.ai/docs/guides/overview/multimodal/tts),
[live speech catalog](https://openrouter.ai/api/v1/models?output_modalities=speech),
Expand Down
103 changes: 68 additions & 35 deletions packages/backend/src/handlers/internalVoiceRealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ export const createInternalVoiceRealtimeHandler = ({
? null
: {
runRealtimeConversation: async (snapshot, context) => {
const workflowStartedAt = Date.now();
if (mode === 'standard')
realtimeLogger.info(
'Standard Voice Workflow started.'
);
try {
if (!mode || !persona)
throw new Error('Voice mode is unavailable.');
Expand All @@ -392,6 +397,10 @@ export const createInternalVoiceRealtimeHandler = ({
persona,
}
);
if (mode === 'standard')
realtimeLogger.info(
`Standard Voice Workflow completed disposition=${result.finalResponse?.disposition ?? 'missing'} workflowMs=${Date.now() - workflowStartedAt}`
);
const answer = result.finalResponse;
if (
answer?.disposition ===
Expand Down Expand Up @@ -420,6 +429,12 @@ export const createInternalVoiceRealtimeHandler = ({
disposition: 'answer_too_long',
},
};
} catch (error) {
if (mode === 'standard')
realtimeLogger.warn(
`Standard Voice Workflow failed workflowMs=${Date.now() - workflowStartedAt}`
);
throw error;
} finally {
if (mode === 'standard') cancelProgressCue();
}
Expand Down Expand Up @@ -459,15 +474,13 @@ export const createInternalVoiceRealtimeHandler = ({
message: 'Approved answer speech could not be generated.',
code: 'speech_synthesis_failed',
});
realtimeLogger.warn('OpenRouter voice synthesis failed.', {
provider: selection.provider,
model: selection.model,
voice: selection.voice,
selectionSource: selection.selectionSource,
responseFormat: 'pcm',
synthesisMs: Date.now() - synthesisStartedAt,
error: error instanceof Error ? error.message : String(error),
});
const providerStatus =
error instanceof Error
? /\bHTTP (\d{3})\b/u.exec(error.message)?.[1]
: undefined;
realtimeLogger.warn(
`Standard Voice TTS synthesis failed provider=${selection.provider} httpStatus=${providerStatus ?? 'unknown'} synthesisMs=${Date.now() - synthesisStartedAt}`
);
};

const synthesizeApprovedDelivery = async (
Expand Down Expand Up @@ -525,21 +538,17 @@ export const createInternalVoiceRealtimeHandler = ({
state.deliveryStatus()?.status !== 'handed_off'
)
return;
realtimeLogger.info('Standard Voice TTS synthesis complete.', {
provider: speechSelection.provider,
model: speechSelection.model,
voice: speechSelection.voice,
selectionSource: speechSelection.selectionSource,
generationId: result.generationId,
responseFormat: 'pcm',
audioBytes: result.audio.byteLength,
synthesisMs: Date.now() - synthesisStartedAt,
});
realtimeLogger.info(
`Standard Voice TTS synthesis complete provider=${speechSelection.provider} voiceSource=${speechSelection.selectionSource.voice} audioBytes=${result.audio.byteLength} synthesisMs=${Date.now() - synthesisStartedAt}`
);
sendServerEvent(ws, {
type: 'output_audio.delta',
audioBase64: result.audio.toString('base64'),
deliveryId: delivery.deliveryId,
});
realtimeLogger.info(
`Standard Voice audio sent to Discord boundary audioBytes=${result.audio.byteLength}`
);
} catch (error) {
reportSynthesisFailure(
state,
Expand Down Expand Up @@ -570,9 +579,16 @@ export const createInternalVoiceRealtimeHandler = ({
if (!attributedSpeakerId) return;
transcriptionController?.abort('superseded');
transcriptionController = controller;
const transcriptionStartedAt = Date.now();
realtimeLogger.info(
`Standard Voice transcription started audioBytes=${audio.byteLength}`
);
void openRouterVoiceService
.transcribe(audio, controller.signal)
.then(({ text, usage }) => {
realtimeLogger.info(
`Standard Voice transcription completed elapsedMs=${Date.now() - transcriptionStartedAt} nonEmpty=${Boolean(text.trim())}`
);
if (
closed ||
controller.signal.aborted ||
Expand Down Expand Up @@ -620,14 +636,12 @@ export const createInternalVoiceRealtimeHandler = ({
'The voice utterance could not be transcribed.',
code: 'transcription_failed',
});
const providerStatus =
error instanceof Error
? /\bHTTP \d{3}\b/u.exec(error.message)?.[0]
: undefined;
realtimeLogger.warn(
'OpenRouter voice transcription failed.',
{
error:
error instanceof Error
? error.message
: String(error),
}
`Standard Voice transcription failed httpStatus=${providerStatus ?? 'unknown'} elapsedMs=${Date.now() - transcriptionStartedAt}`
);
}
})
Expand Down Expand Up @@ -1247,6 +1261,9 @@ export const createInternalVoiceRealtimeHandler = ({
if (event.type === 'session.ready') {
if (sessionReady) return;
sessionReady = true;
realtimeLogger.info(
`Voice session ready mode=${event.mode ?? mode ?? defaultMode}`
);
clearTimer(setupTimeout);
setupTimeout = undefined;
callTimeout = setTimer(
Expand Down Expand Up @@ -1322,6 +1339,9 @@ export const createInternalVoiceRealtimeHandler = ({
event.deliveryId,
event.event
);
realtimeLogger.info(
`Standard Voice playback status=${event.event} accepted=${Boolean(accepted)}`
);
if (
accepted &&
currentDeliveryId === event.deliveryId &&
Expand Down Expand Up @@ -1362,6 +1382,9 @@ export const createInternalVoiceRealtimeHandler = ({
}
const audio = Buffer.from(event.audioBase64, 'base64');
if (audioBytes === 0) {
realtimeLogger.info(
'Standard Voice input audio started.'
);
cancelProgressCue();
transcriptionController?.abort('new_utterance');
transcriptionController = undefined;
Expand Down Expand Up @@ -1395,6 +1418,9 @@ export const createInternalVoiceRealtimeHandler = ({
audioChunks = [];
audioBytes = 0;
if (audio.length === 0) {
realtimeLogger.warn(
'Standard Voice input commit rejected reason=empty_audio'
);
sendServerEvent(ws, {
type: 'error',
message:
Expand All @@ -1403,6 +1429,9 @@ export const createInternalVoiceRealtimeHandler = ({
});
return;
}
realtimeLogger.info(
`Standard Voice input committed audioBytes=${audio.byteLength}`
);
transcribeStandardUtterance(audio);
return;
}
Expand Down Expand Up @@ -1648,15 +1677,19 @@ export const createInternalVoiceRealtimeHandler = ({
SESSION_SETUP_TIMEOUT_MS
);
setupTimeout.unref?.();
realtimeLogger.info('Internal voice session starting.', {
mode,
profileId: persona.profile.id,
personaSelectionSource: persona.selectionSource,
personaOverlaySelection: persona.overlaySelection,
personaOverlaySource: persona.profile.promptOverlay.source,
personaExpressionStrength: persona.expression.strength,
personaExpressionSource: persona.expression.source,
});
realtimeLogger.info(
`Internal voice session starting. mode=${mode} persona=${persona.profile.id} personaSource=${persona.selectionSource}`,
{
mode,
profileId: persona.profile.id,
personaSelectionSource: persona.selectionSource,
personaOverlaySelection: persona.overlaySelection,
personaOverlaySource:
persona.profile.promptOverlay.source,
personaExpressionStrength: persona.expression.strength,
personaExpressionSource: persona.expression.source,
}
);
if (mode === 'standard') {
const bundledVoice =
STANDARD_TTS_PERSONA_VOICES[
Expand Down
Loading
Loading