Skip to content

imcp2-deploy: metrics for deploys, refusals and uploads - #251

Closed
raymondk wants to merge 3 commits into
deploy-5c-embeddersfrom
deploy-5d-metrics
Closed

raymondk wants to merge 3 commits into
deploy-5c-embeddersfrom
deploy-5d-metrics

Conversation

@raymondk

Copy link
Copy Markdown
Contributor

Stacked on #250. Second of four follow-ups preparing the hosted deploy tools for the gateway.

Why

The request metrics cannot see deploys. A deploy is one tools/call inside a POST to the MCP endpoint, answered 200 whether it succeeded, failed, or was refused because every slot was taken. The upload route is visible by status code, but one code covers several reasons. There is no way today to tell whether the concurrency cap is set right or how much the upload store holds.

What changes

imcp2-deploy reports how each deploy call went through a small observer trait (DeployObserver), and takes no metrics dependency. imcp2 implements it with Prometheus collectors, registered by the same Metrics::new an embedder already calls and refreshed by the same Metrics::refresh. An embedder needs no new code.

Series What it answers
imcp2_deploys_running, imcp2_deploy_slots How full the server is
imcp2_deploy_refusals_total{reason} busy, session_busy, stopping. A sustained busy rate means the cap is too low
imcp2_deploys_total{outcome} succeeded, failed, rejected, interrupted
imcp2_deploy_duration_seconds How long a deploy holds its slot
imcp2_deploy_uploads_total{outcome} accepted, bad_ticket, too_large, store_full, session_busy, body_error, storage_error
imcp2_deploy_upload_bytes Size of each accepted archive
imcp2_deploy_upload_store_bytes, ..._capacity_bytes What the upload store holds against its budget
imcp2_deploy_uploads_held, imcp2_deploy_uploads_arriving Uploads waiting and in progress

Every label value is a variant named in code; nothing a client sends becomes a label. All series start at zero. They are process totals with no instance label, since the endpoints of a process share one set of slots and one store.

Notes for review

  • The deploy tool's body moved into deploy_in_slot, which returns the answer together with what to tell the observer, so each exit reports exactly once. Its behaviour is unchanged.
  • The deploy state reports to the first Metrics built over it; a second handle over the same state gets gauges but no counter events.

Testing

  • deploys_and_uploads_are_counted drives uploads and deploy calls through the router and checks each series, including zero-fill and the gauges after a refresh.
  • Workspace tests and the deploy-feature tests pass; clippy is clean with and without the feature.
  • Not covered by a test: the succeeded, failed and interrupted outcomes and session_busy, which need a deploy that runs against a network. They share the code path of the tested rejected outcome.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV

@raymondk
raymondk requested a review from a team as a code owner November 19, 2026 00:35
Copilot AI max review requested due to automatic review settings November 19, 2026 00:35

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

Cancellations during bundle preparation are misclassified as rejections, and uploads dropped while receiving are omitted from outcome counters.

2 open issues
What changed in this PR

Adds deployment observability to hosted servers through the existing Metrics API, while keeping imcp2-deploy independent of Prometheus.

Changes:

  • Tracks deploy outcomes, refusals, durations, upload outcomes, and resource usage.
  • Automatically registers collectors and refreshes gauges through existing metrics integration.
  • Adds router-level metrics coverage and documents the new series.
File Description
src/​metrics/​deploy.rs Defines deploy and upload Prometheus collectors.
src/​metrics.rs Registers deploy collectors and refreshes their gauges.
src/​deploy.rs Connects shared state and upload handling to metrics; adds integration coverage.
README.md Documents metrics and embedder integration.
crates/​imcp2-deploy/​src/​uploads.rs Exposes upload-store usage snapshots.
crates/​imcp2-deploy/​src/​observe.rs Defines observer callbacks and fixed outcome values.
crates/​imcp2-deploy/​src/​lib.rs Reports deploy outcomes and exposes slot usage.

Review effort: Max

Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Comment thread src/deploy.rs Resolved
@raymondk
raymondk force-pushed the deploy-5c-embedders branch from 580ca47 to d5ab142 Compare November 19, 2026 01:11
Copilot AI max review requested due to automatic review settings November 19, 2026 01:14

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

Deployment metrics can overcount active work during draining, misleadingly label server-side setup failures, and omit interruption counts and durations when deployment tasks are cancelled.

3 open issues
2 resolved since last review

Review effort: Max

Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Comment thread crates/imcp2-deploy/src/observe.rs Resolved
raymondk and others added 3 commits November 18, 2026 21:02
…as refused, and how full the server is

A deploy is one `tools/call` inside a `POST`, answered 200 whether it
succeeded, failed or was refused for want of a slot, so the request
metrics say nothing about deploys; and the upload route's status codes
fold several reasons into one.

- imcp2-deploy tells an observer (`DeployObserver`) how each deploy call
  went: refused (busy, session_busy, stopping), or how it ended
  (succeeded, failed, rejected, interrupted) and how long it held its
  slot. It gains no metrics dependency; `DeploySlots` and `Uploads` say
  what they hold.
- imcp2 publishes them through the `Metrics` handle an embedder already
  builds over its servers: `imcp2_deploys_total`,
  `imcp2_deploy_refusals_total`, `imcp2_deploy_duration_seconds`,
  `imcp2_deploy_uploads_total`, `imcp2_deploy_upload_bytes`, and the
  gauges `imcp2_deploys_running`, `imcp2_deploy_slots`,
  `imcp2_deploy_upload_store_bytes` (and its capacity),
  `imcp2_deploy_uploads_held`, `imcp2_deploy_uploads_arriving`, which
  `Metrics::refresh` republishes. Every series starts at zero.
- Every label value is a variant named in code; nothing a client sends
  becomes a label.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
…and an abandoned upload is counted

- A deploy stopped while its bundle was still being read and checked is
  refused with a `RequestError` like a bad bundle is, and was counted as
  `rejected`. The refusal now says it was a stop
  (`RequestError::was_interrupted`), and is counted as `interrupted`.
- An upload whose request is dropped mid-body never returns from the
  receive, so it reached no counter. A guard counts it as `body_error`
  unless the receive answers.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
…oy dropped mid-run is counted, and the server's own failures are not `rejected`

- Deploys holding a slot are counted on their own, not read off the free
  permits: the wait for them to end held the free permits while it
  waited, so a draining server read as full. The wait now listens for a
  deploy ending and holds nothing.
- What became of a deploy that holds a slot is told by a guard, so a call
  whose future is dropped mid-run is counted, as interrupted, instead of
  vanishing from the count and the duration histogram.
- A deploy the server could not prepare (its directory not made, a step
  of its own failing) is `setup_failed`, not `rejected`, and its answer
  says to try again later. `rejected` is documented as what it is, an
  identity that could not be derived included.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
Copilot AI max review requested due to automatic review settings November 19, 2026 02:05

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

Disk-space failures during valid archive extraction lose their server-fault classification and are incorrectly counted as rejections rather than setup failures.

1 open issue
3 resolved since last review

Review effort: Max

})
.await
.map_err(|e| RequestError(format!("bundle extraction panicked: {e}")))?;
.map_err(|e| RequestError::server_fault(format!("bundle extraction panicked: {e}")))?;
@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 metrics are in #259.

@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