Repository navigation
fix(prompts): let volume analysis cover a whole brand instead of failing past 50 prompts - #747
Merged
Merged
Conversation
…ing past 50 prompts
The Prompts page sent every unanalyzed prompt inline in one request, and the
route refused more than 50 of them. A brand with 100 active prompts was shown
an "Analyze 100 prompts" button that could only ever return 400, and the page
turned the reason into "Volume analysis failed" — so the one system that knew
what was wrong never said it.
Raising the cap alone would not have worked. Each prompt costs an LLM call plus
a DataForSEO call and they run in order, measured at a 6.4s median across 1,215
consecutive rows: about eleven minutes for 100 prompts, far past what a request
can be held open for.
So the brand, not a list of prompts, is now the unit of work. The route starts
the run and returns 202; the page follows a status endpoint and shows real
progress ("Analyzing 32/100..."). Each prompt is saved as it lands, so a closed
tab costs nothing already done. Quota still counts one run per click.
Along the way, the prompt reads no longer assemble a list of ids to filter on
and no longer trust an un-paginated select — the two shapes that lost data in
#714, #740 and #741, and that a 1000-prompt brand sits exactly on the edge of.
Inactive prompts are now skipped rather than spending an LLM call and a
DataForSEO call on a row no surface reads.
Failures reach the user as wording chosen for a person. The server's text names
batch sizes, upstream APIs and Postgres columns; none of it is shown. The
actions return a small set of codes instead of throwing, which also fixes the
quota message never appearing — it was matched on text that Next.js redacts in
production.
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Volume analysis could not be run on a brand with more than 50 prompts, and the page did not say why.
The Prompts page sent every unanalyzed prompt inline in one request, and
POST /api/volumes/analyze-batchrefused more than 50 of them. A brand with 100 active prompts was therefore shown an "Analyze 100 prompts" button whose only possible outcome was400, and the page turned the server's reason intoVolume analysis failed— so the one component that knew what was wrong never said it. No run larger than 50 prompts exists anywhere in the usage history; the ceiling was never reachable.Raising the cap alone would not have fixed it. Each prompt costs an LLM call plus a DataForSEO call and they run in order, which measures at a 6.4s median across 1,215 consecutive rows in production — roughly eleven minutes for 100 prompts, far past what a request can be held open for.
So the brand, not a list of prompts, is now the unit of work:
202immediately; the run continues in the background. This mirrors the existingPOST /api/internal/analyze-volumesused by the Stripe success flow.GET /api/volumes/status/:brandIdreports{ running, total, analyzed }, and the page polls it to show real movement —Analyzing 32/100...— instead of an indefinite spinner.await, because a check followed by an await leaves a gap two simultaneous clicks both pass through — which would analyze every prompt twice and bill the quota twice.Errors are now written for a person
Server text names batch sizes, upstream APIs and Postgres columns; none of it reaches the UI. The actions return a small closed set of codes (
quota_exceeded,plan_limit,failed) instead of throwing, and the page chooses the wording.This also fixes a second, quieter bug: the quota message never appeared. It was selected by matching on text that Next.js redacts in production, so an exhausted quota showed the same generic failure as everything else.
Two latent data bugs closed along the way
The prompt reads no longer assemble a list of ids to filter on, and no longer trust an un-paginated select — the two shapes that silently lost data in #714, #740 and #741. A brand is allowed up to 1000 prompts today, which sits exactly on the 1000-row cap. Scoping through the
prompt_setsembed keeps the filter one id wide and pages the rest.Inactive prompts are now skipped rather than spending an LLM call and a DataForSEO call on a row no surface reads.
Related issue
None — found while investigating a failing toast on the Prompts page.
Type of change
fix— Bug fixHow to test
Requires a brand with more than 50 active prompts and no volume data.
Analyze N prompts.Analyzing 0/N...upward roughly every 10s. Previously this returnedVolume analysis failedimmediately for any N above 50.Volume analysis finished, and the table filled in.Analyze. Expected:Every active prompt already has volume data.The server changes require a deploy — the page polls an endpoint that does not exist on the current build.
Verification already done
analyzeBrandVolumes/getVolumeProgress, 17 new route-level tests driving the real router over HTTP.is_activefilter, the pagination and the claim ordering each fails the test written for it.getVolumeProgressreturned{ total: 3, analyzed: 3 }— an embed filter that did not work would have returned 12/11.yarn lint,yarn typecheck,yarn format:checkandyarn buildpass fromweb/;yarn lint,yarn format:checkandyarn testpass fromserver/.Not covered: the browser polling loop itself, and no real analysis was triggered — that spends DataForSEO and LLM credit.
Out of scope
POST /api/volumes/refresh(the Refresh Volumes button) is still synchronous and has the same shape, though it is faster since it skips the LLM. Worth the same treatment separately.Checklist
feature/,fix/,chore/,docs/)yarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)