Depends on #3869
This is the Phase 2 follow-up to #3869 (auth credential expiration with retry). Phase 1 handles stale credentials reactively (detect 401/403, recreate client). This issue eliminates the problem proactively by resolving credentials on every operation rather than at client creation time.
Context: With session-scoped clients, outgoing credentials are resolved once during SessionFactory.MakeSession() and held for the session lifetime. Short-lived credentials (OAuth tokens, expiring API keys) can become stale mid-session, triggering the retry path in #3869. This issue removes that failure mode entirely for credentials with a known expiry.
Implementation:
Part 1 — Per-request identity resolution:
- Modify
identityPropagatingRoundTripper in pkg/vmcp/client/client.go to read identity from the request context on each operation, instead of capturing it at client creation time
- This ensures every backend call automatically picks up the latest credentials without any expiry tracking logic
- Eliminates stale credential issues entirely for backends that return fresh credentials on each resolution
Part 2 — Proactive client recreation for known-expiry credentials:
Acceptance Criteria
RFC: THV-0038 — Session-scoped client lifecycle
Depends on #3869
This is the Phase 2 follow-up to #3869 (auth credential expiration with retry). Phase 1 handles stale credentials reactively (detect 401/403, recreate client). This issue eliminates the problem proactively by resolving credentials on every operation rather than at client creation time.
Context: With session-scoped clients, outgoing credentials are resolved once during
SessionFactory.MakeSession()and held for the session lifetime. Short-lived credentials (OAuth tokens, expiring API keys) can become stale mid-session, triggering the retry path in #3869. This issue removes that failure mode entirely for credentials with a known expiry.Implementation:
Part 1 — Per-request identity resolution:
identityPropagatingRoundTripperinpkg/vmcp/client/client.goto read identity from the request context on each operation, instead of capturing it at client creation timePart 2 — Proactive client recreation for known-expiry credentials:
expclaim, OAuthexpires_inresponse field), schedule proactive client recreation shortly before the expiry timesingleflightdeduplication as [vMCP] Handle auth credential expiration with retry and proactive refresh #3869 to handle concurrent requests during the recreation windowAcceptance Criteria
identityPropagatingRoundTripperresolves identity from the request context on each operation rather than capturing it at construction timeexpclaim orexpires_in), proactive recreation is scheduled before the expiry timesingleflightto deduplicate concurrent requests during the recreation windowRFC: THV-0038 — Session-scoped client lifecycle