Repository navigation
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
Open
agent-relay-code[bot] wants to merge 1 commit into
agent-relay-code[bot] wants to merge 1 commit into
Conversation
…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>
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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/7The 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-botwith 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.
No lock restructuring, migration, or configuration.
Written for commit 98ff32d. Summary will update on new commits.