fix(api): resolve TypeError in chat/completions route - #41
Conversation
initTranslators() is a no-op stub (translators self-register via static imports). Wrapping the call with Promise.resolve() ensures .then() works even when the function returns undefined instead of a Promise.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@codex review |
Summary of ChangesHello @diegosouzapw, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
To use Codex here, create a Codex account and connect to github. |
There was a problem hiding this comment.
Code Review
This pull request correctly resolves a TypeError that occurred when initializing translators. The fix wraps the call to initTranslators() in Promise.resolve() to ensure a promise is always returned. My review includes a suggestion to use an async IIFE, which would make the initialization logic even more robust by caching any potential initialization failures, improving the overall reliability of the singleton initialization pattern.
| initPromise = Promise.resolve(initTranslators()).then(() => { | ||
| console.log("[SSE] Translators initialized"); | ||
| }); |
There was a problem hiding this comment.
While Promise.resolve() correctly fixes the TypeError, using an async IIFE (Immediately Invoked Function Expression) would make the logic slightly more robust, especially regarding error handling. If initTranslators() were to throw an error, this approach would cache the resulting rejected promise, preventing repeated failing attempts on subsequent calls. This improves predictability and aligns well with the singleton pattern you're using for initialization.
initPromise = (async () => {
await initTranslators();
console.log("[SSE] Translators initialized");
})();There was a problem hiding this comment.
Pull request overview
This PR fixes a TypeError that occurred in every chat completion request to /v1/chat/completions. The bug was caused by calling .then() on the return value of initTranslators(), which is a no-op stub function returning undefined (translators self-register via static imports at module load time). The fix wraps the call with Promise.resolve() to ensure it always returns a Promise that can be chained with .then().
Changes:
- Wrapped
initTranslators()call withPromise.resolve()in the ensureInitialized function to handle the undefined return value
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
TLS / Certificate Validation (#50) - src/mitm/server.ts: rejectUnauthorized now defaults to true (opt-out via MITM_DISABLE_TLS_VERIFY=1 env var only) Path Injection (#44, #41-#49) - src/mitm/server.ts: safeLogPath() guards log filenames inside LOG_DIR - src/lib/db/backup.ts: path.resolve() anchor + sep/slash guard on backupId - src/shared/services/backupService.ts: safePath() helper anchors toolId and backupId within BACKUP_DIR (prevents path traversal) - src/app/api/cli-tools/codex-profiles/route.ts: safeProfilePath() helper anchors profileId within PROFILES_DIR Prototype Pollution (#18, #19, #20) - src/lib/usage/usageHistory.ts: byModel/byAccount initialized with Object.create(null); assignments guarded with hasOwnProperty checks Missing Workflow Permissions (#1-#8, #53) - .github/workflows/ci.yml: added global permissions: contents: read Dependabot CVE-2026-0540 (#16) - dompurify updated to ^3.3.2 (fixes XSS vulnerability)
Bug:
Cannot read properties of undefined (reading 'then')in every chat completion request.Root cause:
initTranslators()inopen-sse/translator/index.jsis a no-op stub returningundefined(translators self-register via static imports). The route called.then()on it.Fix: Wrapped with
Promise.resolve()so.then()works regardless of return type.