feat(THU-708): upgrade tinfoil and enable prompt caching#1140
Open
arienemaiara wants to merge 2 commits into
Open
feat(THU-708): upgrade tinfoil and enable prompt caching#1140arienemaiara wants to merge 2 commits into
arienemaiara wants to merge 2 commits into
Conversation
- bump tinfoil 1.1.4 -> 1.1.11 for userCacheSecret support - generate a per-device cache secret in localStorage; it only reaches the attested enclave, never our backend - pass the secret to both system and user SecureClient instances - clear the secret on identity teardown so a new cache namespace starts
Semgrep Security ScanNo security issues found. |
There was a problem hiding this comment.
Pull request overview
Upgrades the tinfoil SDK and wires in a per-device prompt-cache secret so Tinfoil prompt caching can be safely namespaced per device and reset on identity teardown.
Changes:
- Bump
tinfoilfrom^1.1.4to^1.1.11to supportuserCacheSecret. - Add
getUserCacheSecret/clearUserCacheSecretlocalStorage helpers and corresponding unit tests. - Pass the per-device cache secret into both system and user
SecureClientinstances; clear it during identity teardown and test cleanup.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/testing-library.ts | Clears the new cache secret between tests to prevent cross-test leakage. |
| src/lib/cleanup.ts | Clears the cache secret during local identity teardown (clearLocalData). |
| src/lib/auth-token.ts | Adds generation/storage/clearing of a per-device Tinfoil prompt-cache secret. |
| src/lib/auth-token.test.ts | Adds test coverage for secret format, stability, and regeneration after clearing. |
| src/ai/fetch.ts | Injects userCacheSecret into system/user Tinfoil SecureClient construction. |
| package.json | Upgrades tinfoil dependency version. |
| bun.lock | Updates lockfile to reflect the tinfoil upgrade and transitive dependency changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- the store already holds the bearer token, which grants more access - SDK needs the plaintext string, so a wrapping key adds no protection
Comment on lines
+59
to
+68
| export const getUserCacheSecret = (): string => { | ||
| const existing = localStorage.getItem(userCacheSecretKey) | ||
| if (existing) { | ||
| return existing | ||
| } | ||
| const bytes = crypto.getRandomValues(new Uint8Array(32)) | ||
| const secret = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('') | ||
| localStorage.setItem(userCacheSecretKey, secret) | ||
| return secret | ||
| } |
|
Preview environment deployed 🚀
Stack: Auto-destroys on PR close/merge. Login via the bundled Keycloak realm — |
PR Metrics
Updated Fri, 24 Jul 2026 17:19:40 GMT · run #2431 |
raivieiraadriano92
approved these changes
Jul 24, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
cache.mov