Repository navigation
fix(isolation): report effective isolation state instead of treating inherit as disabled - #1152
Merged
Merged
Conversation
`IsolationConfig.Enabled` is a *bool whose nil means "inherit the global isolation setting". `IsEnabled()` returned false for nil, so every caller that asked it "is this server isolated" got the wrong answer for the most common configuration — a server that inherits an enabled global setting and is genuinely running in a container. Delete `IsEnabled()` rather than renaming it, so the compiler surfaces every call site, and replace it with three predicates named for the question they actually answer: `HasEnabledOverride`, `IsExplicitlyEnabled`, `IsExplicitlyDisabled`. None of them can be misread as "is this isolated". That question now has exactly one answer: `config.ResolveIsolation`, which combines the global mode, the per-server override and the structural gates, and reports the deciding rule (`Source`) so "inherit" becomes a distinguishable, explainable state instead of a guess. `upstream/core.IsolationManager.ResolveIsolation` wraps it to keep the deduplicated ignored-opt-in warning, and `ResolveMode`/`ShouldIsolate` now delegate — pinned by a test asserting they never drift. The resolver lives in `config`, not `upstream/core`, because `contracts` must run the same algorithm and cannot import core without an import cycle. Also fixes a second defect in the same struct, found while auditing it: `copyIsolationConfig` and `MergeIsolationConfig` never touched `Mode`, so patching any unrelated isolation field silently erased a server's per-server isolation mode — the primary MCP-34.2 override. Both now carry it, deep-copied. `upstream/manager.go`'s Docker-recovery predicate keeps its existing behaviour (it always meant "explicit opt-in"); the rename is guarded by a new test over the full tri-state. Refs #1142
Every read surface flattened the tri-state per-server override into a single bool, so an inheriting server — running in a container — was reported as `enabled: false` and rendered as unisolated in the Web UI, the tray and the MCP payload. That is the bug in #1142. `isolation.enabled` now carries the EFFECTIVE state, and the raw override travels beside it as `enabled_override` (present only when actually set), plus `mode_override` for the previously invisible MCP-34.2 mode. A new `isolation_effective` block reports `{mode, isolated, global_mode, inherited, source}` so a client can say WHY rather than guessing — `source` is a documented, extensible vocabulary; unknown values mean "inherit". `enabled` stays a non-pointer, always-present bool deliberately: the macOS tray decodes it as a non-optional Swift Bool, so omitting or nulling it would fail Codable for the entire server payload and blank the server list on an older tray. An un-updated client now simply gets a true answer. The block is emitted for every stdio server, including those with no `isolation` key at all — the other half of the reported bug was clients doing `isolation?.enabled ?? false` on an absent block. Fixed along the live path, not just the pretty one: `contracts` `ConvertServerConfig` turned out to be test-only, while the real chain is `runtime.GetAllServers` (map) -> `management.Service` (map -> contracts). Both now go through one shared projection. `ConvertServerConfig` gains the global isolation config so it cannot produce an unresolvable answer. The isolation manager is built once per `GetAllServers` call instead of per server. On the MCP side, `docker_isolation.applies_to_server` was `ShouldIsolate` (docker-only), so a sandbox-isolated server reported false; it is now the resolved `Isolated`. The `server_isolation` sub-block stays deliberately RAW — it is named for the raw view — but omits `enabled` when the override is nil instead of flattening it. Web UI: the Docker Isolation panel leads with the resolved state and its explanation ("Isolated (docker) — Inherits the global setting (docker)"). Refs #1142
…r given `IsolationRequest.Enabled` was a *bool, so an omitted key and a cleared key were the same wire shape: an inheriting server could never be restored once anything wrote an explicit opt-out, and any client that echoed back the (wrongly flattened) `enabled` it had just read would persist one. `Enabled` becomes a `NullableBool` with three states — absent (leave alone), `null` (clear back to inheriting the global setting), and an explicit true/false. `toConfig()` becomes `resolve(existing)`, starting from `CopyIsolationConfig(existing)` so the fields this request type does not expose — `mode`, `log_driver`, `log_max_size`, `log_max_files` — survive a partial patch instead of being dropped. Because the handler now hands over a fully-resolved struct, `Server.UpdateServer` replaces the isolation block wholesale rather than merging non-zero fields. That old merge was itself why clearing any individual override was impossible. `UpdateServer` has one production caller that ever sets `Isolation` (the PATCH handler); the other leaves it nil, which still means "leave unchanged". `mode_override` is added to the request so the MCP-34.2 mode is writable over REST at all. Refs #1142
The macOS tray was a data-corruption path, not just a display bug.
`ServerDetailView` seeded a two-state Docker Isolation toggle from
`server.isolation?.enabled ?? false` — the flattened value, which read
`false` for a server that merely INHERITED global isolation — and then
force-added `enabled` to every isolation PATCH ("always include `enabled`
alongside any sub-field change"). Editing an unrelated field such as the
image therefore persisted an explicit opt-out and silently took a running,
containerised server out of its container. The user was never asked.
`AddServerView` had the create-side version: it emitted
`isolation: ["enabled": dockerIsolation]` unconditionally for stdio, so
every server added from the tray with the default-off toggle got a
permanent explicit opt-out that would ignore global isolation forever. It
now emits the key only when the toggle is on, matching
AddServerModal.vue.
The toggle becomes a three-state picker (Inherit global / Always isolate /
Never isolate) seeded from the RAW `enabled_override`, and `enabled` is sent
ONLY when the picker actually moved — as `true`, `false`, or JSON `null` to
return to inheriting. The patch builder is extracted as a pure static
function so that rule is unit-tested without a running app.
The read-only Config tab now shows the effective state and why
("Isolated (docker) — Inherits the global setting (docker)") instead of a
flag that could not distinguish inherit from opt-out.
Refs #1142
…laiming isolation the spawn path won't deliver Four defects found reviewing the GH #1142 fix, all in the same seam: the read path's new effective-state reporting and the write path disagreed about what `isolation.enabled` means, and `Isolated` was computed from config alone. 1. REST `mode_override` was cast straight to config.IsolationMode with no validation, so PATCH/POST {"isolation":{"mode_override":"bogus"}} returned 200, was persisted to BBolt and mcp_config.json, and only surfaced as a failed config validation on the NEXT daemon start. Same hole on the MCP `upstream_servers` `isolation_json` argument. Both seams now call the shared config.ValidateIsolationModeOverride and reject with a message naming the accepted vocabulary, following the invalidTrustModeMessage pattern. 2. ResolvedIsolation.Isolated was `Mode != none`, which claimed isolation the launcher does not deliver: `wrapWithSandbox` returns the command UNCHANGED off Linux and on kernels without Landlock, and a mode the launcher does not implement (including a pointer-to-"" `isolation.mode`, documented as "unset") falls through every branch and runs unwrapped. Isolated is now gated on what the spawn path actually does, with two new source values — `sandbox-unavailable` and `unsupported-mode` — surfaced through REST/MCP, the Web UI and the tray. Mode is deliberately left alone so the spawn decision is unchanged (the sandbox wrapper still applies its rlimits on Linux) and there remains exactly one mode algorithm. An empty per-server mode now inherits, as documented, instead of resolving to a mode nothing implements. 3/4. `isolation.enabled` meant EFFECTIVE state on reads but set the RAW tri-state override on writes, so any read-modify-write client converted "inherits the global setting" into a permanent explicit override — and with global isolation off, an operator's standing `enabled:true` read back as false and would be written back as an opt-out. Reads and writes now use disjoint key names: `enabled` is read-only and refused with a 400 naming `enabled_override`, which is the writable tri-state (absent = leave, null = clear, bool = set). The macOS tray writes `enabled_override` on both the add and edit paths; an older tray's echo is rejected, so the raw override survives the round trip instead of being silently rewritten. Docs, swagger and the generated TS contracts updated to match.
… key, and route Docker classification through the resolver Round-3 review follow-ups on GH #1142. The release QA gate's quarantine-flow fixture still added its server with `isolation: {enabled: false}`. That key became read-only on writes in this branch, so POST /api/v1/servers now answers 400 and the gate's add-server step — plus every invariant downstream of it — would have failed in CI. The opt-out itself is load-bearing (the fixture runs a HOST binary and must stay native when the docker matrix cell turns global isolation on), so the gate keeps opting out, via the writable `enabled_override`. The body is extracted into quarantineFixtureAddRequest so a unit test can decode it with the server's own request type and fail exactly when the handler would reject it. A repo-wide sweep for other in-tree writers found none: the remaining `isolation.enabled` sites are config-FILE stanzas (cmd/release-gate/matrix.go, scripts/run-web-smoke.sh) or the MCP `isolation_json` surface, which maps straight onto config.IsolationConfig and is unaffected. Docker classification was still implemented twice by hand, from the two legacy booleans only, so it disagreed with the spawn decision in both directions once isolation MODES were involved: a server with `mode: "docker"` and a legacy `enabled: false` is Docker-spawned but was classified non-Docker (generic stdio ENOENT remediation instead of the #696 Docker guidance, no image enrichment, and the short connect timeout mid image-pull), while a `mode: "sandbox"` server under global Docker isolation — and one whose command already invokes docker — were classified Docker-isolated. Both sites now delegate to config.ResolveIsolation, so there is genuinely one algorithm. Also restores @ViewBuilder to configToggleRow: the new static buildIsolationPatch had been inserted directly beneath the attribute, which silently moved it onto a non-View function returning [String: Any]?.
…ervers, and route recovery through the resolver Round-4 review follow-ups on GH #1142. Round 3 routed managed.Client.IsDockerIsolated through config.ResolveIsolation. That was right for the SPAWN question but wrong for the one the predicate actually answers: it feeds only Manager.resolveConnectTimeout, where true raises the connect budget from the resolved init_timeout (30s by default) to a 3-minute floor. The resolver's already-docker structural gate forces mode=none for a server whose OWN command is `docker` — correct, we must never double-wrap it — so such a server silently lost the image-pull grace period and could be killed mid-pull. "Which wrapper do we apply" and "does this server pay Docker startup latency" are two different questions that had been sharing one predicate. They are now named separately. config.ServerDependsOnDocker is built ON TOP of the resolver plus the already-docker structural fact — we containerise it, OR it containerises itself — so there is still exactly one implementation of the isolation algorithm and the two questions cannot silently collapse again. managed.Client.IsDockerIsolated becomes DependsOnDocker and delegates to it. The third classification site, Manager.shouldEnableDockerRecovery, was still hand-rolled from the two legacy booleans and never consulted isolation MODES. It gates the Docker recovery monitor and, via UsesDockerIsolation, shutdown container-cleanup verification — so a global `{mode:"docker", enabled:false}`, or a per-server `isolation.mode:"docker"` with the global flag off, really did containerise servers while recovery stayed off and shutdown skipped cleanup, leaking containers. It now composes the two halves of its question explicitly: the GLOBAL half stays forward-looking (the monitor starts once at construction but servers are added at runtime, so a global resolved mode of docker enables it regardless of the current server list), and the PER-SERVER half applies ServerDependsOnDocker to each configured server. One behaviour change falls out: a legacy per-server `enabled:true` under a none global mode, which the resolver IGNORES, no longer starts the monitor for containers that never exist.
Deploying mcpproxy-docs with
|
| Latest commit: |
bad3896
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://4284c1cd.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-1142-isolation-effective.mcpproxy-docs.pages.dev |
…ifacts oas/docs.go conflicted because both sides regenerated it. Resolved by re-running 'make swagger' over the merged annotations so the spec carries both the bench endpoints from main and the isolation enabled_override / isolation_effective fields from this branch.
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 33426947108 --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.
Fixes #1142.
The problem
isolation.enabledis a*boolwherenildocuments "inherit global".IsolationConfig.IsEnabled()returnedfalsefornil, so every read surface reported servers as unisolated while they were running isolated.Reproduced on
main— persisted config, API answer, and reality disagreeing:The spawn path was always correct (
resolveConfiguredModedowngrades only on an explicitfalse). The defect was purely in reporting — and reporting isolation as off when it is on is the wrong direction to be wrong in for a containment feature.What this changes
IsEnabled()deleted, not renamed — the compiler surfaces all call sites, and no replacement name (HasEnabledOverride/IsExplicitlyEnabled/IsExplicitlyDisabled) can be misread as "is this server isolated". That question now has exactly one answer.config.ResolveIsolationreturns{Mode, Isolated, GlobalMode, Source};ResolveModedelegates to it, so the reported state and the spawn decision cannot drift.isolation_effectiveblock makes "inherit" a first-class state instead of a guess:{"mode":"docker","isolated":true,"global_mode":"docker","inherited":true,"source":"global"}Isolatedreflects delivered confinement, not intent.sandboxmode on macOS/Windows, or on a Linux kernel without Landlock, runs unconfined — it now reportsisolated:falsewith sourcesandbox-unavailablerather than claiming protection that does not exist. Unrecognised and empty modes likewise (unsupported-mode).Modeis deliberately not downgraded, so the launcher still applies the Linux-without-Landlock rlimits.enabledis read-only (effective state);enabled_overrideis the writable tri-state. A read-modify-write client can no longer silently convert "inherit" into a permanent explicit override — it gets a 400 naming the right field.mode_overriderejected with a 400 that names the vocabulary, on REST and on the MCPisolation_jsonsurface, instead of being persisted into a config file the next daemon start refuses to load.enabledto every isolation PATCH, so editing an image silently wrote a permanent opt-out.AddServerViewdid the same unconditionally for every stdio server added from the tray.supervisor.usesDockerIsolation,managed.Client, andManager.shouldEnableDockerRecoveryall route through the resolver, so mode-based isolation now gets recovery monitoring and shutdown container cleanup.ServerDependsOnDockerseparates "we containerise it" from "it pays Docker startup latency", so a server whose own command isdockerkeeps the 3-minute connect budget and is not killed mid image-pull.Verification
Live instance, final build:
Gates:
go build ./...,-tags server,go test ./internal/... -race,go test ./cmd/... -race, golangci-lint v2 → 0 issues,make swaggerin sync, frontend vitest +vue-tscclean, Swift 1160/1161 (the one failure,AppLifecycleTests.testTheSharedJournalNeverWritesToTheRealInstanceRootUnderTests, fails identically on cleanmain— pre-existing/environmental).Review
Four fix→re-review rounds, findings from an independent
opencodecross-review (gpt-5.6-sol) and a three-lens adversarial pass. The two reviewers independently converged on the unvalidatedmode_overrideand the sandbox over-claim. Round 3 introduced a connect-timeout regression that round 4 caught and fixed. Final verdict: clean.Every new test was proven to fail against the unfixed code first.
Deliberate breaking change
POST/PATCH /api/v1/serverswith{"isolation":{"enabled":…}}now returns 400 directing callers toenabled_override. Silently dropping the write would be the same class of bug this PR fixes, and the repo already prefers loud self-diagnosing 400s (invalidTrustModeMessage). In-tree writers were swept: the macOS tray andcmd/release-gateare updated. The MCPisolation_jsonargument is untouched and keeps raw-config semantics.One test assertion added earlier in this branch is deliberately inverted: a legacy per-server
enabled:trueunder anoneglobal mode no longer enables Docker recovery, because the resolver reportsserver-opt-in-ignoredand the server is never containerised.