Skip to content

Harden remote health check status reporting - #7330

Merged
rdimitrov merged 3 commits into
mainfrom
ChrisJBurns/pr-4844-review
Nov 26, 2026
Merged

rdimitrov merged 3 commits into
mainfrom
ChrisJBurns/pr-4844-review

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #4844, which made remote MCP health checks on by default and keeps a failing remote's proxy running as unhealthy until it recovers. Review findings posted after that PR merged turned up three bugs in the new paths. #4844 is not in a release yet, so none of these has shipped.

  • /health exposed secrets in the remote URL. Mark failing remote MCP servers unhealthy instead of starting #4844 pointed the health pinger at the remote's full path and query. When a ping fails, the *url.Error text quotes that full URL. HealthChecker copies it into mcp.error, and the proxy serves it on the unauthenticated /health endpoint, so a token in ?api_key=… or in the path was readable by anyone who could reach the proxy. The pingers now rebuild the *url.Error with only the scheme and host, keeping the inner error so errors.Is still works. Redirect Location values get the same treatment. The pinger's debug logs and the startup debug log in http.go drop the path and query too.
  • Stopping or removing an unhealthy remote could leave the wrong status. thv stop/rm sends SIGTERM and then writes stopped or deletes the status file without waiting. A ping in flight then failed, and the degraded monitor fired onHealthCheckFailed, which wrote unhealthy over stopped or recreated the deleted status file. The monitor now returns without counting or calling back once its context is cancelled or the proxy is stopping. The runner's unhealthy callback also keeps stopping/stopped/removing and skips a workload whose status is missing or unreadable.
  • One failed status write left a recovered remote stuck as unhealthy. The failure callback re-fires on every failed check, but the recovery callback fired once. If that read or write failed (the status file lock gives up after 1s), nothing put it right until the next outage. HealthCheckRecoveredCallback now returns error, and the proxy keeps a pending recovery and calls it again on each passing check until it returns nil. monitorHealth now tracks this in explicit reportedUnhealthy/recoveryPending state instead of leaving the counter at the threshold.
  • Fixed the docs in 03-transport-architecture.md that said remote checks were "always enabled" (they can be turned off) and that the status is written "only on these transitions" (it is rewritten during an outage). The docs also now state that each remote check is a request to the MCP endpoint, which opens and drops a connection for SSE remotes.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Locally, task lint-fix crashes inside staticcheck on the go1.27 toolchain. I ran golangci-lint run --disable staticcheck,unused on ./pkg/transport/... ./pkg/runner/... (0 issues) and am relying on CI for the full run. go test -race passes for those packages. I also turned off the redaction, the shutdown guard and the recovery retry one at a time and confirmed the new tests fail each time.

Changes

File Change
pkg/transport/proxy/transparent/pinger.go Redact the target to scheme and host in ping errors and debug logs; replace net/http's unparseable-Location error, which quotes the raw header
pkg/transport/proxy/transparent/transparent_proxy.go Shutdown guard before health callbacks; explicit reportedUnhealthy/recoveryPending state; recovery retried until handled
pkg/transport/types/transport.go HealthCheckRecoveredCallback returns error
pkg/transport/http.go Remote setup debug log no longer prints the path and query
pkg/runner/runner.go Status callbacks distinguish "not found" from "read failed"; unhealthy keeps stopping/stopped/removing; recovery reports read/write failures
*_test.go Redaction table for both pingers, recovery retry, pre-threshold recovery, no callbacks after shutdown, runner transition cases; nil-callback test now proves the threshold was crossed
docs/arch/*.md, docs/observability.md Health check behaviour and /health redaction

Does this introduce a user-facing change?

Yes:

  • /health error text. Before: when a remote ping fails, mcp.error contained the full remote URL, including path and query. After: it names only the scheme and host, e.g. Get "https://mcp.example.com": dial tcp ….
  • Stopping an unhealthy remote. Before: thv stop / thv rm could leave the workload unhealthy, or recreate its status after removal. After: it ends stopped, or stays removed.
  • Recovery. Before: a remote that recovered while its status write failed stayed unhealthy. After: it returns to running on a later passing check.

Special notes for reviewers

  • Shutdown guard is best-effort. A Stop that lands between the guard and the callback can still let one callback through. Separately, the workload manager writes status from another process, so its write can land between the runner's read and write. thv stop writes stopped last, which covers the common case. Fully closing it needs compare-and-set in StatusManager, which is out of scope. The docs say this.
  • Unparseable Location redaction relies on Go's error text. Go builds that error with %v and no error chain, so it is caught by its message prefix. A test pins it, so a Go change that rewords it fails CI rather than leaking.
  • Out of scope: request-path logs still print the full URL. Pre-existing data-plane logs in transparent_proxy.go still log full upstream URLs: the per-response debug log of req.URL and the redirect warn/info lines. Unlike /health, these need log access to read. Worth a separate change.
  • Unchanged from Mark failing remote MCP servers unhealthy instead of starting #4844: unhealthy can replace auth_retrying. A remote that recovers is then shown running while token refresh may still be retrying.

🤖 Generated with Claude Code

Follow-up to #4844, which turned remote health checks on by default and
keeps failing remotes running as unhealthy.

- Redact ping errors and pinger logs to the remote URL's scheme and
  host. The unauthenticated /health response echoed the ping error,
  which quoted the full remote URL, so secrets in its path or query
  were readable by anyone who could reach the proxy.
- Stop firing health callbacks once the proxy is shutting down, and
  have the runner keep stopping/stopped/removing and skip deleted
  workloads, so stopping or removing an unhealthy remote no longer
  leaves it unhealthy or recreates its status file.
- Make HealthCheckRecoveredCallback return an error and retry it on
  later passing checks, so one failed status write no longer leaves a
  recovered remote stuck as unhealthy.
- Fix the health check docs that contradicted the opt-out and the
  repeated-write behaviour.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the size/L Large PR: 600-999 lines changed label Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 26, 2026
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.87500% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.35%. Comparing base (4062c71) to head (501203e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...g/transport/proxy/transparent/transparent_proxy.go 93.87% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7330      +/-   ##
==========================================
+ Coverage   82.30%   82.35%   +0.04%     
==========================================
  Files         935      936       +1     
  Lines       95295    95494     +199     
==========================================
+ Hits        78436    78642     +206     
+ Misses      16854    16847       -7     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…eview

# Conflicts:
#	docs/arch/08-workloads-lifecycle.md
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 26, 2026
@rdimitrov
rdimitrov merged commit 786be66 into main Nov 26, 2026
47 checks passed
@rdimitrov
rdimitrov deleted the ChrisJBurns/pr-4844-review branch November 26, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants