Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: a chat with earlier messages offers a new chat

ogsamratb4dca50a35d3
diff --git a/apps/app/src/react-app/domains/session/surface/model-modes.ts b/apps/app/src/react-app/domains/session/surface/model-modes.ts
index 8dbed3df..0805fe87 100644
--- a/apps/app/src/react-app/domains/session/surface/model-modes.ts
+++ b/apps/app/src/react-app/domains/session/surface/model-modes.ts
@@ -16,6 +16,7 @@ import type { ModelRef } from "@/app/types";
import type { OmniRushSubagentModelState } from "@/app/lib/omnirush-server";
import { useLinuxSandbox, type LinuxSandboxClient } from "@/react-app/domains/settings/linux-sandbox";
import { useSubagentModel, type SubagentModelClient } from "@/react-app/domains/settings/subagent-model";
+import { getReactQueryClient } from "@/react-app/infra/query-client";
type CatalogModels = OmniRushSubagentModelState["models"];
type Mode = "native" | "box";
@@ -68,7 +69,28 @@ const STARTED_KEY = "omnirush.sessionModelFixed";
/** Chats that sent a prompt: their model is fixed (one model per chat). */
export function chatStarted(sessionId: string | null | undefined): boolean {
if (!sessionId || typeof window === "undefined") return false;
- try { return (JSON.parse(window.localStorage.getItem(STARTED_KEY) ?? "[]") as unknown[]).includes(sessionId); } catch { return false; }
+ try {
+ if ((JSON.parse(window.localStorage.getItem(STARTED_KEY) ?? "[]") as unknown[]).includes(sessionId)) return true;
+ } catch { /* the engine's messages still say */ }
+ return engineHasPrompt(sessionId);
+}
+
+/**
+ * Whether the engine's messages this app holds for a chat (its transcript or
+ * snapshot, session-sync.ts) hold a prompt: a chat started before chats were
+ * marked here, or on another install, is started too.
+ */
+function engineHasPrompt(sessionId: string): boolean {
+ const cache = getReactQueryClient();
+ for (const root of ["react-session-transcript", "react-session-snapshot"]) {
+ for (const [key, data] of cache.getQueriesData<unknown>({ queryKey: [root] })) {
+ if (key[2] !== sessionId) continue;
+ const messages = Array.isArray(data) ? data : (data as { messages?: unknown } | undefined)?.messages;
+ if (!Array.isArray(messages)) continue;
+ if (messages.some((message: { role?: unknown; info?: { role?: unknown } } | null) => (message?.role ?? message?.info?.role) === "user")) return true;
+ }
+ }
+ return false;
}
export function markChatStarted(sessionId: string): void {
diff --git a/apps/app/tests/model-modes.test.ts b/apps/app/tests/model-modes.test.ts
index 72c98978..77890e3f 100644
--- a/apps/app/tests/model-modes.test.ts
+++ b/apps/app/tests/model-modes.test.ts
@@ -1,7 +1,8 @@
import { expect, test } from "bun:test";
+import { getReactQueryClient } from "../src/react-app/infra/query-client";
import { modeSwitchNote as sharedNote } from "../../server/src/model-modes/model-modes.mjs";
-import { chatModeNote, fixedModelNote, modeAllowsModel, modeFallbackModel, modeSwitchNote, newChatAllowsModel } from "../src/react-app/domains/session/surface/model-modes";
+import { chatModeNote, chatStarted, fixedModelNote, modeAllowsModel, modeFallbackModel, modeSwitchNote, newChatAllowsModel } from "../src/react-app/domains/session/surface/model-modes";
// As GET /omnirush/subagent-model lists them: `modes` normalized by the server.
const MODELS = [
@@ -38,3 +39,24 @@ test("a new chat in a sandbox project may start on a model that runs only on thi
expect(fixedModelNote(MODELS, ref("kimi-k3.1-pro"), ref("gpt-6-astra"))).toBe("This chat runs on Kimi K3.1 Pro. Start a new chat to use GPT 6 Astra.");
expect(chatModeNote(MODELS, "native", ref("boxonly-x"))).toBe("This chat runs on Box Only X, which isn't available outside the sandbox. Start a new chat.");
});
+
+test("a chat with a prompt in the engine's messages is started, marked here or not", () => {
+ const store = new Map<string, string>();
+ const host = globalThis as { window?: unknown };
+ const before = host.window;
+ host.window = { localStorage: { getItem: (k: string) => store.get(k) ?? null, setItem: (k: string, v: string) => void store.set(k, v) } };
+ try {
+ const cache = getReactQueryClient();
+ expect(chatStarted("ses_old")).toBe(false);
+ cache.setQueryData(["react-session-transcript", "ws", "ses_old"], [{ role: "user" }, { role: "assistant" }]);
+ expect(chatStarted("ses_old")).toBe(true);
+ cache.setQueryData(["react-session-snapshot", "ws", "ses_snap"], { messages: [{ info: { role: "user" } }] });
+ expect(chatStarted("ses_snap")).toBe(true);
+ cache.setQueryData(["react-session-transcript", "ws", "ses_empty"], []);
+ expect(chatStarted("ses_empty")).toBe(false);
+ store.set("omnirush.sessionModelFixed", JSON.stringify(["ses_marked"]));
+ expect(chatStarted("ses_marked")).toBe(true);
+ } finally {
+ host.window = before;
+ }
+});