Skip to content

feat(prompts): analyze a prompt the moment it is added - #754

Merged
gkhngyk merged 1 commit into
mainfrom
feature/analyze-new-prompt-on-add
Aug 20, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/analyze-new-prompt-on-add

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

A prompt added from the sidebar's Prompts page was written to the database and then left idle until the next daily tracking run. The confirmation toast said as much — "it will be picked up by the next tracking run" — which made the delay honest but no less useless: add a prompt at noon, see nothing until tomorrow morning's scheduled run.

This submits the prompt for analysis as soon as it is saved.

The request names one prompt id, not the brand's unanalyzed set. POST /api/tracking/analyze-new builds its candidate list from active prompts that have no rows in prompt_results. Results arrive asynchronously, so a prompt that is still in flight has no result rows yet and would be swept back into the candidate list — and paid for a second time — by the very next add:

14:00  add A  ->  submit  ->  A in flight, no results yet
14:02  add B  ->  submit  ->  candidates = {A, B}   <- A submitted twice
14:05  add C  ->  submit  ->  candidates = {A, B, C}

Passing only the id that was just created keeps each prompt to exactly one submission, with no new state to track. The route already accepts promptIds and validates them against the brand, so nothing changes server-side.

A refusal is not an error. The daily on-demand cap, the cooldown, a paused brand, an inactive subscription and an unreachable server all leave the prompt saved and the scheduled run to collect it. They change the confirmation message and nothing else — no error toast, no failed-looking state on a write that succeeded. Only unexpected statuses reach the server log.

Scoped to the Prompts page in the sidebar. The brand-level prompts page keeps its existing Analyze Prompts button and is untouched.

No server changes, so no redeploy is needed.

Related issue

None — reported directly.

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. Sidebar → Prompts → Add Prompt, add a prompt to any brand.
  2. The toast reads "Prompt added — analyzing it now." instead of the old "next tracking run" wording.
  3. Results land for that prompt within a few minutes, without waiting for the daily run.
  4. Add two or three prompts in a row: each is submitted on its own, and the earlier ones are not resubmitted.
  5. On a plan whose daily on-demand cap is reachable (Starter: 3/day, 15-minute cooldown), keep adding past the cap. The prompt is still saved, the toast falls back to the "next tracking run" wording, and no error is shown.

Four tests cover the action, the important one asserting the exact request body so a future change back to "the brand's unanalyzed prompts" fails loudly.

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

A prompt added from the Prompts page was written to the database and then
left idle until the next daily tracking run, so a user could add a prompt
and see nothing for up to a day. The toast said as much, which made the
delay honest but no less useless.

Submit the prompt for analysis as soon as it is saved.

The request names the single prompt id that was just created rather than
asking for the brand's unanalyzed set. Results arrive asynchronously, so a
prompt that is still in flight has no result rows yet and would be picked
up — and paid for — a second time by the very next add. Naming the id keeps
each prompt to exactly one submission.

A refusal is not an error. The daily cap, the cooldown, a paused brand, an
inactive subscription and an unreachable server all leave the prompt saved
and the scheduled run to collect it, so they change the confirmation
message and nothing else.

Scoped to the Prompts page in the sidebar; the brand-level page keeps its
existing Analyze Prompts button.
@gkhngyk
gkhngyk merged commit 316e13d into main Aug 20, 2026
6 checks passed
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