Skip to content

test(portal): offline stub test flakes on a cold npx cache (30s bridge timeout) #171

Closed

Description

@KooshaPari

Summary

scripts/test-portal-bridge.sh (the offline stub test, merged in #138) can fail spuriously on a cold npx cache. The bridge step was hard-coded to timeout 30, but npx -y [email protected] can spend longer than that resolving the package, and it writes nothing to stderr while it does. The bridge log then ends up 0 bytes and the assertion reports:

FAIL: mcp-remote never logged that it accepted the client metadata document.

that is, exit code 2 ("the bridge did not prove the client-metadata / callback configuration"). That verdict is wrong: the harness never gave the bridge a chance to prove anything.

Observed 2026-10-21

Run against a clean git archive extraction of merged master (2aea04dd8):

Run Result Duration
1 (cold, after a long idle gap) exit 2, 0-byte bridge.log ~36s (bridge hit the 30s cap)
2 (warm) exit 0, PASS 28s
3 (warm) exit 0, PASS 19s
4 (warm) exit 0, PASS 15s

A bare npx -y [email protected] ... --debug against an unreachable URL produces ~12.7 KB of stderr within a second, so npx itself is healthy; the empty log is specific to the cold-resolve window. 30s sits right on the boundary of observed cold-start cost.

Why this matters

A flaky harness reports false regressions, and exit code 2 specifically means "the bridge rejected or failed to adopt the client metadata document", which is the exact regression this test exists to catch. Conflating "we never observed" with "we observed a rejection" defeats the guard.

Proposed fix

  1. Make the budget configurable: BRIDGE_TIMEOUT="${BRIDGE_TIMEOUT:-120}".
  2. Classify an empty bridge log as an infrastructure failure (exit 1) rather than an assertion failure (exit 2), matching the script's own documented exit-code contract, and print the actionable hint (BRIDGE_TIMEOUT=300 ...).

Acceptance

  • bash -n clean, shellcheck -S warning produces no new warnings versus master.
  • Forcing the path with BRIDGE_TIMEOUT=1 yields exit 1 with the infrastructure message.
  • A normal run still yields exit 0 with all three confirmations intact (client metadata document accepted, callback hostname is 127.0.0.1, callback port derived).

Activity

  1. added
    kilo-triaged
    on Oct 21, 2026
  2. KooshaPari commented on Oct 21, 2026

    @KooshaPari
    OwnerAuthor

    Root-cause correction, plus direct A/B proof of the fix

    My original attribution was wrong and I'm correcting it here.

    The cold-npx hypothesis is disproven

    I claimed a cold npx cache could exceed 30s. Tested it properly with a genuinely empty cache (npm_config_cache pointed at a fresh dir, 0 bytes, so npx had to download [email protected]):

    Condition Script Result
    Cold npm cache (0 B, 18 MB downloaded) old (timeout 30) exit 0, PASS in 13s

    A cold resolve took 13s, not >30s. So cold npx is not the cause. The flake came from some other adverse condition (system load, registry latency, or TLS stub slowness at that moment). The durable statement is the weaker, correct one: the bridge step can exceed a 30s budget under adverse conditions, and a cold cache is one of several candidates rather than the demonstrated one.

    The failure mode is reproduced exactly, and the fix resolves it

    To test the mechanism instead of guessing, I injected a deterministic 45s delay into npx via a PATH shim, which makes the bridge step exceed the old budget while writing nothing to stderr:

    Condition Script Exit Verdict
    45s bridge delay old (timeout 30) 2 FAIL: mcp-remote never logged that it accepted the client metadata document. — the exact false verdict from the original failure
    45s bridge delay new (default 120s) 0 PASS with all three confirmations intact
    45s bridge delay, BRIDGE_TIMEOUT=20 new 1 FAIL: the bridge hit the 20s timeout (exit 124). — and 0 occurrences of the old false verdict

    The third row is the important one: when the budget genuinely is too small, the new script reports an infrastructure failure (exit 1) instead of falsely asserting a CIMD rejection (exit 2). Exit 2 stays reserved for the regression this test actually guards.

    What this changes

    • The diagnosis in test(portal): offline stub test flakes on a cold npx cache (30s bridge timeout) #171 and the PR body said "cold npx cache". That specific claim is retracted; the general claim (budget too tight, empty log misclassified) is confirmed by direct reproduction.
    • No code change needed: the fix is correct for the real mechanism, and the reproduction shows it working on both the pass-through and the too-small-budget paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kilo-triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions