Correlate action code cache with master account + metadata API (CPL-351)#565
Correlate action code cache with master account + metadata API (CPL-351)#565GTC6244 wants to merge 7 commits into
Conversation
…dpoint (CPL-351) Add a secondary metadata index (CacheMetadataIndex) alongside the IPFS action code cache that correlates each cached entry to the master account (account wallet address) that executed it, tracking size, created/last-run timestamps, and run count. Recording is best-effort in lit_action so it never fails execution, and a moka eviction_listener keeps the index consistent when binaries are evicted. Expose GET /core/v1/cache_metadata to return this metadata for the caller's account — never the cached code itself. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a secondary in-memory index in lit-api-server to correlate cached Lit Action code (keyed by IPFS id) with the caller’s master account, and exposes a new /core/v1/cache_metadata endpoint to retrieve cache metadata scoped to the authenticated account.
Changes:
- Introduces
CacheMetadataIndexand wires it into Lit Action execution + IPFS cache eviction flow. - Adds
GET /cache_metadataendpoint and response models to return per-account cache metadata (no binaries). - Regenerates
k6/litApiServer.tsclient types/route for the new endpoint.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lit-api-server/src/main.rs | Creates and manages CacheMetadataIndex; attaches moka eviction listener to keep index consistent. |
| lit-api-server/src/core/v1/models/response.rs | Adds CacheMetadataResponse and CacheEntryMetadataItem API response models. |
| lit-api-server/src/core/v1/endpoints/mod.rs | Registers the new get_cache_metadata route in the v1 route list/spec. |
| lit-api-server/src/core/v1/endpoints/configuration.rs | Implements GET /cache_metadata endpoint (authenticated via ApiKey). |
| lit-api-server/src/core/v1/endpoints/actions.rs | Passes cache-metadata state into Lit Action execution path. |
| lit-api-server/src/core/mod.rs | Exposes the new cache_metadata module. |
| lit-api-server/src/core/core_features.rs | Records executions into the metadata index; adds core handler for returning per-account metadata. |
| lit-api-server/src/core/cache_metadata.rs | New index implementation + unit tests for recording/lookup/eviction cleanup. |
| k6/litApiServer.ts | Updates generated k6 client types and method for /cache_metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…cache-binariesenvironmentsdata-that-are-used-with
…p, no truncation - Recover poisoned RwLock guards in CacheMetadataIndex instead of panicking (record_execution runs on the hot path; remove_entry runs in the moka eviction listener; entries_for_account serves GET requests). - entries_for_account now returns a CacheEntrySnapshot projection so a widely-shared entry no longer clones its account_addresses HashSet per read. - system_time_to_millis saturates the u128→u64 conversion instead of truncating. - Allow clippy::too_many_arguments on build_rocket (now 8 args). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ersion cargo-deny 0.20 moved `--config` from the `check` subcommand to a root-level flag, so the unpinned taiki-e/install-action (which pulled 0.20.2) broke every Rust matrix job with `error: unexpected argument '--config' found`. Move `--config` before `check` and pin the tool to 0.20.2 so an unpinned upgrade can't silently flip the syntax again. Verified against the 0.20.2 binary for all six matrix crates (advisories ok, sources ok, exit 0). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…cache-binariesenvironmentsdata-that-are-used-with # Conflicts: # .github/workflows/rust-ci.yml
🤖 Code review (Claude)This PR adds a Findings1.
Per re-run of an already-cached action the sequence is: Fix: early-return in the listener when 2. Uncached on-chain RPC added to the hot action-execution path (performance)
3. Orphaned metadata when eviction races the recording (minor, related to #1)
4. Invalid API key returns 400, not 401 (minor inconsistency)
Nits
VerdictNeeds changes — finding #1 breaks the core deliverable (run counts / timestamps are reset on every re-execution or entries vanish entirely), and #2 adds an uncached RPC to the hottest path in the server. Both have small, contained fixes. |
…, 401 (CPL-351) - MAJOR: the moka eviction listener treated RemovalCause::Replaced as a removal, so re-inserting an already-cached action (which lit_action does on every request) wiped its metadata — resetting run_count/created_at or making entries vanish. The listener now ignores Replaced (the key is still cached). Added a regression test driving the index through a real moka cache. - Moved the best-effort execution recording (which does an uncached on-chain get_account_wallet_address call) into a tokio::spawn so it no longer adds RPC latency to the POST /lit_action hot path. - get_cache_metadata now returns 401 for an unregistered key (matching the billing convention) and 500 for a genuine RPC/contract failure, instead of a blanket 400. - Documented the bounded (practically unreachable) orphan-metadata race and the internal-only CacheEntrySnapshot.account_count field. - Reverted the rust-ci.yml comment churn now that main carries the same fix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Responses to the Claude review — addressed in
|
…cache-binariesenvironmentsdata-that-are-used-with # Conflicts: # k6/litApiServer.ts # lit-api-server/src/core/core_features.rs # lit-api-server/src/core/v1/endpoints/mod.rs # lit-api-server/src/main.rs # spec.json
Implements CPL-351 by adding a
CacheMetadataIndexsecondary lookup alongside the IPFS action-code cache that correlates each cached entry to the master account (account wallet address) that executed it, tracking size, created/last-run timestamps, and run count. Recording happens best-effort insidelit_actionso a failed on-chain wallet lookup never fails execution, and a mokaeviction_listenerkeeps the index consistent when binaries are evicted, replaced, or removed. A newGET /core/v1/cache_metadataendpoint returns this metadata scoped to the caller's account — never the cached code/binaries themselves. Includes 7 unit tests for the index (recording, shared entries, eviction cleanup) and a regeneratedk6/litApiServer.tsfor the new route.🤖 Generated with Claude Code