Refactor VW OpenAPI regeneration cache to use shared singleflight-style coordination
Summary
Follow-up from PR #4134 review discussion.
The current fix in the VW OpenAPI handler is correct, but the cache/locking flow is still hard to reason about and easy to regress. During review, @ntnn suggested rewriting this closer to the shardlookup cache pattern so concurrent requests share a single in-flight regeneration result instead of manually coordinating lock/unlock/wait/relock behavior.
Problem
The current implementation manually handles:
- per-key locking
- waiting for an in-flight generation to finish
- retrying after failed generations
- cache reuse across concurrent callers
That logic is subtle and review feedback called out that it would be simpler and safer to use a shared singleflight-style mechanism similar to the shardlookup cache pattern.
Goal
Refactor the VW OpenAPI service cache/regeneration path to:
- coalesce concurrent requests for the same key
- ensure all waiters observe the same regeneration result
- avoid manual unlock/relock/wait sequencing where possible
- preserve current behavior for retries after failed generations
Notes
- This is a follow-up cleanup/refactor, not a blocker for PR #4134.
- Please evaluate whether the existing shardlookup pattern can be reused directly or adapted with the current LRU cache.
/area virtual-workspace /kind cleanup
@mjudeikis-bot: The label(s) area/virtual-workspace cannot be applied, because the repository doesn't have them.
In response to this:
Summary
Follow-up from PR #4134 review discussion.
The current fix in the VW OpenAPI handler is correct, but the cache/locking flow is still hard to reason about and easy to regress. During review, @ntnn suggested rewriting this closer to the shardlookup cache pattern so concurrent requests share a single in-flight regeneration result instead of manually coordinating lock/unlock/wait/relock behavior.
Problem
The current implementation manually handles:
- per-key locking
- waiting for an in-flight generation to finish
- retrying after failed generations
- cache reuse across concurrent callers
That logic is subtle and review feedback called out that it would be simpler and safer to use a shared singleflight-style mechanism similar to the shardlookup cache pattern.
Goal
Refactor the VW OpenAPI service cache/regeneration path to:
- coalesce concurrent requests for the same key
- ensure all waiters observe the same regeneration result
- avoid manual unlock/relock/wait sequencing where possible
- preserve current behavior for retries after failed generations
Notes
- This is a follow-up cleanup/refactor, not a blocker for PR #4134.
- Please evaluate whether the existing shardlookup pattern can be reused directly or adapted with the current LRU cache.
/area virtual-workspace /kind cleanup
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
We already have https://github.com/kcp-dev/kcp/blob/5cd080f9d917460f3e89f23ddcb257a121c3ab7c/pkg/shardlookup/ttl_cache.go#L49-L53 abstracting that away with a TTLCache + singleflight. Could make a similar package with an LRUCache + singleflight in the vw framework and use that. Would reduce the boilerplate there as well by a bit.