Skip to content

Conversation

@MasterPtato
Copy link
Contributor

@MasterPtato MasterPtato commented Jan 29, 2026

Fixes RVT-5324

@linear
Copy link

linear bot commented Jan 29, 2026

Copy link
Contributor Author

MasterPtato commented Jan 29, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link

claude bot commented Jan 29, 2026

PR Review: fix(guard): cache custom serve routes

Summary

This PR fixes an issue where custom serve routes were not being cached properly. The key change is modifying the route cache to store RoutingOutput instead of just RouteConfig, allowing both regular routes and custom serve handlers to be cached.

Code Quality - Positive Changes

  • Better abstraction: Caching RoutingOutput instead of RouteConfig is the right design - it treats both routing types uniformly
  • Improved random selection: Using rand::seq::SliceRandom::choose() instead of manual index calculation is cleaner and handles empty slices correctly
  • Code consolidation: Moved caching logic before the match statement, eliminating duplication
  • Better imports: Using use rand::seq::SliceRandom instead of glob import follows Rust best practices

The refactoring in proxy_service.rs:100-136 improves the flow:

  1. Check cache first
  2. Call routing function if cache miss
  3. Cache the result immediately after receiving it
  4. Then process the cached/fresh result

This is much cleaner than the previous approach where caching happened after processing.

Potential Issues

1. TODO Comment Needs Attention (cache/actor.rs:35)

The path() method per the documentation at request_context.rs:18 includes both path AND query. This means different query parameters will produce different cache keys. This might be intentional for actor routing OR it might cause unnecessary cache misses if query params do not affect routing.

Recommendation: Clarify if query params should be in cache key, then either remove the TODO with an explanatory comment or modify the code to exclude query params.

2. Missing Test Coverage

This PR does not include tests for the new caching behavior. Consider adding:

  • Unit test to verify custom serve routes are cached
  • Integration test to confirm cache hits work for both RoutingOutput::Route and RoutingOutput::CustomServe
  • Test to verify empty target lists are handled gracefully

3. Cache Key Documentation (request_context.rs:12-19)

The new comments are helpful but could be clearer with examples like "example.com:8080" for host field.

Performance Considerations

Positive impact:

  • Custom serve routes will now benefit from caching (10-minute TTL), reducing routing function overhead
  • Moving the cache insert before the match statement ensures consistent caching behavior
  • Using SliceRandom::choose is potentially more efficient for large target lists

No concerns:

  • Caching RoutingOutput (which includes Arc) is lightweight since it is reference-counted
  • The 10-minute TTL and 10,000 entry limit remain appropriate

Security Concerns

No issues identified. The changes do not introduce security vulnerabilities.

Recommendations Summary

Priority Item Action
High Resolve TODO comment Clarify if query params should be in cache key
Medium Add test coverage Test custom serve route caching
Low Improve documentation Add examples to RequestContext field comments

Verdict: Approve with Minor Suggestions

The PR successfully fixes the issue and improves code quality. The core implementation is sound. The main action item is resolving the TODO comment about query parameters in the cache key - this could affect correctness depending on your routing requirements.

Before merging:

  • Resolve the TODO at cache/actor.rs:35
  • Consider adding tests for the new caching behavior

Great work on the cleaner abstraction!

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 29, 2026

More templates

@rivetkit/virtual-websocket

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

@rivetkit/cloudflare-workers

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

@rivetkit/db

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

@rivetkit/framework-base

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

@rivetkit/next-js

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

@rivetkit/react

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

rivetkit

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

@rivetkit/sql-loader

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

@rivetkit/engine-runner

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

@rivetkit/engine-runner-protocol

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

commit: ea52472

@MasterPtato MasterPtato force-pushed the 01-28-fix_gateway_configure_cors_for_error_responses branch from 03e46b7 to c9720e1 Compare January 29, 2026 00:46
@MasterPtato MasterPtato force-pushed the 01-28-fix_guard_cache_custom_serve_routes branch from 3388e0f to 4909921 Compare January 29, 2026 00:46
@MasterPtato MasterPtato force-pushed the 01-28-fix_guard_cache_custom_serve_routes branch from 4909921 to ea52472 Compare January 29, 2026 01:27
@MasterPtato MasterPtato force-pushed the 01-28-fix_gateway_configure_cors_for_error_responses branch from c9720e1 to 4e72006 Compare January 29, 2026 01:27
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.

2 participants