Keep MCP credentials alive across provider turns #4659
main fromrefs/pull/4659/head·merged by juliusmarminge View on GitHubSummary#
- Refresh MCP credential liveness whenever a provider turn starts.
- Replace fixed credential expiration with a session liveness window and thread-scoped touch updates.
- Log rejected MCP requests with missing or invalid credentials.
- Decouple preview host assignments from MCP credential expiration.
- Adjust branch toolbar layout sizing behavior.
Testing#
- Added focused MCP session registry coverage for long-lived sessions and unrelated thread activity.
- Not run.
Note
Medium Risk
Changes MCP bearer validity and pruning on /mcp, which sits outside the main environment auth stack; behavior is safer for long sessions but alters when abandoned tokens expire (24h liveness window).
Overview Fixes agents silently losing the preview MCP toolkit when a session runs for a long time without calling browser tools, because the one-shot token minted at session start could no longer be renewed in-process.
MCP credential lifetime drops fixed expiresAt, idle timeout, and max lifetime in favor of a liveness window (default 24h after the last sign of life). Liveness refreshes on MCP requests (resolve) and on touch per thread, which ProviderService.sendTurn invokes so ordinary turns keep the same bearer token valid without re-issuing.
Observability: rejected /mcp calls with missing or bad tokens emit a warning (missing_bearer_token vs unknown_or_expired_token) instead of failing quietly on the client.
Preview automation: host assignment leases no longer inherit MCP credential expiry—stickiness follows live connection identity only, avoiding mid-flow host migration when auth deadlines passed.
Tests cover long sessions refreshed only via touch, unrelated threads not extending each other’s credentials, and expiry when liveness stops.
Note
Keep MCP credentials alive across provider turns using a liveness window#
- Replaces the
idleTimeoutMs/maximumLifetimeMsmodel inMcpSessionRegistrywith a singlelivenessWindowMs(default 24 hours): credentials are pruned only whenlastAliveAtis older than the window. - Adds a
touch(threadId)method toMcpSessionRegistryand atouchActiveMcpThreadhelper so credentials can be refreshed without MCP traffic. ProviderServicecallstouchActiveMcpThreadbefore each provider turn, preventing credential pruning during long sessions.- Removes
expiresAtfromMcpInvocationScope,McpIssuedCredential, andHostAssignment; host assignments now stay valid for the lifetime of the connection instead of expiring on a clock. - Behavioral Change: credentials no longer have a maximum lifetime — they live as long as there is activity within the liveness window.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Needs human review
Changes MCP credential lifetime model from 8-hour max to 24-hour liveness window, with the code itself noting this token is 'the only thing guarding the preview toolkit on a remote-reachable server.' Security-sensitive auth changes warrant human review.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).juliusmarminge merged this0e19c10
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
66249481-b751-41ab-956c-2bb709d2bdeeYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.