feat: 1 free debate after Google login - #66
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (13)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis change adds a database-backed free-debate grant with a 30-minute server-key window, claim and status APIs, account settings display, BYOK/access-code precedence, and authentication-aware API-key messaging. ChangesFree Debate Grant
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant DebateClient
participant softResolveProviderApiKey
participant tryClaimFreeServerAccess
participant PrismaUser
DebateClient->>softResolveProviderApiKey: request provider access
softResolveProviderApiKey->>tryClaimFreeServerAccess: claim for authenticated user
tryClaimFreeServerAccess->>PrismaUser: read and conditionally update grant
PrismaUser-->>tryClaimFreeServerAccess: grant result
tryClaimFreeServerAccess-->>softResolveProviderApiKey: server access status
softResolveProviderApiKey-->>DebateClient: provider key or 402 response
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf9c13e54d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const { tryClaimFreeServerAccess } = await import("@/lib/free-debates") | ||
| if (await tryClaimFreeServerAccess(userId)) return { status: "server" } |
There was a problem hiding this comment.
Defer free grants until saved consensus keys are checked
When a signed-in BYOK-required user has a saved key for a later consensus candidate (for example GPT) but not for an earlier one in resolveConsensusCandidates' order (for example Claude), this call claims the free server window before the loop ever reaches the user's saved key. If the host has credentials for that earlier provider, the verdict uses/burns host access instead of the user's BYOK; if it does not, the grant can still be consumed before falling through to the saved key. The free grant should only be attempted after all saved/body/access-code options for the consensus request have been exhausted.
Useful? React with 👍 / 👎.
| if (existing.freeDebateExpiresAt && existing.freeDebateExpiresAt > now) { | ||
| return true |
There was a problem hiding this comment.
Bind the free window to a single debate
After the first successful claim, every server-key lookup for this user returns true until freeDebateExpiresAt, regardless of which client thread or action made the request. A signed-in user can start one free debate, click New Discussion, and run additional unrelated debates/OCR calls for the rest of the 30-minute window without another decrement, so this implements a temporary account-wide host-key unlock rather than the advertised single free debate.
Useful? React with 👍 / 👎.
| const { tryClaimFreeServerAccess } = await import("@/lib/free-debates") | ||
| if (await tryClaimFreeServerAccess(userId)) return { status: "server" } |
There was a problem hiding this comment.
Check host credentials before claiming the grant
In BYOK-required account deployments where the host has not configured a key for the requested provider (for example the default panel includes Perplexity/Claude/GPT but only Gemini or Vertex is set up), this claims the user's free grant and returns server before verifying that the server can actually serve that provider. The subsequent provider call then fails with a generic model error instead of the previous 402 prompt, and the grant may already be decremented; gate the claim on provider-specific server credentials or claim only once a usable host key path is known.
Useful? React with 👍 / 👎.
Signed-in users get one free debate on host keys (30m window). BYOK and access codes still win; free grant only kicks in after those.