Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: claude chats skip auto compaction and other chats keep their own name

ogsamratfacb4d68f67f
diff --git a/apps/server/src/capture-client.ts b/apps/server/src/capture-client.ts
index 00ecb375..d905c7e5 100644
--- a/apps/server/src/capture-client.ts
+++ b/apps/server/src/capture-client.ts
@@ -75,6 +75,8 @@ export type CaptureMode = "starting" | "worker" | "local" | "restarting" | "down
export type CaptureService = {
/** A Claude chat: its uploads name Claude Code (`version`) as the harness. */
markClaude(sessionId: string, version: string): void;
+ /** A chat pinned to another provider's model: its uploads keep the engine's identity. */
+ markNotClaude(sessionId: string): void;
/** The session uploader has an account to upload to (the sign-in gate's question). */
readonly uploadEnabled: boolean;
/** Where capture runs right now. */
@@ -240,6 +242,10 @@ class CaptureClient implements CaptureService {
this.send({ kind: "call", id: null, method: "markClaude", args: [sessionId, version] });
}
+ markNotClaude(sessionId: string): void {
+ this.send({ kind: "call", id: null, method: "markNotClaude", args: [sessionId] });
+ }
+
boxSession(sessionId: string, box: BoxCaptureInfo | null): void {
this.send({ kind: "call", id: null, method: "boxSession", args: [sessionId, box] });
}
diff --git a/apps/server/src/capture-host.ts b/apps/server/src/capture-host.ts
index 40860b4a..e0a2ad92 100644
--- a/apps/server/src/capture-host.ts
+++ b/apps/server/src/capture-host.ts
@@ -245,6 +245,11 @@ export class CaptureHost {
this.sessionUploader.markClaude(sessionId, version);
}
+ /** A chat pinned to another provider's model: a refused Claude pick never makes its uploads name Claude Code. */
+ markNotClaude(sessionId: string): void {
+ this.sessionUploader.markNotClaude(sessionId);
+ }
+
/** The app's permission mode, named in the setup record of the sessions started after it (sent before each startSession). */
permissionMode(mode: ApprovalMode | null): void {
this.sessionUploader.setPermissionMode(mode);
diff --git a/apps/server/src/capture-protocol.ts b/apps/server/src/capture-protocol.ts
index 5668abec..8bd6ea93 100644
--- a/apps/server/src/capture-protocol.ts
+++ b/apps/server/src/capture-protocol.ts
@@ -20,6 +20,7 @@ export type CaptureStopOptions = { archiveFinals: boolean };
/** CaptureHost methods callable from the main thread, with their arguments. */
export type CaptureCalls = {
markClaude: [sessionId: string, version: string];
+ markNotClaude: [sessionId: string];
startSession: [sessionId: string, workspaceId: string, root: string, turnsBefore?: number];
boxSession: [sessionId: string, box: BoxCaptureInfo | null];
sessionPolicy: [sessionId: string];
@@ -177,6 +178,8 @@ export function invokeCapture(host: CaptureHost, call: CaptureCall): unknown {
switch (call.method) {
case "markClaude":
return host.markClaude(...call.args);
+ case "markNotClaude":
+ return host.markNotClaude(...call.args);
case "startSession":
return host.startSession(...call.args);
case "boxSession":
diff --git a/apps/server/src/claude-code/chat.test.ts b/apps/server/src/claude-code/chat.test.ts
index d3650a16..5afd2ad2 100644
--- a/apps/server/src/claude-code/chat.test.ts
+++ b/apps/server/src/claude-code/chat.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
-import { CLAUDE_CODE_VERSION, CLAUDE_CONTRACT, claudeChatRoute } from "./chat.js";
+import { CLAUDE_CODE_VERSION, CLAUDE_CONTRACT, chatPinRules, claudeChatRoute } from "./chat.js";
import type { ClaudeAccess, ClaudeAuthorization, ClaudeGrant } from "./access.js";
// @ts-expect-error The shared provider is plain JavaScript (opencode-plugins/claude-provider, PARITY with the CLI).
import { CLAUDE_CODE_VERSION as PROVIDER_VERSION, CONTRACT as PROVIDER_CONTRACT } from "../opencode-plugins/claude-provider/index.js";
@@ -73,3 +73,11 @@ describe("Claude turn route", () => {
expect(await handle({ op: "grant", model: "claude-opus-5-5" })).toMatchObject({ ok: false });
});
});
+
+test("a chat pin: no automatic compaction on Claude, the engine's identity on another provider's model (CLI: beforePromptDispatch)", () => {
+ expect(chatPinRules("claude-opus-5-5")).toEqual({ autoCompact: false, identity: "engine" });
+ // An Astra chat where Claude was picked (refused, a new chat offered): compacts as before and never names Claude Code.
+ expect(chatPinRules("gpt-6-astra")).toEqual({ autoCompact: true, identity: "not-claude" });
+ // No pin yet (a new chat's first prompt): the engine's chat model decides.
+ expect(chatPinRules(null)).toEqual({ autoCompact: true, identity: "engine" });
+});
diff --git a/apps/server/src/claude-code/chat.ts b/apps/server/src/claude-code/chat.ts
index 7a3aaa48..0282d3d1 100644
--- a/apps/server/src/claude-code/chat.ts
+++ b/apps/server/src/claude-code/chat.ts
@@ -75,3 +75,18 @@ export function claudeChatRoute(deps: {
return { ok: true, token: grant.token, baseUrl: grant.baseUrl.replace(/\/+$/, ""), client: grant.client };
};
}
+
+/** Whether a model id is one of Claude's. shortcut: by its id prefix, as the gateway names them; upgrade to the account's catalog if a Claude id ever starts otherwise. */
+export function isClaudeModelId(id: string | null | undefined): boolean {
+ return typeof id === "string" && id.startsWith("claude-");
+}
+
+/**
+ * What a prompt's chat pin (the model the gateway bound the chat to, null before its first model request) means
+ * before the prompt goes on (CLI: beforePromptDispatch): a chat on Claude gets no automatic compaction (Claude Code
+ * compacts its own conversation); a chat on another provider's model keeps the engine's identity in its uploads,
+ * also after a refused Claude pick; otherwise the engine's chat model decides.
+ */
+export function chatPinRules(pinned: string | null): { autoCompact: boolean; identity: "not-claude" | "engine" } {
+ return { autoCompact: !isClaudeModelId(pinned), identity: pinned && !isClaudeModelId(pinned) ? "not-claude" : "engine" };
+}
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index ca24b65e..7bf20170 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -258,7 +258,7 @@ import { GOOD_SESSION_ID_PATTERN, readGoodSession } from "./omnirush-good-sessio
import { PROJECT_ARCHIVE_BASE_IDLE_MS, PROJECT_ARCHIVE_BASE_MAX_DEFER_MS, projectArchiveSettings } from "./project-archive.js";
import type { ArchiveApiRequestInit } from "./session-archive/upload.js";
import { runtimeStorageDir } from "./runtime-db.js";
-import { CLAUDE_AUTO_NOTE, CLAUDE_CODE_VERSION, CLAUDE_PROVIDER_ID, claudeChatRoute, type ClaudeChatInput } from "./claude-code/chat.js";
+import { CLAUDE_AUTO_NOTE, CLAUDE_CODE_VERSION, CLAUDE_PROVIDER_ID, chatPinRules, claudeChatRoute, type ClaudeChatInput } from "./claude-code/chat.js";
import { claudeConfigDirOf, uploadClaudeTurn } from "./claude-code/native.js";
import { prepareDesktopInstallLog } from "./install-log-host.js";
import pkg from "../package.json" with { type: "json" };
@@ -373,6 +373,8 @@ const voiceServicesByServer = new WeakMap<ServerConfig, OmniRushVoiceService>();
/** The broker's integrity read (rate-limited there), per server, for the checklist bar's "Good session ★". */
const sessionIntegrityByServer = new WeakMap<ServerConfig, OmniRushGatewayBroker["sessionIntegrity"]>();
const modelSwitchRefusalsByServer = new WeakMap<ServerConfig, OmniRushGatewayBroker["modelSwitchRefusal"]>();
+/** The model a chat is pinned to at the gateway (null before its first model request). */
+const chatPinsByServer = new WeakMap<ServerConfig, (sessionId: string) => string | null>();
/** Each server's Claude turn route (claude-code/chat.ts) and the key its engine's Claude provider sends. */
const claudeTurnsByServer = new WeakMap<ServerConfig, { key: string; handle: ReturnType<typeof claudeChatRoute> }>();
@@ -1426,6 +1428,7 @@ export async function startServer(config: ServerConfig): Promise<ServeResult> {
}
if (gatewayBroker.enabled) sessionIntegrityByServer.set(config, (sessionId, options) => gatewayBroker.sessionIntegrity(sessionId, options));
if (gatewayBroker.enabled) modelSwitchRefusalsByServer.set(config, (sessionId, model) => gatewayBroker.modelSwitchRefusal(sessionId, model));
+ if (gatewayBroker.enabled) chatPinsByServer.set(config, (sessionId) => gatewayBroker.chatModel(sessionId));
if (gatewayBroker.enabled) sideCallsByServer.set(config, brokerSideCall(gatewayBroker, config.omnirushEngineToken ?? ""));
if (gatewayBroker.enabled) computerUseCapabilitiesByServer.set(config, (maxAgeMs) => gatewayBroker.sessionUploadCapabilities({ strict: true, maxAgeMs }));
voiceServicesByServer.set(config, new OmniRushVoiceService(gatewayBroker, {
@@ -2398,8 +2401,11 @@ export async function proxyOpencodeV2Request(input: {
? sessionId
: null;
const engine = capture && uploadedSessionId ? engineTarget(input.connection.url, headers, target.search, "v2") : null;
+ // The model the chat is pinned to: a chat on Claude, or one on another provider where Claude was picked (CLI: beforePromptDispatch).
+ const pinRules = chatPinRules(uploadedSessionId ? chatPinsByServer.get(input.config)?.(uploadedSessionId) ?? null : null);
// Automatic compaction (session-archive/auto-compact.ts), as on the 1.x engine (auto-compact-engine.ts: the 2.x calls).
- const autoCompactor = engine && uploadedSessionId ? autoCompactorsByServer.get(input.config) : undefined;
+ // A Claude chat is left out: Claude Code compacts its own conversation.
+ const autoCompactor = engine && uploadedSessionId && pinRules.autoCompact ? autoCompactorsByServer.get(input.config) : undefined;
if (autoCompactor && engine && uploadedSessionId) {
const outcome = await autoCompactor.beforePrompt(uploadedSessionId, desktopAutoCompactEngine(engine, uploadedSessionId), body)
.catch((error: unknown): AutoCompactOutcome => ({ action: "failed", reason: error instanceof Error ? error.message : String(error) }));
@@ -2424,7 +2430,9 @@ export async function proxyOpencodeV2Request(input: {
capture.boxSession(uploadedSessionId, boxInfo);
capture.permissionMode(await capturePermissionMode(input.config));
// A Claude chat's uploads name Claude Code from its first one, also after a restart (its grant comes later). CLI: beforePromptDispatch.
- if (await engineChatProvider(engine, uploadedSessionId) === CLAUDE_PROVIDER_ID) capture.markClaude(uploadedSessionId, CLAUDE_CODE_VERSION);
+ // A chat pinned to another provider's model stays that chat (a Claude pick is refused there and a new chat offered).
+ if (pinRules.identity === "not-claude") capture.markNotClaude(uploadedSessionId);
+ else if (await engineChatProvider(engine, uploadedSessionId) === CLAUDE_PROVIDER_ID) capture.markClaude(uploadedSessionId, CLAUDE_CODE_VERSION);
capture.startSession(uploadedSessionId, input.workspace.id, input.workspace.path, turnsBefore);
// The turn before's background processes finish writing (at most 10 s after it ended), its project
// delta is taken (at most 5 s more, only when it ended a moment ago), then capture v2's session-start
diff --git a/apps/server/src/session-uploader.test.ts b/apps/server/src/session-uploader.test.ts
index 51840a72..05a3b379 100644
--- a/apps/server/src/session-uploader.test.ts
+++ b/apps/server/src/session-uploader.test.ts
@@ -2589,6 +2589,21 @@ describe("session uploader trace additions", () => {
expect(environment.engine_version).toBe("claude-code/2.1.306");
await recovered.stop();
+ // A chat pinned to another provider's model where Claude was picked (refused, a new chat offered): nothing ran
+ // on Claude, so its uploads keep the engine's identity, even with Claude as its latest model (CLI 142dec4).
+ const refused = makeUploader();
+ refused.markClaude("session-astra-picked-claude-1", "2.1.306");
+ refused.markNotClaude("session-astra-picked-claude-1");
+ refused.startSession("session-astra-picked-claude-1", "workspace-claude", root);
+ await refused.idle("session-astra-picked-claude-1");
+ refused.recordSessionModel("session-astra-picked-claude-1", { provider_id: "omnirush-claude", model_id: "claude-opus-5-5", variant: null, agent: "build" });
+ refused.flushTrace("session-astra-picked-claude-1");
+ await refused.idle("session-astra-picked-claude-1");
+ await refused.stop();
+ const refusedUploads = uploads.filter((item) => item.session_id === "session-astra-picked-claude-1");
+ expect(refusedUploads.length).toBeGreaterThan(0);
+ expect(refusedUploads.map((item) => identity(item)[0]).filter((name) => String(name).includes("claude-code"))).toEqual([]);
+
// Any other chat keeps the engine's identity.
const other = makeUploader();
other.startSession("session-astra-identity-1", "workspace-claude", root);
diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.ts
index f43836ee..075a98c6 100644
--- a/apps/server/src/session-uploader.ts
+++ b/apps/server/src/session-uploader.ts
@@ -4750,6 +4750,8 @@ export class SessionUploader {
private readonly computerUse = new Map<string, ComputerUseEnvironment>();
/** Claude chats (markClaude): their Claude Code version. */
private readonly claudeChats = new Map<string, string>();
+ /** Chats pinned to another provider (markNotClaude). */
+ private readonly notClaudeChats = new Set<string>();
private readonly boxToolchains: ToolchainCache | null;
private readonly excludedHashes: HashCache = new Map();
private spoolCounter = 0;
@@ -5280,12 +5282,20 @@ export class SessionUploader {
const computerUse = this.computerUse.get(sessionId) ?? null;
// A Claude chat: Claude Code is the harness, run in the box under this engine, whose stored events the upload holds (the CLI: the same).
// Also a reopened or recovered chat before its next prompt: the model its stored messages name (a recovered state is not among this.sessions).
- const claude = this.claudeChats.get(sessionId) ?? ((model ?? this.sessions.get(sessionId)?.model)?.provider_id === CLAUDE_PROVIDER_ID ? CLAUDE_CODE_VERSION : undefined);
+ const claude = this.notClaudeChats.has(sessionId) ? undefined : this.claudeChats.get(sessionId) ?? ((model ?? this.sessions.get(sessionId)?.model)?.provider_id === CLAUDE_PROVIDER_ID ? CLAUDE_CODE_VERSION : undefined);
const harness = claude ? { engine_version: `claude-code/${claude}`, harness: { name: "claude-code", engine: "claude-code", version: claude, build_tag: environment.harness.build_tag, host_engine: environment.engine_version, runtime: "box", engine_schema: "opencode-v2" }, engine_schema: "opencode-v2" } as unknown as Partial<UploadEnvironment> : {};
return { ...environment, ...harness, ...boxEnvironment(environment, box?.label ?? null), ...(toolchain ? { toolchain } : {}), ...(box ? { sandbox: box.label } : {}), ...(importedFrom ? { imported_from: importedFrom } : {}), ...(mcpServers ? { mcp_servers: mcpServers } : {}), ...(computerUse ? { computer_use: computerUse } : {}) };
}
/** A Claude chat (opencode-plugins/claude-provider) and its Claude Code version. */
+ /** A chat pinned to another provider's model: a Claude pick refused in it never makes its uploads name Claude Code (CLI: the same). */
+ markNotClaude(sessionId: string): void {
+ if (!sessionId) return;
+ this.claudeChats.delete(sessionId);
+ this.notClaudeChats.add(sessionId);
+ while (this.notClaudeChats.size > 512) this.notClaudeChats.delete(this.notClaudeChats.values().next().value as string);
+ }
+
markClaude(sessionId: string, version: string): void {
if (!sessionId || !version) return;
this.claudeChats.set(sessionId, version);