fix: resolve webpack runtime error in resolution search#740
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
|
Warning Review limit reached
Next review available in: 56 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
WalkthroughThe provider-selection ChangesModel utility migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Blocking finding
lib/utils/index.ts no longer exports getModel, but unchanged server-side callers still import it from the old barrel, including:
lib/agents/writer.tsx:5,35lib/agents/researcher.tsx:13,147lib/actions/system-prompt.ts:7,80lib/actions/chat.ts:24
Because this PR only updates the imports in lib/agents/resolution-search.tsx:2 and mapbox_mcp/hooks.ts:3, these remaining imports resolve to a module without getModel and will fail TypeScript/Next compilation. Update every server-side caller to import getModel from @/lib/utils/server (or the corresponding relative server path) before merging.
I inspected the current head diff, surrounding call sites, discussion, and existing checks. Existing checks show Vercel – qcx failing, while Vercel Preview Comments and GitGuardian Security Checks pass; no test, lint, or build commands were run as part of this review.
…rt from lib/utils and fixing imports
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@lib/utils/server.ts`:
- Around line 20-58: Update the model-selection branches in the server model
factory so each persisted option maps to its actual supported model ID: replace
the legacy IDs for “Grok 4.2,” “Gemini 3,” “Gemini 3.1 Pro,” and “GPT-5.1” with
matching IDs, or explicitly reject any option without a supported ID. Do not
silently return older models from the Grok, Gemini, or OpenAI initialization
paths.
- Around line 66-110: Move provider fallback handling out of the model-selection
function and into the generation path that invokes generateText or streamObject.
Update the flow around the xAI, Gemini, Bedrock, and OpenAI provider handles so
provider/auth errors are caught during generation and the next configured
provider is attempted, while preserving the existing provider order and model
configuration.
In `@mapbox_mcp/hooks.ts`:
- Around line 1-5: Remove the server-only getModel import from the client hook
and keep hooks.ts client-safe. Move generateText and model selection into a
server action or route handler, then update the hook’s generation flow to call
that server boundary while preserving its current behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 81fab221-343d-4115-a0ca-d7a8f00543a6
📒 Files selected for processing (7)
lib/actions/system-prompt.tslib/agents/report/executive-summary.tslib/agents/report/strategic-synthesis.tslib/agents/resolution-search.tsxlib/utils/index.tslib/utils/server.tsmapbox_mcp/hooks.ts
💤 Files with no reviewable changes (1)
- lib/utils/index.ts
📜 Review details
🔇 Additional comments (5)
lib/utils/server.ts (1)
1-16: LGTM!lib/actions/system-prompt.ts (1)
7-7: LGTM!lib/agents/report/executive-summary.ts (1)
2-2: LGTM!lib/agents/report/strategic-synthesis.ts (1)
2-2: LGTM!lib/agents/resolution-search.tsx (1)
2-2: LGTM!
| case 'Grok 4.2': | ||
| if (xaiApiKey) { | ||
| const xai = createXai({ | ||
| apiKey: xaiApiKey, | ||
| baseURL: 'https://api.x.ai/v1', | ||
| }); | ||
| try { | ||
| const modelId = requireVision ? 'grok-vision-beta' : 'grok-2-1212'; | ||
| return xai(modelId); | ||
| } catch (error) { | ||
| console.error('Selected model "Grok 4.2" is configured but failed to initialize.', error); | ||
| throw new Error('Failed to initialize selected model.'); | ||
| } | ||
| } else { | ||
| console.error('User selected "Grok 4.2" but XAI_API_KEY is not set.'); | ||
| throw new Error('Selected model is not configured.'); | ||
| } | ||
| case 'Gemini 3': | ||
| case 'Gemini 3.1 Pro': | ||
| if (gemini3ProApiKey) { | ||
| const google = createGoogleGenerativeAI({ | ||
| apiKey: gemini3ProApiKey, | ||
| }); | ||
| try { | ||
| return google('gemini-1.5-pro-latest'); | ||
| } catch (error) { | ||
| console.error('Selected model "Gemini 3.1 Pro" is configured but failed to initialize.', error); | ||
| throw new Error('Failed to initialize selected model.'); | ||
| } | ||
| } else { | ||
| console.error('User selected "Gemini 3.1 Pro" but GEMINI_3_PRO_API_KEY is not set.'); | ||
| throw new Error('Selected model is not configured.'); | ||
| } | ||
| case 'GPT-5.1': | ||
| if (openaiApiKey) { | ||
| const openai = createOpenAI({ | ||
| apiKey: openaiApiKey, | ||
| }); | ||
| return openai('gpt-4o'); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Honor the model selected by the user.
These branches silently substitute older models: Grok 4.2 returns grok-2-1212, both Gemini 3 choices return Gemini 1.5, and GPT-5.1 returns GPT-4o. Align the persisted option names with the actual model IDs or reject unsupported selections instead of returning a different model.
🤖 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 `@lib/utils/server.ts` around lines 20 - 58, Update the model-selection
branches in the server model factory so each persisted option maps to its actual
supported model ID: replace the legacy IDs for “Grok 4.2,” “Gemini 3,” “Gemini
3.1 Pro,” and “GPT-5.1” with matching IDs, or explicitly reject any option
without a supported ID. Do not silently return older models from the Grok,
Gemini, or OpenAI initialization paths.
| // Default behavior: Grok -> Gemini -> Bedrock -> OpenAI | ||
| if (xaiApiKey) { | ||
| const xai = createXai({ | ||
| apiKey: xaiApiKey, | ||
| baseURL: 'https://api.x.ai/v1', | ||
| }); | ||
| try { | ||
| const modelId = requireVision ? 'grok-vision-beta' : 'grok-latest'; | ||
| return xai(modelId); | ||
| } catch (error) { | ||
| console.warn('xAI API unavailable, falling back to next provider:'); | ||
| } | ||
| } | ||
|
|
||
| if (gemini3ProApiKey) { | ||
| const google = createGoogleGenerativeAI({ | ||
| apiKey: gemini3ProApiKey, | ||
| }); | ||
| try { | ||
| return google('gemini-1.5-pro-latest'); | ||
| } catch (error) { | ||
| console.warn('Gemini 3.1 Pro API unavailable, falling back to next provider:', error); | ||
| } | ||
| } | ||
|
|
||
| if (awsAccessKeyId && awsSecretAccessKey) { | ||
| const bedrock = createAmazonBedrock({ | ||
| bedrockOptions: { | ||
| region: awsRegion, | ||
| credentials: { | ||
| accessKeyId: awsAccessKeyId, | ||
| secretAccessKey: awsSecretAccessKey, | ||
| }, | ||
| }, | ||
| }); | ||
| const model = bedrock(bedrockModelId, { | ||
| additionalModelRequestFields: { top_k: 350 }, | ||
| }); | ||
| return model; | ||
| } | ||
|
|
||
| const openai = createOpenAI({ | ||
| apiKey: openaiApiKey, | ||
| }); | ||
| return openai('gpt-4o'); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== file list =="
git ls-files lib/utils/server.ts
echo
echo "== file size =="
wc -l lib/utils/server.ts
echo
echo "== outline =="
ast-grep outline lib/utils/server.ts --view expanded
echo
echo "== relevant lines =="
sed -n '1,220p' lib/utils/server.ts | cat -n
echo
echo "== search for consumers of the returned model =="
rg -n "create[A-Za-z]+\\(|generateText\\(|streamObject\\(|return .*openai\\(|return .*google\\(|return .*xai\\(" lib -g '!**/dist/**' -g '!**/build/**'Repository: QueueLab/QCX
Length of output: 6969
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== getModel call sites =="
rg -n "\bgetModel\(" lib -g '!**/dist/**' -g '!**/build/**'
echo
echo "== AI SDK provider/generation docs lookup =="
python3 - <<'PY'
import urllib.request, urllib.parse, json, re
queries = [
"ai sdk provider factory returns model object generateText streamObject network request happens later",
"site:ai-sdk.dev createOpenAI model object generateText streamObject",
]
for q in queries:
print(f"\nQUERY: {q}")
PYRepository: QueueLab/QCX
Length of output: 1264
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== ai-sdk dependencies =="
rg -n '"`@ai-sdk/`|ai"' package.json pnpm-lock.yaml package-lock.json yarn.lock -g '!**/node_modules/**'
echo
echo "== provider factories in repo =="
rg -n "create(OpenAI|GoogleGenerativeAI|AmazonBedrock|Xai)\(" lib package.json -g '!**/node_modules/**'Repository: QueueLab/QCX
Length of output: 684
🌐 Web query:
ai-sdk provider factory createOpenAI createGoogleGenerativeAI createXai returns language model object generateText streamObject network request happens later
💡 Result:
When you use factory functions like createOpenAI, createGoogleGenerativeAI, or createXai in the Vercel AI SDK, they do not initiate any network requests at the time of creation [1][2]. These functions simply return a provider instance—a configuration object containing the settings (such as API keys, base URLs, and headers) and the logic required to instantiate specific language models later [1][3][2]. The network request only occurs later, when you actually use the returned language model object in a function such as generateText or streamText [4][5][6]. At that point, the SDK uses the configuration defined in your provider instance to construct and execute the API call to the respective AI service [1][3][7].
Citations:
- 1: https://github.com/vercel/ai/blob/a23b6767/packages/openai/src/openai-provider.ts
- 2: https://github.com/vercel/ai/blob/main/packages/openai/src/openai-provider.ts
- 3: https://github.com/vercel/ai/blob/a23b6767/packages/gateway/src/gateway-provider.ts
- 4: https://ai-sdk.dev/docs/reference/ai-sdk-core/generate-text
- 5: https://ai-sdk.dev/docs/ai-sdk-core/generating-text
- 6: https://ai-sdk.dev/v7/docs/reference/ai-sdk-core/stream-text
- 7: https://github.com/vercel/ai/blob/a23b6767/packages/ai/src/generate-text/stream-text.ts
Move fallback selection to the generation path. createXai(...), google(...), bedrock(...), and openai(...) only return model handles; provider/auth failures surface when generateText or streamObject runs. As written, the first configured provider is returned immediately, so later fallbacks never execute.
🤖 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 `@lib/utils/server.ts` around lines 66 - 110, Move provider fallback handling
out of the model-selection function and into the generation path that invokes
generateText or streamObject. Update the flow around the xAI, Gemini, Bedrock,
and OpenAI provider handles so provider/auth errors are caught during generation
and the next configured provider is attempted, while preserving the existing
provider order and model configuration.
| 'use client'; | ||
|
|
||
| import { useState, useCallback, useRef, useEffect } from 'react'; | ||
| import { generateText } from 'ai'; | ||
| import { getModel } from '@/lib/utils'; | ||
| import { getModel } from '@/lib/utils/server'; |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔴 Critical | 🏗️ Heavy lift
Do not import the server model utility into a Client Component.
'use client' makes this entire dependency graph client-side, but getModel reads server environment credentials and imports getSelectedModel. This recreates the mixed client/server bundle failure the PR is intended to fix. Move generateText and model selection behind a server action or route handler, then call that boundary from this hook.
🤖 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 `@mapbox_mcp/hooks.ts` around lines 1 - 5, Remove the server-only getModel
import from the client hook and keep hooks.ts client-safe. Move generateText and
model selection into a server action or route handler, then update the hook’s
generation flow to call that server boundary while preserving its current
behavior.
This PR fixes the 'TypeError: Cannot read properties of undefined (reading 'call')' by isolating server-only utilities from the shared
@/lib/utilsmodule. The mixed client/server imports in@/lib/utilswere poisoning the client bundle, causing webpack runtime failures when client components (likeResolutionCarousel) imported common helpers likenanoidorcn.Summary by CodeRabbit