Skip to content

Cold /api/studies: one routing build instead of 551 (28–40 s → 1.5 s over MCP) - #42

Merged
alisman merged 1 commit into
masterfrom
session/federation
Oct 19, 2026
Merged

alisman merged 1 commit into
masterfrom
session/federation

Conversation

@alisman

@alisman alisman commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Problem

The first /api/studies after a deploy took 28–40 s with GENIE over MCP. With GENIE direct it took 4–5 s.

The endpoint looks up every study's access at once (Promise.all over 551 studies). Each lookup needs the routing table. While the first build waited on the network, every other lookup found the table empty and started its own build: 551 builds for one answer. Over MCP that's 551 calls to the simulated peer; direct, it's 1,102 small queries.

Fix

studyRouting() keeps the build in progress, so callers that arrive during it wait for the same one. The build runs detached from any single reader's cancellation, since it answers them all. A failed or partial build is still not kept.

test/routing.test.ts: 50 concurrent lookups on a cold process ask the peer for its studies once. Without the fix the test sees 50.

Measured

On a fresh production build: three cold starts each, then a warm request.

cold before cold after MCP calls (cold)
GENIE over MCP 28.5–39.9 s 1.3–1.5 s 552 → 2
GENIE direct 4.3–5.1 s 0.7–0.9 s 0

Warm requests take about 0.03 s either way, before and after. scripts/gate.sh green (1263 unit tests, 253 e2e checks).

🤖 Generated with Claude Code

https://claude.ai/code/session_01QLBVrkqBG7J7pqX6Qygx3z

…t runs

A cold /api/studies took 28–40 s with GENIE over MCP (4–5 s direct). It looks up every study's
access at once (Promise.all over 551 studies), each lookup needs the routing table, and while the
first build waited on the network every other lookup found the table empty and started its own:
551 builds for one answer — 551 MCP calls to the simulated peer, or 1,102 small queries direct.

studyRouting() now keeps the build in progress, so callers that arrive during it wait for the same
one. It runs detached from any one reader's cancellation, since it answers them all; a failed or
partial build is still not kept.

test/routing.test.ts: 50 concurrent lookups on a cold process ask the peer for its studies once
(it sees 50 without the change).

Measured on a fresh production build (three cold starts each, then a warm request):
  over MCP: cold 28.5–39.9 s, 552 MCP calls  →  1.3–1.5 s, 2 calls
  direct:   cold 4.3–5.1 s                  →  0.7–0.9 s
  warm: ~0.03 s either way, before and after.
scripts/gate.sh green (1263 unit, 253 e2e).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QLBVrkqBG7J7pqX6Qygx3z
@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cohort-lab Ready Ready Preview Oct 19, 2026 7:52am UTC

Request Review

@alisman
alisman merged commit 05abd19 into master Oct 19, 2026
5 checks passed

This branch was successfully deployed

1 active deployment
Preview — 115304ce Deployed Oct 19, 2026 by vercel[bot]
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.

1 participant