Skip to content

fix(serve): stop persisting CLI flag and env overrides into the config file - #1299

Merged
Dumbris merged 6 commits into
mainfrom
claude/confident-panini-c552d5
Sep 18, 2026
Merged

Dumbris merged 6 commits into
mainfrom
claude/confident-panini-c552d5

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 18, 2026

Copy link
Copy Markdown
Member

Summary

mcpproxy serve persisted its config at three sites (auto-generated api_key, first-run telemetry notice, recordStartupOutcome) by marshalling the in-memory config — which already carried every CLI flag override. So serve --listen :0 (or --listen "", now mapped to :0) wrote "listen": ":0" into mcp_config.json, and the next unflagged serve or tray-launched core silently booted in stdio mode. Verified empirically 2026-09-17 with a fresh {"mcpServers":[]} config.

What changed

  • serveConfigSaver (cmd/mcpproxy/main.go): loadConfig now returns (cfg, saver, err). saver.save reads the config file as its base (config.ReadFile, snapshot of the same at startup as fallback) and overlays only what serve owns: the API key it generated itself (into an empty api_key only) and cfg.Telemetry. All three save sites use it; recordStartupOutcome takes the save func as a parameter.
  • config.ReadFile (internal/config/loader.go): DefaultConfig() + loadConfigFile, nothing else. LoadFromFile is not a read — it applies MCPPROXY_* env overrides, copies MCPPROXY_API_KEY into api_key via Validate, creates data_dir, and replaces the process-global registry list — none of which a save may do.
  • config.LoadWithPath: Load() discarded the file it discovered (./mcp_config.json or the home file) and runServer re-derived <data_dir>/mcp_config.json, a possibly different, never-loaded file. The saver and NewServerWithConfigPath now use the file that was actually loaded. Load() keeps its signature.

Because the base is the file rather than the live config, this also stops --read-only, --log-level, --disable-management, --data-dir, and MCPPROXY_* env values from leaking through these three sites, and a late fatal-serve save no longer resurrects a startup-era server list over changes the runtime persisted since.

The --listen "" → :0 mapping is untouched.

Not fixed here (pre-existing, same class)

Two other persist paths still marshal the live config with overrides: the telemetry service's anonymous-id persist (internal/telemetry/telemetry.go persistConfigLocked, semver builds only) and Runtime.SaveConfiguration (every API-driven config change). A config-level strip would break the UI's legitimate restart-gated listen edits (internal/runtime/restart_gated.go), so that needs a persisted-vs-effective split — follow-up. Also pre-existing: recordStartupOutcome / MaybePrintFirstRunNotice mutate cfg.Telemetry without the telemetry service's mutex.

Tests

cmd/mcpproxy/serve_flag_persistence_test.go drives loadConfig with a cobra command bound to the package globals, then the save sites, and decodes the file as raw JSON:

  • each of the 6 loadConfig flags (incl. --listen :0) + runServer's --read-only/--log-level mutations do not reach the file; generated api_key and telemetry do
  • MCPPROXY_API_KEY and MCPPROXY_LISTEN are never written
  • a late save keeps servers/settings the runtime persisted after startup, and a key rotated later
  • the fallback (file vanished) keeps the file's key
  • legacy teams block survives (loader normalization)
  • without --config, saves land in the discovered ./mcp_config.json, not <data_dir>/mcp_config.json

Every test was watched failing against the old behaviour before its fix.

Verification

  • go test ./cmd/mcpproxy ./internal/config ✅
  • golangci-lint v2.6.2 with .github/.golangci.yml: 0 issues ✅
  • ./scripts/test-api-e2e.sh: 65/65 (one earlier run had 2 unidentified failures, then 5 consecutive clean runs — timing flake)
  • Cross-review opencode run --model github-copilot/gpt-5.6-sol: 5 rounds; rounds 1–4 each surfaced a genuine issue (late-save clobber, env API key, LoadFromFile side effects, legacy teams erasure, discovery-path mismatch), all fixed with a test; round 5 VERDICT: CLEAN.

🤖 Generated with Claude Code

Dumbris and others added 5 commits September 18, 2026 06:08
`serve` saves the config at three sites (auto-generated api_key, first-run
telemetry notice, recordStartupOutcome) and wrote the in-memory cfg, which
already carried every CLI flag override. `serve --listen :0` therefore
wrote `"listen": ":0"` into mcp_config.json and the next unflagged start
(or the tray-launched core) silently booted in stdio mode.

loadConfig now snapshots the file-loaded config before any flag override
and returns a serveConfigSaver; its save() writes that snapshot plus only
the runtime-generated fields (api_key, telemetry). All three save sites
use it, and recordStartupOutcome takes the save func as a parameter. The
snapshot precedes runServer's own overrides too, so --read-only,
--log-level, --disable-management etc. no longer leak either.

Co-Authored-By: Claude Opus 5 <[email protected]>
…PI key

Cross-review round 1 (gpt-5.6-sol): the fatal-serve-error save can fire
hours after startup and would have written the startup-era snapshot over
servers the runtime persisted since; and Validate() copies
MCPPROXY_API_KEY into cfg.APIKey, so every save wrote that secret to disk.

serveConfigSaver.save now re-reads the file as its base (snapshot only if
the file is unreadable), takes api_key from the raw file, and overlays
only the key serve generated itself plus cfg.Telemetry.

Co-Authored-By: Claude Opus 5 <[email protected]>
Cross-review round 2 (gpt-5.6-sol): config.LoadFromFile is not a read —
it applies MCPPROXY_* env overrides, copies MCPPROXY_API_KEY into api_key
via Validate, creates data_dir and replaces the process-global registry
list; the fallback path dropped a configured key when the file vanished;
and a startup-generated key overrode a key rotated later via the API.

The base is now DefaultConfig + json.Unmarshal of the file (snapshot of
the same at startup as fallback), and the generated key only fills an
empty api_key. This also stops env overrides leaking on the serve path.

Co-Authored-By: Claude Opus 5 <[email protected]>
Cross-review round 3 (gpt-5.6-sol): a bare json.Unmarshal skipped the
read-time normalizations loadConfigFile applies (legacy "teams" →
"server_edition", created stamps), so a serve-time save erased a legacy
teams block. Export config.ReadFile — DefaultConfig + loadConfigFile,
nothing else — and use it as the saver's base so it stays in lockstep
with the loader.

Co-Authored-By: Claude Opus 5 <[email protected]>
Cross-review round 4 (gpt-5.6-sol): without --config, config.Load()
discovers ./mcp_config.json or the home file but discarded the path, and
runServer re-derived <data_dir>/mcp_config.json — a possibly different,
never-loaded file that the merge would read as its base.

Add config.LoadWithPath (Load keeps its signature) reporting the file it
read or created, absolute; the saver carries that path and runServer uses
it for every save and for the runtime's config path.

Co-Authored-By: Claude Opus 5 <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

TestNoDoorPublishesARawServerLeaf keys config-returning functions by
bare name and requires unanimity; a config.ReadFile that returns
*Config tainted every os.ReadFile call in the scanned trees (flagged
internal/tray/managers.go:loadIcon). All five red CI jobs were this
one test.

Co-Authored-By: Claude Opus 5 <[email protected]>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 34.32836% with 44 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/config/loader.go 0.00% 25 Missing ⚠️
cmd/mcpproxy/main.go 55.00% 18 Missing ⚠️
cmd/mcpproxy/startup_outcome.go 50.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: claude/confident-panini-c552d5

Available Artifacts

  • archive-darwin-amd64 (30 MB)
  • archive-darwin-arm64 (27 MB)
  • archive-linux-amd64 (18 MB)
  • archive-linux-arm64 (16 MB)
  • archive-windows-amd64 (30 MB)
  • archive-windows-arm64 (26 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (24 MB)
  • installer-dmg-darwin-arm64 (21 MB)
  • smart-mcp-proxymcpproxy-goX9EU1G.dockerbuild (0 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 35324363616 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit 62bf655 into main Sep 18, 2026
41 checks passed
Dumbris added a commit that referenced this pull request Sep 18, 2026
…gnature

CI on PR #1300 failed to build cmd/mcpproxy on every platform: "assignment
mismatch: 2 variables but loadConfig returns 3 values". Unrelated to this
PR's instance-ID changes -- main itself is currently broken this way (#1299
changed loadConfig to also return a *serveConfigSaver, and the
listen_flag_test.go added by #1301 wasn't updated for it). Discard the
unused saver return to match the real signature.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Dumbris added a commit that referenced this pull request Sep 18, 2026
…p file (#1300)

* fix(docker): scope instance ID to data dir instead of a host-wide temp file

GetInstanceID() persisted to a single filepath.Join(os.TempDir(), ...) file
shared by every process a user runs on a host, so any two concurrent
mcpproxy processes (a scratch dev instance next to the main app, two
separate installs) silently got the SAME instance ID. That defeats
com.mcpproxy.instance container-ownership labels used by
manager.go's cleanup and by the ownership filter added in PR #1298 for
same-host instances (cross-host-shared-daemon cases still work).

Scope the ID to the process's data dir instead (cfg.DataDir, set once via
core.SetInstanceDataDir from upstream.NewManager, the common construction
point for every entry point) since concurrent instances on one host already
require distinct data dirs -- BBolt locks config.db. Fall back to a fresh
per-process UUID when no data dir is known yet. On first run under a data
dir, adopt-then-retire the legacy shared file so pre-upgrade containers
stay cleanable by whichever instance starts first, without letting every
future data dir keep re-adopting the same shared ID.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(docker): close legacy-instance-id adoption race found by cross-review

codex gpt-5.6-sol review of the instance-ID fix (PR #1300) found that
adoptLegacyInstanceID's read-then-remove let two concurrent processes both
read the same legacy id before either deleted the file, recreating the very
host-wide-shared-id bug the fix targets. Claim the legacy file via
os.Rename to a process-unique path instead: rename atomically fails once
another process has already claimed the source, so exactly one process
adopts a given legacy id.

Also fixes a test bug the same review caught: the subprocess helper tests
never overrode legacyInstanceIDPath in the child process, so they could
have adopted-and-deleted a real machine's actual pre-upgrade legacy file.
Threads a scratch path through an env var instead. Adds a goroutine-race
test (50x under -race) proving the claim is exclusive.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(test): make legacy-id claim path unique per call, not just per PID

Windows CI failed TestAdoptLegacyInstanceIDConcurrentClaimIsExclusive
(#1300 windows-amd64
build): all 8 concurrent goroutines got 0 adopters instead of exactly 1.
The test spawns racers as goroutines in one OS process, so they all share
one os.Getpid() and therefore compute the identical claim destination --
a collision that can't happen in real usage (real racers are always
separate processes with distinct PIDs). On Windows that collision made
every racer's rename fail.

Add an atomic per-call sequence number alongside the PID in the claim
path, so it can never collide even when called concurrently within one
process. No behavior change for the real (cross-process) case.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(docker): use a random claim path and preserve claims on save failure

Second codex gpt-5.6-sol review round on PR #1300. opencode's Copilot quota
was still exhausted, so codex gpt-5.6-sol (the documented fallback) reviewed
again. Findings:

1. adoptLegacyInstanceID removed the claimed legacy file unconditionally,
   even when the subsequent save to the new per-data-dir location failed --
   silently losing the id on the next restart. Now the claim file is only
   removed after a successful save; on failure it's left in place so it
   isn't silently destroyed.

2. The PID+sequence claim-path suffix (from the previous round's Windows
   fix) doesn't guarantee cross-restart uniqueness -- PIDs get reused, and
   the review argued a stale claim file from a crash could collide with a
   later process's first claim. Go's os.Rename on Windows actually uses
   MOVEFILE_REPLACE_EXISTING (verified against the Go 1.26 stdlib source),
   so this wouldn't have caused a failure the way the review described, but
   using a random UUID instead of PID+sequence removes any theoretical
   collision outright and is simpler.

3. Test coverage: TestGetInstanceIDDistinctAcrossConcurrentProcesses ran its
   two subprocesses sequentially despite its name; and there was no test of
   the ACTUAL cross-process legacy-claim race (only an in-process
   goroutine simulation, which artificially shares one PID across racers).
   Added TestGetInstanceIDCrossProcessLegacyClaimIsExclusive (two real
   subprocesses racing over one seeded legacy file) and
   TestAdoptLegacyInstanceIDPreservesClaimWhenSaveFails, and made the
   existing "concurrent processes" test actually start both processes
   concurrently.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(test): match TestLoadConfig_ListenFlag to loadConfig's 3-value signature

CI on PR #1300 failed to build cmd/mcpproxy on every platform: "assignment
mismatch: 2 variables but loadConfig returns 3 values". Unrelated to this
PR's instance-ID changes -- main itself is currently broken this way (#1299
changed loadConfig to also return a *serveConfigSaver, and the
listen_flag_test.go added by #1301 wasn't updated for it). Discard the
unused saver return to match the real signature.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Dumbris added a commit that referenced this pull request Sep 18, 2026
…, MCPPROXY_* env or the env API key (#1302)

* fix(serve): stop persisting CLI flag overrides into the config file

`serve` saves the config at three sites (auto-generated api_key, first-run
telemetry notice, recordStartupOutcome) and wrote the in-memory cfg, which
already carried every CLI flag override. `serve --listen :0` therefore
wrote `"listen": ":0"` into mcp_config.json and the next unflagged start
(or the tray-launched core) silently booted in stdio mode.

loadConfig now snapshots the file-loaded config before any flag override
and returns a serveConfigSaver; its save() writes that snapshot plus only
the runtime-generated fields (api_key, telemetry). All three save sites
use it, and recordStartupOutcome takes the save func as a parameter. The
snapshot precedes runServer's own overrides too, so --read-only,
--log-level, --disable-management etc. no longer leak either.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(serve): base serve saves on the current file, never persist env API key

Cross-review round 1 (gpt-5.6-sol): the fatal-serve-error save can fire
hours after startup and would have written the startup-era snapshot over
servers the runtime persisted since; and Validate() copies
MCPPROXY_API_KEY into cfg.APIKey, so every save wrote that secret to disk.

serveConfigSaver.save now re-reads the file as its base (snapshot only if
the file is unreadable), takes api_key from the raw file, and overlays
only the key serve generated itself plus cfg.Telemetry.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(serve): read the merge base without loader side effects

Cross-review round 2 (gpt-5.6-sol): config.LoadFromFile is not a read —
it applies MCPPROXY_* env overrides, copies MCPPROXY_API_KEY into api_key
via Validate, creates data_dir and replaces the process-global registry
list; the fallback path dropped a configured key when the file vanished;
and a startup-generated key overrode a key rotated later via the API.

The base is now DefaultConfig + json.Unmarshal of the file (snapshot of
the same at startup as fallback), and the generated key only fills an
empty api_key. This also stops env overrides leaking on the serve path.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(serve): merge base goes through the loader's read step

Cross-review round 3 (gpt-5.6-sol): a bare json.Unmarshal skipped the
read-time normalizations loadConfigFile applies (legacy "teams" →
"server_edition", created stamps), so a serve-time save erased a legacy
teams block. Export config.ReadFile — DefaultConfig + loadConfigFile,
nothing else — and use it as the saver's base so it stays in lockstep
with the loader.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(serve): save to the config file that was actually loaded

Cross-review round 4 (gpt-5.6-sol): without --config, config.Load()
discovers ./mcp_config.json or the home file but discarded the path, and
runServer re-derived <data_dir>/mcp_config.json — a possibly different,
never-loaded file that the merge would read as its base.

Add config.LoadWithPath (Load keeps its signature) reporting the file it
read or created, absolute; the saver carries that path and runServer uses
it for every save and for the runtime's config path.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(config): rename ReadFile to DecodeConfigFile for the oauth door scan

TestNoDoorPublishesARawServerLeaf keys config-returning functions by
bare name and requires unanimity; a config.ReadFile that returns
*Config tainted every os.ReadFile call in the scanned trees (flagged
internal/tray/managers.go:loadIcon). All five red CI jobs were this
one test.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(config): split persisted config from effective config for process-only overrides

Every persist path saved the LIVE config — the file plus the `serve` CLI
flags, the MCPPROXY_* env overrides and the MCPPROXY_API_KEY that Validate
folds into api_key. PR #1299 fixed serve's own three saves; the runtime's
SaveConfiguration (every API-driven server change) and telemetry's first-run
anonymous_id write still marshalled the whole effective config, so
`serve --listen :0` (or MCPPROXY_LISTEN, or the env API key) landed in
mcp_config.json the first time a server was enabled from the Web UI.

The fix is a process-wide override registry in internal/config:

- OverrideForProcess(cfg, Field, source, value) sets the effective value and
  records (field, process value, file value at load). The loader routes
  every MCPPROXY_* override through it, Validate the env API key, and
  cmd/mcpproxy every serve flag (loadConfig + the new applyServeLoggingFlags /
  applyServeRuntimeFlags).
- PersistableConfig(effective, path) restores the file's current value for
  every field whose effective value STILL equals its override. A field
  edited since (the Settings page changing listen, the tray picking an
  alternate port, an API toggle of read-only) no longer matches and is
  persisted as the edit it is — which keeps the restart-gated listen flow
  working, where a blanket "restore the file value" would have thrown the
  edit away.
- SaveConfig applies it centrally, so runtime, telemetry, the server
  edition's admin handlers and the load-modify-save CLI subcommands are all
  covered. The runtime additionally computes the persistable form for its
  config-watcher self-write markers and the watcher's memory-vs-disk
  comparison, otherwise its own saves would read as external edits and
  reload the file over the hot overrides.

Env-sourced entries are rebuilt on every load (a reload reflects the
variables set now); flag entries survive reloads.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(config): close the review-round-1 gaps in the process-override registry

- EnsureAPIKey let MCPPROXY_API_KEY replace a key the FILE holds without
  recording it, so the next runtime/telemetry save wrote the env secret over
  the file key. Recorded as an env override (only when it actually differs,
  so Validate's record keeps the real file value).
- The registry now keys entries by (field, source): a field overridden by
  env AND a flag keeps both records, and a reload — which rebuilds the env
  set — no longer drops the flag record and turns its value into "an edit".
  A flag layered over an env override inherits the env record's file value
  as its fallback.
- The loader rebuilds the env entries as ONE registry update
  (envOverrideBatch.commit) instead of clear-then-add under separate locks,
  so a save on another goroutine can never observe an empty registry
  mid-reload and persist the overrides.
- ReapplyFlagOverrides re-layers the serve flags onto a freshly reloaded
  config (configsvc.ReloadFromFile and the legacy fallback); the loader only
  re-applies env, so a hand edit of an unrelated key used to switch
  --read-only / --tool-response-mode off.
- Documented the inherent limitation: an explicit edit that sets an
  overridden field to exactly the override's value is indistinguishable from
  a round trip (unreachable from the Web UI, which already shows that value).

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(config): retire superseded overrides; re-apply flags on the running config only

Review round 2:

- An override the running config no longer carries was superseded by an
  API edit (a hot apply, UpdateListenAddress). It is now retired
  (RetireSupersededOverrides, called from ApplyConfig with what the process
  adopted and from SaveConfiguration with the live config), so a reload no
  longer resurrects the flag over the edit, and — the sharper case — an edit
  BACK to the override's value persists as the edit it is instead of being
  swapped for the file value.
- ReapplyFlagOverrides(cfg, live) runs on the runtime's pinned live copy, not
  inside configsvc.ReloadFromFile: the desired config stays the file, so a
  pending file edit of a restart-gated flag field (listen) is still reported
  as pending and not clobbered by a later save. The pinned config is
  republished whenever it differs from the raw file.
- A repeated registration of the same override (loadConfig and runServer
  both applied --tool-response-limit) inherits the previous record's file
  value; the duplicate registration is also removed.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(runtime): reload side effects follow the running config, not the raw file

Review round 3 (Sol, partial — quota): after republishing the pinned +
flag-reapplied config, ReloadConfiguration kept feeding the RAW file
snapshot to the upstream manager, applyComponentConfigLocked (truncator,
logging), telemetry and the update checker — so a hot reload rebuilt the
truncator from the file's tool_response_limit while r.cfg said the flag's.
Parity with ApplyConfig, which applies hotCfg: every side effect now takes
the running config; the restart-required warning still diffs the file.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(config): one effective override per field; retire on what the API saved

Review round 4 (codex gpt-5.6-sol; the opencode Copilot models are out of
monthly quota):

- A flag shadows an env override of the same field, so only that winner may
  decide whether the field was edited. The shadowed env record used to
  intercept an API edit that happened to equal the env value and restore
  the file value instead. PersistableConfig and RetireSupersededOverrides
  now resolve one effective override per field; a superseded field forgets
  its whole stack (the loader re-records env on the next reload).
- ApplyConfig retires against what the API SAVED (newCfg), not the pinned
  hotCfg: editing listen under --listen ends that override for this process
  even though the listener stays bound, so an edit back to the flag's value
  ("cancel the pending change") is persisted as asked — disk, the desired
  config and the API result agree again.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(runtime): desired config keeps the hot flags after a reload; retire only edited fields

Review round 5 (codex gpt-5.6-sol): after a disk reload the desired config
was the raw file, so GET /config showed read_only_mode=false under
--read-only and any unrelated PUT round-tripped that value back — retiring
the flag and hot-applying the file's value.

- ReloadConfiguration's desired config is now pinRestartGated(fileCfg,
  pinned): the file's restart-gated fields (a pending listen edit stays
  pending) with the hot flags riding along, exactly like the startup
  desired config.
- ApplyConfig retires an override only when the apply MOVED the field
  relative to its merge base (RetireEditedOverrides(baseCfg, newCfg)); a
  round trip of a value the base already held is not an edit.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(runtime): retire an edited override before the save, on "moved" alone

Review round 6 (codex gpt-5.6-sol): after a reload the desired listen is
the file's, so an API edit setting it to the flag's own address is a
distinguishable edit (base != next == override) — but retirement ran after
the save and required the value to differ from the override, so
PersistableConfig swapped the edit for the file value and the override
stayed. RetireEditedOverrides now retires every field the apply moved
relative to its merge base, whatever it moved to, and ApplyConfig calls it
before config.SaveConfig.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(runtime): put a retired override back when the save fails

Review round 7 (codex gpt-5.6-sol): retirement precedes the save, so a
transient write failure left the field retired while the live config still
carried the override — the next unrelated save would have written it, for
MCPPROXY_API_KEY the secret, into the file. RetireEditedOverrides returns
what it removed; ApplyConfig restores it on the save error path.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(config): never remove an override record — the editing save ignores it instead

Review round 8 (codex gpt-5.6-sol): removing a record on an API edit
opened a window in which a concurrent save of the still-live config
(telemetry) had no protection and could write MCPPROXY_API_KEY to disk.

Retirement is gone. The save that persists an API edit is
SaveConfigWithEdits(cfg, mergeBase, path): the overridden fields that MOVED
between the merge base (the desired config) and the saved config are the
caller's edits and are written as they are, whatever they moved to; every
other save keeps restoring the CURRENT file value — which after the edit's
save is the edit itself. No mutable state, no window. ApplyConfig uses it
and marks its self-write with the same bytes; ReapplyFlagOverrides skips
(keeps) a flag the live config superseded. All earlier scenarios (toggle
back, cancel a pending listen edit, edit to the flag's own value after a
reload, failed save) are re-expressed as tests against the new seam, plus
a concurrent stale-save test for the api_key leak.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(config): serialise every in-process save's read-base-then-write

Review round 9 (codex gpt-5.6-sol): a save reads the file as its base and
writes a whole replacement, so an API edit landing between another save's
read and write was reverted (the residual window telemetry.persistConfig
documents, widened by the base read). SaveConfigWithEdits now holds one
package mutex across the read and the write, so in-process savers — the
runtime, telemetry, serve's own saves — always read the file the previous
save wrote. A test hook between the two steps pins the schedule.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(config): follow the ReadFile→DecodeConfigFile rename from #1299

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(test): make TestApplyConfig_FailedSaveKeepsTheOverrideProtected Windows-safe

Follow-up to cb35775 (the main merge-conflict resolution for this PR).

The test simulated a failed atomic config save by os.Chmod'ing the config
directory to 0o500. That works on POSIX but Windows does not enforce
Unix-style directory permission bits via os.Chmod the same way, so the
GitHub Actions windows-latest runner could still write into the
"read-only" directory and the save silently succeeded, failing the test
with "An error is expected but got nil".

Replace it with a mechanism that fails identically on every OS: point the
save at a path whose parent is a plain file instead of a directory.
writeConfigFile's os.MkdirAll(dir, 0700) pre-flight does a pure-Go
`Stat(dir); if err == nil && !IsDir() { return ENOTDIR }` check before any
OS-specific mkdir syscall, so this induces the same real write failure on
Linux, macOS and Windows. The broken path is scoped to this one
ApplyConfig call only (the runtime's own cfgPath stays a real writable
directory), so the later SaveConfiguration() still exercises "disk
recovered" for real.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
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