Skip to content

Report each deploy phase as it completes, and stop the deploy when the call is cancelled - #242

Closed
raymondk wants to merge 26 commits into
deploy-3-mcp-toolsfrom
deploy-4-streaming
Closed

raymondk wants to merge 26 commits into
deploy-3-mcp-toolsfrom
deploy-4-streaming

Conversation

@raymondk

Copy link
Copy Markdown
Contributor

Stacked on #232 (deploy-3). Fourth step of the deploy stack, and the first of the work that brings the deploy tool to the hosted server: the call shape both servers will share.

What

icp_deploy_bundle stays one blocking call, but now reports each phase as it completes and stops when the call is cancelled.

Why

A deploy lasts from seconds to minutes (canister creation, installs, a frontend's asset sync) and the call said nothing until it ended. On the hosted server a silent minutes-long call is also what trips a client's per-call timeout. Progress notifications fix both: the client sees each phase, and the MCP SDK clients reset their timeout on every progress notification.

How

  • deploy::Watch is handed to deploy_bundle: a stop token and an optional lines sender. collect_log sends each log line the moment it is made, so the outcome's log and the streamed lines are the same lines in the same order (test: the_log_is_streamed_as_it_is_made).
  • The run is raced against stop with a biased select!: cancelling drops the run at its next await, which is the next canister call or plugin step. A canister call already in flight completes on the network. The outcome reports a new status, interrupted, with every canister created before the stop in created and canister_ids, like a failure does. The tool returns it as an error result, like a failure.
  • An interrupted deploy keeps its working directory (test: an_interrupted_deploy_stops_and_keeps_its_directory): whoever asked for the stop may be a client that went away and will never read the answer, so the directory's mapping file stays as the record, as it does for a run that is cut off.
  • The tool forwards each line to the client mid-call: as a progress notification when the request carried a progress token, else as a logging message. MCP logging is deprecated (SEP-2577) and rmcp marks it so; it is used only as the fallback, under #[allow(deprecated)] with the reason. The local server declares the logging capability so a client expects it.
  • stop is the request context's cancellation token, which rmcp cancels on the client's notifications/cancelled. The hosted server will add the connection going away as a second source in a later PR.
  • Skill, tool description, server instructions and README say the call lasts as long as the deploy, to send a progress token, and what cancelling does.

Not here: the hosted composition, the bundle upload, concurrency across sessions. Those are the next PRs on this stack.

🤖 Generated with Claude Code

raymondk and others added 25 commits November 11, 2026 21:17
…ted input

The first of three changes that bring `icp deploy` to the local MCP
server through the icp CLI's own project library. This one is the
library's `Host` for a bundle — the `.tar.gz` that `icp project bundle`
writes — and nothing yet drives it.

A bundle is handed over by an agent, so the host takes it for exactly
what a bundle is and no more:

- `extract_bundle` unpacks it into a scratch directory under a
  compressed-size limit (256 MiB) and a decompressed-stream limit
  (1 GiB), refusing symlinks and other non-file entries, and anything
  under `.icp/`, the state a deploy seeds itself.
- `BundleFs` is the `FileSystem` the library reads the project through:
  backed by the index of what extraction wrote, so a path is normalized
  against the bundle root (`..` clamped, absolute re-anchored) and looked
  up there. A path the archive did not carry is "not in the bundle",
  whatever exists on disk at that spelling. Writes land only in scratch
  directories the filesystem created.
- `IcMainnet` is the network seam: the `ic` network with the pinned
  mainnet root key, and nothing else.
- `BundledWasm` serves local wasm sources from the index, sha256
  verified; `NoScripts` runs pre-built steps and refuses script ones.
- `check_bundle` validates the whole bundle before a deploy would run:
  one pre-built step per canister naming a wasm in the archive that
  hashes to its checksum, every sync plugin in the archive, no scripts,
  an environment on `ic`.

The crate is `publish = false` by construction: `icp-project` and its
siblings are git dependencies, which crates.io refuses, so this cannot
live in `imcp2-core`. The four icp-cli crates are pinned to one rev.
`icp-sync-plugin` brings wasmtime into the workspace. The manifest
carries the full dependency list so the lockfile lands once; a few deps
(rmcp, base64) are used only by the tools that follow.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…store the crate version

Four review findings on the host:

- The network seam accepted any connected network claiming the mainnet
  root key, so a manifest could point the user's signed calls at an
  endpoint of its choosing. Only the reserved `ic` network is served
  now: that name, the mainnet endpoint and the mainnet root key, which
  is what the loader supplies and refuses to let a manifest redeclare.
- A canister directory spelled absolutely (`/etc`) resolved inside the
  bundle for every reader that goes through `BundleFs`, but the
  sync-plugin runtime takes it as a host path and makes a directory
  outside the project its own sandbox root. `check_bundle` now holds
  each canister directory to the bundle root by spelling.
- The `.icp/` guard at extraction tested the archive path's first
  component, which `./.icp/...` sidesteps. It tests the normalized path.
- The root crate had slipped back to 0.6.0 while the others are at
  0.6.1, which the release guard refuses. Restored, lockfile included.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Four more review findings on the host:

- Directory lookups scanned the whole index per call, which a recursive
  glob over a bundle of many files turned quadratic. A path set orders
  by component, so a directory's descendants sit right after it: `is_dir`
  and `read_dir` now take one range lookup and read while the prefix
  holds. An archive is also capped at 250,000 entries, since the byte
  budget alone admits millions of empty files.
- Canister names that differ only in letter case passed, and the
  library's artifact store keys build output by name on disk, where a
  case-insensitive volume would hand the last-built module to both.
  `check_bundle` refuses them.
- A gzip-compressed module hashed correctly however much it expanded to,
  and the library gunzips it in memory, unbounded, to read its Candid
  interface. `check_bundle` streams it through a bounded decoder first,
  holding it to 100 MiB expanded, the IC's own ceiling on a module.
- The `.icp/` guard at extraction compared case-sensitively, which
  `.ICP/` sidesteps on a case-insensitive disk. Compared without case.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…eate

Two more costs a bundle could run up past the budgets that were there, and
one it still can, named for what it is.

The project loader reads an argument or variable file into every canister
that names it and keeps each copy, so the extraction budget bounded none
of it: fifty canisters naming one file of 100 MiB would hold 5 GiB. The
loader now reads through a metered view of the bundle, charged by file
size before each read, with 256 MiB for everything it loads; the phases
keep reading the bundle itself, where a module is read as often as the
deploy needs it.

The entry cap counted archive records, but `unpack_in` creates the missing
parents of every entry, so a few files at the bottom of long, distinct
directory chains cost inodes the count never saw. Extraction now counts
files and directories alike, charging each directory an entry's path
implies once, read off the index and the directory entries written so far.
Since that walk costs a lookup per component, an entry's path is first
held to Linux's PATH_MAX, past which nothing could be created anyway.

What stays unbounded is a sync plugin's memory: the runner in
icp-sync-plugin bounds compute time and stack and builds its own engine
and store, so a store limiter belongs there. The host's docs say so, so
the gap is not mistaken for a bound.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The index-backed filesystem went: the confinement it provided is now the
library's own. dfinity/icp-cli#866 (issue #865) adds `files::Confined`,
the host filesystem held to one directory: every path is resolved
against the root before the disk sees it, and one that comes to rest
outside — by climbing, by being absolute elsewhere, or through a symlink
inside pointing out — is refused. The loader resolves every path a
manifest names through the filesystem it is given, so that one seam
holds all of them, canister directories included, which is also why the
spelling check on canister directories went: a directory outside the
root is not found, and the project does not load.

What stays here is what the library cannot know about an archive: the
bounds on its size, its decompressed size, its files and directories
and their paths, the refusal of symlinks, device nodes and `.icp`, the
metered view the loader reads through, and the checks on the bundle's
shape before any phase runs.

The four icp-cli crates are pinned to that branch's head until it is on
main.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…aths to it

The check read, hashed and gunzipped a module once per canister naming
it, and nothing summed the expansions: a manifest of ten thousand
canisters on one gzip module expanding to the 100 MiB limit had it
decompress a terabyte before refusing anything, and ten thousand
kilobyte-sized gzip files did the same without repeating a name. Now
each file is read, hashed and expanded once, by where it lies on disk
(`Verified`), and the expansions are summed under
`MAX_WASM_BYTES_IN_ALL`, the extraction budget again: compressing a
module buys nothing against it.

The check also said nothing about what a sync step declares under
`dirs:` and `files:`. The runtime resolves each against the canister
directory, confined to the project, and reads every `files:` entry into
a string of its own before the plugin runs — so a missing file, or a
path outside the bundle, failed at sync, after the canisters had been
created and paid for, and a 100 MiB file declared a hundred times asked
for 10 GiB. `check_declared` now holds each entry to the runtime's rule
(relative, within the root, present, a directory where `dirs:` says so)
and the files, counted as often as declared, to `MAX_PLUGIN_INPUT_BYTES`
per step. Which of the two settings a plugin's interface accepts stays
the runtime's to tell.

Two regressions for what the move to `Confined` already fixed: the
parents a directory entry implies are counted once, and an empty
directory entry is a directory of the bundle.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
dfinity/icp-cli#868 completes the rule #866 began, split three ways
(#863): the user's own project may link wherever it likes, `icp project
bundle` writes an archive of regular files and directories alone, and a
consumer of a bundle it does not trust refuses any other entry on the
way in. `files::Confined` is accordingly held to the root by the
spelling of each path alone — it no longer canonicalizes the root or
follows symlinks to see where a path comes to rest — and `Confined::new`
is infallible.

This crate is that consumer: extraction already refuses a symlink, a
device node and anything else that is not a regular file or directory,
so the lexical check is complete here. The pin moves to the head of the
stack, the docs say why the extractor's refusal is what the confinement
relies on, and the one call site follows the signature.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…m upstream

The rule for a project someone else handed over now lives in icp-project
(dfinity/icp-cli#871, `icp_project::untrusted`, what the CLI's
`--untrusted` flag applies), so the host composes it as the CLI does
instead of assembling its own from the seams: the project is loaded
through `Confined::refusing_links`, which refuses a path through a
symlink anywhere under the root; no recipe is fetched (`NoRecipes`); and
the loaded project is vetted (`Vetted`) before it is handed out, so a
build step that is not a pre-built module from a file in the project, or
a sync step that is not a plugin from one, fails the load.

With the loader the one gate on the project's shape, the hand-rolled
`NoRecipes`, the `Build` backstop and the script checks in `check_bundle`
go; the builder is the library's own, and the syncer takes a runner that
spawns nothing, since no script step reaches it. Extraction still
refuses a symlink on the way in, and the filesystem now refuses one
again should it appear under the root later.

Pins the four icp-cli crates to the head of #871. Two tests: the load
refuses a script step, a remote module and a recipe, naming each; and
the bundle filesystem refuses a link made after extraction.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…t runs

dfinity/icp-cli#871 has moved its line: between reading and running,
rather than around the project directory. Reading is no longer
restricted — the loader reads argument files, manifests and recipes
from wherever the manifest points, through the ordinary filesystem —
and what runs is held to the list: each build step a pre-built module,
each sync step a plugin, and the file each names within the project,
judged by where it really is once every link is followed and every `..`
applied. `Confined::refusing_links` and `NoRecipes` are gone from
upstream, `Vetted::new` takes the filesystem the paths resolve through,
and `--untrusted` sits on `build`, `deploy` and `sync` rather than on
every command.

The host follows. The bundle is still read through `Confined` — a bundle
has no business outside its own directory, and the vet resolves each
module through the same seam — but the confinement is this crate's
choice now, not the rule's. No recipe is fetched, by this crate's rule
rather than the library's: the CLI would render one and vet the steps
it produces, a bundle has none, so the resolver that refuses them is
back here, naming the recipe. The refusal wording follows upstream: a
step is "not a pre-built module", not "from a file in the project", and
a module linked out of the root is refused for where it resolves, not
for passing through a link.

Pins the four icp-cli crates to the head of #871. The test that read a
link made after extraction as a filesystem refusal now loads a project
through one: a link out fails the load naming where it leads, a link
within is let be, a dangling one is refused. The read-budget test's
archive carries the module its manifest names, as the vet now asks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
dfinity/icp-cli#871 now asks, after resolving where a module or plugin
really is, whether a regular file is there, since a directory cannot be
read as a module and a pipe is read from whoever writes to it. The vet
asks the filesystem it is given, and a path that does not resolve is now
refused as resolving "to anything" rather than "to a file".

The host follows, and resolves the extraction root once before the
filesystem is held to it. The vet hands the filesystem a resolved path,
and `Confined` holds every path to the root by spelling alone, so a root
named through a link — macOS keeps its temporary directories under
`/var`, a link to `/private/var` — would put every resolved path outside
it and refuse every bundle. `dunce` resolves it, as icp-project's own
host filesystem does, keeping a Windows path free of the `\\?\` prefix.

Pins the four icp-cli crates to the head of #871. Two tests: a directory
of the bundle named as a module fails the load naming what was found,
and a root named through a link is the directory it leads to.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…handle

The pin moves from the #866 -> #871 stack to #873, the same `--untrusted`
feature with `files::Confined` built on cap-std. What changes for the
host:

The confined filesystem opens the root once as a directory handle and
makes every read beneath it, so the operating system refuses a path that
leaves the root; on top of that a path through a symlink is refused
wherever it leads, within the root or without. The vet asks that
filesystem whether what a step names is a regular file, so a module
named through a link now fails the load as not a regular file of the
project, where before one resolving within the root was let be. The
root is matched as spelled, so the extraction directory is no longer
canonicalized and `dunce` goes; a root named through a link holds the
project as it is.

`NoRecipes` is the library's own now, and so is holding a plugin's
`dirs:` and `files:` to the project at the load: this crate's resolver
goes, and its declared-paths check keeps only the byte budget the
runtime's reads are held to. The tests read the new refusals, and the
docs name #873 on #868.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
dfinity/icp-cli#873 is merged (8f98455, on #868's merge e097f7f), as one
squash of the two heads this crate followed. The code is the same as the
head it was pinned at; the merge adds a doc note on `untrusted::vet` and
`Vetted::new` that the filesystem handed in must be the one that confines
the project, which the host's composition already satisfies. The pin
moves to main, and the manifest and docs stop saying it awaits that.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The second of three changes bringing `icp deploy` to the local MCP
server. On top of the bundle host, this adds what runs a deploy:

- `deploy_bundle(identity, request)`: read the bundle (a regular file by
  absolute path, or bytes), extract it, 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 same entry point `icp deploy` uses, so creation, id
  wiring, settings, install/upgrade with the Candid check and the sync
  steps behave as the CLI does. The outcome carries the status, the
  canisters created, the resulting mapping (the id store read back,
  always merged with what was created, so a failed run still reports
  every canister it made) and the event stream rendered as a log.
- `AgentCalls`: the library's `CanisterCalls` over `ic-agent`, modelled
  on icp-app's own implementation minus proxy routing, with certified
  reads via `read_state`. The agent is built by the first phase that
  reaches the network, as the CLI does.

The tests run the real pipeline offline: a hand-built bundle is
extracted, loaded, checked and stopped at the create phase with
`no_create`, exactly where `icp deploy --no-create` stops. A checksum
mismatch, a script step, a managed network or a testnet, a path the
bundle does not hold, an unknown environment or canister, and a bundle
path that is not a regular file are each refused as request errors
before any phase.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… split comment

Two review findings on the host (#230) are now also covered through the
real pipeline: a manifest that spells a canister's directory as `/etc`,
with the `canister.yaml` the loader looks for carried in the archive at
that spelling, and a manifest that declares a connected network claiming
the mainnet root key over a loopback endpoint. Both are refused before
any phase. The comment above the manifest-path test had been split in
two by an insertion; it is whole again.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Two of the host bounds from #230 through the real pipeline: a
gzip-compressed module that hashes correctly but expands past the module
limit, and two canisters whose names differ only in letter case. Both
refused before any phase.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… check off the workers

Four more things a request could do to the deploy before any phase ran,
each now refused at the door.

The library resolves the install mode only when it installs, after the
canisters exist, and panics on a spelling it does not know; a typo would
create funded canisters and unwind without reporting them. The mode is
checked against the four the library takes before anything is read.

A bundle file was sized by its path and then read to its end, so a file
replaced or grown in between was read whole. The open file is sized again
and read to the limit plus one byte, which is enough to tell it outgrew
the limit; the path is still checked first, so a pipe is never opened.

The library parses a canister's Candid arguments at install and its
module's `candid:service` interface at the upgrade check, with no depth
guard and on the worker thread, where nesting past the stack aborts the
process. The bundle's arguments and interfaces are held to the bound the
call tools apply to caller-supplied Candid (`guard_candid_text`, now
public in imcp2-core) in check_bundle, and the interface the deployed
canister answers with is held to it in the calls adapter, so neither
side of the comparison can be deeper than the parser can take.

check_bundle reads, hashes and gunzips every module, up to a gigabyte of
them, so like extraction it now runs off the runtime's workers.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A canister directory outside the root is now something the loader does
not find, and a variable file outside it is refused by the filesystem as
outside, so the two tests read those messages rather than the host's
old ones. A wasm outside the root is refused earlier still, by the
untrusted rule's vet at the load: it asks the bundle's filesystem where
the module really is, and nothing outside the root resolves through it,
so the test reads that.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The untrusted rule now holds at the load, naming the step it refuses, so
the test reads that refusal, and the preflight comment no longer counts a
script step among what the check catches.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… workers

What a certificate proves about a metadata section is decided in one
function over the tree alone, so each branch is read from a fixture with
no network: a section the tree holds, a canister proven to exist without
it (no module, or a module without that section), a canister proven
absent, a pruned section and a pruned controllers entry, which each prove
nothing and are reported as such rather than guessed at.

The project load reads the manifest and every file a canister names with
the filesystem's own blocking reads, up to the metered budget, and ran on
the runtime's worker that took the call; it now runs on a blocking thread
as extraction and the bundle check already do, and the lazy loader keeps
what it loaded for every ask after.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The last of three changes bringing `icp deploy` to the local MCP server:
the tools over the bundle host and the deploy pipeline, and their wiring.

- `icp_deploy_bundle` takes a bundle (by absolute path, or inline as
  base64 bounded on its length before decoding), the environment name,
  and optionally the canister-id mapping an earlier deploy returned;
  it answers with the status, the mapping to pass back next time, the
  canisters created and a per-phase log, as structured content under a
  declared output schema. It needs a session granted "Actions &
  questions", checked before the bundle is decoded.
- Calls are signed as the user's CLI identity: their default Internet
  Identity account at `https://cli.id.ai`, the origin `icp identity
  link web` signs in at, so canisters created here are the ones `icp`
  lists and controls, funded from the same cycles balance. It is not the
  management identity the canister lifecycle tools act as; the docs say
  so. A per-app delegation lives five minutes and a deploy can run
  longer, so the agent signs through `RefreshingIdentity`, which swaps
  in a fresh delegation from the session store every ten seconds, for
  the same principal, until the deploy ends.
- `icp_cycles_balance` reports that principal and its cycles-ledger
  balance, the check a deploy that will create canisters starts with.
  Core's tool of that name sits in the protocol half the local server
  does not serve; this is the same logic on the served surface.
  `cycles_balance_of` is split out of core's `cycles_balance` and
  `Identities::agent_as` made public for it.
- The local server composes the deploy router next to the login tools,
  serves the `skill://deploy-with-mcp` skill (bundle, deploy, write the
  mapping back into `.icp/data/mappings/<environment>.ids.json`) ahead
  of core's bundled skills, and adds a DEPLOYING paragraph to its
  instructions. README and the crate docs describe the tool, the
  identity it acts as and the `ic`-only rule.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…t past a cut-off

What the review found around the tools rather than in the pipeline, each
taken as it was raised.

A deploy signs as the account the first derivation resolved the session's
default to, and asks for that account by number from then on (core's
delegated_identity_resolved reports it): the default is the user's to
change, and a refresh that came back as another principal would have been
refused until the delegation in hand expired. When the store reports the
grant over — II's one terminal answer, RECONNECT_MSG, now public — the
identity stops signing at once instead of riding out that delegation.

Two deploys at once for one project, each with the mapping as it was
before either, would create two sets of canisters: a server runs one at a
time, and refuses rather than queues a second, since its mapping would be
stale by the time it ran. And a deploy's working directory is kept under
the OS's local data directory until the outcome is assembled, so a call
cut off mid-deploy leaves `.icp/data/mappings/<env>.ids.json` with every
canister it created where the README and the skill say to look.

The balance check reads the Internet Computer through the same mainnet
agent a deploy uses, whatever endpoint the rest of the server is pointed
at. `bundle_path` is trimmed and must be absolute before any I/O, and an
unparsable id is reported as what it is, not a valid principal. The deploy
skill joins the first page of resources alone.

The identity the tools act as is described as what it is: the default II
account at cli.id.ai, which `icp identity link web` links the CLI to —
the CLI's own principal only when its selected identity is that link.
The README, the skill, the server instructions and the module docs say
so, and point at `icp identity principal` for the comparison.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A deploy cut off mid-run leaves the ids it created in its working
directory, under the local data directory the README points at. With
none reported by the OS the server fell back to the system temporary
directory in silence, where a cleanup may remove the record before the
user looks; it now fails at startup, naming what to set.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…esources

The skill around `icp_deploy_bundle` was served as the MCP resource
`skill://deploy-with-mcp` alone, and not every client reads resources
(review on #232). `icp_deploy_guide` returns the same document as a tool
result, text and structured content, as core serves its Candid guide both
ways. The server's instructions and README say so, and the round-trip
test calls it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Every deploy runs in a fresh, randomly named directory under the user's
local data directory (or the system temporary directory), and nothing
reads it but that run. Its mode followed the umask, though, so another
user of the machine could read what the bundle holds and the ids the
deploy records wherever the parent allowed it. On Unix the directory is
now made with mode 0700. A test creates two and checks that they differ,
sit under the parent, and are the owner's alone (review on #232).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…e call is cancelled

A deploy lasts from seconds to minutes, and until now the call said
nothing until it ended. The pipeline now hands each log line to a
watcher the moment it is made, and the tool delivers it to the client
mid-call: as a progress notification when the request carried a
progress token (which is also what keeps a client's per-call timeout
from running out), else as a logging message. The local server declares
the logging capability so a client expects the latter.

The same watch carries a stop: cancelling the request drops the run at
its next step (a canister call already in flight completes on the
network), and the outcome reports `interrupted` with every canister the
run had created, like a failure does. An interrupted deploy keeps its
working directory, since whoever asked for the stop may be a client that
went away and will never read the answer; the directory's mapping file
remains the record, as for a run that is cut off.

Co-Authored-By: Claude Fable 5.1 <[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 submitted creation results before their IDs are persisted, leaving untracked canisters and causing duplicates on retry.

6 open issues
What changed in this PR

Extends the deploy tools introduced in #232 with progress reporting and request cancellation, preparing a shared call shape for local and hosted servers while keeping deployment as one blocking call.

Changes:

  • Adds streamed phase logs, cancellation handling, and an interrupted outcome that retains the working directory.
  • Forwards updates through MCP progress notifications, with logging as the fallback.
  • Updates deployment guidance and adds streaming and interruption tests.
File Description
crates/​imcp2-local/​src/​server.rs Declares logging support and updates deployment instructions.
crates/​imcp2-local/​README.md Documents progress, cancellation, and recovery behavior.
crates/​imcp2-deploy/​static/​skills/​deploy-with-mcp.md Updates agent guidance for watching and interrupted deploys.
crates/​imcp2-deploy/​src/​lib.rs Connects request cancellation, forwards updates, and handles interrupted results.
crates/​imcp2-deploy/​src/​deploy.rs Adds Watch, streams logs, handles interruption, and adds tests.
crates/​imcp2-deploy/​Cargo.toml Adds the cancellation-token dependency.
Cargo.lock Records the deploy crate’s tokio-util dependency.

Review effort: Max

tokio::pin!(run);
tokio::select! {
biased;
_ = watch.stop.cancelled() => None,
Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Comment on lines +390 to +393
outcome.log.push(format!(
"interrupted; the deploy directory '{}' is kept, with the ids it recorded",
workdir.display()
));
Comment on lines +438 to +440
// The sender went with the run; the forwarder ends once it has
// delivered what is left.
let _ = forwarder.await;
Comment on lines +515 to +516
let mut progress = 0.0;
while let Some(line) = lines.recv().await {
// A running deploy reports each phase mid-call: as progress when the
// request carried a token, else as a logging message, which a client
// only expects from a server that declares it.
info.capabilities.logging = Some(Default::default());
Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Co-authored-by: Arshavir Ter-Gabrielyan <[email protected]>
@raymondk
raymondk marked this pull request as ready for review November 18, 2026 01:22
@raymondk
raymondk requested review from a team and a max review from Copilot November 18, 2026 01:22

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

Cancellation can discard an in-flight creation reply before the canister ID is persisted, leaving a paid-for canister untracked and risking duplicate creation and additional cycle charges on retry.

5 open issues
2 previously missed issues

In code that hasn't changed since last review

Low severity Test does not verify streaming before deployment completes

crates/​imcp2-deploy/​src/​deploy.rs:1019

The test waits for the entire deploy to finish before reading its first streamed line, so it would also pass if all lines were buffered and sent only at the end. That leaves the new mid-call delivery guarantee untested. Run the receiver concurrently with a deterministically paused deploy, or keep an event reporter open in a collector test, and assert that a completed task's line arrives while the deployment/collector is still pending.

Low severity Cancelled-call guidance relies on an unavailable result

crates/​imcp2-deploy/​static/​skills/​deploy-with-mcp.md:157

A cancelled MCP request may not deliver a result the caller can use, so telling the agent to do step 3 from an interrupted answer is not a reliable recovery path. Direct cancelled calls to recover the mapping from the retained working directory in pitfall 8; use the returned mapping when an answer is actually received. Same issue in crates/imcp2-local/README.md:173–174.

1 resolved since last review

Review effort: Max

@raymondk

Copy link
Copy Markdown
Contributor Author

Closing: folded into the re-cut stack. The pipeline side of this change (Watch, the stop token, the interrupted status, the kept working directory) is in #231, and the tool side (forwarding each phase as a progress notification or log message, cancellation) is in #232. The suggestion applied here to the icp_cycles_balance description is in #232, where that description was later shortened further.

@raymondk raymondk closed this Nov 18, 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