Repository navigation
Harden Recoup MCP tools for OpenAI review - #1297
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Pre-merge checks:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf13010ebd
ℹ️ 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".
| const key = Buffer.from(process.env.OAUTH_INDEX_KEY ?? "", "base64"); | ||
| if (key.length !== 32) throw new Error("Social refresh quote signing unavailable"); |
There was a problem hiding this comment.
Decouple refresh quotes from optional OAuth secrets
When OAuth is disabled or an API-key/Privy deployment does not provision OAuth secrets, every scrape_artist_socials preview now fails with the generic scrape error because the standard MCP path still registers this tool through baseHandler (app/mcp/route.ts), while OAUTH_INDEX_KEY is documented as configuration for the separately enabled OAuth runtime. This turns a previously usable standard MCP tool into a complete outage in a supported non-OAuth configuration; sign quotes with a secret required by the standard MCP runtime or explicitly introduce and validate a generally required quote-signing secret.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
7 issues found and verified against the latest diff
Confidence score: 2/5
executeQuotedSocialRefresh.tscan dispatch multiple distinct quotes against the same unreserved balance, leaving some work unbilled under concurrent execution. Reserve credits atomically before dispatch.registerGetCatalogSongsTool.tsacceptsstart_pagevalues near one billion, which can trigger an impractically large offset. Cap the page range or reject pages beyond the catalog total.registerGetCatalogSongsTool.tscan return a raw Supabase error when the catalog-membership query fails. Log the diagnostic server-side and return a generic access error.registerScrapeArtistSocialsTool.tsandprojectPublicScrapeResults.tsexceed the stated 100-line limit. Move the quote-result mapping and projection helpers or allowlists into focused modules.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/mcp/tools/artistSocials/executeQuotedSocialRefresh.ts">
<violation number="1" location="lib/mcp/tools/artistSocials/executeQuotedSocialRefresh.ts:54">
P1: This read-only gate does not reserve credits across distinct quotes. Concurrent executions can each see the same balance, claim separate quotes, and dispatch before either debit; the account can receive extra unbilled scrapes or be charged after the approved balance is exhausted. Replace this check with an atomic reservation/charge or an account-scoped lock covering dispatch.</violation>
</file>
<file name="lib/catalog/analyzeFullCatalog.ts">
<violation number="1" location="lib/catalog/analyzeFullCatalog.ts:11">
P3: The new pagination options leave `analyzeFullCatalog`'s public documentation inaccurate: it still promises to fetch all songs and omits the 1-based `startPage`/`nextPage` contract. Update the JSDoc so callers do not assume a single call analyzes the entire catalog.</violation>
</file>
<file name="lib/mcp/tools/catalogs/registerGetCatalogSongsTool.ts">
<violation number="1" location="lib/mcp/tools/catalogs/registerGetCatalogSongsTool.ts:18">
P2: `start_page` permits an offset of nearly one billion rows. Cap page requests to a realistic bound or obtain the total before applying the offset and reject pages beyond the catalog.</violation>
<violation number="2" location="lib/mcp/tools/catalogs/registerGetCatalogSongsTool.ts:46">
P3: Move the account and catalog-access checks into a dedicated `validateGetCatalogSongs...` operation validator, then have this callback consume its validated result before running `analyzeFullCatalog`; keeping authorization in the orchestration handler makes this entry point’s access contract easy to bypass or diverge when reused.
(Based on your team's feedback about centralizing handler validation.)</violation>
<violation number="3" location="lib/mcp/tools/catalogs/registerGetCatalogSongsTool.ts:46">
P2: A catalog-membership query failure can propagate the raw Supabase error through this MCP callback. Catch the authorization/read failure, log the diagnostic server-side, and return a generic catalog-access-unavailable error.</violation>
</file>
<file name="lib/mcp/tools/artistSocials/registerScrapeArtistSocialsTool.ts">
<violation number="1" location="lib/mcp/tools/artistSocials/registerScrapeArtistSocialsTool.ts:69">
P2: Custom agent: **Enforce Clear Code Style and Maintainability Practices**
This module is now 117 lines, exceeding Rule 3’s under-100-line limit. Move the quote-result mapping into a focused helper so the registration module stays below the limit.</violation>
</file>
<file name="lib/mcp/tools/artistSocials/projectPublicScrapeResults.ts">
<violation number="1" location="lib/mcp/tools/artistSocials/projectPublicScrapeResults.ts:1">
P2: Custom agent: **Enforce Clear Code Style and Maintainability Practices**
This module is 123 lines, exceeding the rule’s under-100-line limit. Move the allowlists or projection helpers into a separate module to bring it below the limit.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| const claims = quote.verify(approvedQuote); | ||
| if (!claims) return { kind: "invalid_quote" }; | ||
|
|
||
| const gate = await checkCreditsAvailable({ accountId, creditsToDeduct: maximumCredits }); |
There was a problem hiding this comment.
P1: This read-only gate does not reserve credits across distinct quotes. Concurrent executions can each see the same balance, claim separate quotes, and dispatch before either debit; the account can receive extra unbilled scrapes or be charged after the approved balance is exhausted. Replace this check with an atomic reservation/charge or an account-scoped lock covering dispatch.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/artistSocials/executeQuotedSocialRefresh.ts, line 54:
<comment>This read-only gate does not reserve credits across distinct quotes. Concurrent executions can each see the same balance, claim separate quotes, and dispatch before either debit; the account can receive extra unbilled scrapes or be charged after the approved balance is exhausted. Replace this check with an atomic reservation/charge or an account-scoped lock covering dispatch.</comment>
<file context>
@@ -0,0 +1,60 @@
+ const claims = quote.verify(approvedQuote);
+ if (!claims) return { kind: "invalid_quote" };
+
+ const gate = await checkCreditsAvailable({ accountId, creditsToDeduct: maximumCredits });
+ if (gate.kind === "insufficient_credits") return gate;
+ if (!(await claimSocialRefreshQuote(claims.id, claims.expiresAt))) return { kind: "used_quote" };
</file context>
| @@ -0,0 +1,123 @@ | |||
| interface PublicScrapeItem { | |||
There was a problem hiding this comment.
P2: Custom agent: Enforce Clear Code Style and Maintainability Practices
This module is 123 lines, exceeding the rule’s under-100-line limit. Move the allowlists or projection helpers into a separate module to bring it below the limit.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/artistSocials/projectPublicScrapeResults.ts, line 1:
<comment>This module is 123 lines, exceeding the rule’s under-100-line limit. Move the allowlists or projection helpers into a separate module to bring it below the limit.</comment>
<file context>
@@ -0,0 +1,123 @@
+interface PublicScrapeItem {
+ [key: string]: string | number | PublicScrapeItem | PublicScrapeItem[];
+}
</file context>
| execute: params => | ||
| executeQuotedSocialRefresh(params, args.artist_account_id, args.approved_quote), | ||
| }); | ||
| if (result.kind === "quote") { |
There was a problem hiding this comment.
P2: Custom agent: Enforce Clear Code Style and Maintainability Practices
This module is now 117 lines, exceeding Rule 3’s under-100-line limit. Move the quote-result mapping into a focused helper so the registration module stays below the limit.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/artistSocials/registerScrapeArtistSocialsTool.ts, line 69:
<comment>This module is now 117 lines, exceeding Rule 3’s under-100-line limit. Move the quote-result mapping into a focused helper so the registration module stays below the limit.</comment>
<file context>
@@ -52,7 +63,30 @@ export function registerScrapeArtistSocialsTool(server: McpServer): void {
+ execute: params =>
+ executeQuotedSocialRefresh(params, args.artist_account_id, args.approved_quote),
});
+ if (result.kind === "quote") {
+ return getToolResultSuccess({
+ success: true,
</file context>
| export interface AnalyzeFullCatalogOptions { | ||
| catalogId: string; | ||
| criteria: string; | ||
| startPage?: number; |
There was a problem hiding this comment.
P3: The new pagination options leave analyzeFullCatalog's public documentation inaccurate: it still promises to fetch all songs and omits the 1-based startPage/nextPage contract. Update the JSDoc so callers do not assume a single call analyzes the entire catalog.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/catalog/analyzeFullCatalog.ts, line 11:
<comment>The new pagination options leave `analyzeFullCatalog`'s public documentation inaccurate: it still promises to fetch all songs and omits the 1-based `startPage`/`nextPage` contract. Update the JSDoc so callers do not assume a single call analyzes the entire catalog.</comment>
<file context>
@@ -3,10 +3,12 @@ import { type CatalogSongWithArtists } from "@/lib/supabase/catalog_songs/select
export interface AnalyzeFullCatalogOptions {
catalogId: string;
criteria: string;
+ startPage?: number;
}
</file context>
| accountIdOverride: undefined, | ||
| }); | ||
| if (!accountId) return getToolResultError(error ?? "Authentication required."); | ||
| const catalogs = await selectAccountCatalogs(await getCatalogOwnerIds(accountId), { |
There was a problem hiding this comment.
P3: Move the account and catalog-access checks into a dedicated validateGetCatalogSongs... operation validator, then have this callback consume its validated result before running analyzeFullCatalog; keeping authorization in the orchestration handler makes this entry point’s access contract easy to bypass or diverge when reused.
(Based on your team's feedback about centralizing handler validation.)
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/catalogs/registerGetCatalogSongsTool.ts, line 46:
<comment>Move the account and catalog-access checks into a dedicated `validateGetCatalogSongs...` operation validator, then have this callback consume its validated result before running `analyzeFullCatalog`; keeping authorization in the orchestration handler makes this entry point’s access contract easy to bypass or diverge when reused.
(Based on your team's feedback about centralizing handler validation.) </comment>
<file context>
@@ -16,19 +32,27 @@ export function registerGetCatalogSongsTool(server: McpServer): void {
+ accountIdOverride: undefined,
+ });
+ if (!accountId) return getToolResultError(error ?? "Authentication required.");
+ const catalogs = await selectAccountCatalogs(await getCatalogOwnerIds(accountId), {
+ catalogIds: [args.catalog_id],
+ });
</file context>
Summary
nextPageasstart_page. Catalog matching does not debit Recoup credits.Evidence
Merge Danger
Door Two-way. API change with no migration. The paid quote flow uses the existing
REDIS_URLconfiguration. Verify Redis on the target deployment before invoking a paid refresh.Blast radius MCP social refresh, scrape results and catalog matching. Callers need to handle the new approval preview, reduced scrape result fields and catalog pagination. Historical scrape runs without ownership records cannot be read through MCP. REST social scrape pricing and execution are covered by existing regression tests.
The OpenAI draft has not been submitted. Rescan after the API changes are deployed and the reviewer account smoke tests pass.