Skip to content

feat: 1 free debate after Google login - #66

Merged
aiedwardyi merged 2 commits into
mainfrom
feat/free-debate-after-login
Jul 15, 2026
Merged

feat: 1 free debate after Google login#66
aiedwardyi merged 2 commits into
mainfrom
feat/free-debate-after-login

Conversation

@aiedwardyi

Copy link
Copy Markdown
Owner

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.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7c613d7d-6a39-4ae7-982d-1ac4ce592819

📥 Commits

Reviewing files that changed from the base of the PR and between 586b891 and 4540e48.

📒 Files selected for processing (13)
  • README.md
  • prisma/migrations/20260715000000_add_free_debate_grant/migration.sql
  • prisma/schema.prisma
  • src/__tests__/api-key-errors.test.ts
  • src/__tests__/byok-route-guards.test.ts
  • src/__tests__/free-debates.test.ts
  • src/app/api/free-debate/route.ts
  • src/app/page.tsx
  • src/components/SettingsModal.tsx
  • src/hooks/useDebateEngine.ts
  • src/lib/api-key-errors.ts
  • src/lib/free-debates.ts
  • src/lib/server-provider-keys.ts

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added one complimentary debate for newly signed-in accounts when authentication and server-key access are enabled.
    • Free access remains available for a 30-minute window and is shown in account settings.
    • Google sign-in prompts now explain free-debate availability and when the allowance has been used.
    • BYOK and access codes continue to take priority and do not consume the free allowance.
  • Documentation

    • Updated setup guidance with free-debate behavior and provider spending-limit recommendations.

Walkthrough

This 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.

Changes

Free Debate Grant

Layer / File(s) Summary
Grant storage and atomic claiming
prisma/schema.prisma, prisma/migrations/..., src/lib/free-debates.ts, src/__tests__/free-debates.test.ts, README.md
Adds grant fields to User, implements status and atomic claim helpers with expiry and race handling, and documents the behavior.
Server-key resolution and precedence
src/lib/server-provider-keys.ts, src/__tests__/byok-route-guards.test.ts
Allows authenticated users to claim server-key access when required keys are enabled while preserving request-body key and access-code precedence.
Grant status API and account display
src/app/api/free-debate/route.ts, src/components/SettingsModal.tsx
Adds an authenticated status endpoint and displays free-debate availability or active usage in account settings.
Auth-aware key prompts and consensus messages
src/lib/api-key-errors.ts, src/hooks/useDebateEngine.ts, src/app/page.tsx, src/__tests__/api-key-errors.test.ts
Tailors missing-key and consensus messaging for anonymous, signed-in, and exhausted-grant states.

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
Loading

Possibly related PRs

  • aiedwardyi/quorum#54: Introduces the BYOK-required resolution flow extended here with free-debate claims.
  • aiedwardyi/quorum#56: Modifies the same getApiKeyPromptMessage flow used for auth-aware messaging.
  • aiedwardyi/quorum#60: Modifies the same provider-key resolution and access-code precedence paths.

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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

@aiedwardyi
aiedwardyi merged commit 01a8004 into main Jul 15, 2026
1 of 2 checks passed
@aiedwardyi
aiedwardyi deleted the feat/free-debate-after-login branch July 15, 2026 10:42

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment on lines +61 to +62
const { tryClaimFreeServerAccess } = await import("@/lib/free-debates")
if (await tryClaimFreeServerAccess(userId)) return { status: "server" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment thread src/lib/free-debates.ts
Comment on lines +40 to +41
if (existing.freeDebateExpiresAt && existing.freeDebateExpiresAt > now) {
return true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +61 to +62
const { tryClaimFreeServerAccess } = await import("@/lib/free-debates")
if (await tryClaimFreeServerAccess(userId)) return { status: "server" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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