← Back to Pull requests

router: test that members who leave leave nothing behind #759

Open
unknown opened this pull request with 567 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 19, 2026 12:27 UTC
Author

Refs #277

This is the regression test offered on #277 for the remaining item 1, router memory after members leave. As discussed there, it is parked until both upstream fixes are released:

  • libp2p/go-libp2p-pubsub#735: gossipsub keeps the writer context of every peer it ever talked to.

  • libp2p/go-libp2p#3559: pstoremem never expires addrs downgraded from ConnectedAddrTTL.
  • Once both are in a release, the change that bumps go-libp2p-pubsub and go-libp2p removes the two skips, and CI checks the pickup from then on.

    What the test does

    TestRouterReleasesDepartedMembers in internal/router/member_churn_test.go starts a router through standalone.New. 50 in-process members (plain libp2p hosts running gossipsub) connect, complete the mesh handshake with a credential signed by the control plane's key, and then close. Against a baseline taken once the router settles, it checks three things:

    1. Router goroutines come back within 5 of the baseline. The router's goroutines are told apart from the members' by a pprof label set when the router starts, which every goroutine it spawns inherits. This check passes today and always runs.
    2. Gossipsub per-peer contexts come back to the baseline. The context gossipsub is built with is wrapped in a context that counts its live children, the approach #735's own test uses. This check fails on v0.18.0.
    3. Peerstore addrs of the departed members are gone once a mock clock passes RecentlyConnectedAddrTTL and the addr book's gc runs. This check fails on v0.49.0.

    Checks 2 and 3 skip unless AGENTMESH_TEST_UPSTREAM_LEAKS=1 is set, and the skip message names the upstream PR.

    Production change

    Router.Start reads two unexported hooks that only export_test.go sets: a peerstore to build the host on (libp2p.Peerstore(pstoremem.NewPeerstore(pstoremem.WithClock(clk)))), and a wrapper for the context passed to pubsub.NewGossipSub. When neither is set, behavior is unchanged. They are package variables, like goAwayGrace, because the router is built inside standalone and an Options field could not be set from there without exporting it.

    Results

    Current deps (go-libp2p-pubsub v0.18.0, go-libp2p v0.49.0):

  • Default run: passes in about 1.3s (1.8s with -race), with the two upstream checks skipped.

  • With AGENTMESH_TEST_UPSTREAM_LEAKS=1:

  • - The gossipsub check fails, with 12 to 22 of 50 child contexts still live across 6 runs: gossipsub child contexts after 50 members left = 17, want the baseline 0.
    - The peerstore check fails: 50 of 50 departed members still have addrs in the router's peerstore past RecentlyConnectedAddrTTL and the addr book's gc.

    With the fix branches swapped in locally through replace (#735 on v0.18.0, #3559 cherry-picked onto v0.49.0):

  • With both fixes, all three checks pass, including under -race.

  • With only #735, the gossipsub check passes and the peerstore check still fails, so each check tracks its own fix.
  • Things to know

  • The peerstore check waits up to a minute of wall time. pstoremem's gc runs on its own one-minute real-time ticker, which the mock clock does not drive, so with the fix this check takes up to about 60s. If that is too slow to run on every make test, it could stay behind the variable after the bump, or wait for an upstream way to trigger the gc.

  • Signed peer records are not checked directly. In these versions identify does not store the signed record in the host peerstore. Gossipsub keeps it in a private pstoremem addr book that uses the real clock and that the test cannot reach. The host-peerstore check exercises the same downgrade path that #3559 fixes.

  • Only part of the gossipsub leak is visible per run. On v0.18.0 only part of the departed peers' contexts leak, 12 to 22 of 50 in my runs. With 50 members the check has failed every time, and after the fix it is 0.

  • Members use a minted credential, not /enroll. The control plane runs with an operator signing key file (Ed25519 plus the required P-256), so the test signs member Biscuits itself and avoids the enrollment rate limit of 10/s. Joining takes about 0.1s for 50 members.
  • Validation

  • go build ./...

  • go vet ./internal/router/ ./internal/standalone/

  • golangci-lint run ./... (v2.14.0, the version hack/lint.sh pins): 0 issues

  • deadcode check from hack/lint.sh: clean

  • go test -race -count=1 ./internal/router/ ./internal/standalone/: pass

  • go test -race -count=3 -run TestRouterReleasesDepartedMembers ./internal/router/: pass
  • Diff: 567 lines (+425 / -142) across 7 files Reviewer: aojea Review duration: 26715m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 567 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.379
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #759"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.7% (MEDIUM) · Higher = larger blast radius
    49.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 26.5% · Safe to merge
    26.5%