[AI] fix client connection dropping api/* error replies

Found via the browser smoke test: opening an e2e-encrypted budget without the
key surfaced as "undefined is not an object" instead of an error. The server
connection forwards api/* handler failures as {type:'reply', id, error}, but
the web client connection only read `result`, silently resolving undefined for
every failed api/* call. Reject when the reply carries an error, matching the
server's envelope (and the old api rpc behavior). The electron client has the
same latent gap; left untouched here.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
github-actions[bot]
2026-06-09 22:24:41 +01:00
parent 8ddb3f20c3
commit 778ed25cf9

View File

@@ -50,7 +50,7 @@ function handleMessage(msg) {
handler.reject(error);
}
} else if (msg.type === 'reply') {
const { id, result, mutated, undoTag } = msg;
const { id, result, mutated, undoTag, error } = msg;
const handler = replyHandlers.get(id);
if (handler) {
@@ -60,7 +60,13 @@ function handleMessage(msg) {
undo.gc(undoTag);
}
handler.resolve(result);
// api/* handler failures arrive as a reply carrying `error` (see
// platform/server/connection); reject rather than resolving undefined.
if (error) {
handler.reject(error);
} else {
handler.resolve(result);
}
}
} else if (msg.type === 'push') {
const { name, args } = msg;