Skip to content

fix(prompts): hold a topic's name to 100 characters where it's typed and saved - #1678

Merged
gkhngyk merged 8 commits into
ansvisor:mainfrom
cihan-gyk:fix/topic-name-length
Oct 28, 2026
Merged

gkhngyk merged 8 commits into
ansvisor:mainfrom
cihan-gyk:fix/topic-name-length

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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.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 on the brand's Topics page stop at 100 (maxLength).
  • createTopic, createTopics and updateTopic trim the name, then refuse one that's still too long, 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.
  • b5d8069: 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 reads TOPIC_NAME_CHARS, so the web keeps one number. The server's copy in brand-setup-input.js stays, 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:

Related issue

Follow-up from #1611 / #1661.

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. cd web && npx vitest run src/lib/actions/topic.test.ts src/lib/ai-brand-setup.test.ts
  2. Prompts › Topics › Add topic: the box stops at 100 characters.

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

Full checks were run in one tree with this batch's eight follow-up branches merged (after the review fixes):

  • server format, lint and npm test (no SUPABASE_* env, as in CI): 249 files, 3,365 tests passed;
  • web format, lint (0 errors; 7 warnings already on main), typecheck, 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

cihan-gyk and others added 8 commits October 28, 2026 04:58
… 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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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's topic: 100 against this PR's topic: 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, createTopics and updateTopic refuse a name over 100 after trimming, before anything is written. In createTopics the 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 (maxLength also 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.
    • topicNameFits counts UTF-16 units, as zod's max and maxLength do, so the web and the API agree on what fits.
  • Tests. topic.test.ts and ai-brand-setup.test.ts pass at the head. With main's topic.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:

  1. 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.topic before it sends, and say so.
  2. The MCP's accept path (mcp/data.ts), as the description says, doesn't cut a long name yet.
  3. The .slice in acceptTopicSuggestion can split an emoji's pair at the cut; #1661's cut helper handles that.

@gkhngyk
gkhngyk merged commit 49ad547 into ansvisor:main Oct 28, 2026
4 of 5 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.

2 participants