Skip to content

fix(mcp): bound Relaycast and relaygate calls made under the hosted-MCP owner lock - #258

Open
agent-relay-code[bot] wants to merge 1 commit into
mainfrom
fix/mcp-relay-call-deadline
Open

agent-relay-code[bot] wants to merge 1 commit into
mainfrom
fix/mcp-relay-call-deadline

Conversation

@agent-relay-code

@agent-relay-code agent-relay-code Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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.
  • withOwnerLock marks 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_relay releases 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 a RelaycastCallError with 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: pass
  • test/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.ts 61/61, gate-only-hosted-participants 12/12, relaycast-dm-recipient 3/3, lazy-relaycast-binding 16/16, mcp-desktop-link 9/9, messaging 33/33, message-deliveries 5/5, capy-mcp-identity 7/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


Start Proof
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.

Written for commit 98ff32d. Summary will update on new commits.

View guided diff Turn on auto-fix

…CP owner lock

Hosted MCP tool calls verify, register, recover and release their relay
participant inside a transaction that holds the user and organization
advisory locks plus the per-owner lock. Those remote 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 that needs them.

Calls made while the owner lock is held now share one 10-second budget,
counted from when the locks are held. A call started after the budget is
spent is refused without being sent. Calls outside the lock (sends, inbox
reads, launches) are unchanged. A timed-out write is reported with the
existing unknown-outcome wording, and a timed-out leave keeps the
participant so a retry completes it.

A Relaycast answer whose body is lost mid-read is now an unknown outcome
instead of an unlabelled error.

Co-Authored-By: Claude <noreply@anthropic.com>
@agent-relay-code agent-relay-code Bot added the merge-train:hold Do not merge until the owner gives the go label Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c1eac0f6-740a-4d49-a43d-d154fd0ad71e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-train:hold Do not merge until the owner gives the go

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants