Skip to content

fix(prompts): stop suggestion refresh failing on high-volume estimates - #480

Merged
gkhngyk merged 2 commits into
mainfrom
fix/suggestion-refresh-retry
Jul 18, 2026
Merged

gkhngyk merged 2 commits into
mainfrom
fix/suggestion-refresh-retry

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Generating prompt suggestions from the Prompts page failed with "No object generated: response did not match schema." — reproducibly, on every attempt.

Root cause: the refresh endpoint's generateObject schema capped estVolume at .max(100000). The generation prompt shows the model the brand's real tracked volumes and explicitly asks it to calibrate estimates against them — so on a brand with high tracked volumes the model legitimately returns six-figure estimates. One over-cap value makes zod reject the entire batch, and because the calibration instruction reproduces the same magnitudes every time, the failure is deterministic (reproduced against the production code path with a real brand context: suggestions[3].estVolume = 112800 > 100000 — the other 7 suggestions were fine and the JSON was valid).

Fix:

  • Remove the .max(100000) ceiling from the schema; out-of-range protection is now a Math.min(estVolume, 10_000_000) clamp at the insert site — one absurd estimate caps out instead of sinking the whole batch.
  • Wrap the generateObject call in the bounded withRetry (3 attempts) that the onboarding suggestion endpoint already uses (Onboarding: retry LLM suggestion calls, then fall back to manual entry when they fail #379 pattern), so genuinely transient schema misses — short reason, missing item — get a fresh sample instead of failing the request.

Verified with the same context that failed before: two consecutive runs both return 8 valid suggestions.

Related issue

None — reported from local testing.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Pick a brand whose tracked prompts have high analyzed AI volumes (six-figure top volumes).
  2. On /dashboard/prompts, expand the Prompt Suggestions card and hit Refresh.
  3. Suggestions generate successfully; previously this returned the schema error every time.
  4. Stored est_volume values are plausible (clamped at 10M as a sanity bound).

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

gkhngyk added 2 commits July 19, 2026 00:20
The refresh endpoint's generateObject schema capped estVolume at 100000,
but the prompt feeds the model the brand's real tracked volumes and asks
it to calibrate against them — on high-volume brands it legitimately
estimates six figures, one over-cap value made zod reject the ENTIRE
batch ("No object generated: response did not match schema"), and the
failure repeated deterministically on every retry.

Drop the schema ceiling and clamp at the insert site instead (one absurd
estimate caps out rather than sinking the batch), and wrap the call in
the #379 withRetry pattern the onboarding suggestion endpoint already
uses, so genuinely transient schema misses get a second sample.

Verified against the production code path with a real brand context:
failed 100% before (suggestions[3].estVolume=112800 > 100000), succeeds
consistently after.
@gkhngyk
gkhngyk merged commit ccaa154 into main Jul 18, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the fix/suggestion-refresh-retry branch July 18, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant