Repository navigation
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
Draft
polis-topic-names: a typed program that asks a model to name a run's topics (called by nothing yet)#3479colinmegill wants to merge 4 commits into
colinmegill wants to merge 4 commits into
Conversation
…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
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.
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: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 runspolis-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-versionandx-api-key, plus what the HTTP client adds; none of them names the project. The key is read only fromDELPHI_NAMING_ANTHROPIC_API_KEYand is never printed.Outcomes
A failed call is an outcome in
names.jsonwith exit status 0. It is never a crash, and it never causes more than one retry:namedtoo_large(over 400 topics or 120,000 counted input tokens),over_run_cap(the worst case, priced before the call, passesDELPHI_NAMING_RUN_MAX_USD, default $0.50),no_keyhttp_<status>,timeout(300 s),connect_error,refused,truncatedbad_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.jsonand 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 asunknown), 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-namesruns 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.wrong_language.wrong_language.named.http_429; no key, over the cap and too large make no call.names.jsonare checked.names.jsonnor the log line. Unit tests run the reply parser over 3,000 random edits of a saved reply and 2,000 random byte strings.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