Skip to content

feat(sdk): skip unchanged syncCode uploads by digest - #666

Merged
miyaontherelay merged 4 commits into
mainfrom
ms/native-c-content-addressed-sync-code
Oct 16, 2026
Merged

miyaontherelay merged 4 commits into
mainfrom
ms/native-c-content-addressed-sync-code

Conversation

@miyaontherelay

@miyaontherelay miyaontherelay commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Change

Pack the working tree once, hash the deterministic gzip archive, and send codeSha256 to Cloud prepare. On a verified cache hit, submit the prepared run without an archive PUT. On a miss, upload through the existing run-scoped Cloud API credential. A server without the cache receipt keeps the legacy upload path.

The 256 MiB uncompressed cap, Git exclusions, symlink rules, and sandbox extraction path are unchanged. Archives above 64 MiB compressed take the legacy upload path, so the cache never asks Cloud to buffer a larger archive. A cache hit receives a 300-second default budget for run submission, where Cloud now performs the R2 copy after admission; an explicit caller timeout remains honored. Prepare keeps the normal 30-second budget. The response digest and digest-coded key must match the local archive before the client trusts a hit.

Dependency: cloud#5216 merged on 2026-10-16. Verify that its Cloud contract is deployed before publishing the SDK. No package publish is included.

Rebase onto main (7f57c0b)

Rebased cleanly after #669 and #670 merged. The separate missing-copy recovery follow-up remains on its own local branch and is not included here.

$ TMPDIR=/tmp node node_modules/vitest/vitest.mjs run tests/cloud-sync.test.ts
 Test Files  1 passed (1)
      Tests  45 passed (45)
$ npm run typecheck
> tsc --noEmit && tsc -p tsconfig.type-tests.json
exit 0
$ npm run typecheck:tests
> tsc -p tsconfig.tests.json
exit 0
$ npm run build
> tsc && node scripts/make-cli-executable.mjs
exit 0
$ git diff --check origin/main...HEAD
exit 0

Without TMPDIR=/tmp, 44/45 passed; the authored-flow fixture under /Volumes/Paris Drive/... failed because its space was encoded as %20 in a loader URL. This failure is independent of the changed files and passes with a space-free temp path.

Security and retention

The digest is a content identifier, not an authorization credential. Cloud derives its cache namespace from authenticated workspace and user IDs, verifies the uploaded bytes against the digest, and copies a hit into the run prefix only after admission. The SDK never accepts an inconsistent hit receipt and never receives direct R2 credentials. Cloud's run-prefix copy preserves workspace retention; the shared upload cache has a short lifecycle.

For a 54 MiB transmitted archive, an unchanged run saves 54 MiB of client upload and its full HTTP PUT. At 10–50 MiB/s uplink that removes roughly 1.1–5.4 seconds of transfer time before request overhead; local tar/gzip and the server-side R2 copy still run, so the net latency gain needs measurement after deploy. The research report does not establish whether the observed 54 MiB is compressed or uncompressed.

Verification

  • npm ci in packages/sdk: succeeded (194 packages; no node_modules symlink).
  • TMPDIR=/tmp node ./node_modules/vitest/vitest.mjs run tests/cloud-sync.test.ts --minWorkers=1 --maxWorkers=1 --testTimeout=20000: 45/45 passed.
  • node ./node_modules/typescript/bin/tsc --noEmit && node ./node_modules/typescript/bin/tsc -p tsconfig.type-tests.json --noEmit: passed.
  • npm run build: passed.
  • npm run typecheck:tests: passed.
  • git diff --check: passed.
  • Mutations: replacing the cache-hit guard with an unconditional upload makes the unchanged-tree test fail (1/1); using raw file permission bits makes the deterministic digest test fail (1/1); reversing the 64 MiB decision makes the size-cutoff test fail (1/1); removing the run-submit copy budget makes the cache-hit deadline test fail (1/1). All mutations were restored.
  • The archive sorts entries, normalizes tar metadata and executable modes, uses fixed gzip compression, and writes gzip OS=255; packing the same tree twice yields the same digest.
  • The repository's npm test prep could not run here because rustc is unavailable; the focused SDK suite above ran directly with an isolated /tmp test home.

Agent Relay sessions

  • codex session 01a13937 · opened via gh pr create · last active 2026-10-16

Note

Medium Risk
Changes the cloud run admission path and depends on the new prepare/cache contract; incorrect hit validation or timeout behavior could block or delay runs, though legacy upload remains for large archives and cache misses.

Overview
Adds content-addressed code sync for hosted syncCode runs: the SDK packs the working tree, computes a SHA-256 of the deterministic gzip tarball (when the archive is ≤ 64 MiB compressed), and sends codeSha256 on /api/v1/workflows/prepare.

On a verified cache hit (matching codeCache receipt and code-sha256-<digest>.tar.gz key), it skips the archive PUT and submits the run with a default 300s submit timeout so Cloud can copy from R2 after admission. On a miss—or when the archive is too large—it keeps the legacy upload path.

Packing now normalizes the gzip OS byte to 255 so identical trees produce stable bytes and digests despite platform/mtime noise (executable bits still affect the digest). Prepare responses with inconsistent cache metadata are rejected before any upload.

Reviewed by Cursor Bugbot for commit 7f57c0b. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b16dd355-2af4-4552-9d2f-30fc3cca394e
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@miyaontherelay
miyaontherelay force-pushed the ms/native-c-content-addressed-sync-code branch from 2a81cba to 7f57c0b Compare October 16, 2026 08:22
@miyaontherelay
miyaontherelay marked this pull request as ready for review October 16, 2026 08:33

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found 1 potential issue (1 medium).

Open in Capy

Comment thread packages/sdk/src/cloud-run.ts Resolved
@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found in the changed code.

Summary

The SDK hashes the packed archive and skips the upload when Cloud returns a matching cache hit.

  • Unchanged code trees can skip their archive upload.
  • The same working tree now produces a stable cache digest.

miyaontherelay explicitly deferred missing-copy recovery to a separate follow-up branch.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Pack working tree] --> B{Compressed size at most 64 MiB?}
  B -->|Yes| C[Hash archive]
  B -->|No| D[Prepare without digest]
  C --> E[Prepare with digest]
  E --> F{Receipt consistent?}
  F -->|No| G[Reject response]
  F -->|Yes| H{Cache hit?}
  D --> I[Upload archive]
  H -->|No| I
  H -->|Yes| J[Submit with 300-second default]
  I --> K[Submit with normal budget]
Loading

Reviews (1) · Last reviewed commit: "fix(sdk): allow cache copy during run su..." · Reviewed by Greptile

@miyaontherelay
miyaontherelay merged commit f47cb2b into main Oct 16, 2026
11 checks passed
@miyaontherelay
miyaontherelay deleted the ms/native-c-content-addressed-sync-code branch October 16, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant