Skip to content

fix(isolation): report effective isolation state instead of treating inherit as disabled - #1152

Merged
Dumbris merged 8 commits into
mainfrom
fix/1142-isolation-effective-enabled
Sep 1, 2026
Merged

Dumbris merged 8 commits into
mainfrom
fix/1142-isolation-effective-enabled

Conversation

@Dumbris

@Dumbris Dumbris commented Aug 31, 2026

Copy link
Copy Markdown
Member

Fixes #1142.

The problem

isolation.enabled is a *bool where nil documents "inherit global". IsolationConfig.IsEnabled() returned false for nil, so every read surface reported servers as unisolated while they were running isolated.

Reproduced on main — persisted config, API answer, and reality disagreeing:

persisted:      [{"image": "node:20"}]        <- no `enabled` key: inherit
API reports:    {"enabled": false, ...}       <- wrong
docker ps:      node:20 ... running           <- actually isolated

The spawn path was always correct (resolveConfiguredMode downgrades only on an explicit false). 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.
  • One resolver: config.ResolveIsolation returns {Mode, Isolated, GlobalMode, Source}; ResolveMode delegates to it, so the reported state and the spawn decision cannot drift.
  • New isolation_effective block makes "inherit" a first-class state instead of a guess:
    {"mode":"docker","isolated":true,"global_mode":"docker","inherited":true,"source":"global"}
  • Isolated reflects delivered confinement, not intent. sandbox mode on macOS/Windows, or on a Linux kernel without Landlock, runs unconfined — it now reports isolated:false with source sandbox-unavailable rather than claiming protection that does not exist. Unrecognised and empty modes likewise (unsupported-mode). Mode is deliberately not downgraded, so the launcher still applies the Linux-without-Landlock rlimits.
  • Read/write keys separated. enabled is read-only (effective state); enabled_override is 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.
  • Unknown mode_override rejected with a 400 that names the vocabulary, on REST and on the MCP isolation_json surface, instead of being persisted into a config file the next daemon start refuses to load.
  • macOS tray fixed — it seeded its isolation editor from the flattened bool and force-added enabled to every isolation PATCH, so editing an image silently wrote a permanent opt-out. AddServerView did the same unconditionally for every stdio server added from the tray.
  • Docker classification unified: supervisor.usesDockerIsolation, managed.Client, and Manager.shouldEnableDockerRecovery all route through the resolver, so mode-based isolation now gets recovery monitoring and shutdown container cleanup.
  • ServerDependsOnDocker separates "we containerise it" from "it pays Docker startup latency", so a server whose own command is docker keeps the 3-minute connect budget and is not killed mid image-pull.

Verification

Live instance, final build:

1. isolation:  {"enabled": true, "image": "node:20"}
   effective:  {"mode":"docker","isolated":true,"global_mode":"docker",
                "inherited":true,"source":"global"}
   persisted:  [{"image": "node:20"}]      <- tri-state intact on disk
   docker ps:  1 node:20 container          <- report matches reality
2. PATCH {"isolation":{"enabled":false}}        -> HTTP 400 (read-only)
3. PATCH {"isolation":{"mode_override":"bogus"}} -> HTTP 400
4. PATCH {"isolation":{"image":"node:22"}}       -> HTTP 200
   persisted: [{"image": "node:22"}]      <- no `enabled` injected

Gates: go build ./..., -tags server, go test ./internal/... -race, go test ./cmd/... -race, golangci-lint v2 → 0 issues, make swagger in sync, frontend vitest + vue-tsc clean, Swift 1160/1161 (the one failure, AppLifecycleTests.testTheSharedJournalNeverWritesToTheRealInstanceRootUnderTests, fails identically on clean main — pre-existing/environmental).

Review

Four fix→re-review rounds, findings from an independent opencode cross-review (gpt-5.6-sol) and a three-lens adversarial pass. The two reviewers independently converged on the unvalidated mode_override and 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/servers with {"isolation":{"enabled":…}} now returns 400 directing callers to enabled_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 and cmd/release-gate are updated. The MCP isolation_json argument is untouched and keeps raw-config semantics.

One test assertion added earlier in this branch is deliberately inverted: a legacy per-server enabled:true under a none global mode no longer enables Docker recovery, because the resolver reports server-opt-in-ignored and the server is never containerised.

`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.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

…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-commenter

codecov-commenter commented Aug 31, 2026 •

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/1142-isolation-effective-enabled

Available Artifacts

  • archive-darwin-amd64 (29 MB)
  • archive-darwin-arm64 (26 MB)
  • archive-linux-amd64 (17 MB)
  • archive-linux-arm64 (15 MB)
  • archive-windows-amd64 (29 MB)
  • archive-windows-arm64 (26 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (23 MB)
  • installer-dmg-darwin-arm64 (21 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 33426947108 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit 84ef98c into main Sep 1, 2026
42 checks passed
@Dumbris
Dumbris deleted the fix/1142-isolation-effective-enabled branch September 1, 2026 02:39
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.

isolation.enabled: nil (inherit global) is reported as false, so isolated servers display as unisolated

2 participants