Skip to content

Scope Tinfoil prompt cache by user#234

Merged
AnthonyRonning merged 3 commits into
masterfrom
codex-tinfoil-glm-cache-pricing-opensecret
Jul 15, 2026
Merged

Scope Tinfoil prompt cache by user#234
AnthonyRonning merged 3 commits into
masterfrom
codex-tinfoil-glm-cache-pricing-opensecret

Conversation

@AnthonyRonning

@AnthonyRonning AnthonyRonning commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • set Tinfoil user_cache_secret to the SHA-256 hash of the authenticated user UUID
  • overwrite caller-provided cache identifiers and omit the field from non-Tinfoil requests
  • update tinfoil-go to v0.14.3 and its required Go 1.26.5 build image

Testing

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-features (215 passed, 16 database-only tests ignored)
  • go mod verify
  • go test ./...
  • CGO_ENABLED=0 go build ./...

Open in Devin Review

Summary by CodeRabbit

  • New Features

    • Added provider-managed user cache secrets for Tinfoil requests, using a stable per-user SHA-256 value.
    • Ensured the proxy overwrites any client-supplied user_cache_secret for the Tinfoil provider.
    • Removed unsupported cache-related request fields for non-Tinfoil providers.
  • Maintenance

    • Updated the Tinfoil proxy build/runtime Go version and refreshed Go module dependencies.
    • Updated PCR history data with a new recorded entry (development and production).

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e686fdf5-f29e-4169-bd3e-446c95a62e8d

📥 Commits

Reviewing files that changed from the base of the PR and between b6931d9 and 3b8c4d3.

⛔ Files ignored due to path filters (3)
  • pcrDev.json is excluded by !pcrDev.json
  • pcrProd.json is excluded by !pcrProd.json
  • tinfoil-proxy/dist/tinfoil-proxy is excluded by !**/dist/**
📒 Files selected for processing (2)
  • pcrDevHistory.json
  • pcrProdHistory.json

Walkthrough

The OpenAI proxy now applies provider-specific cache fields, including hashed Tinfoil user secrets. The Tinfoil proxy updates its Go toolchain and modules, while development and production PCR history files receive new signed records.

Changes

Provider Cache Handling

Layer / File(s) Summary
Apply provider-managed cache fields
src/web/openai.rs
Completion requests remove cache_salt, inject a stable SHA-256 user UUID hash for Tinfoil, and strip user_cache_secret for other providers. Unit tests cover these behaviors.

Tinfoil Proxy Build Updates

Layer / File(s) Summary
Update Go toolchain and modules
tinfoil-proxy/Dockerfile, tinfoil-proxy/go.mod
The builder uses Go 1.26.5, direct dependencies are upgraded, and indirect module requirements are refreshed. The entrypoint remains /tinfoil-proxy.

PCR History Updates

Layer / File(s) Summary
Append PCR history records
pcrDevHistory.json, pcrProdHistory.json
Both history files append records containing PCR measurements, timestamps, and signatures.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant get_chat_completion_response
  participant apply_provider_managed_request_fields
  participant ProviderAPI
  Client->>get_chat_completion_response: Send completion request and user UUID
  get_chat_completion_response->>apply_provider_managed_request_fields: Apply provider-specific fields
  apply_provider_managed_request_fields-->>get_chat_completion_response: Return updated request
  get_chat_completion_response->>ProviderAPI: Forward completion request
Loading

Possibly related PRs

Poem

A bunny hashes secrets bright,
Tinfoil caches them just right.
Go tools hop to versions new,
PCR records gain a few.
Across the fields and build today,
Fresh signed trails mark the way.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: scoping Tinfoil prompt cache to the authenticated user.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex-tinfoil-glm-cache-pricing-opensecret

Comment @coderabbitai help to get the list of available commands.

devin-ai-integration[bot]

This comment was marked as resolved.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/web/openai.rs (1)

1267-1270: 🔒 Security & Privacy | 🔵 Trivial

Unsalted hash makes user_cache_secret predictable to anyone who knows the user's UUID.

tinfoil_user_cache_secret is a plain SHA-256(uuid_bytes) with no server-side key/salt. Since it's deterministic and derivable from just the UUID, any party that later learns a user's UUID (e.g. via logs, another API, or token claims) can recompute the exact same value sent to the third-party Tinfoil provider and correlate that user's cache entries across sessions — the field is functionally an obfuscated identifier rather than a secret. Consider deriving this with HMAC-SHA256 using a server-held secret key instead of a bare hash, so correlation requires server cooperation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/web/openai.rs` around lines 1267 - 1270, Update tinfoil_user_cache_secret
to derive the cache secret with HMAC-SHA256 using a server-held secret key,
rather than hashing user_uuid directly. Reuse the existing application
secret/configuration mechanism and preserve deterministic output for the same
user and key, while ensuring callers continue receiving the encoded digest
string.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/web/openai.rs`:
- Around line 1267-1270: Update tinfoil_user_cache_secret to derive the cache
secret with HMAC-SHA256 using a server-held secret key, rather than hashing
user_uuid directly. Reuse the existing application secret/configuration
mechanism and preserve deterministic output for the same user and key, while
ensuring callers continue receiving the encoded digest string.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6a994a73-f89a-47cc-a866-ff402d23c658

📥 Commits

Reviewing files that changed from the base of the PR and between a3ecc93 and b6931d9.

⛔ Files ignored due to path filters (1)
  • tinfoil-proxy/go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • src/web/openai.rs
  • tinfoil-proxy/Dockerfile
  • tinfoil-proxy/go.mod

@AnthonyRonning
AnthonyRonning merged commit e8229a1 into master Jul 15, 2026
12 checks passed
@AnthonyRonning
AnthonyRonning deleted the codex-tinfoil-glm-cache-pricing-opensecret branch July 15, 2026 03:12
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.

1 participant