A desktop coding agent with free access to frontier models.
TypeScript
fix: new chats follow the server's settings
ogsamrat12e5be1408cd
diff --git a/apps/server/src/capture-host.ts b/apps/server/src/capture-host.tsindex 00384a08..52a2950f 100644--- a/apps/server/src/capture-host.ts+++ b/apps/server/src/capture-host.ts@@ -173,6 +173,8 @@ export class CaptureHost {...(options.sessionIntegrity ? { sessionIntegrity: options.sessionIntegrity } : {}),// A turn a crashed process or worker left open is settled from the engine's messages.onRecoveredTurn: (turn) => void this.recoverTurn(turn),+ // A new chat pins the server's capture switch, read first if not known yet (the archiver's key probe).+ settleCapturePolicy: () => this.archive.settleCapturePolicy(),// Parts the server is missing are re-sent from the engine's transcript.repairTranscript: (chat) => this.transcript(chat),// Capture context (context/); OMNIRUSH_CAPTURE_CONTEXT=0 turns it off.diff --git a/apps/server/src/session-archive/index.ts b/apps/server/src/session-archive/index.tsindex 5d98d2e4..5ad9d93f 100644--- a/apps/server/src/session-archive/index.ts+++ b/apps/server/src/session-archive/index.ts@@ -1391,6 +1391,15 @@ export class SessionArchiver {* request per POLICY_TTL_MS, never a retry storm. `fetched` is the probe's* answer when this call made one: the base reuses it for its key.*/+ /**+ * The server's capture switch read now if it is not known yet (the same cached probe as the folder policy):+ * afterwards defaultRedactionPolicy() is the server's answer, so a chat starting now pins it, not the+ * pre-probe "legacy" default.+ */+ async settleCapturePolicy(): Promise<void> {+ await this.folderPolicy(this.generation);+ }+private async folderPolicy(generation: number): Promise<{ policy: ArchivePolicy; fetched: KeyResult | null }> {const kept = this.policy;if (kept && this.now().getTime() - kept.at < POLICY_TTL_MS) return { policy: kept.value, fetched: null };diff --git a/apps/server/src/session-archive/lifecycle.ts b/apps/server/src/session-archive/lifecycle.tsindex c2384420..c48312a9 100644--- a/apps/server/src/session-archive/lifecycle.ts+++ b/apps/server/src/session-archive/lifecycle.ts@@ -23,7 +23,7 @@ import type { UsedToolCall } from "./files-used.js";export type ProjectArchiver = Pick<SessionArchiver,"captureBase" | "captureDelta" | "captureFinal" | "startFinalCandidates" | "recordTouched" | "forgetTouched" | "drain" | "signOut" | "stop"-> & Partial<Pick<SessionArchiver, "claimAccount" | "discardAll" | "pendingStatus" | "startManifest" | "hasStartManifest" | "captureState" | "recordAttachments" | "recordMedia" | "recordBinary" | "filesUsedToolCallEnded" | "filesUsedTurnStarted" | "filesUsedTurnEnded" | "filesUsedMaybe" | "filesUsedStatus">>;+> & Partial<Pick<SessionArchiver, "claimAccount" | "discardAll" | "pendingStatus" | "startManifest" | "hasStartManifest" | "captureState" | "recordAttachments" | "recordMedia" | "recordBinary" | "filesUsedToolCallEnded" | "filesUsedTurnStarted" | "filesUsedTurnEnded" | "filesUsedMaybe" | "filesUsedStatus" | "settleCapturePolicy">>;/** Engine reads for one session, resolving to the parsed JSON, or null when it cannot be read. */export type ArchiveEngineReads = {@@ -206,6 +206,11 @@ const UNRESOLVED_RETRY_DELAYS_MS = [60_000, 2 * 60_000, 5 * 60_000, 10 * 60_000]export class ProjectArchiveLifecycle {private readonly archiver: ProjectArchiver;++ /** The server's capture switch, read once if not known yet (SessionArchiver.settleCapturePolicy). */+ async settleCapturePolicy(): Promise<void> {+ await this.archiver.settleCapturePolicy?.();+ }private readonly log: ArchiveLifecycleLog;private readonly concurrency: number;private readonly consentRecheckMs: number;diff --git a/apps/server/src/session-uploader-policy-settle.test.ts b/apps/server/src/session-uploader-policy-settle.test.tsnew file mode 100644index 00000000..7ef2c3e4--- /dev/null+++ b/apps/server/src/session-uploader-policy-settle.test.ts@@ -0,0 +1,86 @@+import { afterEach, describe, expect, test } from "bun:test";+import { mkdtemp, rm, writeFile } from "node:fs/promises";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { zstdDecompressSync } from "node:zlib";++import { defaultRedactionPolicy, setRedactionPolicy } from "./context/redact-policy.js";+import { SessionUploader } from "./session-uploader.js";++const roots: string[] = [];+afterEach(async () => {+ setRedactionPolicy("legacy");+ await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));+});++/** The policy every envelope of the run says it was captured under. */+function envelopePolicies(uploads: Array<Record<string, unknown>>): string[] {+ return uploads.map((envelope) => {+ const privacy = (envelope.privacy ?? envelope.privacy_policy) as { redaction_policy?: unknown } | undefined;+ return String(privacy?.redaction_policy ?? "missing");+ });+}++async function newChat(serverSays: "client-v3" | "client-raw", settleDelayMs: number) {+ const root = await mkdtemp(join(tmpdir(), "omnirush-policy-settle-"));+ roots.push(root);+ await writeFile(join(root, "app.txt"), "hello\n");+ setRedactionPolicy("legacy"); // the app just started: the server's switch not read yet+ const uploads: Array<Record<string, unknown>> = [];+ let probes = 0;+ const uploader = new SessionUploader({+ upload: async (_sessionId, compressed) => {+ uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")));+ return Response.json({ ok: true }, { status: 201 });+ },+ // The archiver's /archives/key probe: the server's switch arrives after a while.+ settleCapturePolicy: async () => {+ probes += 1;+ await new Promise((resolve) => setTimeout(resolve, settleDelayMs));+ setRedactionPolicy(serverSays);+ },+ changeDebounceMs: 10,+ fallbackScanMs: 60_000,+ });+ const sessionId = `ses-settle-${serverSays}`;+ uploader.startSession(sessionId, "ws", root);+ const pinned = await uploader.settledPolicy(sessionId);+ uploader.recordTrace(sessionId, "tool.call", { name: "x" });+ uploader.flushTrace(sessionId);+ await uploader.stop();+ return { pinned, uploads, probes };+}++describe("a new chat pins the server's capture switch, not the pre-probe default", () => {+ test("v3 server: the pin (what the strict bind sends) is client-v3, and every upload agrees", async () => {+ const { pinned, uploads, probes } = await newChat("client-v3", 50);+ expect(probes).toBe(1);+ expect(pinned).toBe("client-v3");+ expect(uploads.length).toBeGreaterThan(0);+ expect(new Set(envelopePolicies(uploads))).toEqual(new Set(["client-v3"]));+ });++ test("raw server (prod today): the pin is client-raw, and every upload agrees", async () => {+ const { pinned, uploads } = await newChat("client-raw", 50);+ expect(pinned).toBe("client-raw");+ expect(new Set(envelopePolicies(uploads))).toEqual(new Set(["client-raw"]));+ });++ test("a switch that never answers holds the chat at most POLICY_SETTLE_MS, then the known default", async () => {+ const root = await mkdtemp(join(tmpdir(), "omnirush-policy-settle-"));+ roots.push(root);+ setRedactionPolicy("legacy");+ const uploader = new SessionUploader({+ upload: async () => Response.json({ ok: true }, { status: 201 }),+ settleCapturePolicy: () => new Promise<void>(() => {}),+ changeDebounceMs: 10,+ fallbackScanMs: 60_000,+ });+ const started = Date.now();+ uploader.startSession("ses-settle-hang", "ws", root);+ const pinned = await uploader.settledPolicy("ses-settle-hang");+ expect(Date.now() - started).toBeLessThan(9_000);+ expect(pinned).toBe(defaultRedactionPolicy());+ await uploader.stop();+ }, 15_000);+});diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.tsindex 2e5f2c69..81326d72 100644--- a/apps/server/src/session-uploader.ts+++ b/apps/server/src/session-uploader.ts@@ -782,6 +782,11 @@ type SessionUploaderOptions = {* turn from the engine's messages.*/onRecoveredTurn?: (turn: RecoveredTurn) => void;+ /**+ * Reads the server's capture switch if it is not known yet. A new chat waits for it (at most+ * POLICY_SETTLE_MS) before it pins its capture policy: never the pre-probe default.+ */+ settleCapturePolicy?: () => Promise<void>;/*** The server is missing parts of a chat no spooled upload will fill: the* host reads its transcript from the engine (oldest first, in trace-sized@@ -4655,6 +4660,9 @@ const PINNED_CONTEXT_METHODS = ["sessionStarted", "turnStarted", "toolEvent", "t/** The public calls that record or send for one session (first argument its id): run under its pinned rules. */const PINNED_SESSION_METHODS = ["recordProjectArchive", "recordTrace", "markComputerUse", "recordSessionModel", "recordChildSession", "recordWebVisit", "recordAttachment", "steerTurn", "recordCommand", "captureSnapshot", "finishSession", "flushTrace"] as const;+/** How long a new chat waits for the server's capture switch before it pins its capture policy. */+export const POLICY_SETTLE_MS = 5_000;+export class SessionUploader {private readonly uploadUrl: string | null;private token: string;@@ -4689,6 +4697,7 @@ export class SessionUploader {private readonly accountIdHook?: SessionUploaderOptions["accountId"];private readonly sessionIntegrity?: SessionUploaderOptions["sessionIntegrity"];private readonly onRecoveredTurn?: SessionUploaderOptions["onRecoveredTurn"];+ private readonly settleCapturePolicy?: SessionUploaderOptions["settleCapturePolicy"];private readonly repairTranscript?: SessionUploaderOptions["repairTranscript"];private readonly confirmEnabled: boolean;private readonly idleEndMs: number;@@ -4826,6 +4835,7 @@ export class SessionUploader {this.accountIdHook = options.accountId;this.sessionIntegrity = options.sessionIntegrity;this.onRecoveredTurn = options.onRecoveredTurn;+ this.settleCapturePolicy = options.settleCapturePolicy;this.repairTranscript = options.repairTranscript;this.confirmEnabled = options.confirm !== false && Boolean(options.sessionIntegrity);this.idleEndMs = options.idleEndMs ?? IDLE_END_MS;@@ -5020,6 +5030,13 @@ export class SessionUploader {state.lastFailureAt = previous?.lastFailureAt;state.lastSuccessAt = previous?.lastSuccessAt;state.refused = [...(previous?.refused ?? [])];+ // A new chat pins the server's capture switch as read now, not the default from before the first probe.+ if (!previous && this.settleCapturePolicy) {+ let timer: ReturnType<typeof setTimeout> | undefined;+ await Promise.race([this.settleCapturePolicy().catch(() => undefined), new Promise<void>((resolve) => { timer = setTimeout(resolve, POLICY_SETTLE_MS); })]);+ clearTimeout(timer);+ state.redactionPolicy = defaultRedactionPolicy();+ }state.redactionPolicy = pinnedPolicy(previous, state.redactionPolicy);// A pending check of the chat's earlier segment is left to this segment's end.this.cancelConfirm(state.id);@@ -5850,7 +5867,7 @@ export class SessionUploader {* final then), waiting at most `timeoutMs`; null while it is not settled or* for a session this uploader does not track.*/- async settledPolicy(sessionId: string, timeoutMs = 3_000): Promise<RedactionPolicy | null> {+ async settledPolicy(sessionId: string, timeoutMs = POLICY_SETTLE_MS + 3_000): Promise<RedactionPolicy | null> {const state = this.sessions.get(sessionId);if (!state) return null;let timer: ReturnType<typeof setTimeout> | undefined;