Skip to content

Prompts: allow multiple US states per prompt, and count quota by tracked location rather than by prompt row #691

Closed

Description

@gkhngyk

Problem

Two related gaps in how geo-targeting is modelled.

1. Only one US state can be selected. State targeting lands on the brand, not the prompt: brands.state is a single text column (CHECK (state IS NULL OR state ~ '^[A-Z]{2}$'), see the 00043 block in supabase/schema.sql), and the UI exposes it as a single-select in onboarding, brand creation and brand settings. A brand that wants to see how answers differ between, say, California and Texas has to choose one — even though prompts.regions is already a text[] and country-level targeting has always been multi-select.

2. Quota ignores how much tracking a prompt actually buys. Plan limits are enforced on the row count of prompts — getOrgPromptCount and the cap check in savePromptSet both count rows. But the tracking cost scales with regions: the worker computes prompt × (models + scrapers) × regions (tracking-worker.js#L178-L185). So one prompt tracked in 3 regions consumes 3× the scraper spend of a single-region prompt while counting as 1 against a 50-prompt plan. Adding multi-state targeting on top of that widens the gap further.

Proposal

Treat prompt × location as the billable unit, and let a prompt target several US states.

Quota: a prompt targeting N locations counts as N against maxPrompts. The capacity endpoint and the save-time cap both switch from row counts to the summed location count, and the wizards' inline counter ("X of 50 used") reflects the same number so users see the cost before they save rather than after.

Multi-state: two shapes are worth weighing before implementation — whoever picks this up should pick one deliberately and note why:

  • extend the existing prompts.regions array with sub-country codes (US-CA, US-TX), keeping one list as the single source of truth for "where is this tracked"; or
  • add a separate per-prompt states text[], leaving regions as country-level.

The first keeps one code path for counting, quota and task expansion; the second avoids touching existing region parsing. Either way the value belongs on the prompt rather than the brand, so different prompts can target different states.

Note that Google AI Overview / AI Mode use a different sub-country mechanism and never read brands.state — that asymmetry needs to survive the change (or be addressed explicitly).

Migration and billing risk — please handle deliberately

This changes what an existing customer's plan allows. Any brand that already tracks prompts across multiple regions will jump in usage the moment the new counting lands, and some orgs will land over their limit without having done anything.

Decide up front and state it in the PR:

  • do existing prompt sets get grandfathered until their next save, or is the new count applied immediately?
  • does exceeding the cap block only new saves, or does it also stop tracking for existing prompts?
  • is there a warning surface before it bites (Settings → Billing, or the prompts page)?

A query over current data — how many orgs would exceed their plan under the new counting — should come before the code, since it decides whether this needs a comms plan.

Acceptance criteria

  • A prompt can target multiple US states; tracking produces one result per prompt × location, as it already does for regions.
  • Quota counts locations, not prompt rows, in the capacity endpoint, the save-time cap and the wizard counters — with the error message spelling out the location math.
  • The chosen storage shape is documented in the PR, along with how Google AIO / AI Mode sub-country targeting continues to work.
  • Existing customers' migration path is explicit and implemented (grandfathering or immediate), not left implicit.

Activity

  1. added
    enhancement
    on Aug 10, 2026
  2. self-assigned this
    on Aug 10, 2026
  3. gkhngyk commented on Aug 10, 2026

    @gkhngyk
    ContributorAuthor

    Clarifying the billable unit, since it drives the whole design:

    A location is every place a prompt is actually sent to — country and state alike. One prompt tracked in the US and Germany is 2; one prompt tracked in California and Texas is 2; one tracked in Germany plus two US states is 3. The rule follows the tracking cost directly: each location produces its own set of scraper and model calls (prompt × (models + scrapers) × locations in the worker), so it is the unit the plan should meter.

    Two consequences worth stating explicitly:

    • This is not a state-only change. Multi-country prompts already multiply cost today while counting as one row, so the counting fix applies to countries whether or not multi-state ships with it.
    • Because of that, the migration question in the issue body is unavoidable: orgs with multi-region prompts will see their usage rise the moment counting changes, without having touched anything. That number should be measured before the code lands.
  4. gkhngyk commented on Aug 10, 2026

    @gkhngyk
    ContributorAuthor

    The check has to cover editing, not just adding

    Concretely: an org on a 50-prompt plan that has used all 50 must be refused when it opens one existing prompt and adds a second country or state to it. That request grows tracked locations from 50 to 51 exactly like creating a 51st prompt would, so it has to fail the same way, with the same message.

    That's not how the code is shaped today, and two things stand in the way:

    1. updatePrompt cannot change locations at all. It only accepts text, category, platforms, models and isActive (prompt.ts#L302-L311) — regions isn't in the payload, so editing a saved prompt's targeting isn't possible in the product right now. Multi-state targeting is worth little without it, so that capability belongs in this issue.

    2. updatePrompt enforces no plan limit, which was harmless while quota counted rows (an edit never changed the count) and becomes a hole the moment locations are the unit.

    So every write path that can raise the location total needs the same guard, not just the two that have it today:

    path guard today needed
    savePromptSet row-count cap location-count cap
    addPromptToSet enforceLimit(maxPrompts) location-count aware
    addPromptToBrand none found location-count cap
    updatePrompt none location-count cap once it accepts regions

    The rule to implement is the delta, not the total: an edit should be measured by how many locations it adds, so that re-saving a prompt unchanged at exactly the limit still succeeds, while adding one more location at the limit fails. Removing a location must free capacity immediately.

    Worth mirroring in the UI too — if the org is at its cap, the location selector should show why an additional pick is unavailable rather than failing after the fact.

  5. gkhngyk commented on Aug 10, 2026

    @gkhngyk
    ContributorAuthor

    Cloud-only: self-host must stay unmetered

    The location-based counting is a plan limit, so it applies on cloud only. Self-host has no prompt ceiling today and must not gain one here.

    The existing plumbing already guarantees this and simply needs to be left intact: getPlan short-circuits to PLANS.self_hosted whenever IS_CLOUD !== 'true' (server/src/config/plans.js#L158), and that plan carries maxPrompts: -1, which every cap check reads as unlimited (maxPrompts !== -1 gates the rejection). The same -1 is mirrored in web/src/config/plans.ts for the client-side capacity display.

    So the requirement for this work is a negative one — don't regress it:

    • No write path may reject a save, an edit, or an added location when the plan is self_hosted; the sentinel must keep flowing through the new location-count checks exactly as it does through today's row-count ones.
    • The capacity counters in the wizards keep reading Unlimited rather than "N of ∞ locations used".
    • Enterprise carries the same -1, so it must stay unmetered too.

    Worth a test that pins it: a self-host org at any number of prompts and locations can still add another. It is the kind of guarantee that breaks quietly, since a cloud-only test suite would never notice.

  6. added
    prompts
    on Aug 12, 2026
  7. gkhngyk commented on Aug 23, 2026

    @gkhngyk
    ContributorAuthor

    Scope note for part 2, out of the #781 review: the plan cards still label maxPrompts as "N prompts" (web/src/components/settings/plan-switcher.tsx and the onboarding plan step). That stays literally accurate while the UI can only create single-location prompts, but the moment multi-location targeting ships the displayed unit diverges from the metered one. Part 2 should relabel these to prompt locations (i18n strings included) alongside the multi-state work.

  8. gkhngyk commented on Aug 24, 2026

    @gkhngyk
    ContributorAuthor

    Part 2 is up in #783 (part 1 was #781, merged).

    One deploy-ordering constraint worth repeating outside the PR body: 00071_prompt_state_locations.sql must be applied after the server deploy, not before. It rewrites the one brand that uses brands.state from ['US'] to ['US-DE'], and the currently running worker passes a prompt's region straight through as Cloro's country field — so that row would be submitted as country "US-DE" and rejected, failing that brand's tracking until the deploy landed. The new worker parses the code first, so once it is live the order stops mattering. The migration is deliberately left unapplied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementprompts

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions