Skip to content

polis-topic-names: a typed program that asks a model to name a run's topics (called by nothing yet) - #3479

Draft
colinmegill wants to merge 4 commits into
edgefrom
topic-names/model-client
Draft

colinmegill wants to merge 4 commits into
edgefrom
topic-names/model-client

Conversation

@colinmegill

@colinmegill colinmegill commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

What anyone will observe

Nothing. This adds a program that no process runs yet: no route, no pipeline step, no setting, no stored data and no Compose service changes. No schema change.

What it is

A new Rust crate in the queue-rs workspace, queue-rs/polis-topic-names, with one program:

polis-topic-names name --in hierarchy.json --out names.json \
  --namer '{"model":"claude-haiku-5-5","prompt":"polis-topic-names/1","thinking":"default"}'

Given a Delphi run's topic hierarchy (every topic of every layer, with its parent, keywords and three sample comments), it asks one model, Claude Haiku 5.5 or Claude Sonnet 5.5, to name every topic in one call. It checks the reply and writes names.json. That file holds the names when every check passed. Otherwise it holds the reason, so the caller keeps its keyword names. A later change to the Delphi pipeline will run it the way the pipeline runs polis-topic-map.

The request is a measured whole-hierarchy call, byte for byte, with one sentence added: "Write every name in the language most of these comments are written in." A test compares the body with two saved bodies of that measurement.

What leaves the network when it is one day called

One HTTPS request to the Messages API per run, plus at most one retry. For every topic it sends the id, layer, parent's id, number of comments, at most five keywords and at most three sample comments (text only). It also sends the instruction. It sends nothing about authors or participants: no comment id, vote or time, and no conversation title, description or code. The headers are content-type, anthropic-version and x-api-key, plus what the HTTP client adds; none of them names the project. The key is read only from DELPHI_NAMING_ANTHROPIC_API_KEY and is never printed.

Outcomes

A failed call is an outcome in names.json with exit status 0. It is never a crash, and it never causes more than one retry:

  • named
  • before any call: too_large (over 400 topics or 120,000 counted input tokens), over_run_cap (the worst case, priced before the call, passes DELPHI_NAMING_RUN_MAX_USD, default $0.50), no_key
  • the call: http_<status>, timeout (300 s), connect_error, refused, truncated
  • the reply: bad_json (not the schema's shape, invalid usage counts, a body over 4 MiB, or a stop reason other than the provider's known ones), bad_cover (a topic missing, unknown or repeated), wrong_language (names not in the comments' script or language, mis-encoded, or holding a control or invisible formatting character), bad_length (over 50 characters), repeated_names (within a layer)

The one retry happens only after HTTP 429, 500, 502, 503, 504 or 529, or a failed connection. Exit status 2 means a usage error and 1 means unreadable input; in both cases nothing is written.

What a reply can put in names.json and the log line: the names, only when every check passed (cleaned, 1 to 50 characters, no control characters), and fixed words: the outcome, a reason of fixed text and counts, the stop reason when it is one of the provider's known words (any other is recorded as unknown), the HTTP status and the usage counts. An error body is not read past its status.

The cost check

Before any call, the worst case is the counted input tokens at the input price plus 32,000 output tokens at the output price, compared with the cap. The counted input tokens are the request body's length in UTF-8 bytes. That is an upper bound on the provider's input tokens for text in any script, given one assumption about the tokenizer: every token stands for at least one byte. A count of characters is not a bound, because one character is one to four bytes and a rare character can be several tokens. The body's own JSON (1,204 bytes for Bowling Green) covers the provider's framing of the one message. Bowling Green: 70,540 bytes, worst case $0.0231 on Haiku and $0.4611 on Sonnet; its calls reported 25,445 input tokens. The bound is for one attempt; if the provider charged for an attempt that is then retried, a run can cost up to twice it.

Tests

make check-polis-topic-names runs format, clippy with warnings denied, and the tests. A new job in the queue-rs workflow calls it. Every test is offline: each model call goes to a local HTTP stub, and none reaches a provider.

  • The request body equals two saved bodies plus the sentence, and only the named headers reach the stub.
  • All 36 saved whole-hierarchy replies, for three public conversations (Bowling Green 2050, an Austrian conversation on mobility, vTaiwan UberX), parse and cover every topic.
    • The Haiku replies that named Chinese or German comments in English give wrong_language.
    • A mis-encoded Urdu reply gives wrong_language.
    • The rest give named.
  • Every other outcome is covered, with the number of calls it makes: 429 then 200 is one retry; 429 twice is http_429; no key, over the cap and too large make no call.
  • The program's argv, environment, exit statuses and names.json are checked.
  • Replies no provider should send (usage counts of the wrong type or overflowing, unknown stop reasons, control characters in names, an oversize body, invalid UTF-8, an error body) are each an outcome, and a marker planted in them reaches neither names.json nor the log line. Unit tests run the reply parser over 3,000 random edits of a saved reply and 2,000 random byte strings.
  • The counted input is checked on the fixtures' Chinese and German text, on ten other scripts, and against Bowling Green's recorded input tokens.

Fixtures, and where they come from: queue-rs/polis-topic-names/tests/fixtures/README.md. Only Bowling Green keeps sample comments, because the request-body test compares its bytes; the vTaiwan and Mobilität hierarchies hold the topic ids and structure, one invented sentence per topic in Chinese or German for the language check, and no keywords.

🤖 Generated with Claude Code

colinmegill and others added 4 commits November 24, 2026 03:15
…ilure an outcome (nothing calls it yet)

A new crate in the queue-rs workspace. Given a Delphi run's topic hierarchy
(hierarchy.json), `polis-topic-names name` asks Claude Haiku 5.5 or Claude
Sonnet 5.5 to name every topic in one call, checks the reply, and writes
names.json: the names, or the outcome word and reason the caller keeps its
keyword names for (no_key, over_run_cap, too_large, http_<status>, timeout,
connect_error, refused, truncated, bad_json, bad_cover, wrong_language,
bad_length, repeated_names). At most one retry; the worst case is priced
before the call and compared with the per-run cap.

The request body is a measured whole-hierarchy call's body, byte for byte,
plus one sentence asking for names in the comments' language; a test compares
it with two saved bodies. All tests are offline, through a local HTTP stub,
over the saved replies of three public conversations.

Nothing in Polis runs it: no route, pipeline step, setting or stored data
changes. The checks run as `make check-polis-topic-names`, which the queue-rs
workflow's new job calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
Checked addition of the reply's usage counts (an overflowing count is
bad_json, not a panic), only known stop reasons kept, the cost check counts
the body's UTF-8 bytes, and the vTaiwan and Mobilitaet fixture samples
replaced by invented sentences. Three regression tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…g but checked names and fixed words; the cost bound counted in bytes

The reply boundary. The body of an HTTP 200 reply is read to at most
4 MiB (a longer one is bad_json, unread). Usage must be an object of
non-negative integer counts whose prompt total fits in a u64, else
bad_json with a fixed reason; output_tokens of the wrong type is no
longer read as zero. A name holding a control character or an invisible
formatting character (bidirectional controls, zero-width space,
byte-order mark, tag characters) is refused as wrong_language; the
zero-width joiner and non-joiner stay accepted. New tests:
reply_boundary (oversize, invalid UTF-8, usage types, control
characters, an error body, the program's log line with a planted marker)
and unit tests that run the parser over 3,000 random edits of a saved
reply and 2,000 random byte strings.

The cost bound. The counted input is the body's UTF-8 bytes; the README
gives why that bounds the provider's input tokens in any script, its one
assumption (every token stands for at least one byte), and Bowling
Green's arithmetic: 70,540 bytes, $0.0231 on Haiku, $0.4611 on Sonnet.
counted_input tests it on the fixtures' Chinese and German text, on ten
other scripts, and against Bowling Green's recorded input tokens.

The fixtures. The vTaiwan and Mobilitaet hierarchies keep no source
text: their samples were already invented sentences, and their keywords,
words taken from the comments, are now empty lists. Bowling Green keeps
its samples for the request-body test's byte comparison.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…he run's cap

Review round: the worst case of a second attempt is reserved inside the cap before the first is sent, so a retried call the provider charged for cannot take a run past its cap. When two attempts do not fit, the call is made once and a failure is its outcome.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1

This branch has not been deployed

No deployments
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.

1 participant