Repository navigation
Conversation
What review found a write-enabled session, a restart or a disconnect could leave behind on the shared server, each closed: - Uploads have a budget. A session has one upload at a time (a PUT while another of its own is arriving is refused, and one that begins replaces the archive it was holding), and every archive the store has counts against MCP_DEPLOY_MAX_STORED_UPLOAD_BYTES, reserved before the body is read. A PUT abandoned mid-body takes its partial file and reservation with it. - A start clears the run before: uploads nothing can deploy are removed, and a cut-off deploy's directory is cut down to the ids it recorded. A sweep every minute removes lapsed uploads on an idle server and id records older than seven days. - An interrupted deploy keeps its id record, not its whole bundle. - The deploy slots and the upload store are the process's: /mcp and /mcp-beta, and every router built from either, share one Deploys. - On the shutdown signal running deploys are told to stop before the drain, so each answers with the canisters it created instead of being killed with the unit; a deploy asked for meanwhile is refused. - A stop during extraction, loading or checking ends the deploy there, before anything is created. - The hosted router test no longer asks Internet Identity for a delegation: the made-up session's grant has lapsed, so it is refused locally. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
There was a problem hiding this comment.
🟡 Changes recommended
Critical cancellation and cleanup flaws can orphan uploads and extracted bundles or lose accepted canister-creation results, risking resource exhaustion and duplicate funded canisters on retry.
5 open issues
Read-only bundle directories can prevent payload cleanup · New Cancelled uploads can leave untracked archive files · New SIGTERM can orphan accepted canister creation requests · New Install shutdown cancellation before identity refresh · New Preserve the previous archive when replacement uploads fail · New
What changed in this PR
This PR hardens hosted deployment resource limits and lifecycle handling, building on #243 without changing the intended successful deploy flow.
Changes:
- Adds process-wide upload budgets and shared deployment slots across endpoints.
- Connects shutdown and disconnect signals to deploy interruption and preflight checks.
- Adds startup and periodic cleanup, with supporting tests and documentation.
| File | Description |
|---|---|
src/main.rs |
Parses upload budgets, initializes shared deploy state, and signals shutdown. |
src/lib.rs |
Accepts shared Deploys state when configuring MCP servers. |
src/deploy.rs |
Adds shared state, periodic cleanup, upload error responses, and router tests. |
README.md |
Documents upload limits, interruption, and record retention. |
deploy/native/README.md |
Describes native deployment limits and restart behavior. |
deploy/native/imcp2.service |
Updates comments describing graceful shutdown; service settings are unchanged. |
crates/imcp2-deploy/static/skills/deploy-with-mcp.md |
Updates upload replacement, retry, and restart guidance. |
crates/imcp2-deploy/src/uploads.rs |
Adds storage reservations, receive guards, replacement rules, and cleanup tests. |
crates/imcp2-deploy/src/lib.rs |
Exposes shared slots and connects server stop signals to deploy tools. |
crates/imcp2-deploy/src/deploy.rs |
Adds preflight stop checks, interrupted-directory pruning, and record expiry helpers. |
Review effort: Max
…e deploy runs, a refused replacement, and read-only bundle directories - A stop no longer drops a deploy mid-call. A canister call in flight may already have created and funded a canister that only its answer names, so the calls are wrapped (`UntilStopped`): one in flight runs to its answer, which the deploy records as always, and any asked for after the stop is refused unmade, so the run ends by itself within a step. It is given twenty seconds to, and the answer says so if a call was given up on. A run that has made no call is still dropped where it is. - The stop is in place before the deploy's identity is fetched, and that wait gives way to it: a request no longer holds its slot and its upload through a network wait, deaf to a stopping server. - A session's replacement upload that is refused for room leaves the upload it held: the held bytes count as room, and the held archive goes only once the new one is let in. - Extraction gives every file and directory the owner's own mode instead of the archive's, so a directory an archive marks read-only cannot leave a tree the server cannot remove. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
There was a problem hiding this comment.
🟡 Changes recommended
Critical cancellation, shutdown, and recovery bugs can lose created canister IDs, cause duplicate funded deployments, and delete or strand deployment files.
9 open issues
Retain recovery records when a stopped deploy succeeds · New Preserve unresolved create errors and warn about incomplete mappings · New Enforce deadlines inside blocking plugin and host-call waits · New Set extracted directory permissions from the actual filesystem entry · New Cancellation can orphan an archive created by the background worker · New Claim the state directory before destructive startup recovery · New Wait for active deploys before shutting down transports · New Cancelled uploads can leave untracked archive files Warn users to reconcile uncertain creates before retrying · New
4 resolved since last review
Review effort: Max
| if !begun.load(Ordering::SeqCst) { | ||
| return None; | ||
| } | ||
| tokio::time::timeout(grace, run).await.ok() |
There was a problem hiding this comment.
Agreed that the outer timeout cannot fire while a plugin holds the thread, and not fixed here. Two things bound it today: a plugin's canister calls go through the same wrapped calls, so each is refused once the stop is set, and the upstream runtime enforces its own epoch deadline on plugin CPU time. A hard deadline inside the runner has to come from icp-sync-plugin; leaving this open to track that.
…ctory has one owner, and an interrupted deploy claims no more than it knows - A stopping process waits for its deploys to have ended before it exits (`Deploys::stopped`, the grace and a margin): a deploy waiting on a call in flight whose client has gone holds no connection for the drain to wait on, and the process would have exited under it. - A deploy that finishes after it was asked to stop keeps its record, as an interrupted one does: the client that went away never read its ids. - An interrupted deploy's answer passes on what its run ended with, and warns when a call went unanswered that the canister it was creating may exist unlisted; the skill says what to do about it before a retry. - The deploy directory is locked before a start clears it, so a second server over a state directory in use is refused instead of removing the first one's uploads and deploys. `Deploys::new` returns a `Result`. - An extracted entry's mode follows what it is on disk, not its header: an old-style header names a directory as a regular file ending in `/`. - An upload's file is created before the first wait, so an abandoned request cannot have the file appear after its cleanup has run. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
There was a problem hiding this comment.
🟡 Changes recommended
Router state does not retain the directory lock, allowing another Deploys instance to delete live uploads or prune active deployments after the original ownership handles are dropped.
3 open issues
8 resolved since last review
Wait for active deploys before shutting down transports Claim the state directory before destructive startup recovery Cancellation can orphan an archive created by the background worker Set extracted directory permissions from the actual filesystem entry Preserve unresolved create errors and warn about incomplete mappings Retain recovery records when a stopped deploy succeeds Cancelled uploads can leave untracked archive files Warn users to reconcile uncertain creates before retrying
Review effort: Max
…mes no command that cannot find a lost canister - The lock on the deploy directory is held by a router's state too. A router outlives the `Deploys` it was made from if its embedder lets it, still receiving uploads and running deploys there; with the lock gone, a second server would have cleared them as leftovers. - The skill no longer offers `icp canister list` as the way to find a canister whose creation went unanswered: it lists the project's canister names, not what an identity controls. It says that nothing here can find it, and that the user must before a retry. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because ownership-lifetime and parallel-create error handling risks could cause live-file deletion or unsafe retries, while key recovery guarantees remain unverified by the tests.
2 resolved since last review
Review effort: Max



Summary
Stacked on #243. Addresses the review findings there that are about what the shared server can be made to hold, and what happens to a deploy when the server or the client goes away. Nothing here changes what a deploy does when it runs to the end.
PUTand fill the state filesystemPUTwhile one is arriving answers 409), and a store-wide budget,MCP_DEPLOY_MAX_STORED_UPLOAD_BYTES(default eight archives' worth), reserved before the body is read (507 past it). An archive counts until its deploy lets go of it.receivefuture leaves a partial file nothing sweeps.icp/data/mappings(the ids). A start does the same for deploys a killed process left, and records older than seven days are removed.MCP_SERVE_BETA=1) and permcp_router()callDeploysper process holds the slots, the upload store and the stop signal;McpServer::with_deploynow takes it.TimeoutStopSec=30kills running deploys on restartAPI changes
imcp2::deploy::Deploysis new;McpServer::with_deploytakes it instead of aDeployConfig.DeployConfiggainsmax_stored_upload_bytes.imcp2_deploy:DeploySlots,IcDeployTools::with_slotsand::stopped_by,Uploads::with_budgetand::sweep,prune_abandoned_deploys,remove_old_deploy_records;ReceiveErrorgainsBusyandFull.imcp2-localis affected in one way: an interrupted deploy's directory now holds only the id record. The skill text already points at that file.Not in this PR
The sync-plugin memory limit, the crates.io packaging of
imcp2with an unpublishedimcp2-deploy, and correlatingnotifications/cancelledwith a running deploy are still open on #243.Testing
cargo test --workspace --all-targetsandcargo test -p imcp2 --features deploy --all-targetspass, clippy is clean on both. New tests cover each row above; the interruption test is now deterministic (it stops the deploy from the log line that says it started).🤖 Generated with Claude Code
https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV