Repository navigation
fix(prompts): hold a topic's name to 100 characters where it's typed and saved - #1678
Merged
Merged
Conversation
… and count their daily allowance per person too Follow-ups from ansvisor#1611's review. Bounds. /topics/suggest, /prompts/from-topics and /competitors/suggest put the brand's name, description, website and every topic into a model's prompt with no length check, up to three attempts each, under a 50 MB body limit. They now parse the body with one schema (lib/brand-setup-input.js): names, industry and website up to 200 characters, the description up to 2,000, and up to 20 topics of 100. Past them: 400, before any model is asked. The Topics page's refresh reads the brand from the database, so it cuts the same fields to the same lengths instead. The web never meets them: ai-brand-setup.ts cuts the name, description and website it sends (a description kept in the brand's settings may be longer), counting UTF-16 units as zod does and never splitting an emoji, and the custom topic boxes in onboarding and Add brand stop at 100. One allowance per person. Calls were counted under user:<id> before the organization existed and under org:<id> after, so one person could get two allowances in a day. Each call is now taken from the person's count and, once it exists, the organization's; a call either refuses counts neither. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… batches the API takes, with the brand cut to its limits The brand's Prompts page called /prompts/from-topics itself, with every topic the brand tracks selected and the brand's stored name, industry and description as they are. Since the setup routes are bounded (20 topics, a 2,000-character description), a brand with 21 topics or a longer description got a 400 on Generate. It now uses setup's generatePromptsFromTopics, which cuts the name, industry and description to the API's lengths and asks for more than 20 topics in batches of 20, side by side, returning every group in the topics' order (no topics, no call). The industry the page sends is kept and cut too. Tests: the helper with 21 topics against an API that answers 400 past its limits, a failing batch, no topics; the page generating for a brand with 21 topics and a 2,500-character description. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l takes at a word /topics/suggest returned the model's topic names as they came: nothing held a name to a length, and /prompts/from-topics refuses one past 100 characters. Choosing such a topic in setup then failed the prompts step with a 400. generateTopicIdeas (onboarding's /topics/suggest and the Topics page's suggestions refresh) now trims each name and cuts one past 100 characters at a word (lib/brand-setup-input.js boundedTopicName: back to the last space unless that drops most of it, a dangling "&", "/", "," or dash goes too, never half an emoji); an empty name is left out. A max in the schema would re-run the whole research instead. Tests: boundedTopicName's cuts; /topics/suggest with a long and an empty name, every name returned passing promptsFromTopicsSchema. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s a renewed count move to the end Each onboarding call now counts for the person and the organization, two keys a call. The test's MAX_ENTRIES calls put 10,000 keys into a map of 5,000, so the first organization's counts were dropped on the first day and came back at the end anyway: the test passed with the renewed count left in place. MAX_ENTRIES / 2 calls fill the map exactly; checked by renewing the count in place, which the test now fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and saved Follow-up from ansvisor#1661's review. Setup's prompt generation takes topics of up to 100 characters (ansvisor#1611's bounds), but topics.name has no length check, so a topic named by hand past 100 made Generate fail with a 400. - TOPIC_NAME_CHARS (lib/topic-names.ts) is 100, the API's limit. - The add and rename boxes on Prompts › Topics and the brand's Topics page stop at it (maxLength). - createTopic, createTopics and updateTopic refuse a longer name, trimmed first, before anything is written. - Accepting a topic suggestion cuts the model's name to fit instead of refusing it; the other ways topics are made already cut at 60. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es' one constant Stacked on fix/onboarding-input-bounds, which brought BRAND_SETUP_LIMITS: its `topic` (100) is now TOPIC_NAME_CHARS, the length the Topics pages and actions hold a name to, so the web keeps one number for it. The server's own copy in brand-setup-input.js stays, as server and web share no module. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
approved these changes
Oct 28, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, with follow-ups.
What I checked:
- Own change. c02cb2d and b5d8069, on top of #1661's four commits (merged in at 36c83ba). Those four are what #1661's squash (6b41c1c) put on main, line for line.
- Merge state. Against main (b591947) it has one conflict, in
web/src/lib/ai-brand-setup.ts: main'stopic: 100against this PR'stopic: TOPIC_NAME_CHARS. Both sides add the line, because main has #1661 squashed and this branch has its commits. Rebasing the two own commits onto main (or taking this side) resolves it. With that resolved, the topic, setup, brand, Prompts and onboarding tests pass (15 files, 95 tests). It shares no file with #1670, #1671, #1674 or #1675. - The limit.
createTopic,createTopicsandupdateTopicrefuse a name over 100 after trimming, before anything is written. IncreateTopicsthe check runs before the delete of the brand's existing topics, so a refused list leaves them as they were. Both single-topic actions save the trimmed name.- The add and rename boxes on Prompts › Topics and on the brand's Topics page stop at 100 (
maxLengthalso cuts a paste). - The other ways topics are made already cut at 60 (bulk import, accepted prompt suggestions), and a suggestion accepted from the Topics tab is now cut to 100.
topicNameFitscounts UTF-16 units, as zod'smaxandmaxLengthdo, so the web and the API agree on what fits.
- Tests.
topic.test.tsandai-brand-setup.test.tspass at the head. With main'stopic.ts, the new test fails.
Web before the API: web only. The API's 100-character limit for Generate is already on main from #1661; this PR stops new topics from going past it.
Follow-ups:
- Topics already longer than 100. This stops new ones, but a brand that already has one still can't use Generate on its Prompts page, since one refused batch fails the call. The Prompts page could leave out (or cut) a topic over
BRAND_SETUP_LIMITS.topicbefore it sends, and say so. - The MCP's accept path (
mcp/data.ts), as the description says, doesn't cut a long name yet. - The
.sliceinacceptTopicSuggestioncan split an emoji's pair at the cut; #1661'scuthelper handles that.
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
Follow-up from #1661's review: a topic's name is held to 100 characters where it's typed and saved.
Stacked on #1661 (onboarding input bounds), which sets the 100-character topic limit for prompt generation. Merge this after it. This PR's own commits are c02cb2d and b5d8069.
Setup's prompt generation takes topics of up to 100 characters (#1661). But
topics.namehas no length check, so a topic named by hand past 100 made Generate fail with a 400.TOPIC_NAME_CHARS(lib/topic-names.ts) is 100, the API's limit.maxLength).createTopic,createTopicsandupdateTopictrim the name, then refuse one that's still too long, before anything is written.BRAND_SETUP_LIMITS.topic(fix(server): bound what brand setup sends to the model, and count onboarding calls per person and per organisation #1661, web) now readsTOPIC_NAME_CHARS, so the web keeps one number. The server's copy inbrand-setup-input.jsstays, because server and web share no module.Where people see it: Prompts › Topics and the brand's Topics page: the "Add topic" and rename boxes stop at 100 characters.
Follow-ups:
accept_topic_suggestionpath (mcp/data.ts) doesn't cut a long name yet;topic-suggestions.ts'.slice()could split an emoji (fix(server): bound what brand setup sends to the model, and count onboarding calls per person and per organisation #1661'scuthelper would fix it).Related issue
Follow-up from #1611 / #1661.
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 && npx vitest run src/lib/actions/topic.test.ts src/lib/ai-brand-setup.test.tsChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Full checks were run in one tree with this batch's eight follow-up branches merged (after the review fixes):
npm test(noSUPABASE_*env, as in CI): 249 files, 3,365 tests passed;vitest(445 files, 4,353 tests) and build: all pass.Browser check (local, 1024 px): Prompts › Topics › Add Topic stops at 100 characters; the Action Center drawer opens without errors, and Check now doesn't show on tasks the API doesn't check.
A pre-push review was run on all eight branches of this batch, and its before-merge findings are fixed.
🤖 Generated with Claude Code