← Back to PRs

#22285: Voice-call: add onCallEnded lifecycle callback

by MegaPhoenix92 open 2026-02-21 00:16 View on GitHub →
channel: voice-call size: S
## Summary Adds an optional `onCallEnded` lifecycle callback to the voice-call extension. The callback fires once when a call terminates through any path: - Provider `call.ended` event (normal completion, remote hangup) - Non-retryable `call.error` event - Bot-initiated `endCall()` hangup The callback is wrapped in try/catch so a misbehaving consumer cannot break the call teardown flow. This enables extensions to react to call completion — for example, bridging call transcripts into the main agent session, logging call metrics, or triggering follow-up workflows. **Changes:** - `context.ts` — add `onCallEnded` to `CallManagerHooks` type - `manager.ts` — accept callback in constructor, thread to context - `events.ts` — fire on `call.ended` and non-retryable `call.error` - `outbound.ts` — fire on bot hangup via `endCall()` - `runtime.ts` — thread `onCallEnded` param through `createVoiceCallRuntime` - `manager.test.ts` — 5 new tests covering all end paths + error resilience ## Test plan - [x] `pnpm build` passes - [x] `pnpm vitest --run extensions/voice-call/src/manager.test.ts` — 16 tests pass (11 existing + 5 new) - [x] Format check passes (`pnpm format:check`) - [x] No new TS errors (only pre-existing discord `send.components.test.ts`) - [x] Callback fires on `call.ended`, `endCall()`, and non-retryable `call.error` - [x] Callback does NOT fire on retryable `call.error` - [x] Throwing callback does not break call teardown 🤖 AI-assisted PR (reviewed and tested manually) <!-- greptile_comment --> <h3>Greptile Summary</h3> Added optional `onCallEnded` lifecycle callback to voice-call extension. The callback fires when a call terminates through normal completion, non-retryable errors, or bot-initiated hangup. Implementation follows the existing `onCallAnswered` hook pattern with try/catch protection to prevent callback errors from breaking call teardown. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The implementation is clean, well-tested (5 new tests covering all paths), follows existing architectural patterns (`onCallAnswered` hook), and includes proper error handling with try/catch blocks to prevent callback errors from breaking teardown. The changes are backward-compatible (optional parameter) and touch only the necessary files. - No files require special attention <sub>Last reviewed commit: 7e1b38a</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs