Skip to content

chore(rsc): add use cache example with closure encryption - #1398

Merged
hi-ogawa merged 21 commits into
mainfrom
fix/issue-1393
Aug 5, 2026
Merged

chore(rsc): add use cache example with closure encryption#1398
hi-ogawa merged 21 commits into
mainfrom
fix/issue-1393

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

use cache can mostly reuse the existing use server closure encryption machinery, but one twist is that the naive copy of implementation would make decryption inside the hoisted function happens too late and encrypted closure argument (which involves non-deterministics IV) would cause unstable cache key.

This PR pre-decrypts closure captures when building the cache key. A framework-owned envelope provides a sentinel so the wrapper can distinguish encrypted closure-bound arguments from normal call arguments. This works with the existing encode/decode hooks and does not require new transform metadata, contrary to the issue’s initial framing.

The new example verifies stable cache identity across fresh ciphertext, different captured values producing different entries, and captured plaintext staying out of server responses.

Co-authored-by: OpenCode <noreply@opencode.ai>
@hi-ogawa hi-ogawa changed the title feat(rsc): demonstrate encrypted cache captures feat(rsc): add use cache example with closure encryption Aug 5, 2026
@hi-ogawa hi-ogawa changed the title feat(rsc): add use cache example with closure encryption chore(rsc): add use cache example with closure encryption Aug 5, 2026
Co-authored-by: OpenCode <noreply@opencode.ai>
hi-ogawa and others added 5 commits August 5, 2026 14:46
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
hi-ogawa and others added 4 commits August 5, 2026 15:33
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Exclude React form transport fields from cache identity while preserving the original FormData for execution.

Co-authored-by: OpenCode <noreply@opencode.ai>
hi-ogawa and others added 10 commits August 5, 2026 17:20
Co-authored-by: OpenCode <noreply@opencode.ai>
Keep FormData cache identity unchanged and point to custom form adaptation as the framework-level improvement path.

Co-authored-by: OpenCode <noreply@opencode.ai>
Store the asynchronous encryption result in the envelope so the cache wrapper can inspect its sentinel without awaiting the argument.

Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
@hi-ogawa
hi-ogawa marked this pull request as ready for review August 5, 2026 09:06
Comment on lines +68 to +73
// TODO: On a cache miss, the hoister-generated implementation decrypts the
// original envelope again. A tighter adapter could reuse these captures.
const cacheArguments = [
...(await decryptCacheCaptures(firstArgument)),
...admittedArgs.slice(1),
]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To highlight the use server encryption parallel, this PR first lands with this approach. In principle, it's possible to decrypt once and reuse, which is deferred to follow-up PR #1403

@hi-ogawa
hi-ogawa merged commit f97d959 into main Aug 5, 2026
27 checks passed
@hi-ogawa
hi-ogawa deleted the fix/issue-1393 branch August 5, 2026 09:19
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.

Support use cache with closure encryption

1 participant