Skip to content

fix(runtime): make quarantined capture replacement tests deterministic (Spec fix-1453) - #1455

Merged
github-actions[bot] merged 3 commits into
mainfrom
fix-1453-quarantine-capture-race
Oct 1, 2026
Merged

github-actions[bot] merged 3 commits into
mainfrom
fix-1453-quarantine-capture-race

Conversation

@Dumbris

@Dumbris Dumbris commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #1453

Root cause

This is a test bug, not a production ordering bug. The capture path persists only inside the manager's current-client critical section after re-checking the client pointer, the connection epoch and the supervisor discovery generation, so a response from a replaced connection can never be written.

TestCaptureQuarantinedToolDefinitions_DropsReplacementBeforePersist swapped the manager entry to server B directly and left the desired config at A. It also started the capture before startup had settled. Several startup actors still carried the initial config: the asynchronous AddServer in LoadConfiguredServers, the supervisor's delayed 500ms startup reconcile, and the capture's own inspection-exemption reconcile. When one of them ran after the test hook it correctly reconciled the manager back to the desired config, replacing B with a fresh A. The capture then retried against that genuinely current client and stored old_definition, never current_definition, which is the exact signature in #1453. Slower runners (Windows CI) widen all three windows. The two sibling tests share the same family of races.

Flakes fixed

All four are test-only; no production behaviour changes.

  1. TestCaptureQuarantinedToolDefinitions_DropsReplacementBeforePersist (Flaky on Windows: TestCaptureQuarantinedToolDefinitions_DropsReplacementBeforePersist (stale definition persisted) #1453): startup actors reconciled the manager back to the desired config after the test's direct swap.

  2. The two sibling capture-replacement tests, which share the same startup-settling race.

  3. TestDescribeToolCheck_ReadySetPayload: stateSnapshot.IndexedGH (and the approvals slice) compared JSON in index iteration order, which is not deterministic, so an identical set intermittently differed only in order. The snapshot now sorts by name before marshalling; verified with -count=50 (plain and -race).

  4. TestSearchRegistryServers_CacheEntryIsStampedInternal (internal/runtime/registry_cache_stamp_test.go, shuffle lane): the fake registry counted every request reaching its loopback port, including a stray request from another package's test binary that reused the port. It now counts only GET ?version=latest with an atomic counter and restores the package-global registry list on cleanup. Production fetches once and serves the second search from cache.

Changes

  • Supervisor gains a small read-only observability seam, ReconcileQuiescent(), backed by an in-flight action counter and a "startup reconcile has run" flag. It is never consulted by production logic and follows the existing CaptureReplacementQueued precedent.
  • The three capture-replacement tests settle startup through a shared helper (startup reconcile finished, initial client created, inspection exemption granted, connection bound) before the test begins, with no sleeps.
  • The drops-replacement test now replaces through the production desired-config path (UpdateConfig and the supervisor reconcile) instead of poking the manager.
  • No change to capture or production ordering. No user-visible change on any surface (REST, MCP, CLI, Web UI, macOS). No spec documents are affected.

Tests

  • New TestSupervisor_ReconcileQuiescent (false before startup reconcile, false while an action is in flight, true once everything finishes).
  • Load stress, 12 parallel race-enabled test binaries with GOMAXPROCS=1, 120 runs of each of the four capture tests: the original tests failed 10 times (1 drops-replacement, 9 serializes); the hardened tests failed 0 times.
  • go test -race ./internal/runtime/... passes, including repeated -count runs at GOMAXPROCS=1.

Follow-up

Out of scope here and to be filed separately: supervisor reconcile actions can execute plans computed from a superseded config snapshot or exemption state (a late connect with the old config landing after a newer reconnect, and a stale disconnect landing after an inspection exemption).

#1453)

Add a read-only supervisor ReconcileQuiescent seam and settle startup
actors before the capture-replacement tests swap clients. The drops-
replacement test now replaces through the desired-config reconcile path.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 45082df
Status: ✅  Deploy successful!
Preview URL: https://534ef723.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-1453-quarantine-capture.mcpproxy-docs.pages.dev

View logs

F3.1: harden TestSearchRegistryServers_CacheEntryIsStampedInternal against
the shuffle-lane flake. Count only the registry list request (GET with
version=latest) with an atomic counter so a stray request cannot inflate
the fetch count, and reset the process-wide registry list and relaxed SSRF
flag with t.Cleanup(registries.SetRegistriesFromConfig(nil)).
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix-1453-quarantine-capture-race

Available Artifacts

  • archive-darwin-amd64 (31 MB)
  • archive-darwin-arm64 (28 MB)
  • archive-linux-amd64 (18 MB)
  • archive-linux-arm64 (17 MB)
  • archive-windows-amd64 (31 MB)
  • archive-windows-arm64 (27 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (26 MB)
  • installer-dmg-darwin-arm64 (24 MB)
  • smart-mcp-proxymcpproxy-goQRCQPZ.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 36844593772 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@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

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved (Model B): Paperclip review verdicts = ACCEPT and qa-gate green at this head SHA. Arming auto-merge; GitHub merges when all required checks pass.

@github-actions
github-actions Bot merged commit 542143f into main Oct 1, 2026
59 checks passed
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.

Flaky on Windows: TestCaptureQuarantinedToolDefinitions_DropsReplacementBeforePersist (stale definition persisted)

2 participants