Skip to content

feat: free debate discovery and budget-limit copy - #70

Merged
aiedwardyi merged 3 commits into
mainfrom
feat/free-debate-discovery
Jul 21, 2026
Merged

aiedwardyi merged 3 commits into
mainfrom
feat/free-debate-discovery

Conversation

@aiedwardyi

@aiedwardyi aiedwardyi commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Shows the free-debate offer on the welcome screen and separates daily budget limits from missing-key errors in 402 handling.

Review fixes applied: 5a087d1 - configured-flag key check, fetch abort on cleanup, budget copy promises only unused grants.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 38 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 68326fd8-0fc0-48ad-8de6-b2e28b4c0ba8

📥 Commits

Reviewing files that changed from the base of the PR and between 5f3f478 and b162c9b.

📒 Files selected for processing (3)
  • src/__tests__/api-key-errors.test.ts
  • src/components/WelcomeHero.tsx
  • src/lib/api-key-errors.ts
📝 Walkthrough

Walkthrough

HTTP 402 handling now distinguishes missing API keys from host budget exhaustion across debate and OCR flows. API-key parsing and budget messages are generalized, tests are expanded, and the welcome hero adds session-aware free-debate eligibility hints.

Changes

HTTP 402 handling and free debate

Layer / File(s) Summary
402 parsing contract and messages
src/lib/api-key-errors.ts, src/__tests__/api-key-errors.test.ts
Adds Blocked402, strict payload and response parsing, budget message variants, and coverage for valid, malformed, and unparsable responses.
402 consumer branching
src/hooks/useDebateEngine.ts, src/lib/file-parser.ts
Debate and OCR flows distinguish host_budget_exceeded from no_key, updating messages, stopping relevant flows, and requesting keys only when a provider is available.
Free debate eligibility hint
src/components/WelcomeHero.tsx
Uses session status and concurrent free-debate/API-key requests to render localized sign-in or free-debate-ready hints.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant WelcomeHero
  participant FreeDebateAPI
  participant UserAPIKeys
  User->>WelcomeHero: Open welcome screen
  WelcomeHero->>FreeDebateAPI: Check free-debate eligibility
  WelcomeHero->>UserAPIKeys: Check saved API keys
  FreeDebateAPI-->>WelcomeHero: Eligibility state
  UserAPIKeys-->>WelcomeHero: API-key state
  WelcomeHero-->>User: Render localized free-debate hint
Loading

Possibly related PRs

  • aiedwardyi/quorum#54: Introduces the route-side no_key 402 contract consumed by these parsing changes.
  • aiedwardyi/quorum#58: Added the original API-key parsing helpers that this PR generalizes into parse402*.
  • aiedwardyi/quorum#67: Establishes the no_key and host_budget_exceeded blocked-response semantics used here.

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

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

Actionable comments posted: 4

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

Inline comments:
In `@src/components/WelcomeHero.tsx`:
- Around line 327-349: Update the useEffect request flow in WelcomeHero so it
creates an AbortController, passes its signal to both fetch calls in decide, and
aborts the controller during cleanup alongside setting cancelled. Ensure the
promise handling ignores the expected abort error while preserving handling for
other failures and preventing stale state updates.
- Around line 333-340: Update the grant readiness condition in the WelcomeHero
data-loading logic to use grant.active rather than negating it. Preserve the
existing remaining-call and hasKey checks so the “ready” hint appears only for
users with an active grant and no saved API key.
- Around line 333-340: Update the free-debate readiness logic in the WelcomeHero
grant/key-status flow so an unavailable or non-OK user API keys response fails
closed instead of being treated as having no keys. Require a valid key-status
result before returning "ready", while preserving the existing saved-key
detection and grant eligibility checks.

In `@src/hooks/useDebateEngine.ts`:
- Around line 415-416: Require blocked?.kind === "no_key" before treating a 402
response as an API-key issue: update the handler around
src/hooks/useDebateEngine.ts lines 415-416 to call onApiKeyRequired only for
that kind and otherwise show a generic request failure; update lines 715-721 to
use the missing-consensus-key message only for no_key and analysis failure for
unclassified responses; apply the same explicit-kind guard in the stopped-debate
consensus flow at lines 844-853.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c11e91c4-ffe8-4821-84e4-9c3eaceca4cd

📥 Commits

Reviewing files that changed from the base of the PR and between 7307b8f and 5f3f478.

📒 Files selected for processing (5)
  • src/__tests__/api-key-errors.test.ts
  • src/components/WelcomeHero.tsx
  • src/hooks/useDebateEngine.ts
  • src/lib/api-key-errors.ts
  • src/lib/file-parser.ts
📜 Review details
🧰 Additional context used
🪛 React Doctor (0.7.6)
src/components/WelcomeHero.tsx

[warning] 327-327: fetch() inside useEffect can race, double-fire, or leak. Use a data-fetching layer or Server Component instead.

Use a data-fetching layer or Server Component so fetches do not race, double-fire, or leak from useEffect.

(no-fetch-in-effect)

🔇 Additional comments (6)
src/lib/api-key-errors.ts (1)

14-50: LGTM!

src/__tests__/api-key-errors.test.ts (1)

4-62: LGTM!

src/hooks/useDebateEngine.ts (1)

11-13: LGTM!

Also applies to: 561-565

src/lib/file-parser.ts (1)

4-4: LGTM!

Also applies to: 253-256

src/components/WelcomeHero.tsx (2)

4-9: LGTM!

Also applies to: 28-38, 392-405


324-350: 🎯 Functional Correctness

Recompute eligibility when the user identity changes.

The effect is keyed only by authentication status, but /api/free-debate and /api/user-api-keys are user-specific. If account switching changes session data while status remains "authenticated", the previous account’s hint can persist. Include a stable session user identifier in the dependency list, or verify that WelcomeHero remounts on account changes.

Comment thread src/components/WelcomeHero.tsx
Comment thread src/components/WelcomeHero.tsx
Comment thread src/hooks/useDebateEngine.ts

@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: 5f3f478b60

ℹ️ 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 thread src/components/WelcomeHero.tsx Outdated
Comment thread src/lib/api-key-errors.ts Outdated
@aiedwardyi
aiedwardyi merged commit cf3342a into main Jul 21, 2026
1 of 2 checks passed
@aiedwardyi
aiedwardyi deleted the feat/free-debate-discovery branch July 21, 2026 06:58
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