Skip to content

Deploy tools 1/6: a bundle host in imcp2-core - #254

Closed
raymondk wants to merge 3 commits into
mainfrom
deploy-core-1-bundle-host
Closed

raymondk wants to merge 3 commits into
mainfrom
deploy-core-1-bundle-host

Conversation

@raymondk

Copy link
Copy Markdown
Contributor

First of six PRs that add deploying an icp project bundle to the MCP servers. Together they replace #230, #246, #231, #247, #232, #243, #249, #250, #251, #252 and #253: the same code, each piece once and in its final form, living in imcp2-core instead of a separate imcp2-deploy crate.

What this PR adds

imcp2_core::deploy::host: takes a bundle archive and turns it into something the icp CLI's project library can deploy from, treating the bundle as untrusted input. Nothing calls it yet.

  • Extraction. Reads the archive as a stream and writes only regular files and directories, confined to one directory. Two sizes are enforced as it reads: the archive's, and the space the entries occupy (whole 4 KiB blocks plus 1 KiB per entry, which is what a bundle costs a server that keeps it on a RAM filesystem). The server sets the limits (BundleLimits).
  • Loading the project. Uses the library's own untrusted rule: no script steps, no remote sources, no recipes, no paths through links. What the load retains is metered.
  • Checks before a deploy (check_bundle). Every module matches its recorded checksum; Candid text is within what the parser can take; the per-canister module copies the deploy will make are counted against the limit; every sync plugin is one the server runs (AllowedPlugins).

The dependency cost lands here

There is no cargo feature: the deploy tools are part of every build of imcp2-core. This PR adds icp-project and its sibling crates, and through icp-sync-plugin the wasmtime runtime. imcp2-core goes from about 360 to about 515 crates in its dependency tree. I have not measured the effect on build time or binary size.

The candid floor moves to 0.10.39 for the subtype check a deploy's upgrade compatibility check runs.

Why one crate

Both servers use this code, so it has to live somewhere both depend on. A separate published crate meant a fourth version to keep in lockstep, a manual first publish, and a second build configuration to test. Folding it into imcp2-core removes all three.

Stack

  1. Bundle host (this PR)
  2. Upload store
  3. Deploy pipeline
  4. MCP tools and the local server
  5. Remote server
  6. Metrics

Until the tools land in PR 4, the module's items are pub so the intermediate PRs build without dead-code warnings.

Testing

Each PR in the stack passes cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace --all-targets on its own. The tree at the top of the stack is identical, file for file, to the old chain's final state with the crate folded in.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV

…sted project, and the checks before a deploy

The first step of deploying an icp project bundle from the MCP servers:
`imcp2_core::deploy::host`, which takes a bundle archive and makes of it
something the icp CLI's project library can deploy from, treating the
bundle as untrusted input. Nothing calls it yet.

- **Extraction** reads the archive as a stream and writes regular files and
  directories only, confined to its directory, refusing the `.icp` state a
  deploy seeds for itself. Both sizes are held as it reads: the archive's,
  and what the entries occupy (whole 4 KiB blocks and 1 KiB an entry, which
  is what a bundle costs a server that keeps it in memory). How large is
  the server's to say (`BundleLimits`).
- **The project** is loaded through the library's own untrusted rule
  (`icp_project::untrusted`): no script step, no remote source, no recipe,
  no path through a link; what the load retains is metered.
- **The checks before a deploy** (`check_bundle`): every canister built by
  one pre-built module that hashes to its recorded checksum, the Candid a
  bundle carries held to what the parser takes, the copy of each
  canister's module the deploy will keep counted against the limit, and
  every sync plugin one the server runs (`AllowedPlugins`: any, on the
  user's own machine; the releases a server knows, by the hash of their
  module, where it deploys for others).

This is where the dependency cost lands: `icp-project` and its siblings,
and with `icp-sync-plugin` the wasmtime runtime, in every build of
imcp2-core. The `candid` floor moves to 0.10.39 for the subtype check a
deploy's upgrade compatibility check runs.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV

Copilot AI 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.

🟡 Changes recommended

Unaccounted build scratch space and extraction path memory can exceed resource budgets, while Windows path aliases can bypass protection of .icp state.

5 open issues
What changed in this PR

Adds the shared bundle-host foundation for future deployment tools in imcp2-core, for use by both servers. This first stack step handles untrusted bundles; nothing calls it yet.

Changes:

  • Adds streaming extraction with configurable limits and confined, metered project loading.
  • Adds mainnet-only preflight checks for checksums, Candid safety, module-copy space, and allowed sync plugins.
  • Integrates the icp CLI dependencies and raises the Candid floor to 0.10.39 with a subtype regression test.
File Description
crates/​imcp2-core/​src/​lib.rs Exposes the deploy module and Candid text guard.
crates/​imcp2-core/​src/​deploy/​mod.rs Documents the staged deployment module and exports the host.
crates/​imcp2-core/​src/​deploy/​host.rs Implements extraction, host adapters, preflight checks, plugin policy, and tests.
crates/​imcp2-core/​src/​calls.rs Makes the guard public and adds the subtype regression test.
crates/​imcp2-core/​Cargo.toml Adds deployment dependencies, runtime features, and test support.
Cargo.toml Raises the workspace Candid version floor.
Cargo.lock Records the new deployment dependency tree and version updates.

Review effort: Max

Comment on lines +922 to +923
directory = directory.saturating_add(occupies(module));
if directory > directory_bytes {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's correct ... despite nothing actually getting built, the file moves twice. If many canisters reference the same wasm the cli will keep an extra copy for each canister.
This is probably an improvement we can make in icp-cli.

Comment thread crates/imcp2-core/src/deploy/host.rs Resolved
Comment on lines +1346 to +1352
let implied: Vec<Utf8PathBuf> = rel
.ancestors()
.skip(1)
.filter(|dir| !dir.as_str().is_empty())
.take_while(|dir| !dirs.contains(*dir))
.map(Utf8Path::to_path_buf)
.collect();
Comment on lines +937 to +940
if let Some(CanisterArgs::Text { content, format }) = args {
if *format == Default::default() {
guard_candid_text(&format!("`{field}`"), content)
.map_err(|e| at(Unsupported(e)))?;
Comment on lines +1274 to +1278
let decoder = Limited {
inner: flate2::read::GzDecoder::new(source),
left: limits.stream_bytes(),
tripped: Some((meter, limits.extracted_bytes)),
};
…t only by how the archive spells it

An entry under `.icp/` was refused by comparing its first component with
the name. A name is the disk's to interpret: Windows takes `.icp.`,
`.icp ` and `.icp::$INDEX_ALLOCATION` for `.icp`, so an archive could
supply the id mappings the check is there to keep out.

The spelling check stays, as the refusal that names the entry before it
is written. Once the archive is out, the extraction directory is asked
whether `.icp` is there, which answers for every spelling the disk
honours.

The Windows alias test is gated to Windows and has not been run: CI
tests on Linux only.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
candid 0.10.41 makes the subtype check linear on a chain of `opt`
aliases; candid_parser 0.4.2 loads a long alias chain without
overflowing the stack or taking quadratic time.

candid_parser 0.4 wraps a function's argument and result types in
`IDLArgType`, so the two places that document them read `.typ`.

icp-project 0.1.0 requires candid_parser 0.3, so the tree now holds
both: the library's own parsing still runs on 0.3.2.

The comment on the candid floor in Cargo.toml is dropped.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
@aterga aterga closed this Nov 19, 2026
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