Repository navigation
fix: apply tool inventories in capture order so stale captures cannot overwrite newer state (Spec 117 PR-3; #1565) - #1609
Merged
Conversation
Every upstream tools/list now carries a managed.InventoryCapture
{Seq, Epoch, Client}: a process-global sequence stamped by the flight
leader before the upstream request and shared with coalesced waiters.
The manager retires replaced and removed clients, and the sweep gets one
capture per server (DiscoverToolsReportCaptured).
The runtime admits each inventory under the server's tool-approval lock,
in the same hold as its record, index, last-good snapshot and StateView
writes (Spec 116 D15): a capture older than one already applied, or from
a retired or reconnected client, writes nothing; a lenient empty result
is an observation fence; the approval reindex and the sweep fallback
re-apply the retained snapshot only while its capture is still current,
and otherwise re-list or skip.
Related #1565
Deploying mcpproxy-docs with
|
| Latest commit: |
e07f36c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2a3c1a9e.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-117-pr3-capture-ordering.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 38330762638 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…nt-empty observation (Spec 117 PR-3 T306(5r))
Dumbris
added a commit
that referenced
this pull request
Oct 13, 2026
…he current instance in the inventory stress test (Spec 116 PR3 resync) Under Spec 116 PR3 a commit that changes Quarantined unregisters the instance under captureMu (retiring it) and the commit's connect worker installs the instance of the new generation asynchronously. The #1609 stress test required GetClient to succeed synchronously after the final unquarantine, which fails whenever the last toggle left the server quarantined (5/20 under GOMAXPROCS=2). Wait for the current instance to be registered and connected; the final capture and the index/approval consistency check are unchanged.
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.
Scope
Spec 117 PR-3 only (#1565): tool inventories are applied in the order they were captured, so an older
tools/listresult that reaches the apply late cannot overwrite newer approval records, index entries, last-good snapshots or StateView (dispatch) hints.tools/listcarriesmanaged.InventoryCapture{Seq, Epoch, Client}. The flight leader stamps it from a process-global counter when it owns the list and before the upstream request; coalesced waiters get the capture of the flight they joined (held in the existing per-flightlistToolsCall). New:ListToolsCaptured,ListToolsFreshCaptured.ListTools/ListToolsFreshkeep their signatures.Client.Retire()(atomic flag) is set by the manager when it replaces (endpoint change) or removes a client, undercaptureMuW.CaptureIsCurrent= same client, not retired, connection epoch unchanged.Manager.DiscoverToolsReportCapturedreturns one capture per listed server, from that server's own list.admitInventoryHeldruns under the server's tool-approval lock, in the same hold as every write of the pass, in all inventory paths: sweep, single-server discovery (connect,tools/list_changed, refresh), quarantined review capture, lenient-empty observation, and the snapshot reconciliations (approval reindex, sweep fallback).appliedand writes nothing else.lastGoodToolsgets a parallellastGoodCaptureand is replaced only by a newer-or-equal capture.Design decisions and deviations from the spec
Main already had a lot of the original design when this was written. Spec 116 D15 already runs the eligibility check, decisions, deletes, eviction, index writes, last-good snapshot and StateView publish in one approval-lock hold. Every ineligible writer (quarantine, disable, PATCH, reload, restart persist) is a
Runtime.Committhat stores the row and purges the index under that lock, which closed G8 and G9. Details are inspecs/117-review-bound-approvals/research.md→ "PR-3 implementation notes".No separate
publishedcounter. The StateView publish already runs inside the admitted hold, soappliedgates it.appliedanddefinitionsadvance at admission. A newer capture whose apply later fails still fences older ones, and the retained snapshot is not re-applied over its partial writes (the reindex re-lists instead). This is the fence half of FR-018.No
Manager.WithCaptureCurrent. Currency is a lock-free atomic check under the approval lock. A reconnect or replacement after the check produces a newer capture, and that capture has to take the same lock. HoldingepochMuacross a 320-tool apply would block connect/disconnect. The quarantined capture keeps main's outerWithCurrentClientOnEpochwrapper. No new lock edge is added in either direction.Not in this PR (follow-up):
ErrReviewNotRecorded/503;These cover storage-failure modes and do not depend on ordering. FR-034/FR-035 writer routing (
persistServerIneligibleLocked, the CI guard script) is superseded by Spec 116's single commit pipeline.Lock order
Unchanged:
configCommitMu(Spec 116) →captureSnapMu→ per-server approval lock → storage / index / supervisor state. The new code takes no lock of its own. Inside the approval lock it only reads two client atomics (retired,connectionEpoch).Retireis an atomic store made under the manager's existingcaptureMu+musection.Compatibility
tools/list) instead of re-applying the old connection's snapshot.Verification
Failing first on main (942afe6): 4 tests in
internal/runtime/inventory_capture_order_test.go:changedhold;All pass on the fix.
Other new tests (pass on the fix):
-racestress test (refresh, sweeps, reindex, approve/block/enable, quarantine-toggle commits, upstream flips) with a goroutine dump on timeout.Test lanes:
go test -race -tags server -timeout 30m -skip "E2E|Binary|MCPProtocol|TestInfoEndpoint|TestGracefulShutdownNoPanic|TestSocketInfoEndpoint" ./internal/...: green../scripts/test-api-e2e.sh(scratch port): 70/70.go test ./tests/tpa-attack-lab/: ok.make build: ok.--build-tags server: no finding in changed files.Live reproduction on main, without test hooks:
read_notedestructive and a refresh holds it aschanged.call_tool_readreaches the upstream.The fixed binary drops the stale capture ("Tool inventory dropped: a newer capture was already applied").
read_notestays held and unindexed, andcall_tool_readis refused with 0 upstream calls. After operator approval, the index anddescribe_toolcarry the destructive hints. A restart keeps this state.SC-005: 320-tool refresh, median ~49 ms on main vs ~48 ms on the fix.
Concurrency loop: 50 iterations of refresh + approve + quarantine toggle. Status latency is ≤10 ms, and the review state and the index agree at the end.
Cross-model review (zcode / Opus concurrency review per T313) is left to the lead.
Fixes #1565
🤖 Generated with Claude Code