A desktop coding agent with free access to frontier models.
TypeScript
fix: a chat open in another place explains itself
ogsamrat8dd04f5612ed
diff --git a/apps/app/tests/claude-offer.test.tsx b/apps/app/tests/claude-offer.test.tsxindex 95bbc07b..4c97d515 100644--- a/apps/app/tests/claude-offer.test.tsx+++ b/apps/app/tests/claude-offer.test.tsx@@ -84,7 +84,7 @@ test("native Claude save sends host authority and aborts the same registered trainvokeDesktop(command: string, input: unknown) {commands.push({command, input});if (command === "__downloadClaudeArchive") return refuseExport- ? Promise.resolve({status: 409, statusText: "Conflict", headers: [], path: null, bytes: 0, body: JSON.stringify({message: "Another process is using this session or its operation owner is unknown"})})+ ? Promise.resolve({status: 409, statusText: "Conflict", headers: [], path: null, bytes: 0, body: JSON.stringify({code: "session_in_use", message: "Another process is using this session or its operation owner is unknown"})}): pending;if (command === "__cancelTransfer") { rejectDownload(new DOMException("Cancelled", "AbortError")); return Promise.resolve(true); }throw new Error(`Unexpected native operation: ${command}`);diff --git a/apps/desktop/electron/binary-transfer.test.mjs b/apps/desktop/electron/binary-transfer.test.mjsindex fe505ced..13a7f72d 100644--- a/apps/desktop/electron/binary-transfer.test.mjs+++ b/apps/desktop/electron/binary-transfer.test.mjs@@ -50,6 +50,28 @@ test("Claude archive cancellation before or during the dialog never starts a fet});});+test("Claude archive conflict preserves the safe response body without creating a destination", async () => {+ await withWorkspace(async (root, stagingDir) => {+ const body = JSON.stringify({code: "session_in_use", message: "Another process is using this session or its operation owner is unknown"});+ const result = await downloadClaudeArchive({+ url: "http://127.0.0.1:39876/workspace/project/claude/sessions/00000000-0000-4000-8000-000000000001/export",+ }, {+ localServerUrl: "http://127.0.0.1:39876", allowedUrlPrefixes: [], stagingDir,+ chooseDestination: async filename => path.join(root, filename),+ fetcher: async (_url, init) => {+ assert.equal(init.method, "POST");+ return new Response(body, {status: 409, headers: {"content-type": "application/json"}});+ },+ });+ assert.equal(result.status, 409);+ assert.equal(result.body, body);+ assert.equal(result.path, null);+ assert.equal(result.bytes, 0);+ assert.deepEqual(await readdir(root), []);+ await assert.rejects(readdir(stagingDir), {code: "ENOENT"});+ });+});+test("Claude archive abort cancels a stalled stream and removes private staging bytes", {timeout: 5000}, async () => {await withWorkspace(async (root, stagingDir) => {const controller = new AbortController();diff --git a/apps/server/src/claude-code/native-capture.test.ts b/apps/server/src/claude-code/native-capture.test.tsindex f69dc97c..d3e2b2ab 100644--- a/apps/server/src/claude-code/native-capture.test.ts+++ b/apps/server/src/claude-code/native-capture.test.ts@@ -10,6 +10,7 @@ import { ClaudeAccessError, ClaudeDeviceAccess } from "./access.js";import { CLAUDE_VERSION, MODEL } from "./sandbox-assets.js";import { SDK_INSTALL_PIN } from "./sandbox-lock.js";import { ClaudeRuntime } from "./runtime.js";+import { ApiError } from "../errors.js";test("managed Claude availability requires an enabled compatible catalog, never just relay access", async () => {const valid = {enabled: true, version: CLAUDE_VERSION, sdk: SDK_INSTALL_PIN, models: [MODEL]};@@ -595,8 +596,9 @@ test("canonical sealed archives resume native uploads, preserve ZIP bytes and keexpect(fs.readFileSync(path.join(stateDirectory, "upload-events.jsonl"), "utf8")).toContain("archive_manifest_members_mismatch");});-function savedRuntimeFixture(access?: () => Promise<{owner: string; capabilities?: string[]}>) {- const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "claude-offline-"))); roots.push(root);+function savedRuntimeFixture(access?: () => Promise<{owner: string; capabilities?: string[]}>, runtimeSubdirectory = "") {+ const temp = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "claude-offline-"))); roots.push(temp);+ const root = path.join(temp, runtimeSubdirectory); fs.mkdirSync(root, {recursive: true});const owner = "local-owner", id = "00000000-0000-4000-8000-000000000001";const hash = (bytes: string | Buffer) => createHash("sha256").update(bytes).digest("hex");const dir = path.join(root, hash(owner), id); fs.mkdirSync(path.join(dir, "images"), {recursive: true});@@ -639,12 +641,67 @@ test("offline export refuses live and unknown lock owners without clearing theirconst f = savedRuntimeFixture(async () => ({owner: "local-owner"}));for (const owner of [{pid: process.pid, nonce: "live"}, {pid: 0, nonce: "unknown"}, {pid: "bad"}, {pid: process.pid, nonce: "live", identity: {boot: "unverifiable"}}]) {const lock = JSON.stringify(owner); fs.writeFileSync(path.join(f.dir, "operation.lock"), lock);- await expect(f.runtime.export(f.id)).rejects.toThrow();+ const error = await f.runtime.export(f.id).catch(error => error);+ expect(error).toBeInstanceOf(ApiError);+ expect(error).toMatchObject({status: 409, code: "session_in_use", message: "Another process is using this session or its operation owner is unknown", details: undefined});expect(fs.readFileSync(path.join(f.dir, "operation.lock"), "utf8")).toBe(lock);expect(fs.existsSync(path.join(f.dir, `${f.id}.zip`))).toBe(false);}});+test("Claude HTTP export preserves operation-owner conflicts and masks unexpected failures", async () => {+ const {startServer} = await import("../server.js");+ const {TokenService} = await import("../tokens.js");+ const f = savedRuntimeFixture(undefined, "claude-sessions");+ const serverRoot = path.dirname(f.root), workspace = path.join(serverRoot, "workspace");+ fs.mkdirSync(workspace, {recursive: true});+ const dir = f.dir;+ const priorEnv = new Map<string, string | undefined>();+ const overrides = {+ OMNIRUSH_DATA_DIR: path.join(serverRoot, "data"), OMNIRUSH_TOKEN_STORE: path.join(serverRoot, "tokens.json"),+ OMNIRUSH_RUNTIME_DB: path.join(serverRoot, "runtime.sqlite"),+ OMNIRUSH_GATEWAY_URL: "", OMNIRUSH_ACCESS_TOKEN: "", OMNIRUSH_REFRESH_TOKEN: "",+ };+ for (const [key, value] of Object.entries(overrides)) { priorEnv.set(key, process.env[key]); process.env[key] = value; }+ let server: Awaited<ReturnType<typeof startServer>> | undefined;+ try {+ const config: import("../types.js").ServerConfig = {+ host: "127.0.0.1", port: 0, configPath: path.join(serverRoot, "server.json"),+ token: "fixture-collaborator-token", hostToken: "fixture-host-token", approval: {mode: "auto", timeoutMs: 1000}, corsOrigins: [],+ workspaces: [{id: "workspace", name: "Fixture", path: workspace, preset: "starter", workspaceType: "local"}],+ authorizedRoots: [workspace], readOnly: false, startedAt: Date.now(), tokenSource: "cli", hostTokenSource: "cli", logFormat: "pretty", logRequests: false,+ };+ const ownerToken = await new TokenService(config).create("owner");+ server = await startServer(config);+ const url = `http://127.0.0.1:${server.port}/workspace/workspace/claude/sessions/${f.id}/export`;+ const request = () => fetch(url, {method: "POST", headers: {authorization: `Bearer ${ownerToken.token}`}, signal: AbortSignal.timeout(5000)});+ const lockFile = path.join(dir, "operation.lock"), state = fs.readFileSync(path.join(dir, "session.json")), manifest = fs.readFileSync(path.join(dir, "native/manifest.json"));+ for (const owner of [{pid: process.pid, nonce: "live-private-canary"}, {pid: 0, nonce: "unknown-private-canary"}]) {+ const lock = JSON.stringify(owner); fs.writeFileSync(lockFile, lock);+ const response = await request();+ expect(response.status).toBe(409);+ expect(await response.json()).toEqual({code: "session_in_use", message: "Another process is using this session or its operation owner is unknown"});+ expect(fs.readFileSync(lockFile, "utf8")).toBe(lock);+ expect(fs.existsSync(path.join(dir, `${f.id}.zip`))).toBe(false);+ expect(fs.readFileSync(path.join(dir, "session.json"))).toEqual(state);+ expect(fs.readFileSync(path.join(dir, "native/manifest.json"))).toEqual(manifest);+ }+ fs.writeFileSync(lockFile, "{private-unexpected-error-canary");+ const unexpected = await request();+ expect(unexpected.status).toBe(500);+ expect(await unexpected.json()).toEqual({code: "internal_error", message: "Unexpected server error"});+ expect(fs.readFileSync(lockFile, "utf8")).toBe("{private-unexpected-error-canary");+ fs.unlinkSync(lockFile);+ const exported = await request();+ expect(exported.status).toBe(200);+ expect(exported.headers.get("content-type")).toBe("application/zip");+ expect(Buffer.from(await exported.arrayBuffer())).toEqual(fs.readFileSync(path.join(dir, `${f.id}.zip`)));+ } finally {+ await server?.stop();+ for (const [key, value] of priorEnv) { if (value === undefined) delete process.env[key]; else process.env[key] = value; }+ }+}, 15_000);+test("offline lookup rejects owner and session path mismatches, ambiguous IDs and symlink escapes", async () => {const f = savedRuntimeFixture(async () => ({owner: f.owner}));const state = path.join(f.dir, "session.json"), original = fs.readFileSync(state);diff --git a/apps/server/src/claude-code/runtime.ts b/apps/server/src/claude-code/runtime.tsindex b587ecf9..387ba7dd 100644--- a/apps/server/src/claude-code/runtime.ts+++ b/apps/server/src/claude-code/runtime.ts@@ -20,6 +20,7 @@ import { zipDirectory } from "./zip.js";import { REPLAY_ADAPTER } from "./replay-adapter.js";import { writeBundleManifest } from "./bundle-manifest.js";import { ClaudeAccessError, claudeResponseHeaders } from "./access.js";+import { ApiError } from "../errors.js";export type ClaudeBudgetSnapshot = {status: "known" | "unknown"; model: string; revision?: string;@@ -794,7 +795,7 @@ export class ClaudeRuntime {if (fs.existsSync(file)) {this.localPath(file, false);const bytes = fs.readFileSync(file, "utf8"), prior: unknown = JSON.parse(bytes);- if (!deadLockOwner(prior)) throw new Error("Another process is using this session or its operation owner is unknown");+ if (!deadLockOwner(prior)) throw new ApiError(409, "session_in_use", "Another process is using this session or its operation owner is unknown");fs.unlinkSync(file);}}