Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(assistant): keep OpenAI tool chats working without stored items (#2845)

Joshua46398779affa
diff --git a/src/helpers/providerHttpErrors.js b/src/helpers/providerHttpErrors.js
index 9b28db33f..579f5276d 100644
--- a/src/helpers/providerHttpErrors.js
+++ b/src/helpers/providerHttpErrors.js
@@ -113,6 +113,7 @@ const QUOTA_SIGNAL =
/insufficient_quota|credit balance|insufficient (credits|balance|funds)|out of credits|payment required/i;
const MODEL_SIGNAL =
/model_not_found|model[^.\n]{0,80}(not found|does not exist|not available|is not supported)|(unknown|invalid|unsupported) model/i;
+const MISSING_ITEM_SIGNAL = /\bitem with id\b[^.\n]{0,80}\bnot found\b/i;
const NETWORK_CODES = new Set([
"ENOTFOUND",
@@ -186,6 +187,8 @@ function codeForStatus(status, text, selfHosted) {
if (status === 403) return C.ACCESS_DENIED;
if (status === 429) return C.RATE_LIMITED;
if (status === 404) {
+ // OpenAI 404s an input item it no longer holds; the model itself is fine.
+ if (MISSING_ITEM_SIGNAL.test(text)) return C.BAD_REQUEST;
// A self-hosted 404 is far more often a wrong URL than a wrong model.
return selfHosted && !MODEL_SIGNAL.test(text) ? C.ERROR : C.MODEL_NOT_FOUND;
}
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.ts
index 3c5b3c20c..b4fdd133c 100644
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@ -946,10 +946,18 @@ class ReasoningService extends BaseReasoningService {
...(reasoningEffort && provider === "gemini"
? { google: { thinkingConfig: { thinkingLevel: reasoningEffort, includeThoughts: false } } }
: {}),
+ // store: false makes the SDK resend each tool step's reasoning inline
+ // (encrypted) rather than by id: a Zero Data Retention org keeps nothing
+ // to look an id up in, so the step after a tool call would 404.
// The SDK sends a Responses effort only for model ids it knows as reasoning
// models; forceReasoning covers newer OpenAI ids such as gpt-6-astra.
- ...(reasoningEffort && provider === "openai"
- ? { openai: { reasoningEffort, forceReasoning: true } }
+ ...(provider === "openai"
+ ? {
+ openai: {
+ store: false,
+ ...(reasoningEffort ? { reasoningEffort, forceReasoning: true } : {}),
+ },
+ }
: {}),
...(reasoningEffort && provider === "custom" ? { openai: { reasoningEffort } } : {}),
};
diff --git a/test/helpers/providerHttpErrors.test.js b/test/helpers/providerHttpErrors.test.js
index cb3e66e65..49cb9fd36 100644
--- a/test/helpers/providerHttpErrors.test.js
+++ b/test/helpers/providerHttpErrors.test.js
@@ -162,6 +162,27 @@ test("a self-hosted 404 without a model signal is a generic error, not a model e
assert.equal(c.messageParams.provider, "Your server");
});
+test("a 404 for a missing conversation item doesn't blame the model", async () => {
+ const c = await classify({
+ provider: "OpenAI",
+ surface: "llm",
+ status: 404,
+ model: "gpt-5-mini",
+ body: {
+ error: {
+ message:
+ "Item with id 'rs_123' not found. Items are not persisted for Zero Data Retention " +
+ "organizations. Remove this item from your input and try again.",
+ type: "invalid_request_error",
+ code: null,
+ },
+ },
+ });
+ assert.equal(c.code, "PROVIDER_BAD_REQUEST");
+ assert.equal(c.messageKey, "providerErrors.badRequest");
+ assert.equal(c.settingsTarget, undefined);
+});
+
test("413, other 4xx, timeouts, 5xx and unknown statuses", async () => {
assert.equal((await classify({ status: 413, body: "" })).code, "PROVIDER_PAYLOAD_TOO_LARGE");
for (const status of [400, 415, 422]) {
diff --git a/test/services/openaiZeroRetentionToolLoop.test.js b/test/services/openaiZeroRetentionToolLoop.test.js
new file mode 100644
index 000000000..bf18bb44b
--- /dev/null
+++ b/test/services/openaiZeroRetentionToolLoop.test.js
@@ -0,0 +1,125 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const { createRendererServer, installBrowserGlobals } = require("../lib/rendererTestHarness");
+
+// An own OpenAI key in a Zero Data Retention organization: OpenAI keeps nothing
+// between requests, so the step after a tool call must resend the reasoning
+// item itself (encrypted) instead of pointing at a stored copy by id.
+
+const ZDR_MISSING_ITEM =
+ "Item with id 'rs_test' not found. Items are not persisted for Zero Data Retention " +
+ "organizations. Remove this item from your input and try again.";
+
+function sse(events) {
+ return new Response(events.map((event) => `data: ${JSON.stringify(event)}\n\n`).join(""), {
+ status: 200,
+ headers: { "content-type": "text/event-stream" },
+ });
+}
+
+const created = (id) => ({
+ type: "response.created",
+ response: { id, created_at: 1, model: "gpt-5-mini" },
+});
+const completed = {
+ type: "response.completed",
+ response: { usage: { input_tokens: 1, output_tokens: 1 } },
+};
+
+// Conservative legacy fixture: encrypted reasoning only comes back when requested.
+function toolCallResponse(body) {
+ const wantsEncrypted = (body.include || []).includes("reasoning.encrypted_content");
+ const reasoning = {
+ type: "reasoning",
+ id: "rs_test",
+ ...(wantsEncrypted ? { encrypted_content: "encrypted-reasoning" } : {}),
+ };
+ const call = {
+ type: "function_call",
+ id: "fc_test",
+ call_id: "call_test",
+ name: "search_notes",
+ arguments: "{}",
+ };
+ return sse([
+ created("resp_1"),
+ { type: "response.output_item.added", output_index: 0, item: reasoning },
+ { type: "response.output_item.done", output_index: 0, item: reasoning },
+ { type: "response.output_item.added", output_index: 1, item: call },
+ { type: "response.output_item.done", output_index: 1, item: { ...call, status: "completed" } },
+ completed,
+ ]);
+}
+
+function answerResponse() {
+ const message = { type: "message", id: "msg_test" };
+ return sse([
+ created("resp_2"),
+ { type: "response.output_item.added", output_index: 0, item: message },
+ { type: "response.output_text.delta", item_id: "msg_test", delta: "We chose the pilot." },
+ { type: "response.output_item.done", output_index: 0, item: message },
+ completed,
+ ]);
+}
+
+test("OpenAI reasoning model: the step after a tool call works without stored items", async (t) => {
+ installBrowserGlobals(t, {
+ window: { electronAPI: { getOpenAIKey: async () => "test-key" } },
+ });
+ const vite = await createRendererServer(t, { cachePrefix: "openwhispr-openai-zdr-" });
+ const reasoningService = (await vite.ssrLoadModule("/services/ReasoningService.ts")).default;
+ const { usePolicyStore } = await vite.ssrLoadModule("/stores/policyStore.ts");
+ usePolicyStore.setState({ status: "unmanaged", appVersion: "1.8.3", policy: null });
+ const { ToolRegistry } = await vite.ssrLoadModule("/services/tools/ToolRegistry.ts");
+ t.after(() => reasoningService.destroy());
+
+ const registry = new ToolRegistry();
+ registry.register({
+ name: "search_notes",
+ description: "Search notes",
+ parameters: { type: "object", properties: {}, additionalProperties: false },
+ readOnly: true,
+ execute: async () => ({ success: true, data: [], displayText: "No notes" }),
+ });
+
+ const bodies = [];
+ const originalFetch = globalThis.fetch;
+ t.after(() => {
+ globalThis.fetch = originalFetch;
+ });
+ globalThis.fetch = async (_url, init) => {
+ const body = JSON.parse(init.body);
+ bodies.push(body);
+ if (bodies.length === 1) return toolCallResponse(body);
+ if (body.input.some((item) => item.type === "item_reference")) {
+ return new Response(
+ JSON.stringify({
+ error: { message: ZDR_MISSING_ITEM, type: "invalid_request_error", code: null },
+ }),
+ { status: 404, headers: { "content-type": "application/json" } }
+ );
+ }
+ return answerResponse();
+ };
+
+ const stream = reasoningService.processTextStreamingAI(
+ [{ role: "user", content: "What did we decide in the Acme kickoff note?" }],
+ "gpt-5-mini",
+ "openai",
+ { systemPrompt: "Answer the user." },
+ registry.toAISDKFormat()
+ );
+ const chunks = [];
+ for await (const chunk of stream) chunks.push(chunk);
+
+ assert.equal(bodies.length, 2);
+ for (const body of bodies) assert.equal(body.store, false);
+ const resent = bodies[1].input.find((item) => item.type === "reasoning");
+ assert.equal(resent?.encrypted_content, "encrypted-reasoning");
+ const answer = chunks
+ .filter((chunk) => chunk.type === "content")
+ .map((chunk) => chunk.text)
+ .join("");
+ assert.equal(answer, "We chose the pilot.");
+});