Repository navigation
feat(prompts): target prompts at multiple countries and US states - #783
Merged
Merged
Conversation
Part 2 of #691, and the part that makes part 1 usable: until now nothing in the product could put more than one location on a prompt. Prompts inherited the brand's country at creation and could never be retargeted, so the location-based quota metered a dimension users could not reach. Locations are now a per-prompt list of codes — a country (DE) or a US state (US-CA) — edited from the prompt card. One shared parse decides what a code means, mirrored deliberately in web/src/lib/region.ts and server/src/lib/locations.js, so the picker can never offer targeting the worker cannot run. Google AI Overview and AI Mode have no sub-country mechanism, so their state locations collapse to one country-wide task instead of running the identical country query once per state. That was the expensive failure mode: double spend, plus two result rows differing only by a state label neither run honoured. The picker says so on screen when it applies. State targeting moves off the brand: brands.state was applied to every US task the brand ran, which would have silently overridden per-prompt targeting. It is now only the default location offered to new prompts, and 00071 folds the one brand using it into its prompts' own locations — quota-neutral, since a prompt tracking US-DE costs the same one location as one tracking US. That migration must be applied AFTER deploying the server; the running worker would submit "US-DE" as a country. Locations get their own value-returning action rather than a field on updatePrompt: they are the only prompt edit a plan can refuse, and a refusal must reach the user as a value, not a masked digest (#427). The picker bounds itself to the org's remaining capacity, so the cap is visible before a save rather than after it.
This was referenced Aug 24, 2026
Merged
gkhngyk
added a commit
that referenced
this pull request
Aug 25, 2026
Locations became editable per prompt in #783, one card at a time. A brand with 310 prompts needed 310 edits to start tracking Germany, which is the operation multi-location targeting exists for. The brand's prompt page gets a Locations dialog beside Analyze Prompts: pick add or remove, pick the locations, pick the prompts. It adds and removes rather than assigning a list, because a selection can hold prompts targeting different places and assigning one list to all of them would erase that targeting without saying so. Adding a location a prompt already has costs nothing, and a removal that would leave a prompt with no location at all skips it and says how many stayed — a prompt with no location cannot be tracked, and refusing the whole batch over one single-location prompt would be worse than reporting it. Cost is on screen before the click: how many prompts change, how many locations that adds, and where it lands against the plan. The dialog prices the change with planBulkLocationChange and the server action enforces it with the same function, so the preview and the guard cannot disagree. The cap is measured once for the batch and the write goes out as a single statement (apply_prompt_locations, 00074, applied). Looping the single-prompt action would check the cap per prompt and could stop half-way, leaving a partly-retargeted selection and a bill for whatever landed first. Current locations are re-read server-side: quota arithmetic must not rest on numbers the client sent.
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
Part 2 of #691, and the part that makes part 1 usable. Until now nothing in the product could put more than one location on a prompt: prompts inherited the brand's country at creation and could never be retargeted, so the location-based quota metered a dimension users could not reach.
Locations are now per-prompt. A location code is a country (
DE) or a US state (US-CA), edited from the prompt card. One shared parse decides what a code means — mirrored deliberately inweb/src/lib/region.tsandserver/src/lib/locations.js, the same split as the citation hostname helpers — so the picker can never offer targeting the worker cannot run. Codes with no mechanism behind them (DE-BY,US-ZZ) are rejected rather than silently degraded to their country.Google engines collapse instead of double-spending. Google AI Overview and AI Mode have no sub-country mechanism (they use location/uule, which Cloro's AI endpoints don't accept). A prompt targeting California and Texas therefore submits one country-wide Google task, not two identical ones. That was the expensive failure mode this could have shipped with: double scraper spend, plus two result rows differing only by a state label neither run honoured. The task counter reflects the collapse, so the progress bar doesn't promise work that is never submitted, and the picker says so on screen when the situation applies.
State targeting moves off the brand.
brands.statewas applied to every US task the brand ran, which would have silently overridden per-prompt targeting — two sources of truth for one question. It is now only the default location offered to new prompts; the worker no longer reads it. Migration00071folds the one brand currently using it into its own prompts' locations (US→US-DE), which is quota-neutral: a prompt trackingUS-DEcosts the same one location as one trackingUS.API models get state targeting too, via
user_location.region(the providers take a region name, soCA→ "California"). Country-only locations produce byte-identical payloads to today.Locations get their own value-returning action (
updatePromptLocations) rather than a field onupdatePrompt: they are the only prompt edit a plan can refuse, and a refusal must reach the user as a value, not a masked digest (#427). The picker bounds itself to the org's remaining capacity, so the cap is visible before a save rather than after it, and the last location cannot be removed.Also closes the labelling gap noted in #781's review: the plan cards now read "N prompt locations tracked".
00071_prompt_state_locations.sqlmust be applied after the server deploy, not before. The running worker passes a prompt's region straight through as Cloro'scountryfield, so a row readingUS-DEwould be submitted as country "US-DE" and rejected — that brand's tracking would fail until the deploy landed. The new worker parses the code first, so once it is live the order stops mattering. It is deliberately not applied yet. (Dry-run verified against production: 50 rows, all['US'] → ['US-DE'].)Related issue
Closes #691.
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
cd web && yarn test(134 pass) andcd server && yarn test(396 pass) — new suites cover code parsing, the Google collapse,user_locationshapes, and the Delaware/GermanyDEcollision.regionstamped as the full code (US-CA); Google rows are stamped with the country.IS_CLOUDunset): the picker shows "N tracked" with no cap and never disables.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)