feat: add service-level auth token to email inbound flow#229
Conversation
The email agent was getting zero MCP tools because the ChatRequestBody had no authToken. Pass RECOUP_API_KEY as authToken so the email flow gets the same MCP tools (sandbox, etc.) as the chat UI and API paths. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
You have run out of free Bugbot PR reviews for this billing cycle. This will reset on March 17. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughEnvironment variable Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/const.ts`:
- Line 32: RECOUP_API_KEY currently defaults to an empty string which hides a
missing configuration; change its initialization to mirror the startup guard
used by PRIVY_PROJECT_SECRET by throwing an explicit Error when
process.env.RECOUP_API_KEY is not set (refer to the existing
PRIVY_PROJECT_SECRET pattern) so the app fails fast at startup instead of
silently using "" for RECOUP_API_KEY.
| */ | ||
| export const RECOUP_ORG_ID = "04e3aba9-c130-4fb8-8b92-34e95d43e66b"; | ||
|
|
||
| export const RECOUP_API_KEY = process.env.RECOUP_API_KEY || ""; |
There was a problem hiding this comment.
RECOUP_API_KEY should fail fast when unset, not silently fall back to "".
PRIVY_PROJECT_SECRET on lines 3–5 guards against a missing env var at startup with an explicit throw. RECOUP_API_KEY is equally load-bearing in production — it's the service-level auth token that gates MCP tool access in the email inbound flow. Falling back to "" means the app starts up successfully even if this env var is never configured in Vercel, and every inbound email request will carry an empty authToken with no error signal — silently regressing to pre-PR, tool-less behavior. The PR description itself calls out configuring this env var as a manual step, making the silent-failure risk concrete.
Apply the same startup-guard pattern used by PRIVY_PROJECT_SECRET:
🛡️ Proposed fix: fail fast on missing RECOUP_API_KEY
+if (!process.env.RECOUP_API_KEY) {
+ throw new Error("RECOUP_API_KEY environment variable is required");
+}
+
-export const RECOUP_API_KEY = process.env.RECOUP_API_KEY || "";
+export const RECOUP_API_KEY = process.env.RECOUP_API_KEY;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export const RECOUP_API_KEY = process.env.RECOUP_API_KEY || ""; | |
| if (!process.env.RECOUP_API_KEY) { | |
| throw new Error("RECOUP_API_KEY environment variable is required"); | |
| } | |
| export const RECOUP_API_KEY = process.env.RECOUP_API_KEY; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@lib/const.ts` at line 32, RECOUP_API_KEY currently defaults to an empty
string which hides a missing configuration; change its initialization to mirror
the startup guard used by PRIVY_PROJECT_SECRET by throwing an explicit Error
when process.env.RECOUP_API_KEY is not set (refer to the existing
PRIVY_PROJECT_SECRET pattern) so the app fails fast at startup instead of
silently using "" for RECOUP_API_KEY.
Summary
RECOUP_API_KEYconstant tolib/const.ts(reads fromprocess.env.RECOUP_API_KEY)authToken: RECOUP_API_KEYin theChatRequestBodybuilt byvalidateNewEmailMemory, so the email agent gets MCP tools (sandbox, etc.) instead of zero toolsvalidateNewEmailMemory.test.tswith 3 tests covering authToken presence, correct body shape, and duplicate detectionTest plan
chatRequestBody.authTokenequalsRECOUP_API_KEYpnpm buildsucceeds with no type errorsRECOUP_API_KEYenv var in Vercel for the API project (same value as tasks)[email protected]requesting a sandbox command — agent should now use MCP tools🤖 Generated with Claude Code
Summary by CodeRabbit