From 28761f9c2558450ffb7ec00571043207f2deb047 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:41:29 -0600 Subject: [PATCH] perf(workspaces): read a downloaded snapshot archive once, in the encrypt pass (#21683) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Remote agents work in sandboxes, and the server saves each sandbox workspace as an encrypted snapshot in object storage > - One Node main thread on the server controls every run, so per-agent byte work on that thread limits how many agents one server can hold > - The save path read every downloaded archive twice: a main-thread SHA-256 re-hash after the download, then a full read in the off-thread encrypt pass that already computes the same digest > - This pull request removes the main-thread re-hash and checks the encrypt pass's digest and size against the sandbox receipt instead > - The benefit is one full archive read per save instead of two, and no archive hashing on the main thread, with the same integrity guarantee ## Linked Issues or Issue Description Refs the 1,000-concurrent-agents plan in `doc/plans/2026-11-13-thousand-concurrent-agents.md` (Phase 1, "Workspace snapshot" row). **What existing behavior does this improve?** Saving a remote workspace snapshot after a run. **Subsystem affected** Server: remote workspace snapshot save (`remote-workspace-transport.ts`, `remote-workspace-snapshot-storage.ts`, `remote-workspaces.ts`). **Current behavior** `captureSandboxWorkspaceArchive` streams the whole downloaded archive through `createHash` on the main thread to compare it with the sandbox receipt. Then `uploadWorkspaceSnapshot` reads the whole archive again on a worker thread to encrypt it, and computes the same plaintext digest. **Proposed behavior** After the download, the server checks only the file size against the receipt. The encrypt pass compares its plaintext digest and size with the receipt. A mismatch fails with the same `remote_workspace_capture_transfer_mismatch` error before the upload attempt is recorded and before any object is stored. **Reason and benefit** One full read and one SHA-256 of each archive leave the server's main thread (about 0.36 ms of main-thread time per MB on a loaded dev machine; 37 ms for a 100 MB archive, at event-loop utilization 1.0 for that time). ## What Changed - `captureSandboxWorkspaceArchive` no longer re-hashes the downloaded archive. It checks with `lstat` that the download is a file with the receipt's byte size, and fails with `remote_workspace_capture_transfer_mismatch` when it is not. - `uploadWorkspaceSnapshot` accepts an optional `expectedArchive` (`sha256`, `byteSize`). After the encrypt pass, it compares the sealed plaintext digest and size with it. A mismatch throws `remote_workspace_capture_transfer_mismatch` before the attempt enters `metadata.uploads` and before `putFile`. The scratch ciphertext is removed as before. - `saveRemoteWorkspace` passes the sandbox receipt as `expectedArchive` when it captured an archive. - The save-level `verifyMs` timing field is removed, because that step no longer exists. The storage-level `verifyMs` stays. - `doc/run-log-events.md` says that the encrypt step is the only full read and where a mismatch fails. Callers that relied on the early hash keep their behavior: - Unchanged-snapshot reuse (`findUnchangedWorkspaceSnapshot`) compares the sandbox receipt, not the local hash. When it reuses the parent, the local copy is used only to list directories, and `readRemoteWorkspaceArchiveDirectories` verifies the manifest digest. - Reuse of an earlier upload attempt or an already uploaded snapshot does not read the archive. Those objects were verified when they were stored. - The read-only disk-full fallback builds its archive on the server, so its receipt always matches. Its behavior does not change. - The error message and the failure path do not change, so the save failure code, retry and fallback stay the same. ## Verification - Red/green: `remote-workspace-transport.test.ts` "leaves the downloaded archive's single full read to the encrypting upload" counts main-thread read streams of the downloaded archive during capture. On master it is 1 (fails). With this change it is 0 (passes). The encrypt pass is the one remaining read. - New: digest mismatch and size mismatch in `uploadWorkspaceSnapshot` reject with the transfer-mismatch error, do not call `putFile`, and leave the row `pending` with no recorded attempt. A retry with the right receipt saves. - New: an end-to-end `saveRemoteWorkspace` with a transfer that flips one byte (same size) fails with the transfer-mismatch error, stores nothing, keeps the writer and the previous snapshot, and a retry saves and restores the right content. - New: a download whose size differs from the receipt fails in capture. - `cd server && npx vitest run src/services/remote-workspace-snapshot-storage.test.ts src/services/remote-workspace-transport.test.ts src/services/remote-workspaces.integration.test.ts src/services/remote-workspace-transfer-timeout.test.ts src/services/remote-workspace-readonly-capture-budget.test.ts src/services/sandbox-disk-full-fault.test.ts` passes: 6 files, 360 tests. `src/services/remote-workspace-snapshot-reuse.test.ts` passes: 32 tests. - `npx tsc --noEmit -p server/tsconfig.json` passes. ## Risks - Low risk. A same-size corrupt download is now detected in the encrypt pass instead of right after the download. It is still detected before any attempt is recorded or any object is stored. - When the sandbox reports an unchanged workspace, a corrupt local copy no longer fails the save. The save reuses the verified parent snapshot, which matches the sandbox's content. The local copy is used only for its manifest, and the manifest digest is verified. - The save-level `saveTiming.verifyMs` field is gone. No code reads it. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with tool use (shell, file edits, test runs). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 --- doc/run-log-events.md | 2 +- .../services/remote-workspace-archive-io.ts | 1 + .../remote-workspace-snapshot-storage.test.ts | 12 +++++++ .../remote-workspace-snapshot-storage.ts | 5 ++- .../remote-workspace-transport.test.ts | 32 +++++++++++++++++ .../services/remote-workspace-transport.ts | 18 ++++------ .../remote-workspaces.integration.test.ts | 36 +++++++++++++++++-- server/src/services/remote-workspaces.ts | 3 +- 8 files changed, 92 insertions(+), 17 deletions(-) diff --git a/doc/run-log-events.md b/doc/run-log-events.md index 2da5478d001..964850fdbe0 100644 --- a/doc/run-log-events.md +++ b/doc/run-log-events.md @@ -723,7 +723,7 @@ run phases: | `workspace.snapshot.sandbox_upload` | Inside `sandbox_restore`: copy the archive into the sandbox. | | `workspace.snapshot.sandbox_extract` | Inside `sandbox_restore`: verify and unpack the archive, then publish the restored folder. | | `storage.snapshot.prior_attempts` | Check whether an earlier upload attempt already landed. | -| `storage.snapshot.encrypt` | Hash the archive, encrypt it and hash the encrypted file, in one pass on a worker thread. | +| `storage.snapshot.encrypt` | Hash the archive, encrypt it and hash the encrypted file, in one pass on a worker thread. This is the only full read of a downloaded archive: one whose digest or size differs from the sandbox's receipt fails here, before any upload is recorded. | | `storage.snapshot.digest` | Record the digest of the encrypted file. The `encrypt` pass computes it, so this step takes no time. | | `storage.snapshot.put` | Upload the encrypted archive (multipart above 16 MiB). | | `storage.snapshot.verify` | Confirm the stored object (its size when the backend checked every part, otherwise a full read-back). | diff --git a/server/src/services/remote-workspace-archive-io.ts b/server/src/services/remote-workspace-archive-io.ts index af338322d85..bc21e43be6d 100644 --- a/server/src/services/remote-workspace-archive-io.ts +++ b/server/src/services/remote-workspace-archive-io.ts @@ -1 +1,2 @@ export const WORKSPACE_ARCHIVE_IO_BUFFER_BYTES = 1024 * 1024; +export const REMOTE_WORKSPACE_CAPTURE_TRANSFER_MISMATCH = "remote_workspace_capture_transfer_mismatch"; diff --git a/server/src/services/remote-workspace-snapshot-storage.test.ts b/server/src/services/remote-workspace-snapshot-storage.test.ts index b2aa609e849..6749677c0a7 100644 --- a/server/src/services/remote-workspace-snapshot-storage.test.ts +++ b/server/src/services/remote-workspace-snapshot-storage.test.ts @@ -234,6 +234,18 @@ suite("remote workspace snapshot storage", () => { expect(reads).toBe(2); expect(put).not.toHaveBeenCalled(); }); + it.each([["digest", 0], ["size", 1]] as const)("rejects an archive whose %s differs from the sandbox receipt before recording or storing it", async (_field, extra) => { + const f = await fixture(); const put = vi.spyOn(storage, "putFile"); + const expectedArchive = { sha256: extra ? f.captured.sha256 : createHash("sha256").update("other archive").digest("hex"), + byteSize: f.captured.byteSize + extra }; + await expect(uploadWorkspaceSnapshot({ ...f.upload, expectedArchive })).rejects.toThrow("remote_workspace_capture_transfer_mismatch"); + expect(put).not.toHaveBeenCalled(); + const [row] = await db.select().from(executionWorkspaceSnapshots).where(eq(executionWorkspaceSnapshots.id, f.row.id)); + expect(row).toMatchObject({ status: "pending", objectKey: null, sha256: null }); + expect(row?.metadata?.uploads ?? []).toEqual([]); + const ref = await uploadWorkspaceSnapshot({ ...f.upload, expectedArchive: { sha256: f.captured.sha256, byteSize: f.captured.byteSize } }); + expect(ref.manifestDigest).toBe(f.captured.manifestDigest); + }); it("reconciles an upload whose reply was lost after object persistence, without the old scratch file", async () => { const f = await fixture(); const put = storage.putFile.bind(storage); let loseReply = true; storage.putFile = async input => { const result = await put(input); if (loseReply) { loseReply = false; throw new Error("lost upload reply"); } return result; }; diff --git a/server/src/services/remote-workspace-snapshot-storage.ts b/server/src/services/remote-workspace-snapshot-storage.ts index 16973bf3d69..a6abb807021 100644 --- a/server/src/services/remote-workspace-snapshot-storage.ts +++ b/server/src/services/remote-workspace-snapshot-storage.ts @@ -16,7 +16,7 @@ import { localEncryptedProvider } from "../secrets/local-encrypted-provider.js"; import type { StoredSecretVersionMaterial } from "../secrets/types.js"; import type { StorageService } from "../storage/types.js"; import { abortSnapshotAttemptUploads, notifyRemoteWorkspaceSnapshots, snapshotAttemptKeys, REMOTE_WORKSPACE_SNAPSHOT_GRACE_MS } from "./remote-workspace-snapshot-retention.js"; -import { WORKSPACE_ARCHIVE_IO_BUFFER_BYTES } from "./remote-workspace-archive-io.js"; +import { REMOTE_WORKSPACE_CAPTURE_TRANSFER_MISMATCH, WORKSPACE_ARCHIVE_IO_BUFFER_BYTES } from "./remote-workspace-archive-io.js"; const SCHEMA = "paperclip.workspace-snapshot.v1"; const KEY_SCHEMA = "paperclip.workspace-snapshot-key.v1"; @@ -199,6 +199,7 @@ type WorkspaceSnapshotUpload = { /** Receives per-step durations and storage request counts. */ timing?: WorkspaceSnapshotStorageTiming; verification?: "readback" | "upload"; + expectedArchive?: { sha256: string; byteSize: number }; }; /** Upload attempts are journaled before remote I/O. The caller owns publication. */ @@ -326,6 +327,8 @@ async function uploadVerifiedWorkspaceSnapshot(input: WorkspaceSnapshotUpload, v const after = await lstat(input.archivePath); if (!before.isFile() || before.isSymbolicLink() || sealed.plaintextBytes !== before.size || after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size || after.mtimeMs !== before.mtimeMs || after.ctimeMs !== before.ctimeMs) failure("archive_changed"); + if (input.expectedArchive && (sealed.plaintextSha256 !== input.expectedArchive.sha256 + || sealed.plaintextBytes !== input.expectedArchive.byteSize)) throw new Error(REMOTE_WORKSPACE_CAPTURE_TRANSFER_MISMATCH); const plaintext = { sha256: sealed.plaintextSha256, byteSize: sealed.plaintextBytes }; const { material } = await localEncryptedProvider.createVersion({ value: JSON.stringify({ schema: KEY_SCHEMA, ...identity, dataKey: dataKey.toString("base64"), plaintextSha256: plaintext.sha256, plaintextBytes: plaintext.byteSize }) }); diff --git a/server/src/services/remote-workspace-transport.test.ts b/server/src/services/remote-workspace-transport.test.ts index 8197db8ec2c..f49487d126e 100644 --- a/server/src/services/remote-workspace-transport.test.ts +++ b/server/src/services/remote-workspace-transport.test.ts @@ -26,6 +26,16 @@ import { createRunPreparationTiming, drainRunPreparationPhases, measureRunPhase import { restoreRemoteWorkspaceArchive } from "./remote-workspace-snapshot-archive.js"; import { readWorkspaceInventory, readonlyWorkspaceInventoryScript } from "./remote-workspace-readonly-inventory.js"; +const archiveReads = vi.hoisted(() => ({ paths: [] as string[] })); +vi.mock("node:fs", async (importOriginal) => { + const actual = await importOriginal(); + const createReadStream = ((file: Parameters[0], ...rest: unknown[]) => { + archiveReads.paths.push(String(file)); + return (actual.createReadStream as (...args: unknown[]) => ReturnType)(file, ...rest); + }) as typeof actual.createReadStream; + return { ...actual, createReadStream, default: { ...actual, createReadStream } }; +}); + const exec = promisify(execFile); describe("remote workspace transport safety with real sandbox commands", () => { @@ -243,6 +253,28 @@ describe("remote workspace transport safety with real sandbox commands", () => { } finally { await captured.cleanup(); } }); + it("leaves the downloaded archive's single full read to the encrypting upload", async () => { + await fs.writeFile(path.join(workspace, "large.bin"), randomBytes(2 * 1024 * 1024 + 11)); + archiveReads.paths.length = 0; + const captured = await captureRemoteWorkspaceArchive({ target: target().remote, remoteCwd: workspace, operationId: randomUUID() }); + try { + expect(archiveReads.paths.filter(file => file === captured.archivePath)).toEqual([]); + expect((await fs.stat(captured.archivePath)).size).toBe(captured.byteSize); + } finally { await captured.cleanup(); } + }); + + it("rejects a downloaded archive whose size differs from the sandbox receipt", async () => { + await fs.writeFile(path.join(workspace, "saved.txt"), "saved work\n"); + const remote = target().remote, syncOut = remote.runner!.syncOut!; + remote.runner!.syncOut = async (operations, options) => { + const result = await syncOut(operations, options); + for (const operation of operations) for (const file of operation.files) await fs.appendFile(file.targetPath, "x"); + return result; + }; + await expect(captureRemoteWorkspaceArchive({ target: remote, remoteCwd: workspace, operationId: randomUUID() })) + .rejects.toThrow("remote_workspace_capture_transfer_mismatch"); + }); + it("times the restore's sandbox upload and extraction as separate run-log steps", async () => { await fs.writeFile(path.join(workspace, "saved.txt"), "saved synthetic files\n"); const { remote, execute } = target(); diff --git a/server/src/services/remote-workspace-transport.ts b/server/src/services/remote-workspace-transport.ts index 79e2fac753f..8e80375eecb 100644 --- a/server/src/services/remote-workspace-transport.ts +++ b/server/src/services/remote-workspace-transport.ts @@ -1,6 +1,5 @@ -import { createHash, randomUUID } from "node:crypto"; -import { createReadStream } from "node:fs"; -import { mkdtemp, realpath, rm, stat } from "node:fs/promises"; +import { randomUUID } from "node:crypto"; +import { lstat, mkdtemp, realpath, rm, stat } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import type { AdapterExecutionTarget } from "@paperclipai/adapter-utils/execution-target"; @@ -12,7 +11,7 @@ import { measureRunPhase } from "./execution-preparation-timing.js"; import type { GitRemoteAuthProvider } from "./git-credentials.js"; import { classifyWorkspaceRestoreFailure } from "@paperclipai/adapter-utils/workspace-restore-merge"; import { MAX_SANDBOX_SYNC_TIMEOUT_MS, type SandboxSyncOperation } from "@paperclipai/adapter-utils/sandbox-managed-runtime"; -import { WORKSPACE_ARCHIVE_IO_BUFFER_BYTES } from "./remote-workspace-archive-io.js"; +import { REMOTE_WORKSPACE_CAPTURE_TRANSFER_MISMATCH } from "./remote-workspace-archive-io.js"; export type RemoteWorkspaceTarget = Extract; @@ -474,8 +473,6 @@ export type RemoteWorkspaceSavePhaseTiming = { captureMs?: number; /** Provider download of the captured archive. */ transferMs?: number; - /** Server-side re-hash of the downloaded archive. */ - verifyMs?: number; byteSize?: number; entries?: number; }; @@ -626,15 +623,12 @@ async function captureSandboxWorkspaceArchive(input: { files: [{ kind: "file", sourcePath: layout === "captured" ? path.posix.join(staged.directory, "captured", "workspace.pcws") : staged.archive, targetPath: archivePath }], }], receipt.byteSize); timing.transferMs = elapsedSince(transferStarted); - const verifyStarted = performance.now(); - const hash = createHash("sha256"); let bytes = 0; - for await (const chunk of createReadStream(archivePath, { highWaterMark: WORKSPACE_ARCHIVE_IO_BUFFER_BYTES })) { hash.update(chunk); bytes += chunk.length; } - timing.verifyMs = elapsedSince(verifyStarted); - if (hash.digest("hex") !== receipt.sha256 || bytes !== receipt.byteSize) throw new Error("remote_workspace_capture_transfer_mismatch"); + const transferred = await lstat(archivePath); + if (!transferred.isFile() || transferred.size !== receipt.byteSize) throw new Error(REMOTE_WORKSPACE_CAPTURE_TRANSFER_MISMATCH); return { ...receipt, archivePath, cleanup: () => rm(root, { recursive: true, force: true }) }; } catch (error) { await rm(root, { recursive: true, force: true }); - if (!(error instanceof Error && error.message === "remote_workspace_capture_transfer_mismatch")) noteProviderRefusal("download", error); + if (!(error instanceof Error && error.message === REMOTE_WORKSPACE_CAPTURE_TRANSFER_MISMATCH)) noteProviderRefusal("download", error); throw error; } } diff --git a/server/src/services/remote-workspaces.integration.test.ts b/server/src/services/remote-workspaces.integration.test.ts index 88cb8cf0a8c..c3d3d8f29dd 100644 --- a/server/src/services/remote-workspaces.integration.test.ts +++ b/server/src/services/remote-workspaces.integration.test.ts @@ -1262,6 +1262,38 @@ require('node:module').syncBuiltinESMExports();`); expect(operations.at(-1)).toMatchObject({ status: "succeeded" }); }, 60_000); + it("rejects a transfer that changed the archive's bytes without storing it, and saves on retry", async () => { + const reserved = await reserve({ kind: "empty" }), remote = await target("corrupted-transfer"); + const prepared = await prepareRemoteWorkspace({ db, storage, workspace: reserved, runId: ids.run, lease: await lease(), target: remote }); + await fs.writeFile(path.join(prepared.remoteRoot, "saved.txt"), "work that must be saved intact\n"); + const syncOut = remote.runner!.syncOut!; + remote.runner!.syncOut = async (operations, options) => { + const result = await syncOut(operations, options); + for (const operation of operations) for (const file of operation.files) { + const bytes = await fs.readFile(file.targetPath); bytes[bytes.length - 1] ^= 0xff; + await fs.writeFile(file.targetPath, bytes); + } + return result; + }; + const put = vi.spyOn(storage, "putFile"); + await expect(saveRemoteWorkspace({ db, storage, workspace: prepared.workspace, runId: ids.run, lease: prepared.lease, + target: remote, boundary: "final", assertOwned: async () => undefined })).rejects.toThrow("remote_workspace_capture_transfer_mismatch"); + expect(put).not.toHaveBeenCalled(); + const pending = await db.select().from(executionWorkspaceSnapshots).where(and( + eq(executionWorkspaceSnapshots.executionWorkspaceId, reserved.id), eq(executionWorkspaceSnapshots.status, "pending"))); + expect(pending.map(row => row.metadata?.uploads ?? [])).toEqual([[]]); + expect(readRemoteWorkspaceAuthority((await workspace(reserved.id)).metadata)).toMatchObject({ dirty: true, writerRunId: ids.run, + snapshotId: readRemoteWorkspaceAuthority(prepared.workspace.metadata)!.snapshotId }); + remote.runner!.syncOut = syncOut; + const saved = await saveRemoteWorkspace({ db, storage, workspace: await workspace(reserved.id), runId: ids.run, lease: prepared.lease, + target: remote, boundary: "final", assertOwned: async () => undefined }); + expect(put).toHaveBeenCalledTimes(1); + await fs.rm(remote.remoteCwd, { recursive: true, force: true }); + const restored = await createSavedWorkspaceLoader(db, storage)({ companyId: ids.company, workspaceId: reserved.id, snapshotId: saved.snapshotId }); + try { expect(await fs.readFile(path.join(restored.root, "saved.txt"), "utf8")).toBe("work that must be saved intact\n"); } + finally { await restored.cleanup(); } + }, 60_000); + it("retains the writer and previous snapshot when object storage fails", async () => { const reserved = await reserve({ kind: "empty" }), first = await target("outage-sandbox"); const prepared = await prepareRemoteWorkspace({ db, storage, workspace: reserved, runId: ids.run, lease: await lease(), target: first }); @@ -1279,7 +1311,7 @@ require('node:module').syncBuiltinESMExports();`); sql`${workspaceOperations.metadata}->>'boundary' = 'final'`))).map(save => save.metadata?.saveTiming); const duration = expect.any(Number), archive = { byteSize: expect.any(Number), entries: expect.any(Number) }; expect(await finalTiming()).toEqual([{ schema: "paperclip.remote-workspace-save-timing.v1", outcome: "failed", totalMs: duration, - captureMs: duration, transferMs: duration, verifyMs: duration, ...archive, storage: expect.objectContaining({ requests: expect.any(Object) }), + captureMs: duration, transferMs: duration, ...archive, storage: expect.objectContaining({ requests: expect.any(Object) }), at: expect.any(String) }]); const beforeSuccess = await workspace(reserved.id); const saved = await saveRemoteWorkspace({ db, storage, workspace: beforeSuccess, runId: ids.run, @@ -1291,7 +1323,7 @@ require('node:module').syncBuiltinESMExports();`); lease: prepared.lease, target: first, assertOwned: async () => undefined })).resolves.toMatchObject({ snapshotId: saved.snapshotId }); expect(await finalTiming()).toEqual([succeededTiming]); expect(await finalTiming()).toEqual([{ schema: "paperclip.remote-workspace-save-timing.v1", outcome: "succeeded", totalMs: duration, - captureMs: duration, transferMs: duration, verifyMs: duration, uploadMs: duration, publishMs: duration, ...archive, + captureMs: duration, transferMs: duration, uploadMs: duration, publishMs: duration, ...archive, storage: expect.objectContaining({ encryptMs: duration, digestMs: duration, putMs: duration, verifyMs: duration, bytes: expect.any(Number), requests: expect.any(Object) }), at: expect.any(String) }]); diff --git a/server/src/services/remote-workspaces.ts b/server/src/services/remote-workspaces.ts index 5e2ebec34a7..14b8939aada 100644 --- a/server/src/services/remote-workspaces.ts +++ b/server/src/services/remote-workspaces.ts @@ -926,7 +926,8 @@ export async function saveRemoteWorkspace(input: { archiveSha256: captured.sha256, archiveBytes: captured.byteSize, timing: storageTiming }) : null; const saved = unchanged ?? await uploadWorkspaceSnapshot({ db: input.db, storage, snapshotId: snapshot.id, companyId: input.workspace.companyId, workspaceId: input.workspace.id, archivePath: captured?.archivePath ?? "", - manifestDigest: existingUpload?.manifestDigest ?? captured!.manifestDigest, timing: storageTiming }); + manifestDigest: existingUpload?.manifestDigest ?? captured!.manifestDigest, timing: storageTiming, + ...(captured ? { expectedArchive: { sha256: captured.sha256, byteSize: captured.byteSize } } : {}) }); timing.uploadMs = Math.max(0, Math.round(performance.now() - uploadStarted)); await input.assertOwned(); const publishStarted = performance.now();