bug(acp): unhandled rejection when sending the approval-mode update can crash the process
What happened?
In packages/cli/src/acp/acpSession.ts, handleApprovalModeChanged sends the mode update with a discarded promise:
void this.sendUpdate({
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: `[MODE_UPDATE] ${payload.mode}` },
});
sendUpdate() awaits connection.sessionUpdate(), which rejects when the ACP connection is closed or the client returns an error. ApprovalModeChanged is a global coreEvents event, so it can fire after the connection is gone. The rejection is then unhandled, and under Node's default (--unhandled-rejections=throw) it terminates the process.
The neighbouring handleRetryAttempt already handles this correctly (.catch(err => debugLogger.error(...))), so the two handlers are inconsistent.
What did you expect to happen?
A failed mode-update notification should be logged and ignored, the same way a failed retry notification is, and never crash the process.
Client information
Reproduced on current main at the unit level, with no live ACP client needed. Emit CoreEvent.ApprovalModeChanged for a session whose sendUpdate returns a rejected promise: vitest reports an Unhandled Rejection for the approval-mode handler, while the same test for the retry handler passes.
Login information
Not applicable.
Anything else we need to know?
I have a fix ready (add the same .catch() as handleRetryAttempt) with a table test covering both handlers: all 142 ACP tests pass, and tsc, eslint and prettier are clean. Could a maintainer triage this and add help wanted if it's appropriate for community contribution? I'll open the PR as soon as it's labeled.
There is a problem with the Gemini CLI issue triaging. Please check the action logs for details.