Skip to content

fix(web-ui): share one in-flight auth probe between App mount and the router guard - #1294

Merged
Dumbris merged 3 commits into
mainfrom
fix/router-auth-guard-race
Sep 18, 2026
Merged

Dumbris merged 3 commits into
mainfrom
fix/router-auth-guard-race

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 17, 2026

Copy link
Copy Markdown
Member

Summary

Found while verifying Spec 107 PR-C: on a hard reload of a deep server-edition route (/ui/my/tokens, /ui/servers, …) App.vue's mount-time checkAuth() and the router guard's checkAuth() ran concurrently, each issuing its own /status + /auth/me pair, and the guard decided isTeamsEdition / isAuthenticated from whichever run it happened to await.

  • auth.ts: checkAuth() shares one in-flight probe; concurrent callers join it, so every reader sees a single fully-settled result and a hard reload issues one probe pair instead of two. checkAuth({ fresh: true }) queues a new probe behind the in-flight one for callers that must read with the current credentials (reloadAfterAuth after the API key is repaired); loading stays true until the newest run settles.
  • router/index.ts: guard extracted as the exported authGuard so a test can mount it on a memory router with stub views; it now loops while (loading) so a fresh probe queued behind the run it joined is drained before routing.
  • App.vue: reloadAfterAuth passes fresh: true.
  • New frontend/tests/unit/auth-guard-hard-reload.spec.ts (13 tests): mount-vs-initial-navigation race for /my/tokens, /servers, /activity as tenant and admin (one probe, correct view + title), tenant → admin route → dashboard, signed-out → /login, fresh-probe queueing, and the drain case (fails under the old if).

What did NOT reproduce

The reported symptom — Dashboard/Usage content rendering under a correct target title — did not reproduce on the PR-C branch + this fix's base: 30+ Playwright hard loads (tenant and admin, with and without 300–600 ms injected latency on /auth/me and on JS chunks), the real server-edition-tenant.spec.ts, and the in-app browser all rendered the target view every time, before and after this change. Playwright's own failure snapshot in the PR-C worktree shows heading "Agent Tokens" rendered too.

The e2e failure at the token-mint step has a different cause, in the spec (PR-C branch, not touched here):

  1. page.locator('input[type="text"]').first() resolves to the hidden Add-Server modal's name input in TopHeader (placeholder="e.g., github-server"), so fill() waits 60 s for visibility. Fix: click Create Token, then fill dialog.modal-open → getByPlaceholder(/ci-pipeline/).
  2. waitForURL(u => !u.pathname.startsWith('/login')) is vacuous under the /ui/ base (pathname is /ui/login).
  3. assertNoApiKeyLeakage awaits req.allHeaders(), which hangs on a fetch aborted by the next page.goto; req.headers() is enough for the X-API-Key check.
    With 1–3 patched locally the test proceeds to assertAll2xx, which then reports real PR-C findings (pre-login 401s tracked from /ui/, tenant 403s on /onboarding/state and /secrets/config).

PR-C's App.vue also has a reloadAfterAuth → checkAuth() call that should become checkAuth({ fresh: true }) on rebase.

Verification

  • npx vitest run — 123 files / 1277 tests pass; vue-tsc --noEmit clean.
  • Server edition rebuilt with the PR-C branch merged + this fix, run via scripts/dev-server-edition.sh --phase c: tenant and admin hard loads of /ui/my/tokens, /ui/servers, /ui/activity render the target view, and the network log shows exactly one /auth/provider + one /auth/me per reload (was two of each).
  • Cross-model review (opencode, gpt-6-astra): 3 rounds, rounds 1–2 each raised one P2 (both fixed with regression tests), round 3 CLEAN.

🤖 Generated with Claude Code

Dumbris and others added 3 commits September 17, 2026 10:14
… router guard

On a hard reload App.vue's onMounted checkAuth() and the router guard's
checkAuth() for the initial navigation ran concurrently, each issuing its
own /status + /auth/me pair. The guard now joins the run already in flight
(one probe per reload) and decides isTeamsEdition / isAuthenticated from a
single fully-settled result. The guard is exported as authGuard so a unit
test can replay the mount-vs-initial-navigation race on a memory router.

Co-Authored-By: Claude Opus 5 <[email protected]>
Cross-review P2: joining the in-flight run is right for the mount/guard
pair but wrong for the recovery path — a probe issued with the stale key
could be reused after the key was repaired. checkAuth({ fresh: true })
queues a new probe behind the in-flight one; loading stays true until the
newest run settles.

Co-Authored-By: Claude Opus 5 <[email protected]>
…h probe wins

Cross-review round 2 P2: with a single await, a fresh probe queued behind
the run the guard joined left loading=true while the guard routed on the
superseded result. Loop on loading so the decision comes from the newest
settled probe. Regression test fails under the old `if`.

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

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: becb5fb
Status: ✅  Deploy successful!
Preview URL: https://be41421a.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-router-auth-guard-race.mcpproxy-docs.pages.dev

View logs

@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

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/router-auth-guard-race

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-go6YZ8NL.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 35194064292 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit e9881a0 into main Sep 18, 2026
40 checks passed
@Dumbris
Dumbris deleted the fix/router-auth-guard-race branch September 18, 2026 03:03
Dumbris added a commit that referenced this pull request Sep 18, 2026
…er probe

The merge of origin/main (#1294, shared in-flight auth probe) into
107-b-oidc-front-door (#1292, generic OIDC provider) combined without a
conflict, but PR-B's auth store change (probe() now calls
authApi.getProvider() instead of api.getStatus() for edition detection,
Spec 107 FR-030/FR-041) left the test file's mocks pointed at the old
api.getStatus() call, so every test silently no-oped through probe()'s
catch block. Repoint the spy at authApi.getProvider() and update the
resolved payload shape ({ display_name } instead of
{ data: { edition } }); the in-flight-probe-sharing behaviour under test
is unchanged.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Dumbris added a commit that referenced this pull request Sep 18, 2026
…ess, telemetry v13 (Spec 107 PR-B) (#1292)

* docs(specs): Spec 107 — server edition SSO front door hardened for real IdPs

Generic OIDC provider, IdP-group → server allowlist, attributable JSONL
audit line, and a freeze/cut of the latent multiuser/credential-injection
code, split into four PRs (A freeze/cut, B OIDC + front door + telemetry,
C entitlement predicate + tenant session, D audit line).

Judge-panel drafted; cross-model reviewed over nine rounds (codex gpt-5.6-sol),
~130 findings resolved. Un-parks roadmap epic sso.

* test(spec-107): PR-A red tests, server-tag lint job and release notice

Related #1177

* refactor(serveredition): freeze the latent credential-injection chain and normalise removed config keys (Spec 107 PR-A)

Related #1177

* fix(storage): enforce the agent-token cap per owner, not per deployment (Spec 107 PR-A)

Closes #1177

* fix(spec-107): address adversarial review of PR-A

* fix(spec-107): codex round 1 for PR-A

* fix(spec-107): codex round 2 for PR-A

* fix(spec-107): codex round 3 for PR-A

* fix(spec-107): codex round 4 for PR-A

* docs(spec-107): PR-A verification and task ticks

* docs(roadmap): link PR-A

* test(oauthserver): fake OIDC identity provider and server-edition dev rig (Spec 107 PR-B)

* test(serveredition): red tests for the generic OIDC provider, subject binding and refusals (Spec 107 PR-B)

* feat(serveredition): generic OIDC provider with JWKS-verified ID tokens, groups capture and subject binding (Spec 107 PR-B)

Related #1169

* test(serveredition): red tests for trusted proxies, public URL, cookie security and forced MCP auth (Spec 107 PR-B)

* feat(serveredition): front door behind an ingress — public URL, trusted proxies, cookie security policy, forced MCP auth, provider probe (Spec 107 PR-B)

* feat(config,telemetry): hot-reload clauses, docs and OAS for the PR-B keys; telemetry v13 server-edition fields (Spec 107 PR-B)

* fix(spec-107): gate fixes for PR-B

* docs(spec-107): PR-B automated-check evidence

* fix(spec-107): cross-review round 1 for PR-B

* fix(spec-107): cross-review round 2 for PR-B

* fix(spec-107): cross-review round 3 for PR-B

* fix(spec-107): cross-review round 3 for PR-B

* fix(spec-107): cross-review round 4 for PR-B

* fix(spec-107): cross-review round 5 for PR-B

* fix(spec-107): cross-review round 6 for PR-B

* docs(spec-107): PR-B real-instance verification, gate re-run, task ticks

T062/T063: real-instance verification of the OIDC front door (happy-path
login, groups, /auth/me, agent-token mint + /mcp initialize/tools-list,
ErrorMode tamper matrix, cookie Secure matrix behind a simulated trusted vs
untrusted proxy) and the telemetry v13 payload (server vs personal). T064:
full gate set re-run on HEAD after cross-review round 6 touched the config
load path, oauth_handler.go and telemetry.go — all green. T066: tick
completed PR-B tasks (T032-T066); ROADMAP.md regenerated.

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

* docs(roadmap): link PR-B

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

* fix(ci): pull forward the Windows heap-corruption + Pass-2 race fix (#1288)

This branch diverged from main before #1288 landed, so PR-B's CI hit the
exact regression it fixed: handleAddFromRegistry's success path dereferenced
a nil cfg, chi's recoverer turned the panic into a bare 500, and the
recovered hardware fault corrupted the Go heap on windows/amd64 under Go
1.26 (golang/go#81238) — the internal/httpapi test binary crashed with
"found pointer to free object" and took the whole Windows unit-test job (and
the binaries job's httpapi/scanner test bundle) down with it. Cherry-picked
the same fix main already carries: the nil-config guard with a JSON 500 (and
its pinning test), plus the unrelated Pass-2 temp-dir teardown race fix in
the scanner test this same upstream commit bundled.

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

* docs(spec-107): record the CI red/fix cycle for PR-B

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

* docs(spec-107): record PR-B CI green

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

* fix(spec-107): cross-review round 7 for PR-B

* fix(spec-107): cross-review round 8 for PR-B

* fix(web-ui): update hard-reload auth-guard test for the FR-030 provider probe

The merge of origin/main (#1294, shared in-flight auth probe) into
107-b-oidc-front-door (#1292, generic OIDC provider) combined without a
conflict, but PR-B's auth store change (probe() now calls
authApi.getProvider() instead of api.getStatus() for edition detection,
Spec 107 FR-030/FR-041) left the test file's mocks pointed at the old
api.getStatus() call, so every test silently no-oped through probe()'s
catch block. Repoint the spy at authApi.getProvider() and update the
resolved payload shape ({ display_name } instead of
{ data: { edition } }); the in-flight-probe-sharing behaviour under test
is unchanged.

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

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

Mirrors main's ce5c2f7 fix for the same loadConfig signature mismatch
that broke the Build Binaries CI job on this PR.

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

---------

Co-authored-by: Claude Sonnet 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