Skip to content

fix(upstream): docker recovery survives launchd minimal PATH + stale state - #441

Merged
Dumbris merged 1 commit into
mainfrom
fix/docker-recovery-shellwrap-stale-state
Apr 30, 2026
Merged

Dumbris merged 1 commit into
mainfrom
fix/docker-recovery-shellwrap-stale-state

Conversation

@Dumbris

@Dumbris Dumbris commented Apr 30, 2026

Copy link
Copy Markdown
Member

Summary

Two bugs combined to make Docker recovery permanently dead when mcpproxy boots from a macOS .app bundle / LoginItem (launchd hands the parent PATH=/usr/bin:/bin:/usr/sbin:/sbin):

  1. checkDockerAvailability skipped shellwrap — used a bare exec.Command("docker", "info") whose lookup goes through os.Getenv("PATH"). Every other docker call site in the codebase (runtime.IsDockerAvailable, core/docker.go, management/diagnostics, security/scanner/docker) already uses shellwrap.ResolveDockerPath (which probes /Applications/Docker.app/..., /usr/local/bin/docker, /opt/homebrew/bin/docker, login-shell PATH, etc.). The recovery monitor was missed during that migration.

  2. Persisted FailureCount was inherited verbatim — startDockerRecoveryMonitor loaded prior state, including FailureCount=10 from the previous process. The recovery loop's attempt >= maxRetries guard then fired on the very first probe and exited in milliseconds without ever sleeping. Logs showed:

    2026-04-30T19:39:01.303 WARN  Docker unavailable on startup, starting recovery
    2026-04-30T19:39:01.308 ERROR Docker recovery max retries exceeded {"attempts":10}
    

    Five milliseconds. No retry budget. Recovery was dead for the lifetime of that process.

Fix

  • Route checkDockerAvailability through a package-level dockerResolverFn (default: shellwrap.ResolveDockerPath, fallback: bare "docker"). Test-overridable.
  • Add freshenLoadedDockerRecoveryState helper that resets FailureCount / AttemptsSinceUp / RecoveryMode on the loaded state. Telemetry fields (LastSuccessfulAt, LastError, LastAttempt) are preserved so operators can still see prior context.

Tests

  • TestCheckDockerAvailability_UsesShellwrapResolver — fake docker in temp dir + launchd minimal PATH; would fail with bare exec.
  • TestCheckDockerAvailability_FallbackOnResolverFailure — when resolver errors, bare-name exec via ambient PATH still works.
  • TestFreshenLoadedDockerRecoveryState — counters reset, telemetry preserved.
  • TestFreshenLoadedDockerRecoveryState_NilSafe — defensive nil guard.

Test plan

  • go test -race ./internal/upstream/...
  • go test -race ./internal/secureenv/... ./internal/shellwrap/... ./internal/runtime/... ./internal/storage/...
  • go build ./cmd/mcpproxy and go build -tags server ./cmd/mcpproxy
  • Smoke test: env -i PATH=/usr/bin:/bin:/usr/sbin:/sbin mcpproxy serve with a docker-isolated server. Container stays Up >2 min, zero recovery starts, zero ForceReconnectAll rebuilds, no max-retries log line. Without the fix the same env reproduces the original "stuck Loading" behaviour.

🤖 Generated with Claude Code

…state

When mcpproxy boots from a macOS .app bundle / LoginItem, launchd hands
the parent process PATH=/usr/bin:/bin:/usr/sbin:/sbin. Two bugs combined
to make Docker recovery permanently dead for the lifetime of that boot:

1. checkDockerAvailability used a bare exec.Command("docker", "info").
   Go's exec resolves the bare name via os.Getenv("PATH") — i.e. the
   launchd minimal set — so it failed with `executable file not found in
   $PATH` even though /Applications/Docker.app/Contents/Resources/bin/
   docker is right there. Every other docker call site in the codebase
   already routes through shellwrap.ResolveDockerPath (which probes
   well-known install locations and the user's login-shell PATH); the
   recovery monitor was missed during that migration.

2. startDockerRecoveryMonitor loaded persisted DockerRecoveryState
   verbatim, including FailureCount. After a previous process bled out
   at the retry limit, the new process inherited attempt=10 and the
   recovery loop's `attempt >= maxRetries` guard fired on the first
   probe — exiting in milliseconds without ever sleeping. Logs showed
   the symptom: "Docker recovery max retries exceeded (attempts=10)"
   5 ms after "Docker unavailable on startup".

Fix:
- Route checkDockerAvailability through dockerResolverFn (default:
  shellwrap.ResolveDockerPath, fallback: bare "docker"). Test-overridable.
- Add freshenLoadedDockerRecoveryState helper that resets FailureCount /
  AttemptsSinceUp / RecoveryMode on the loaded state. Telemetry fields
  (LastSuccessfulAt, LastError, LastAttempt) are preserved.

Tests:
- TestCheckDockerAvailability_UsesShellwrapResolver — installs a fake
  docker in a temp dir, sets PATH=launchd-minimal, asserts the resolver
  is consulted (would fail with bare exec).
- TestCheckDockerAvailability_FallbackOnResolverFailure — when the
  resolver errors, bare-name exec via the ambient PATH still works.
- TestFreshenLoadedDockerRecoveryState — counters reset, telemetry kept.
- TestFreshenLoadedDockerRecoveryState_NilSafe — defensive nil guard.

Verified locally with env -i PATH=/usr/bin:/bin:/usr/sbin:/sbin running
mcpproxy serve: shellwrap resolves docker via the well-known
/Applications/Docker.app path on the very first probe; no recovery loop
runs; no max-retries log line. Without the fix, the same env reproduces
the original "stuck Loading + max retries exceeded in 5ms" pattern.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/docker-recovery-shellwrap-stale-state

Available Artifacts

  • archive-darwin-amd64 (26 MB)
  • archive-darwin-arm64 (23 MB)
  • archive-linux-amd64 (15 MB)
  • archive-linux-arm64 (13 MB)
  • archive-windows-amd64 (26 MB)
  • archive-windows-arm64 (23 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (19 MB)
  • installer-dmg-darwin-arm64 (18 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 25178547330 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit 46a52da into main Apr 30, 2026
23 checks passed
@Dumbris
Dumbris deleted the fix/docker-recovery-shellwrap-stale-state branch April 30, 2026 17:16
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