Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assistant/src/calls/call-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,9 @@ export class CallController {

private isExpectedAbortError(err: unknown): boolean {
if (!(err instanceof Error)) return false;
return err.name === 'AbortError' || err.name === 'APIUserAbortError';
return err.name === 'AbortError'
|| err.name === 'APIUserAbortError'
|| err.message === 'Session is already processing a message';
Comment thread
noanflaherty marked this conversation as resolved.
}

private isCurrentRun(runVersion: number): boolean {
Expand Down
14 changes: 13 additions & 1 deletion assistant/src/calls/voice-session-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface VoiceTurnHandle {
function buildVoiceCallControlPrompt(opts: {
isInbound: boolean;
task?: string | null;
isCallerGuardian?: boolean;
}): string {
const config = getConfig();
const disclosureEnabled = config.calls?.disclosure?.enabled === true;
Expand Down Expand Up @@ -134,8 +135,16 @@ function buildVoiceCallControlPrompt(opts: {
);

if (opts.isInbound) {
if (opts.isCallerGuardian) {
lines.push(
'10. If the latest user turn is [CALL_OPENING], this is your user calling you. Answer casually and briefly, like picking up a call from someone you know well. For example: "Hey!" or "What\'s up?" Do NOT introduce yourself, do NOT say you are calling on behalf of anyone, and do NOT ask how you can help in a formal way. Keep it short and natural.',
);
} else {
lines.push(
'10. If the latest user turn is [CALL_OPENING], greet the caller warmly and ask how you can help. Vary the wording; do not use a fixed template.',
);
}
lines.push(
'10. If the latest user turn is [CALL_OPENING], greet the caller warmly and ask how you can help. Vary the wording; do not use a fixed template.',
'11. If the latest user turn includes [CALL_OPENING_ACK], treat it as the caller acknowledging your greeting and continue the conversation naturally.',
);
} else {
Expand Down Expand Up @@ -201,9 +210,12 @@ export async function startVoiceTurn(opts: VoiceTurnOptions): Promise<VoiceTurnH

// Build the call-control protocol prompt so the model knows how to emit
// control markers (ASK_GUARDIAN, END_CALL, CALL_OPENING, etc.).
const isCallerGuardian = opts.guardianContext?.actorRole === 'guardian';

const voiceCallControlPrompt = buildVoiceCallControlPrompt({
isInbound: opts.isInbound,
task: opts.task,
isCallerGuardian,
});

const { run, abort } = await orchestrator.startRun(
Expand Down
13 changes: 12 additions & 1 deletion assistant/src/runtime/run-orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,18 @@ export class RunOrchestrator {
const session = await this.deps.getOrCreateSession(conversationId, transport);

if (session.isProcessing()) {
throw new Error('Session is already processing a message');
// Voice barge-in can race with turn teardown. Wait briefly for the
// previous run to finish aborting before giving up.
const maxWaitMs = 3000;
const pollIntervalMs = 50;
let waited = 0;
while (session.isProcessing() && waited < maxWaitMs) {
await new Promise(resolve => setTimeout(resolve, pollIntervalMs));
waited += pollIntervalMs;
Comment thread
noanflaherty marked this conversation as resolved.
}
if (session.isProcessing()) {
throw new Error('Session is already processing a message');
}
}

// Determine the correct strictSideEffects value for this run:
Expand Down