Repository navigation
feat(prompts): count only active prompt locations toward the plan limit - #1034
Merged
gkhngyk merged 3 commits intoOct 15, 2026
Merged
Conversation
Paused prompts don't run, so they no longer take room on the plan (org_prompt_location_usage now filters on is_active, 00128). Resuming a paused prompt brings its locations back, so it is metered like adding them: setPromptActive refuses with a plan_limit value when there is no room. That closes the pause, add new prompts, resume the old ones way past the limit. Location edits on paused prompts cost nothing until the prompt is resumed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
@gkhngyk this is ready for review. Paused prompts no longer count toward the plan's prompt-location limit, and resuming one is metered like adding it, so the "pause, add new ones, resume the old ones" way past the limit is closed. Things to look at:
Code review, |
…sh safe Second review pass on the active-only prompt quota: - the edit dialog shows a plain message for non-plan failures instead of the raw database error; - setPromptActive returns a failed limit check as a value (ansvisor#427) instead of throwing; - the brand Prompts page keeps its last quota when the refresh after a toggle fails, so the location pickers don't become uncapped; - the prompt-usage doc no longer says paused prompts count; - tests for a missing prompt, a failed limit check, and location edits on paused vs active prompts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
@gkhngyk I pushed a follow-up commit (19ad264) after a second review pass:
The description's Review section is updated. Lint, typecheck, |
Resolves the conflicts with the bulk import (ansvisor#1013): prompt.ts keeps both setPromptActive and importPrompts, and the Prompts page imports both. The import RPC (00122) counts locations through org_prompt_location_usage, which 00128 limits to active prompts, so imports follow the same count. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 15, 2026
gkhngyk
approved these changes
Oct 15, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, thanks. Migration 00128 is applied to production.
cihan-gyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Oct 15, 2026
Since ansvisor#1034, only active prompts count toward the plan and resuming one is metered like adding its locations. The bulk bar's Resume went straight to the write, so pausing prompts, filling their room and resuming them all at once got past the limit. setPromptsActive now prices the paused prompts in the selection with activationDelta, through the same check as setPromptActive, and writes nothing when they don't fit; the bar shows the limit message as the row menu does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
9 of 12 tasks
gkhngyk
pushed a commit
that referenced
this pull request
Oct 15, 2026
* feat(content): show and enforce the monthly content opportunity quota Plans get a monthly limit on new content opportunities (Starter 10, Growth 50, Enterprise/self-hosted unlimited), counted separately from the existing brief quota and renewing with the subscription. Usage is recorded in opportunity_usage, so dismissed and deleted opportunities still count. The nightly generation claims slots atomically per organization (claim_opportunity_usage) before calling the model and hands back the ones it doesn't use. The Content page leads its stat row with a usage card for both counters, and GET /api/content/usage exposes the same figures. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(content): skip opportunities whose prompt and fan-out baskets duplicate an existing one Before the model is called, every open cluster's prompt basket and fan-out basket are compared with the brand's open, sent and recently dismissed opportunities (Dice overlap, prompts weighted 0.6, queries 0.4). A match is not generated, so it costs no model call and no quota slot; an open match takes the cluster in as a related cluster and counts it as duplicatesMerged, which the detail panel shows. Dismissed opportunities block their baskets for 90 days. The threshold is configurable through OPPORTUNITY_DUPLICATE_THRESHOLD and tuned against a test set of known duplicate and distinct pairs. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(content): add a "+ New" button to generate opportunities on demand The header gets a primary "+ New" (replacing the self-hosted-only Generate) that opens a dialog: an optional focus (topic or prompt), an optional free-text idea and a count capped by the plan (Starter 3, Growth 5 per request) and what is left of the month. POST /api/content/opportunities/generate validates the request, returns the job a repeated idempotency key already started, and queues the same per-cluster generation with the count, focus and idea; quota slots are claimed atomically and handed back on failure. Placeholder rows show while it runs, the result toast reports created and skipped duplicates, and a failure offers Retry. Opportunities now record their source (system, manual, prompt) in a new column; the list shows a badge for non-system ones and filters by source, and the summary aggregates take the same filter. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(content): show when each opportunity was suggested, with sort and date filter The list gets a Suggested column (relative for a week, then a short date, in the UI's language, full date and time on hover, hidden below 1280px), Newest/Oldest sorting, a date filter (All time, This month, Last 30 days, Custom) kept in the URL and applied to the summary figures too (migration 00127), a dot on rows suggested since the last visit, and suggested_at in ISO 8601 in the CSV export. The detail panel's date now follows the UI language instead of the browser's. Each row also says what it was built for: a topic's prompt group with its prompt count, or a single prompt. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(content): keep internal indexes and misspelled competitors out of opportunity text Opportunity text leaked the generator's bracketed indexes ("targeting prompt [0]", "improve [P2] by … from [P1]") and misspelled competitor names ("Profund"). New opportunities are cleaned before they're saved: each index becomes what it stood for in that run (cluster label, page title, existing opportunity) and near-miss competitor names their configured spelling. Stored opportunities are left as they are and cleaned when read: list, detail, CSV, webhooks, brief generation and the Action Center title all show readable text. Since the lists an old index pointed into weren't stored, read-time cleaning doesn't guess by position: pages read "the page" and prompt indexes the opportunity's own prompt. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(content): suggest another angle on an opportunity An opportunity's panel gets "Another angle": one more opportunity for the same need with a different content type, format, audience or decision, optionally steered by a short direction. POST /api/content/:id/alternative queues it as a content job for the opportunity's cluster (or the cluster its prompt is in today), skipping coverage and the duplicate check since the user asked for it; it uses one quota slot, handed back on failure. The alternative stands beside the original, marked "Alternative" with a link to it. Dismissing from the panel now asks why: the topic doesn't matter, or the topic is right and the angle wrong, which goes on to ask for another angle. The reason is kept in source_data while the opportunity stays dismissed and dropped when it's restored; the write only lands on an unchanged row, so it can't drop a concurrent source_data update. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(prompts): suggest content for a prompt from its row menu PROMPT-006: the prompts table's row menu gets "Suggest content", which writes one content opportunity for that prompt's cluster, tagged source 'prompt' and counted against the monthly content quota. - POST /api/content/prompts/:promptId/suggest checks, in order: a repeated request, a job still running for the prompt, an open opportunity that already answers it ({ existingId }, no quota used), then the quota (429), and only then queues the job. - The generator's explicit mode revisits a cluster whose opportunity was dismissed or finished, never one with an open opportunity, skips the duplicate check, merging and reopening, and reports the created or covering opportunity id. - GET /api/content/prompts/:promptId/suggestion lets the menu open an existing suggestion once the quota is used up. - The page follows the job and toasts "Content suggestion created · Open" or "Open existing". Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(prompts): add a bulk action bar for selected prompts PROMPT-006: ticking rows in the prompts table opens a bar with the row menu's actions for all of them: Pause / Resume, Suggest content and Delete. - Selection is limited to the rows on screen and starts over when the page, search, filters, sort, location, date range or brand change. - Pause / Resume and Delete each write once (setPromptsActive, deletePrompts). Delete asks first and keeps the 10-second Undo; rows the write leaves out come back into view. - Suggest content takes as many prompts as one "+ New" request may (Starter 3, Growth 5, never more than is left of the month) and asks for them one after another, stopping at the monthly limit or at a job that outlives the wait, then sums the run up in one toast. - The single-row flow now goes through suggestForPrompt, so the row menu and the bar report outcomes the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(prompts): meter a bulk resume against the plan's prompt locations Since #1034, only active prompts count toward the plan and resuming one is metered like adding its locations. The bulk bar's Resume went straight to the write, so pausing prompts, filling their room and resuming them all at once got past the limit. setPromptsActive now prices the paused prompts in the selection with activationDelta, through the same check as setPromptActive, and writes nothing when they don't fit; the bar shows the limit message as the row menu does. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(prompts): delete selected prompts a few per call A bulk delete sent up to a page of prompts in one statement. Each prompt takes its answers and citations with it, so on big brands the statement outran the 8-second timeout and everything rolled back. - deletePrompts takes at most PROMPT_DELETE_BATCH (3) prompts per call. - The page deletes with deleteInBatches, one call after another, after the Undo window and on unmount alike; deletes queue behind each other. - The bulk bar shows the progress of a delete that needs several calls. - A failed call stops the run: what came before stays deleted, the rest comes back into the list and the toast says how many were deleted. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Cihan <[email protected]>
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
The plan's prompt limit (
maxPrompts, counted in prompt locations since #691) also counted paused prompts. Paused prompts don't run (the tracking worker only picksis_activeprompts), so users were paying plan room for prompts that cost nothing.Now only active prompt locations count. To keep the limit meaningful, resuming a paused prompt is metered like adding it. Otherwise someone could pause prompts, fill their room with new ones, then resume the old ones and end up over the limit. With this PR, that resume is refused with the usual plan-limit message.
What changes:
00128_count_active_prompt_locations.sql:org_prompt_location_usageaddsand p.is_active. Same signature, grants and security invoker as 00070.schema.sqlis regenerated.setPromptActive(id, isActive)(new server action): the only way a prompt's active state changes after it's created.{ code: 'plan_limit', error }as a value (Query fan-out: long hang then production-masked server error surfaced raw in the UI #427) and writes nothing.updatePromptno longer takesisActive.activationDelta()inprompt-locations.ts: how many locations making prompts active adds. Ready for the bulk resume in feat(prompts): add a bulk action bar for selected prompts #1029.updatePromptLocationsand tobulkUpdatePromptLocations/planBulkLocationChange. The resume then meters the full count.savePromptSetcounts only the prompts it saves as active.setPromptActive. A refusal shows "Not enough room to resume" with the exact numbers; the edit dialog shows it inline.Scope notes:
brands.is_active) is unchanged. A paused brand's active prompts still count, which is the conservative side and leaves no way past the limit.addPromptToSet,updatePromptLocations) have the same check-then-write shape. A locked RPC (likeclaim_opportunity_usage) could cover all of them in a follow-up.setPromptsActive) should useactivationDeltafor resumes once this merges. I'll do that on whichever PR lands second.Review
I ran a code review before opening this. It found 10 things and 9 are fixed here:
updatePromptkept a second, throwing activation path;setPromptActivehad no tests;The race above is the one left, as a note.
A second review pass found 8 more and 5 are fixed in a follow-up commit:
setPromptActivethrew (masked in production) when the limit check itself failed;prompt-usage.tsstill said paused prompts count;Left as notes:
Related issue
Builds on #691 (location-based prompt quota). No issue for this one: it's a product request to stop paused prompts counting, without opening a way around the limit.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
supabase/migrations/00128_count_active_prompt_locations.sql).NEXT_PUBLIC_IS_CLOUD=trueinweb/.env.local, set the demo org'splantostarter(50 locations), and restart the web dev server.growth(200): resuming works.self_hostedandNEXT_PUBLIC_IS_CLOUD=false: no limit, and pause/resume work as before.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 7 warnings are in code this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn test: 522/522, including the newactions/prompt.test.ts(9 cases) and theactivationDelta/ paused-bulk cases.yarn build: passed.bash supabase/build-schema.sh:schema.sqlis up to date.🤖 Generated with Claude Code