Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

Say "Could not save this voice chat." when the save's answer is not JSON (#655)

kevinb6932d31a8d6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 784fdc80..d6bf5ed4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -243,6 +243,14 @@ An installed or cached Bun that is not the pinned version is no longer accepted,
every start, and OpenBot acquires its own copy instead. The version already on the machine is left
exactly as it is and simply not used.
+### A voice chat that could not be saved says so in a sentence
+
+Saving a finished voice call read the server's answer as JSON without a fallback. When something in
+front of OpenBot answered instead, such as a proxy's 502 page, the call's card gave the JSON
+parser's error as the reason (in Chrome, "Unexpected token '<' ... is not valid JSON"); an answer
+without a saved session failed on a property read the same way. Both now read "Could not save this voice chat.", the
+message the card already uses, and the call stays on the card to retry.
+
### Organization sign-in survives a callback that arrives in pieces
The loopback listener that receives an organization or provider sign-in read the callback once and
diff --git a/app/src/lib/voice/archive.ts b/app/src/lib/voice/archive.ts
index 784da463..7194ebaf 100644
--- a/app/src/lib/voice/archive.ts
+++ b/app/src/lib/voice/archive.ts
@@ -98,10 +98,13 @@ export function saveVoiceSession(
headers: { "content-type": "application/json", "x-openbot-voice": "1" },
body: payload,
});
- const body = await response.json();
- if (!response.ok && !body.session)
+ // A proxy's error page is not JSON, and its parser message is no sentence for a person.
+ // Without a session there is nothing saved to show, whatever the status, as `client` holds.
+ const body: { session?: VoiceSessionRecord; error?: string } =
+ await response.json().catch(() => ({}));
+ if (!body.session)
throw new Error(body.error ?? "Could not save this voice chat.");
- const session: VoiceSessionRecord = body.session;
+ const session = body.session;
forgetVoiceCall(session, ownerId);
queryClient.setQueryData<VoiceSessionRecord[]>(
keys.saved(input.channelId),
diff --git a/app/tests/voice-archive.test.ts b/app/tests/voice-archive.test.ts
index 5ecf9a35..96415969 100644
--- a/app/tests/voice-archive.test.ts
+++ b/app/tests/voice-archive.test.ts
@@ -100,6 +100,35 @@ test("a busy summary response retains the server's durable transcript instead of
expect(records[0]?.saveError).toBe("Summary service busy");
});
+test("a save answered by a page that is not JSON reads as a failed save, not a parser error", async () => {
+ for (const [id, response] of [
+ [
+ "proxy",
+ () =>
+ new Response("<html><body>502 Bad Gateway</body></html>", {
+ status: 502,
+ headers: { "content-type": "text/html" },
+ }),
+ ],
+ ["empty", () => new Response(null, { status: 204 })],
+ ] as const) {
+ mockFetch(async (_input, init) =>
+ init?.method
+ ? response()
+ : Response.json({ sessions: [], nextCursor: null }),
+ );
+ saveVoiceSession(voiceSessionInput(call(id)));
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ const record = (await loadVoiceArchive("channel-1")).find(
+ (entry) => entry.id === id,
+ );
+ expect(record?.saveState).toBe("unsaved");
+ expect(record?.saveError).toStartWith("Could not save this voice chat.");
+ mock.restore();
+ queryClient.clear();
+ }
+});
+
test("save failure remains retryable with the same session id and original transcript", async () => {
const sent: unknown[] = [];
let fail = true;