Skip to content

feat(cache): add in flight deduping#4459

Open
MasterPtato wants to merge 1 commit into03-18-fix_cache_clean_up_libfrom
03-19-feat_cache_add_in_flight_deduping
Open

feat(cache): add in flight deduping#4459
MasterPtato wants to merge 1 commit into03-18-fix_cache_clean_up_libfrom
03-19-feat_cache_add_in_flight_deduping

Conversation

@MasterPtato
Copy link
Contributor

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@railway-app
Copy link

railway-app bot commented Mar 19, 2026

🚅 Deployed to the rivet-pr-4459 environment in rivet-frontend

Service Status Web Updated (UTC)
frontend-cloud 😴 Sleeping (View Logs) Web Mar 19, 2026 at 9:02 pm
frontend-inspector 😴 Sleeping (View Logs) Web Mar 19, 2026 at 9:02 pm
website ❌ Build Failed (View Logs) Web Mar 19, 2026 at 8:53 pm
mcp-hub ✅ Success (View Logs) Web Mar 19, 2026 at 8:52 pm
ladle ❌ Build Failed (View Logs) Web Mar 19, 2026 at 8:51 pm

Copy link
Contributor Author

MasterPtato commented Mar 19, 2026

@MasterPtato MasterPtato force-pushed the 03-18-fix_cache_clean_up_lib branch from 175706a to 17d21f5 Compare March 19, 2026 20:53
@MasterPtato MasterPtato force-pushed the 03-19-feat_cache_add_in_flight_deduping branch from 75e1e38 to bc5d6d3 Compare March 19, 2026 20:53
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 19, 2026

More templates

@rivetkit/cloudflare-workers

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/cloudflare-workers@4459

@rivetkit/framework-base

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/framework-base@4459

@rivetkit/next-js

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/next-js@4459

@rivetkit/react

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/react@4459

rivetkit

pnpm add https://pkg.pr.new/rivet-dev/rivet/rivetkit@4459

@rivetkit/sql-loader

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sql-loader@4459

@rivetkit/sqlite-vfs

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sqlite-vfs@4459

@rivetkit/traces

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/traces@4459

@rivetkit/workflow-engine

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/workflow-engine@4459

@rivetkit/virtual-websocket

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/virtual-websocket@4459

@rivetkit/engine-runner

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner@4459

@rivetkit/engine-runner-protocol

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner-protocol@4459

commit: b395fae

@claude
Copy link

claude bot commented Mar 19, 2026

Code Review: feat(cache): add in-flight deduplication

Good overall direction. Deduplicating concurrent cache fetches is a useful optimization that prevents thundering-herd on cold keys. Test suite is comprehensive and the HashMap refactor of GetterCtx is clean.

CRITICAL 1: Leases never cleaned up on getter error. In req_config.rs, if tokio::try_join! propagates an error, execution jumps past the lease-cleanup loop. The scc::HashMap entries remain permanently because the local broadcast_tx drops but a clone still lives inside the map. All future requests for those keys find an occupied entry, subscribe to a channel that never signals, and wait IN_FLIGHT_TIMEOUT (5s). Fix: use a scopeguard or Drop guard to remove entries on scope exit.

CRITICAL 2: Broadcast not sent when getter resolves no keys. broadcast_tx.send(()) is inside the if !entries_values.is_empty() block. If the getter succeeds but resolves zero keys (genuine misses), waiters block for the full 5 seconds. The signal should be sent unconditionally after the getter completes.

MODERATE 3: Getter must now implement Clone (breaking API change). getter.clone() is called in the hot path. This silently requires every callers closure to implement Clone and will fail to compile otherwise. Should be documented in the PR description.

MODERATE 4: buffer_unordered(1024) hardcoded. The concurrency cap for waiting subscribers is arbitrary. Consider making it configurable or deriving it from the actual number of waiting keys.

MINOR 5: timeout_falls_back_to_getter test waits for the full 5-second IN_FLIGHT_TIMEOUT, slowing CI. Consider a shorter constant under cfg(test).

MINOR 6: GetterCtx dedup behavior change. Old code used first-occurrence wins for duplicates; new HashMap::collect uses last-occurrence wins. Functionally equivalent since all entries start as None.

MINOR 7: into_values ordering is now non-deterministic. GetterCtx::into_values returns entries in arbitrary HashMap order. If any caller relied on output order matching input keys, this is a silent behavior change.

Positive: Vec->HashMap refactor is clean (O(1) lookups, natural dedup). get(keys: &[RawCacheKey]) API is better than Vec. Test coverage is solid (dedup, multi-waiter, independent keys, mixed cached+in-flight, timeout fallback). scc::HashMap is appropriate (lock-free). Sending broadcast after cache write is correct.

@MasterPtato MasterPtato force-pushed the 03-19-feat_cache_add_in_flight_deduping branch from bc5d6d3 to b395fae Compare March 21, 2026 01:55
@MasterPtato MasterPtato force-pushed the 03-18-fix_cache_clean_up_lib branch from 17d21f5 to de18421 Compare March 21, 2026 01:55
@MasterPtato MasterPtato mentioned this pull request Mar 21, 2026
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant