A desktop coding agent with free access to frontier models.
TypeScript
fix: one event form per upload schema
ogsamrat4a24452c396e
diff --git a/apps/server/src/capture-client.test.ts b/apps/server/src/capture-client.test.tsindex f39a2ab0..80604678 100644--- a/apps/server/src/capture-client.test.ts+++ b/apps/server/src/capture-client.test.ts@@ -11,6 +11,16 @@ import { startCaptureService, type CaptureService, type CaptureServiceOptions }import { FakeArchiveServer, slowPartTwo } from "./session-archive/fake-archive-server.js";import { openArchive } from "./session-archive/test-helpers.js";+/** Schema 1/2 trace uploads carry their events only in files[0] (__omnirush__/trace.json): read them back as `trace`. */+function withTraceEvents<T>(envelope: T): T {+ const record = envelope as Record<string, unknown>;+ if (record.trace !== undefined || !Array.isArray(record.files)) return envelope;+ const file = (record.files as Array<{ path?: string; content?: string }>).find((item) => item.path === "__omnirush__/trace.json");+ if (!file?.content) return envelope;+ return { ...record, trace: (JSON.parse(file.content) as { events?: unknown[] }).events ?? [] } as T;+}++/*** The capture worker: the session uploader's and the archiver's work runs off the* main event loop, a resumed session starts with the whole workspace, and@@ -76,7 +86,7 @@ function uploadSink() {compressed.push({ sessionId, bytes });return Response.json({ ok: true }, { status: 201 });},- envelopes: (): Envelope[] => compressed.map((item) => JSON.parse(zstdDecompressSync(item.bytes).toString("utf8"))),+ envelopes: (): Envelope[] => compressed.map((item) => withTraceEvents(JSON.parse(zstdDecompressSync(item.bytes).toString("utf8")))),};}@@ -654,6 +664,34 @@ describe("turns left open: worker restarts and quits", () => {expect(JSON.stringify(completed)).toContain("msg_2");}, 60_000);+ test("a recovered turn whose chat is resumed first (the app's task recovery) is marked recovered on that chat", async () => {+ const root = await tempDir("resumed-root");+ await writeFile(join(root, "app.txt"), "hello\n");+ const stateDir = await tempDir("resumed-state");+ const journal = join(stateDir, "omnirush-upload-journal");+ await mkdir(journal, { recursive: true });+ const meta = { v: 1, session_id: SESSION, workspace_id: "workspace-resumed", root, segment: 1, turn_open: true, at: new Date().toISOString() };+ await writeFile(join(journal, "left.jsonl"), `${JSON.stringify({ m: meta })}\n${JSON.stringify({ e: { at: meta.at, type: "tool.call", data: { n: 1 } } })}\n`);+ const sink = uploadSink();+ let lookups = 0;+ const capture = service({+ stateDir,+ worker: false,+ sessionUploader: { upload: sink.upload },+ // No engine yet at the first look; the chat is resumed before the next one.+ engineTarget: async () => {+ lookups += 1;+ if (lookups === 1) capture.startSession(SESSION, "workspace-resumed", root);+ return null;+ },+ });+ await until(() => lookups >= 2 || sink.envelopes().length >= 2, 20_000, "the second look");+ capture.flushTrace(SESSION);+ await capture.stop();+ const events = (sink.envelopes() as unknown as Array<{ trace?: Array<{ type: string; data?: Record<string, unknown> }> }>).flatMap((item) => item.trace ?? []);+ expect(events.some((event) => event.type === "collector.recovered" && event.data?.settled_by === "resumed_chat")).toBe(true);+ }, 40_000);+test("an app quit settles a turn still running before the chat ends", async () => {const root = await tempDir("quit-root");await writeFile(join(root, "app.txt"), "hello\n");diff --git a/apps/server/src/engine-identity.test.ts b/apps/server/src/engine-identity.test.tsindex 080ce916..65b27787 100644--- a/apps/server/src/engine-identity.test.ts+++ b/apps/server/src/engine-identity.test.ts@@ -8,6 +8,16 @@ import constants from "../../../constants.json" with { type: "json" };import { BUNDLED_ENGINE_VERSION, BUNDLED_HARNESS, engineBuildVersion, engineVersionOf, opencodeHarness } from "./engine-identity.js";import { SessionUploader, clientLaunchData } from "./session-uploader.js";+/** Schema 1/2 trace uploads carry their events only in files[0] (__omnirush__/trace.json): read them back as `trace`. */+function withTraceEvents<T>(envelope: T): T {+ const record = envelope as Record<string, unknown>;+ if (record.trace !== undefined || !Array.isArray(record.files)) return envelope;+ const file = (record.files as Array<{ path?: string; content?: string }>).find((item) => item.path === "__omnirush__/trace.json");+ if (!file?.content) return envelope;+ return { ...record, trace: (JSON.parse(file.content) as { events?: unknown[] }).events ?? [] } as T;+}++type Envelope = {snapshot_type: string;environment: Record<string, unknown>;@@ -79,7 +89,7 @@ describe("every upload names its engine", () => {const uploads: Envelope[] = [];const sessionUploader = new SessionUploader({upload: async (_sessionId, compressed) => {- uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope);+ uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope);return Response.json({ ok: true }, { status: 201 });},fallbackScanMs: 60_000,diff --git a/apps/server/src/session-upload-state.test.ts b/apps/server/src/session-upload-state.test.tsindex f7e31e71..d6632d33 100644--- a/apps/server/src/session-upload-state.test.ts+++ b/apps/server/src/session-upload-state.test.ts@@ -15,6 +15,16 @@ import {} from "./session-upload-state.js";import { SessionUploader } from "./session-uploader.js";+/** Schema 1/2 trace uploads carry their events only in files[0] (__omnirush__/trace.json): read them back as `trace`. */+function withTraceEvents<T>(envelope: T): T {+ const record = envelope as Record<string, unknown>;+ if (record.trace !== undefined || !Array.isArray(record.files)) return envelope;+ const file = (record.files as Array<{ path?: string; content?: string }>).find((item) => item.path === "__omnirush__/trace.json");+ if (!file?.content) return envelope;+ return { ...record, trace: (JSON.parse(file.content) as { events?: unknown[] }).events ?? [] } as T;+}++type Envelope = {snapshot_type: string;trigger: string;@@ -130,7 +140,7 @@ describe("session upload state migration", () => {const uploads: Envelope[] = [];const upload = async (_sessionId: string, compressed: Uint8Array) => {- uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope);+ uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope);return Response.json({ ok: true }, { status: 201 });};const second = new SessionUploader({ stateDir, upload, fallbackScanMs: 60_000, retryBaseMs: 10, retryMaxMs: 20 });diff --git a/apps/server/src/session-uploader.server.e2e.test.ts b/apps/server/src/session-uploader.server.e2e.test.tsindex 6a32c83a..55475f1d 100644--- a/apps/server/src/session-uploader.server.e2e.test.ts+++ b/apps/server/src/session-uploader.server.e2e.test.ts@@ -12,6 +12,16 @@ import { FakeArchiveServer } from "./session-archive/fake-archive-server.js";import { manifestOf, openArchive } from "./session-archive/test-helpers.js";import type { ServerConfig } from "./types.js";+/** Schema 1/2 trace uploads carry their events only in files[0] (__omnirush__/trace.json): read them back as `trace`. */+function withTraceEvents<T>(envelope: T): T {+ const record = envelope as Record<string, unknown>;+ if (record.trace !== undefined || !Array.isArray(record.files)) return envelope;+ const file = (record.files as Array<{ path?: string; content?: string }>).find((item) => item.path === "__omnirush__/trace.json");+ if (!file?.content) return envelope;+ return { ...record, trace: (JSON.parse(file.content) as { events?: unknown[] }).events ?? [] } as T;+}++/*** Server-level session uploader behaviour: every session on every provider is* captured the same way (start / trace / end, prompt and turn triggers,@@ -329,7 +339,7 @@ function startMockGateway(archive?: FakeArchiveServer) {const compressed = Buffer.from(await request.arrayBuffer());uploads.push({sessionId: request.headers.get("x-omnirush-session-id"),- envelope: JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope,+ envelope: withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope,});return Response.json({ ok: true }, { status: 201 });}diff --git a/apps/server/src/session-uploader.test.ts b/apps/server/src/session-uploader.test.tsindex 61ddf37a..5f02ce40 100644--- a/apps/server/src/session-uploader.test.ts+++ b/apps/server/src/session-uploader.test.ts@@ -45,6 +45,16 @@ import {} from "./session-uploader.js";import { SESSION_UPLOAD_BUDGET, sessionUploadTimeoutMs, type SessionUploadBudget } from "./session-upload-budget.js";+/** Schema 1/2 trace uploads carry their events only in files[0] (__omnirush__/trace.json): read them back as `trace`. */+function withTraceEvents<T>(envelope: T): T {+ const record = envelope as Record<string, unknown>;+ if (record.trace !== undefined || !Array.isArray(record.files)) return envelope;+ const file = (record.files as Array<{ path?: string; content?: string }>).find((item) => item.path === "__omnirush__/trace.json");+ if (!file?.content) return envelope;+ return { ...record, trace: (JSON.parse(file.content) as { events?: unknown[] }).events ?? [] } as T;+}++const execFileAsync = promisify(execFile);const roots: string[] = [];@@ -98,7 +108,7 @@ describe("session uploader privacy", () => {upload: async (sessionId, compressed) => {uploads.push({sessionId,- envelope: JSON.parse(zstdDecompressSync(compressed).toString("utf8")),+ envelope: withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))),});return Response.json({ ok: true }, { status: 201 });},@@ -132,7 +142,7 @@ describe("session uploader privacy", () => {const uploads: Array<Record<string, unknown>> = [];const sessionUploader = new SessionUploader({upload: async (_sessionId, compressed) => {- const envelope = JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>;+ const envelope = withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>;uploads.push(envelope);if (envelope.snapshot_type === "trace" && uploads.filter((item) => item.snapshot_type === "trace").length === 1) {traceStarted();@@ -166,7 +176,7 @@ describe("session uploader privacy", () => {const uploads: Array<Record<string, unknown>> = [];const sessionUploader = new SessionUploader({upload: async (_sessionId, compressed) => {- uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);return Response.json({ ok: true }, { status: 201 });},fallbackScanMs: 60_000,@@ -197,7 +207,7 @@ describe("session uploader privacy", () => {capabilities: async () => ({ schema_versions: [1, 2], canonical_trace: false, idempotency_key: true, integrity: true, integrity_summary: true }),stateDir,upload: async (_sessionId, compressed, _signal, request) => {- sent.push({ key: request?.idempotencyKey, envelope: JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown> });+ sent.push({ key: request?.idempotencyKey, envelope: withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown> });// An envelope the server refuses keeps its sequence: the next one never reuses its key.return sent.length === 2 ? Response.json({ detail: "bad" }, { status: 422 }) : Response.json({ ok: true }, { status: 201 });},@@ -228,7 +238,7 @@ describe("session uploader privacy", () => {capabilities: async () => ({ schema_versions: [1, 2], canonical_trace: false, idempotency_key: true, integrity: true, integrity_summary: true }),stateDir,upload: async (_sessionId, compressed) => {- envelopes.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ envelopes.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);return Response.json({ ok: true }, { status: 201 });},sessionIntegrity: async (sessionId, options) => {@@ -257,7 +267,7 @@ describe("session uploader privacy", () => {capabilities: async () => ({ schema_versions: [1, 2], canonical_trace: false, idempotency_key: true, integrity: true, integrity_summary: true }),stateDir,upload: async (_sessionId, compressed) => {- envelopes.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ envelopes.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);return Response.json({ ok: true }, { status: 201 });},sessionIntegrity: async () => {@@ -286,7 +296,7 @@ describe("session uploader privacy", () => {capabilities: async () => ({ schema_versions: [1, 2], canonical_trace: false, idempotency_key: true, integrity: true, integrity_summary: true }),stateDir,upload: async (_sessionId, compressed) => {- const envelope = JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>;+ const envelope = withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>;// The server already holds segment 1 up to sequence 5 (this device's ledger was lost).if (envelope.session_segment === 1 && Number(envelope.sequence) <= 5 && envelope.snapshot_type === "trace") {return Response.json({ detail: "idempotency_key_reused" }, { status: 409 });@@ -340,7 +350,7 @@ describe("session uploader privacy", () => {const sessionUploader = new SessionUploader({stateDir,upload: async (_sessionId, compressed) => {- envelopes.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ envelopes.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);return Response.json({ ok: true }, { status: 201 });},fallbackScanMs: 60_000,@@ -361,7 +371,7 @@ describe("session uploader privacy", () => {await writeFile(join(root, "app.txt"), "hello\n");const envelopes: Array<Record<string, unknown>> = [];const upload = async (_sessionId: string, compressed: Uint8Array) => {- envelopes.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ envelopes.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);return Response.json({ ok: true }, { status: 201 });};const crashed = new SessionUploader({ stateDir, upload, fallbackScanMs: 60_000 });@@ -427,6 +437,35 @@ describe("session uploader privacy", () => {expect(parseJournal(`${JSON.stringify({ e: { at: "t", type: "x" } })}\n`)).toBeNull();});+ test("a schema 2 trace upload carries its events in trace.json only; schema 3 in the top-level trace only", async () => {+ const root = await mkdtemp(join(tmpdir(), "omnirush-upload-forms-"));+ roots.push(root);+ for (const canonical of [false, true]) {+ const raw: Array<Record<string, unknown>> = [];+ const sessionUploader = new SessionUploader({+ upload: async (_sessionId, compressed) => {+ raw.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ return Response.json({ ok: true }, { status: 201 });+ },+ capabilities: async () => ({ schema_versions: canonical ? [1, 2, 3] : [1, 2], canonical_trace: canonical }),+ fallbackScanMs: 60_000,+ });+ sessionUploader.startSession("session-forms-1234", "workspace-forms", root);+ sessionUploader.recordTrace("session-forms-1234", "tool.call", {});+ sessionUploader.flushTrace("session-forms-1234");+ await sessionUploader.stop();+ const trace = raw.find((item) => item.snapshot_type === "trace")!;+ const files = trace.files as Array<{ path: string }>;+ if (canonical) {+ expect(Array.isArray(trace.trace)).toBe(true);+ expect(files).toEqual([]);+ } else {+ expect("trace" in trace).toBe(false);+ expect(files.map((file) => file.path)).toEqual(["__omnirush__/trace.json"]);+ }+ }+ });+test("persists session segments and message checkpoints across a resume", async () => {const root = await mkdtemp(join(tmpdir(), "omnirush-upload-resume-"));const stateDir = await mkdtemp(join(tmpdir(), "omnirush-upload-state-"));@@ -435,7 +474,7 @@ describe("session uploader privacy", () => {const makeUploader = () => new SessionUploader({stateDir,upload: async (_sessionId, compressed) => {- uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);return Response.json({ ok: true }, { status: 201 });},fallbackScanMs: 60_000,@@ -468,7 +507,7 @@ describe("session uploader privacy", () => {const uploads: Array<Record<string, unknown>> = [];const sessionUploader = new SessionUploader({upload: async (_sessionId, compressed) => {- uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);return Response.json({ ok: true }, { status: 201 });},changeDebounceMs: 10,@@ -499,7 +538,7 @@ describe("session uploader privacy", () => {const uploads: Array<Record<string, unknown>> = [];const sessionUploader = new SessionUploader({upload: async (_sessionId, compressed) => {- uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);return Response.json({ ok: true }, { status: 201 });},fallbackScanMs: 60_000,@@ -609,7 +648,7 @@ describe("session uploader privacy", () => {const types: string[] = [];// The backend refuses the start snapshot (a 400 is never spooled), so no manifest is accepted.const upload = async (_sessionId: string, compressed: Uint8Array) => {- const type = (JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as { snapshot_type: string }).snapshot_type;+ const type = (withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as { snapshot_type: string }).snapshot_type;types.push(type);return type === "start" ? Response.json({ error: "bad_request" }, { status: 400 }) : Response.json({ ok: true }, { status: 201 });};@@ -649,7 +688,7 @@ const sha256 = (text: string) => createHash("sha256").update(text).digest("hex")function makeUploads() {const uploads: Envelope[] = [];const upload = async (_sessionId: string, compressed: Uint8Array) => {- uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope);+ uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope);return Response.json({ ok: true }, { status: 201 });};return { uploads, upload };@@ -730,7 +769,7 @@ describe("session uploader envelope v2", () => {return { schema_versions: [1, 2, 3], canonical_trace: true };},upload: async (_sessionId, compressed) => {- const envelope = JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope;+ const envelope = withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope;attempts.push(envelope);if (envelope.schema_version === 3 && rejectSchema3) {rejectSchema3 = false;@@ -1024,7 +1063,7 @@ describe("session uploader durable retry", () => {stateDir,upload: async (_sessionId, compressed) => {if (!healthy) return Response.json({ error: "unavailable" }, { status: 503 });- uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope);+ uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope);return Response.json({ ok: true }, { status: 201 });},log: (level, message) => { if (level === "warn") warnings.push(message); },@@ -1101,7 +1140,7 @@ describe("session uploader durable retry", () => {const first = new SessionUploader({stateDir,upload: async (_sessionId, compressed) => {- const envelope = JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope;+ const envelope = withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope;sent.push(String(envelope.snapshot_type));// The server's disk filled up before the session ended.return envelope.snapshot_type === "end" ? Response.json({ detail: "insufficient storage" }, { status: 507 }) : Response.json({ ok: true }, { status: 201 });@@ -2972,7 +3011,7 @@ describe("session uploader gateway auth", () => {upload: async (_sessionId, compressed) => {counters.attempts += 1;const response = respond(counters.attempts);- if (response.ok) uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope);+ if (response.ok) uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope);return response;},...(refresh@@ -3116,7 +3155,7 @@ describe("session uploader snapshot cap", () => {upload: async (_sessionId, compressed) => {const buffer = zstdDecompressSync(compressed);rawBytes.push(buffer.length);- uploads.push(JSON.parse(buffer.toString("utf8")) as Envelope);+ uploads.push(withTraceEvents(JSON.parse(buffer.toString("utf8")) as Envelope));return Response.json({ ok: true }, { status: 201 });},log: (level, message) => { if (level === "warn") warnings.push(message); },@@ -3444,7 +3483,7 @@ describe("session uploader incremental snapshots", () => {stateDir,upload: async (_sessionId, compressed) => {if (status !== 201) return Response.json({ error: "rejected" }, { status });- uploads.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope);+ uploads.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope);return Response.json({ ok: true }, { status: 201 });},changeDebounceMs: 60_000,@@ -3989,7 +4028,7 @@ describe("session uploader incremental snapshots", () => {const growthMB = (peak - baseline) / (1024 * 1024);expect(growthMB).toBeLessThan(120);- const start = JSON.parse(zstdDecompressSync(compressedEnvelopes[0]!).toString("utf8")) as Envelope;+ const start = withTraceEvents(JSON.parse(zstdDecompressSync(compressedEnvelopes[0]!).toString("utf8"))) as Envelope;expect(start.snapshot_type).toBe("start");expect(start.files.reduce((sum, file) => sum + file.content.length, 0)).toBeGreaterThanOrEqual(58 * 1024 * 1024);expect(start.privacy).toMatchObject({ files_truncated: false });@@ -4103,7 +4142,7 @@ describe("integrity confirmation", () => {stateDir,capabilities: FEATURES,upload: async (_sessionId, compressed) => {- sent.push(JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Record<string, unknown>);+ sent.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);return Response.json({ ok: true }, { status: 201 });},sessionIntegrity: async () => Response.json({ integrity: "incomplete", reasons: ["sequence_gaps"], good_session: "pending", segments: [{ segment: 1, sequences: [1, 3], gaps: [2] }] }),diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.tsindex c8c30e90..dd885915 100644--- a/apps/server/src/session-uploader.ts+++ b/apps/server/src/session-uploader.ts@@ -6414,7 +6414,8 @@ export class SessionUploader {},manifest: () => [],privacy: () => privacyPolicy(),- trace: batch.events,+ // One form per schema: the server reads the top-level trace for 3, and only trace.json for 1 and 2.+ ...(version === TRACE_SCHEMA_VERSION ? { trace: batch.events } : {}),});let uploaded = await this.uploadEnvelope(state, "trace", "trace_flush", await makeBody(schemaVersion));if (uploaded === "key_reused") uploaded = await this.uploadEnvelope(state, "trace", "trace_flush", await makeBody(schemaVersion));diff --git a/apps/server/src/turn-diff.test.ts b/apps/server/src/turn-diff.test.tsindex ada88fa2..78ce128d 100644--- a/apps/server/src/turn-diff.test.ts+++ b/apps/server/src/turn-diff.test.ts@@ -8,6 +8,16 @@ import { zstdDecompressSync } from "node:zlib";import { MAX_TURN_DIFF_EVENT_BYTES, MAX_TURN_DIFF_FILE_BYTES, MAX_TURN_DIFF_MS, TurnBaseStore, TurnDiffBuilder, unifiedDiff, type TurnDiffEvent, type TurnDiffInput } from "./turn-diff.js";import { SessionUploader } from "./session-uploader.js";+/** Schema 1/2 trace uploads carry their events only in files[0] (__omnirush__/trace.json): read them back as `trace`. */+function withTraceEvents<T>(envelope: T): T {+ const record = envelope as Record<string, unknown>;+ if (record.trace !== undefined || !Array.isArray(record.files)) return envelope;+ const file = (record.files as Array<{ path?: string; content?: string }>).find((item) => item.path === "__omnirush__/trace.json");+ if (!file?.content) return envelope;+ return { ...record, trace: (JSON.parse(file.content) as { events?: unknown[] }).events ?? [] } as T;+}++type Envelope = { snapshot_type: string; trace?: Array<{ type: string; data?: unknown }> };const roots: string[] = [];@@ -62,7 +72,7 @@ function recordingUploader(options: { stateDir?: string; snapshotMaxBytes?: numbconst uploads: Envelope[] = [];const sessionUploader = new SessionUploader({upload: async (_sessionId, compressed) => {- const envelope = JSON.parse(zstdDecompressSync(compressed).toString("utf8")) as Envelope;+ const envelope = withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Envelope;uploads.push(envelope);await hold?.(envelope);return Response.json({ ok: true }, { status: 201 });