Skip to content

feat(canister): upload_assets writes several files in one call - #149

Merged
lwshang merged 3 commits into
mainfrom
feat/upload-assets
Nov 18, 2026
Merged

lwshang merged 3 commits into
mainfrom
feat/upload-assets

Conversation

@raymondk

Copy link
Copy Markdown
Contributor

Adds upload_assets: (vec UploadAssetArguments) -> (blob), the batch form of upload_asset.

Behaviour

  • All or nothing. Every asset is validated before the sync lock is taken or a byte is staged, and the accepted ones are written by a single final execute_operations call. One bad entry rejects the whole call.
  • Same rules as upload_asset, per asset. Key must start with /, an error page must fit in one chunk, refused in by-proposal mode and while a sync is in progress, stored as the identity encoding only.
  • A key listed twice is rejected, since two writes to one key in one call have no meaningful order.
  • An empty vector is accepted and writes nothing; like any finalized sync it returns the state hash.
  • The assets must fit in one ingress message (~2 MB) together.

upload_asset now reuses it

  • canister_core::upload_asset(arg) is upload_assets(vec![arg]).
  • State::begin_upload_asset is replaced by State::begin_upload_assets; the per-asset chunking and operation building moved into a private stage_uploaded_asset.
  • The by-proposal rejection message no longer names a method ("uploading assets directly is disabled in by-proposal mode…"), since both endpoints share it.

Compatibility

Additive: one new candid method, no changed signature, no stable-state change.

Tests

  • canister-core: batch lands in one step, batch equals the same assets uploaded one by one (same hash and details), one invalid entry rejects the batch, duplicate key rejected, empty batch is a no-op. Existing upload_asset tests now run through the shared path.
  • e2e (preserve.rs): runs the new upload_assets snippet extracted from docs/site-files.md.

Not run locally: canbench (not installed here), so the benchmark job in CI is the first check of that.

🤖 Generated with Claude Code

Adds `upload_assets: (vec UploadAssetArguments) -> (blob)`, the batch form
of `upload_asset`. All assets are validated up front and written in a single
final `execute_operations` call, so a batch lands whole or not at all.

`upload_asset` is now `upload_assets` with one entry: the endpoint forwards
to it and `State::begin_upload_asset` is replaced by `begin_upload_assets`.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@raymondk
raymondk requested a review from a team as a code owner November 17, 2026 19:15
Copilot AI balanced review requested due to automatic review settings November 17, 2026 19:15
@raymondk raymondk mentioned this pull request Nov 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The operation driver can yield between live-store mutations, exposing partial batches and preventing rollback after a later trap; atomic publication or a bounded non-yielding mutation phase is needed, with a regression test crossing the yield boundary.

1 open issue
What changed in this PR

Adds upload_assets for uploading multiple files outside a deploy, reusing the existing sync machinery and preserving the single-file endpoint’s interface.

Changes:

  • Exposes the batch endpoint and routes upload_asset through it.
  • Validates all entries before staging, including duplicate-key rejection.
  • Adds batch tests and a documented example exercised by end-to-end tests.
File Description
docs/​site-files.md Documents batch uploads, limits, and an example call.
crates/​wire-types/​src/​lib.rs Clarifies that upload arguments also represent batch entries.
crates/​e2e/​tests/​preserve.rs Exercises the documented batch call and checks served content.
crates/​canister/​src/​lib.rs Exposes the guarded upload_assets endpoint.
crates/​canister-core/​src/​state/​tests.rs Tests batch results, validation, duplicates, and empty input.
crates/​canister-core/​src/​state/​sync.rs Adds batch validation and shared per-asset staging.
crates/​canister-core/​src/​lib.rs Adds batch orchestration and delegates single-file uploads.
certified-assets.did Declares the additive batch method.
.claude/​rules/​testing.md Updates guidance to mention both documented upload calls.

Review effort: Balanced

Comment thread crates/canister-core/src/lib.rs Resolved
The shared `execute_operations` driver yields to a self-call between
operations once the instruction budget runs low, which commits whatever was
applied so far. A large `upload_assets` batch could therefore be visible
half-written, and a later failure could not roll the first half back.

An upload now applies all of its operations in the message that opened it,
and only the state-hash recompute is handed to the yielding driver. A batch
that fails, or is too large for one message, traps and rolls back whole.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 21:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the batch-upload change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Merges the two batch tests, drops the relative-key and one-by-one tests the
batch tests subsume, shares `body_of` and the canister-shaped upload helper
across test modules, and runs the documented `upload_assets` call inside the
existing preserve e2e test rather than booting a second replica for it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 22:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the additive batch-upload change.

No open issues 🎉

Review effort: Balanced

@raymondk
raymondk added this pull request to stack #151 November 18, 2026 00:00
@lwshang
lwshang merged commit b63c9af into main Nov 18, 2026
8 checks passed
@lwshang
lwshang deleted the feat/upload-assets branch November 18, 2026 06:21
lwshang pushed a commit that referenced this pull request Nov 18, 2026
Stacked on #149. Prepares the `1.0.0` release of the certified-assets
canister and its sync plugin.

## What 1.0.0 changes

The version rule in `wire-types/src/version.rs` already covers it, no
code change needed:

- **From now on a major bump is the breaking one.** Minor and patch
releases (`1.0.0 → 1.1.0`, `1.0.0 → 1.0.1`) must both upgrade in place
and recover stable state. Before this, a minor bump was the escape hatch
for state-shape changes; after it, only `2.0.0` is.
- **`0.4.x → 1.0.0` is itself a series switch.** A `1.0.0` plugin that
meets a `0.4.x` canister tells the user to reinstall, which wipes state
not re-derived from the project (access-protection tokens, files kept by
`_preserve`).

Worth deciding before tagging: the only change since `v0.4.3` is #149,
which is additive and touches no stable state, so nothing in this
release actually needs the reinstall. It is the version number alone
that makes the plugin ask for one. If there are stable-state shapes or
legacy fields you want gone, this is the last release where dropping
them is free.

## Changes

- `Cargo.toml` / `Cargo.lock`: workspace version `0.4.3` → `1.0.0`
- `docs/overview.md`: the example recipe version
- `README.md` (Releasing), `.claude/rules/project-stage.md`,
`docs/governance.md`, a `wire-types` doc comment: the
breaking-vs-non-breaking rule restated for `1.x` (they described the
`0.x` rule)

## After merge

1. `make tag && git push origin v1.0.0`: triggers the release workflow
2. `scripts/publish-recipe.sh v1.0.0 --push`: refreshes the
`icp-cli-recipes` PR with the release's own `recipe.hbs`
3. After that merges, tag `static-site-v1.0.0` in `icp-cli-recipes`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5.2 <[email protected]>
lwshang added a commit to dfinity/icp-cli-recipes that referenced this pull request Nov 18, 2026
Publishes the `static-site` recipe at v1.0.0, pinning the canister and
sync-plugin wasm from dfinity/certified-assets's v1.0.0 release.

## Draft: do not merge yet

The v1.0.0 release of certified-assets does not exist yet. It is
prepared by dfinity/certified-assets#149 and
dfinity/certified-assets#150, and is cut by tagging `v1.0.0` once they
merge.

Until then:

- The two release URLs in `recipe.hbs` return 404.
- The two `sha256` values come from a local `make recipe-release` on the
#150 branch, not from the release CI. They are placeholders: the
released wasm may hash differently.

## Before marking ready

Replace `recipes/static-site/recipe.hbs` with the asset attached to the
release, verbatim, and confirm the two match:

https://github.com/dfinity/certified-assets/releases/download/v1.0.0/recipe.hbs

After merge, tag `static-site-v1.0.0` in this repo to cut the recipe
release.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <[email protected]>
Co-authored-by: Linwei Shang <[email protected]>
lwshang added a commit that referenced this pull request Nov 18, 2026
The deleted v1.0.0 release treated 0.4.x → 1.0.0 as a breaking
(reinstall) switch. But 1.0.0 is 0.4.3 plus `upload_assets` (#149);
stable state (`canister-core/src/store/`) hasn't changed since 0.4.3. So
a reinstall would wipe protection tokens, `authorize`d principals and
preserved files for no reason.

- `Version::series()` maps `0.4` to series `(1, 0)`, so
`upgrade_compatible_with` treats 0.4.x ↔ 1.x as an in-place upgrade. The
plugin's mismatch hint now says to upgrade. `0.3.x` and earlier stay
separate series.
- Updated the docs that said 0.4.x → 1.0.0 is breaking: README,
`project-stage.md` (1.x must also recover 0.4.x state), `governance.md`,
`.did` comments, and an e2e doc comment.

Verified by hand on a local network: deployed the published v0.4.3
recipe wasms, `authorize`d a principal, then ran `icp deploy` with this
branch's build. Result: `version` = 1.0.0, the principal is still
listed, sync reported "3 asset(s) already up to date" (nothing
re-uploaded), and the site serves.

After merge: re-tag `v1.0.0` on the merge commit and republish the
recipe.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

3 participants