fix(mcp): bound Relaycast and relaygate calls made under the hosted-MCP owner lock
What
Hosted MCP tool calls check, register, recover and release their relay participant inside a transaction that holds the user and organization advisory locks plus the per-owner lock. The Relaycast and relaygate calls made there had no deadline. When the upstream stalled, the transaction kept those locks, and the same user's OAuth token refresh (which takes the same user and organization locks) waited behind it, as did every other relay call for that owner.
Change
src/mcp/owner-lock-deadline.ts: calls made while the owner lock is held share one 10-second budget, counted from the moment the locks are held (time spent waiting for the locks does not count). Each call gets what is left of the budget as an abort deadline, composed with the caller's own signal. A call started after the budget is spent is refused without being sent.withOwnerLockmarks its body as running under the lock; the hosted-MCP Relaycast and relaygate clients use the bounded fetch. Calls made outside the lock (sends, inbox reads, launches) pass through unchanged.leave_relayreleases under the lock, so the release is bounded too. A timed-out release rolls the transaction back, keeps the participant row and answers with the existing retryable leave wording; a retry completes the leave whether or not the first release took effect upstream.createRelaycastClient: a response whose body is lost mid-read (for example an abort after the status line) is now aRelaycastCallErrorwith an unknown outcome, under the same status rule as a complete answer, instead of an unlabelled error.
No lock restructuring, no migration, no configuration.
Behaviour to review
- A timed-out registration or token recovery is reported with the existing "outcome may be unknown" wording. The budget is a fixed constant (10 s per lock).
- A lost body on a 404 that the caller would have accepted as "not found" now fails as a known failure rather than being read as "not found".
Checks
Local, on this head, one suite at a time:
tsc --noEmit: passtest/mcp-oauth-admission.test.ts: 63/63 (six new cases: stalled registration ends at the budget and a concurrent refresh completes; in-time calls unaffected and sends carry no deadline; spent budget is refused without sending; stalled leave release, not applied and applied; lost body)test/mcp.test.ts61/61,gate-only-hosted-participants12/12,relaycast-dm-recipient3/3,lazy-relaycast-binding16/16,mcp-desktop-link9/9,messaging33/33,message-deliveries5/5,capy-mcp-identity7/7
The in-memory test database runs one transaction at a time, so the refresh case proves the stalled transaction ends at the budget, not real advisory-lock contention between two connections.
Held for the owner's merge decision.
🤖 Generated with Claude Code

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by cubic
Hosted MCP tool calls now bound the Relaycast and relaygate calls they make while holding the per-owner lock to one shared 10-second budget, counted from when the locks are held. Previously these calls had no deadline, so a stalled upstream kept the locks and blocked the same user's OAuth token refresh and every other relay call needing them.
- A call started after the budget is spent is refused without being sent; sends, inbox reads, and launches run after the lock and are unchanged.
- A timed-out registration or recovery keeps the existing unknown-outcome wording; a timed-out leave rolls back, keeps the participant row, and answers with the retryable leave wording so a retry completes it.
- A Relaycast answer whose body is lost mid-read is now reported with an unknown outcome under the same status rule instead of an unlabelled error.
No lock restructuring, migration, or configuration.