Repository navigation
fix(upstream): docker recovery survives launchd minimal PATH + stale state - #441
Merged
Merged
Conversation
…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]>
Deploying mcpproxy-docs with
|
| Latest commit: |
18c9280
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cff2a166.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-docker-recovery-shellwra.mcpproxy-docs.pages.dev |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 25178547330 --repo smart-mcp-proxy/mcpproxy-go
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs combined to make Docker recovery permanently dead when mcpproxy boots from a macOS
.appbundle / LoginItem (launchd hands the parentPATH=/usr/bin:/bin:/usr/sbin:/sbin):checkDockerAvailabilityskipped shellwrap — used a bareexec.Command("docker", "info")whose lookup goes throughos.Getenv("PATH"). Every other docker call site in the codebase (runtime.IsDockerAvailable,core/docker.go,management/diagnostics,security/scanner/docker) already usesshellwrap.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.Persisted
FailureCountwas inherited verbatim —startDockerRecoveryMonitorloaded prior state, includingFailureCount=10from the previous process. The recovery loop'sattempt >= maxRetriesguard then fired on the very first probe and exited in milliseconds without ever sleeping. Logs showed:Five milliseconds. No retry budget. Recovery was dead for the lifetime of that process.
Fix
checkDockerAvailabilitythrough a package-leveldockerResolverFn(default:shellwrap.ResolveDockerPath, fallback: bare"docker"). Test-overridable.freshenLoadedDockerRecoveryStatehelper that resetsFailureCount/AttemptsSinceUp/RecoveryModeon 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/mcpproxyandgo build -tags server ./cmd/mcpproxyenv -i PATH=/usr/bin:/bin:/usr/sbin:/sbin mcpproxy servewith a docker-isolated server. Container stays Up >2 min, zero recovery starts, zeroForceReconnectAllrebuilds, no max-retries log line. Without the fix the same env reproduces the original "stuck Loading" behaviour.🤖 Generated with Claude Code