Skip to content

imcp2-deploy 3/6: deploy a bundle through icp-project, the pipeline, its events and its interruption - #231

Closed
raymondk wants to merge 2 commits into
deploy-1b-signingfrom
deploy-2-pipeline
Closed

raymondk wants to merge 2 commits into
deploy-1b-signingfrom
deploy-2-pipeline

Conversation

@raymondk

@raymondk raymondk commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

deploy_bundle, the function that runs a deploy, over the host from #230 and the calls from #246. Still no MCP surface.

  • The pipeline. Read the bundle (a regular file by absolute path, or bytes), extract it into a working directory of its own, load the project, check the bundle whole before any phase runs, seed the id store from the caller's canister-id mapping, then resolve_targets and the library's deploy: the entry point icp deploy uses, so creation, id wiring, settings, install or upgrade with the Candid check, and the sync steps behave as the CLI does. The agent is on mainnet (mainnet_agent).
  • Refused at entry. An unknown install mode, an oversized bundle file, and Candid deeper than the guard allows are refused before anything is extracted. The blocking work (extraction, the check, the project load) runs off the async workers.
  • The outcome carries a status (deployed, failed, interrupted, nothing_to_deploy), the canisters created, and the resulting mapping: the id store read back, merged with what was created, so a failed run still reports every canister it made.
  • Events as they happen. Watch hands deploy_bundle a stop token and an optional sender; each log line is sent the moment it is made, so the outcome's log and the streamed lines are the same lines in the same order. Each is also written to the server log, under the caller's span.
  • Interruption. The run is raced against the stop token: cancelling drops it at its next await, which is the next canister call or plugin step. A call already in flight completes on the network. An interrupted deploy keeps its working directory, since whoever asked for the stop may never read the answer and the directory's mapping file is then the record.
  • The working directory is made under a directory the caller names, readable by its owner alone.

What changed in this PR at the re-cut

Review so far

Changes

  • crates/imcp2-deploy/src/deploy.rs (570 lines of code, 600 of tests).
  • crates/imcp2-deploy/Cargo.toml adds tokio-util, serde_json, and tracing-subscriber for one test.

Testing

  • cargo build --locked --workspace --all-targets
  • cargo test --locked --workspace --all-targets
  • cargo fmt --all -- --check

The tests run the real pipeline offline: a hand-built bundle is extracted, loaded through icp-project, checked, and stopped at the create phase with no_create, where icp deploy --no-create stops. Refused before any phase: a checksum mismatch, a script build or sync step, a managed network and a testnet, a path the bundle does not hold, an unknown environment or canister, a bundle path that is not a regular file, an unknown mode, a gzipped module past its limit, two canister names differing only in case. Plus: the log is streamed as it is made, an interrupted deploy stops and keeps its directory, and the events reach the server log.

Not covered: an on-chain deploy. Nothing creates a canister, installs code or runs a sync plugin. The existing PocketIC fixture has no cycles ledger or engine registry, which the create phase needs.

The stack

Six stacked PRs that bring icp deploy to the MCP servers through the icp CLI's own project library. Re-cut on 2026-11-18 so that each file arrives once, in the form it has at the top; the tree at the top is unchanged from before the re-cut, rebased onto current main.

PR What
1 #230 The crate and the icp-project host for an untrusted bundle
2 #246 Signing: canister calls over ic-agent, an identity that refreshes
3 #231 The deploy pipeline, its events and its interruption
4 #247 The upload-ticket store
5 #232 The MCP tools, and the local server serving them
6 #243 The hosted server serving them

#242 (streamed phases, interruption) and #245 (one bundle source per server, crates.io) are closed: their changes are folded into the PRs above.

Checklist

  • I have read the Contributing guidelines.
  • Docs (README / comments) updated for any user-visible change.
  • No secrets, credentials, or internal-only information are included.

🤖 Generated with Claude Code

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

Critical validation and input-bounding gaps can leave funded canisters unreported, trigger stack-overflow aborts, and allow bundle reads to exceed the promised 256 MiB memory limit.

3 open issues
What changed in this PR

Adds the deployment pipeline over the bundle host from #230, using the icp-project operations behind icp deploy. MCP tool exposure remains in #232.

Changes:

  • Adds bundle loading, validation, ID seeding, deployment execution, and outcomes that preserve created canister IDs after failures.
  • Implements signed canister calls and certified reads through ic-agent.
  • Adds offline pipeline, input-rejection, and log-rendering tests; on-chain deployment remains untested.
File Description
crates/​imcp2-deploy/​src/​lib.rs Documents and exports the deployment API.
crates/​imcp2-deploy/​src/​deploy.rs Implements the pipeline, recovery mappings, logs, and offline tests.
crates/​imcp2-deploy/​src/​calls.rs Adapts signed calls and certified reads to CanisterCalls.

Review effort: Balanced

Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Copilot AI balanced review requested due to automatic review settings November 3, 2026 20:34

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

Bundle reads can bypass the 256 MiB limit and exhaust server memory, while invalid install modes can spend cycles before panicking without returning canister IDs needed for recovery.

4 open issues

Review effort: Balanced

Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Copilot AI balanced review requested due to automatic review settings November 3, 2026 23:42

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

Project loading can block Tokio workers with large synchronous filesystem reads, and certificate-result branches affecting upgrade compatibility remain untested.

2 open issues
4 resolved since last review

Review effort: Balanced

Comment thread crates/imcp2-deploy/src/calls.rs Resolved
Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
@raymondk
raymondk marked this pull request as draft November 4, 2026 00:16
@raymondk
raymondk force-pushed the deploy-2-pipeline branch 5 times, most recently from e331f38 to fb78ce5 Compare November 10, 2026 00:54
@raymondk
raymondk marked this pull request as ready for review November 12, 2026 12:57
Copilot AI balanced review requested due to automatic review settings November 12, 2026 12:57

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

Bundle-supplied plugins execute in the server process without a Wasmtime memory limit, allowing a small untrusted plugin to exhaust server memory before its compute-time budget stops it.

4 open issues
2 resolved since last review

Review effort: Balanced

Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Copilot AI balanced review requested due to automatic review settings November 18, 2026 02:00
@raymondk
raymondk removed this pull request from stack #233 November 18, 2026 02:01
@raymondk
raymondk changed the base branch from deploy-1-bundle-host to deploy-1b-signing November 18, 2026 02:01
@raymondk
raymondk added this pull request to stack #248 November 18, 2026 02:02
@raymondk raymondk changed the title imcp2-deploy 2/3: deploy a bundle through icp-project, the pipeline and its signed calls imcp2-deploy 3/6: deploy a bundle through icp-project, the pipeline, its events and its interruption Nov 18, 2026

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

Cancellation can drop an in-flight canister creation before its ID is recorded, leaving a funded canister untracked and risking duplicate creation and funding on retry.

6 open issues

Review effort: Balanced

Comment on lines +351 to +355
tokio::select! {
biased;
_ = watch.stop.cancelled() => None,
result = &mut run => Some(result),
}

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.

Agreed, and not fixed here. Dropping the run while a create call is in flight can leave a funded canister whose id reaches neither report.created nor the kept mapping, and a retry then creates a second one. The fix is cooperative cancellation that lets in-flight creations finish and be recorded, which needs either support in icp-project's deploy or deferring the stop while a create task is open. That is a design change rather than a patch to this select, so it stays open.

Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
… interruption

`deploy_bundle` reads the archive, extracts it into a working directory of
its own, loads the project through the host, and runs the library's deploy
operation as a given identity on mainnet: create the canisters the mapping
does not name, wire their ids, apply settings, install or upgrade, run the
sync steps. The request is refused at entry for what cannot be deployed
(mode, oversized file, deep Candid), and the blocking work runs off the
async workers.

Each phase is reported as it completes to whoever watches (`Watch`), and
written to the server log under the caller's span. A cancelled token stops
the deploy at its next step; the outcome then says `interrupted` and still
carries every canister created, and the working directory is kept.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 03:17
…ough the ways it ends

Three things review found in how a deploy ends:

- The scratch directory is now owned by the extraction while it runs. A
  blocking task is not stopped when the deploy's future is dropped, and
  one that outlived the directory wrote its files back under a path
  nothing removes.
- The lines the deploy adds after the run (where an interrupted deploy's
  directory is kept, a failure to read the ids back or to remove the
  directory) go to the watcher as the run's own lines do, not to the
  outcome's log alone.
- The merge that makes the mapping a retry is handed is a function of its
  own, `ids_for_a_retry`, tested for a store that recorded only some of
  the created canisters and for one that could not be read back.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

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

Cancellation can discard in-flight creation responses, losing funded canister IDs and risking duplicate creation on retry; sync-plugin cancellation and finalization logging also remain unresolved.

7 open issues

Review effort: Balanced

Comment on lines +349 to +350
let run = deploy(&host, &calls, &params, &reporter, &mut report);
tokio::pin!(run);
Copilot AI balanced review requested due to automatic review settings November 18, 2026 03:31

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.

🔵 Needs a closer look

Potentially destructive deployments from duplicate canister principals and cancellation-related loss of recovery IDs require human assessment.

2 open issues
5 resolved since last review

Review effort: Balanced

@raymondk

Copy link
Copy Markdown
Contributor Author

Superseded by the stack #254 → #259, which carries the same code in six PRs from main, with the deploy tools living in imcp2-core instead of a separate crate. The deploy pipeline is in #256.

@raymondk raymondk 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.

2 participants