You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds a read-through cache to pegboard_actor_get_for_kv, eliminating a UDB read-transaction per KV request for actor name and namespace_id lookup. The implementation correctly uses the existing rivet_cache infrastructure and removes the // TODO: Add cache comment.
What works well
Correct caching pattern. The ctx.cache().clone().request().fetch_one_json(...) pattern matches established patterns in runner_config/get.rs and runner/list_runner_config_enabled_dcs.rs.
Correct derives.Serialize and Deserialize were correctly added to Output (required by fetch_one_json). Input doesn't need them.
Cache miss handled correctly. The None (actor not found) case is intentionally not resolved into the cache, matching the fetch_one_json contract — non-existent actors won't be negatively cached indefinitely.
Span moved correctly. The custom_instrument span was moved inside the getter closure, still wrapping only the UDB transaction.
Issues
Missing cache invalidation on actor destroy (correctness concern)
The cached data — actor name and namespace_id — is write-once, so caching it is conceptually safe for a live actor. However, there is no corresponding cache purge in the actor destroy path.
The caller in ws_to_tunnel_task.rs uses this result to verify that the actor exists and belongs to the right namespace. With the default 2-hour TTL, a stale cache entry could allow a destroyed actor's KV operations to proceed for up to 2 hours post-destruction.
The existing purge_runner_config_caches pattern in utils.rs shows the expected approach. A purge("actor.actor_get_for_kv", vec![actor_id]) call should be added in the actor destroy workflow activity (workflows/actor/destroy.rs), mirroring that pattern.
Note: the analogous comment on get_for_runner.rs explicitly acknowledged this: // TODO: Add cache (remember to purge cache when runner changes).
No explicit TTL
The 2-hour default TTL is used silently. Peer operations in this package set explicit TTLs (runner_config/get.rs: 5 s, runner/list_runner_config_enabled_dcs.rs: 1 hr). Since the data is write-once, an explicit .ttl(...) call or a comment explaining why the default is acceptable would improve clarity and guard against future default changes.
None not cached — potential DB pressure for non-existent actors
When the actor is not found, cache.resolve is not called, so every request for a non-existent actor_id hits UDB. This is the right tradeoff to avoid stale positive entries after destroy, but it's worth noting that once the destroy purge is in place, a short-TTL negative cache entry (e.g., 5–30 s) could further reduce DB pressure during destroy races. Lower priority, but worth considering holistically.
Conventions
No issues: no rivet.gg references, no println!/eprintln!, no Mutex<HashMap>, no new unstructured log statements, no anyhow glob imports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: