Skip to content

delphi: a run whose configuration names a namer asks a model for its topic names (no run names one yet) - #3480

Draft
colinmegill wants to merge 11 commits into
edgefrom
topic-names/naming-step
Draft

colinmegill wants to merge 11 commits into
edgefrom
topic-names/naming-step

Conversation

@colinmegill

@colinmegill colinmegill commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Delphi: a run can name its topics with a model in one call, switched off

What anyone will observe: nothing. No admission names a namer, so no run passes --namer, and every run's arguments, step log, manifest and stored results are what they were. Tests prove it at each layer:

  • the job child: with no naming in the configuration, null, or {"by": "keywords"}, the full run's arguments equal today's list exactly (Rust test in queue-rs/src/jobs/child.rs);
  • run_delphi.py: without --namer, the pipeline is called with today's exact argument list, and the manifest's models and cost are today's (delphi/tests/test_topic_namer.py);
  • run_pipeline.py: without a namer, the older naming path runs as before, its step-log entries have exactly today's fields, and the new program is never started (same file).

No schema change, no migration, no Node change, no route, Compose or scheduler change.

What the step does when a run one day names a namer

A run given --namer='{"model":"claude-haiku-5-5","prompt":"polis-topic-names/1","thinking":"default"}' (only with --selection=participant_visible/1):

  1. builds hierarchy.json: every non-noise topic of every layer with its id, layer, size, parent (the topic one layer up holding most of its non-noise comments), five keywords and the three comments nearest its centre in the 2D map;
  2. runs polis-topic-names name --in hierarchy.json --out names.json --namer <json> (the Rust topic namer, built into the Delphi image by the last commit), which makes the one model call and checks the reply;
  3. on outcome named, writes the model's names where the keyword labels go, recorded in the step log as written by the model (model_clusters), so the stored topic map keeps them as written under polis-topic-map.names/3; the manifest's models.topic names the model and cost.llm_tokens_in/out the call's tokens;
  4. on any other outcome, keeps the keyword labels, recorded as fallbacks under keywords (never under the model that was asked), with the outcome and its reason in the step log; models.topic is keywords.

A naming failure never fails the run and nothing retries. The outcomes are the program's (no_key, over_run_cap, too_large, http_<status>, timeout, connect_error, refused, truncated, bad_json, bad_cover, repeated_names, bad_length, wrong_language) plus namer_failed when the program is missing, exits non-zero, does not finish within 900 s, or writes a file that is not its contract, and namer_failed with reason scratch_unavailable when the step's own files or directory cannot be made, written, read or removed (the token counts of a call that was made are kept).

What is stored and what is recorded always agree. The order of writes: the naming's record (outcome, namer, token counts) goes to run_delphi.py first, on a pipe it hands the pipeline (--naming-record-fd), and only then are any labels written. If the record cannot be sent, the model's names are not published: the keyword labels are, under a record that says namer_failed (reason record_unsent) with the call's token counts, sent again. So the only partial state is keyword labels recorded as keywords with the reason; the manifest's models.topic, its cost, the step log and the stored map's provenance all come from that one record.

What would leave the network then

Only what is in hierarchy.json, which the namer sends to the model provider: topic ids, layers, sizes, parent ids, five keywords per topic, and the text of three comments per topic. Never an author, participant, vote, time, comment id, or the conversation's name, description or code. Only the participant-visible comment rule may name a namer (refused in the job child and again in both Python entry points), so its layout holds only comments participants are shown and no comment a moderator removed is sent. Nothing in this change reads, prints or checks a key; the program reads its own.

The step runs inside the Delphi run's own process tree on the Delphi box. By the time it runs, the run's input reads have closed their database connection, so no connection or transaction is held across the model call, and nothing is shared with the web boxes or the vote, comment or next-comment path. Its two files (hierarchy.json, names.json) are removed by the step once read. Under the job daemon their directory is inside the attempt directory that the daemon removes after it has reaped the child's process group, however the child ended (exit, timeout, fence, shutdown, SIGKILL); a run started by hand removes it on exit and on SIGTERM. Nothing a later step or a later run needs is kept there: the record travels on the pipe, and what happened is recorded in the run's step log, stored map and manifest.

Tests

  • queue-rs/src/jobs/child.rs: the namer reaches the pipeline only when named; an unknown model, prompt, thinking setting or key, a non-object, and any other comment rule start no child.
  • delphi/tests/test_topic_namer.py (no model call; a stand-in executable plays the program):
    • the Bowling Green 2050 hierarchy the step builds equals, topic by topic, the one a whole-hierarchy naming study built from the same public layout (fixtures in delphi/tests/fixtures/topic_names/, with their public source in its README);
    • a saved reply's names for those 185 topics are taken as written;
    • each outcome word keeps the keyword labels with its reason, and the older provider path is never called;
    • a program that exits non-zero, writes garbage, an unknown outcome, misses a topic, writes a name over 50 characters, never finishes, or is not installed is namer_failed;
    • with the real topic map generator, the stored map keeps all the model's names as written;
    • the manifest names the model only when it named;
    • run_delphi.py refuses a namer under another comment rule or an unknown model and runs nothing.
  • delphi/tests/test_topic_namer_scratch.py: an occupied directory path, a directory where hierarchy.json or names.json belongs, a file that cannot be removed, and a temporary directory that cannot be made each keep the keyword labels with scratch_unavailable, without failing the run; under the daemon the scratch directory is inside the attempt directory; a run terminated with SIGTERM leaves no scratch directory.
  • delphi/tests/test_topic_namer_record.py: a record that cannot be sent publishes keyword labels under a keyword record that keeps the token counts, and the map's models and the manifest's agree; a record that is never sent never publishes the model's names; the record is read without waiting on a process that still holds the pipe.

The last commit (the image) needs the polis-topic-names crate in the workspace and merges after it.

🤖 Generated with Claude Code

colinmegill and others added 11 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
…ion names one

A full pipeline run whose configuration carries `naming` with `by: model`
gets one more argument, `--namer={"model":..,"prompt":..,"thinking":..}`,
after its selection. Absent, null or `{"by": "keywords"}`, the arguments
are byte for byte what they were.

Refused before a child starts: an unknown model, prompt version or
thinking setting, any other key, a namer that is not an object, and a
namer under any comment rule but participant_visible/1 (so no comment a
moderator removed can be sent to a model). Nothing admits a run with a
namer yet.

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

With `--namer` (run_delphi.py and run_pipeline.py; only with the selection
participant_visible/1), the naming step no longer uses the older per-topic
provider path. It builds hierarchy.json (every non-noise topic of every
layer: id, layer, size, parent, five keywords and the three comments
nearest its centre; comment text and keywords only), runs
`polis-topic-names name --in hierarchy.json --out names.json --namer <json>`,
and on outcome `named` writes the model's names as the layer labels,
recorded as written by the model, so the stored map keeps them under
polis-topic-map.names/3. On any other outcome, or when the program is
missing, crashes, is stopped or breaks its file contract (`namer_failed`),
the keyword labels are kept, recorded as fallbacks under "keywords", with
the outcome and reason in the step log. A naming failure never fails the
run and nothing retries.

The manifest's models.topic is the model only when it named, else
"keywords"; cost.llm_tokens_in/out are the call's tokens. A run without a
namer passes the same arguments and writes the same record and results as
before (tests check the pipeline call, the step-log entries and the
manifest). The naming's files live in a directory of the attempt, removed
when the run ends.

Tests run the step against a stand-in program; no test makes a model call.
The Bowling Green 2050 hierarchy the step builds equals the one a naming
study built from the same public layout (fixtures and their public source
in tests/fixtures/topic_names/README.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
The image builds the topic namer in the same stage as polis-jobs and
polis-topic-map and installs it at /usr/local/bin/polis-topic-names, where
the naming step looks for it. Nothing runs it unless a run is given
--namer, and no admission gives one.

This commit needs the queue-rs/polis-topic-names crate in the workspace;
it merges after that crate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
The naming step runs the topic names program; the Delphi image builds it. This branch carries the program's crate so the two can be checked together.

Co-Authored-By: Claude Fable 5.2 <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
…abels

Creating the step's directory, writing hierarchy.json or reading names.json
can fail (an occupied path, a directory where a file belongs). Each is now a
naming outcome (namer_failed, scratch_unavailable) instead of an exception
that fails the run. Applied as the independent review supplied it.

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
…scratch never outlives the run

What a named run stores and what it records now agree in every case. The
naming's record (outcome, namer, token counts) is sent to run_delphi.py on a
pipe the pipeline is given (--naming-record-fd) before any label is written.
If it cannot be sent, the model's names are not published: the keyword
labels are, under a record that says namer_failed (record_unsent) and keeps
the token counts of the call that was made, sent again. The only partial
state is keyword labels recorded as keywords with the reason. The record no
longer lives in a scratch file, so nothing the manifest needs is there.

Scratch failures are naming outcomes: the step removes hierarchy.json and
names.json once read, and a failure to make, write, read or remove them, or
to make or remove a temporary directory, keeps the keyword labels with the
reason scratch_unavailable and the call's token counts. The step makes its
own directory; run_delphi.py only names it.

Termination: under the job daemon the step's directory is inside the
attempt directory (beside DELPHI_OUTPUT_MANIFEST) that the daemon removes
once it has reaped the child group, however the child ended, SIGKILL
included. A run started by hand removes it on SIGTERM as well as on exit.

A run without a namer is unchanged: same arguments, same child start
(run_child passes descriptors only when given some), same manifest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
Brings the topic names program's review fixes (reply boundary, cost bound, smaller fixtures) beside the naming step.

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

Copy link
Copy Markdown
Contributor

Delphi Coverage Report

File Stmts Miss Cover
polismath/init.py 2 0 100%
polismath/benchmarks/bench_pca.py 128 107 16%
polismath/benchmarks/bench_repness.py 81 65 20%
polismath/benchmarks/bench_update_votes.py 38 28 26%
polismath/benchmarks/benchmark_utils.py 34 0 100%
polismath/components/init.py 1 0 100%
polismath/components/config.py 165 70 58%
polismath/conversation/init.py 2 0 100%
polismath/conversation/conversation.py 1293 264 80%
polismath/conversation/group_vote_counts.py 38 2 95%
polismath/conversation/manager.py 131 42 68%
polismath/database/init.py 1 0 100%
polismath/database/dynamodb.py 392 176 55%
polismath/database/postgres.py 414 95 77%
polismath/delphi_storage/init.py 1 0 100%
polismath/delphi_storage/codec.py 300 22 93%
polismath/delphi_storage/embedding_spool.py 58 6 90%
polismath/delphi_storage/golden_corpus.py 60 9 85%
polismath/delphi_storage/import_report.py 51 3 94%
polismath/delphi_storage/legacy_import.py 171 16 91%
polismath/delphi_storage/postgres.py 51 22 57%
polismath/delphi_storage/production_import.py 614 131 79%
polismath/delphi_storage/resource.py 179 32 82%
polismath/delphi_storage/scan_pacing.py 77 0 100%
polismath/delphi_storage/topic_map.py 128 7 95%
polismath/delphi_storage/writer.py 200 13 94%
polismath/embedding_model.py 197 49 75%
polismath/empty_output.py 29 2 93%
polismath/engine_adapter.py 317 265 16%
polismath/job_child/init.py 382 52 86%
polismath/job_child/census.py 74 9 88%
polismath/job_child/input_bundle.py 106 7 93%
polismath/pca_kmeans_rep/init.py 5 0 100%
polismath/pca_kmeans_rep/clusters.py 257 38 85%
polismath/pca_kmeans_rep/corr.py 98 17 83%
polismath/pca_kmeans_rep/group_k_smoother.py 28 0 100%
polismath/pca_kmeans_rep/legacy_kmeans.py 197 8 96%
polismath/pca_kmeans_rep/pca.py 162 19 88%
polismath/pca_kmeans_rep/repness.py 226 5 98%
polismath/poller/init.py 4 0 100%
polismath/poller/admission.py 318 15 95%
polismath/poller/backfill.py 936 32 97%
polismath/poller/capacity.py 485 27 94%
polismath/poller/capacity_queue.py 248 13 95%
polismath/poller/coordinator_bridge.py 317 317 0%
polismath/poller/math_writer.py 120 3 98%
polismath/poller/promotion.py 112 4 96%
polismath/poller/readiness.py 368 13 96%
polismath/poller/rebuild_child.py 133 5 96%
polismath/poller/recompute_line.py 141 8 94%
polismath/poller/service.py 760 50 93%
polismath/poller/worker_pool.py 143 0 100%
polismath/queue/executor.py 221 111 50%
polismath/regression/init.py 4 0 100%
polismath/regression/clojure_comparer.py 188 20 89%
polismath/regression/comparer.py 891 640 28%
polismath/regression/datasets.py 126 27 79%
polismath/regression/recorder.py 36 27 25%
polismath/regression/utils.py 130 85 35%
polismath/replay/init.py 2 0 100%
polismath/replay/attribution_capture.py 49 0 100%
polismath/replay/axis_continuity.py 347 24 93%
polismath/replay/certify.py 999 59 94%
polismath/replay/crosslang.py 128 2 98%
polismath/replay/decision_ties.py 51 8 84%
polismath/replay/diagnostics.py 50 7 86%
polismath/replay/driver.py 73 1 99%
polismath/replay/dsn_admission.py 36 1 97%
polismath/replay/equiv_query.py 10 0 100%
polismath/replay/event_ingress.py 95 1 99%
polismath/replay/fixture_bundle.py 815 62 92%
polismath/replay/fixture_config.py 266 11 96%
polismath/replay/fixture_extract.py 285 12 96%
polismath/replay/fixture_generate.py 103 1 99%
polismath/replay/fixture_samples.py 157 14 91%
polismath/replay/fixture_selection.py 119 0 100%
polismath/replay/fixture_survey.py 147 11 93%
polismath/replay/legacy_pca.py 29 17 41%
polismath/replay/polarity.py 319 25 92%
polismath/replay/poller_equiv.py 776 99 87%
polismath/replay/prodclone.py 193 2 99%
polismath/replay/real_data.py 146 10 93%
polismath/replay/schedule.py 205 10 95%
polismath/replay/served_math.py 159 4 97%
polismath/replay/shard_bench.py 189 65 66%
polismath/replay/stagecompare.py 890 161 82%
polismath/replay/stages.py 256 40 84%
polismath/replay/stepcompare.py 86 1 99%
polismath/replay/store.py 120 11 91%
polismath/replay/tie_capture.py 107 19 82%
polismath/replay/types.py 58 6 90%
polismath/run_math_pipeline.py 284 93 67%
polismath/selection.py 58 0 100%
polismath/step_log.py 128 16 88%
polismath/tools/engine_rebuild.py 230 11 95%
polismath/types.py 6 0 100%
polismath/utils/cli_flags.py 15 0 100%
polismath/utils/clj_hash.py 44 0 100%
polismath/utils/env_flags.py 13 0 100%
polismath/utils/general.py 63 39 38%
polismath/utils/output_profile.py 66 2 97%
polismath/utils/serialization.py 10 5 50%
polismath/utils/vote_convention.py 159 5 97%
umap_narrative/700_datamapplot_for_layer.py 514 470 9%
umap_narrative/701_static_datamapplot_for_layer.py 310 310 0%
umap_narrative/702_consensus_divisive_datamapplot.py 435 275 37%
umap_narrative/801_narrative_report_batch.py 657 209 68%
umap_narrative/803_check_batch_status.py 268 148 45%
umap_narrative/llm_factory_constructor/init.py 2 0 100%
umap_narrative/llm_factory_constructor/model_provider.py 232 106 54%
umap_narrative/narrative_data.py 178 55 69%
umap_narrative/numerical_stages.py 111 21 81%
umap_narrative/polismath_commentgraph/init.py 1 0 100%
umap_narrative/polismath_commentgraph/cli.py 268 268 0%
umap_narrative/polismath_commentgraph/core/init.py 3 3 0%
umap_narrative/polismath_commentgraph/core/clustering.py 108 108 0%
umap_narrative/polismath_commentgraph/core/embedding.py 104 104 0%
umap_narrative/polismath_commentgraph/lambda_handler.py 219 219 0%
umap_narrative/polismath_commentgraph/schemas/init.py 2 0 100%
umap_narrative/polismath_commentgraph/schemas/dynamo_models.py 80 4 95%
umap_narrative/polismath_commentgraph/tests/conftest.py 17 17 0%
umap_narrative/polismath_commentgraph/tests/test_clustering.py 74 74 0%
umap_narrative/polismath_commentgraph/tests/test_embedding.py 55 55 0%
umap_narrative/polismath_commentgraph/tests/test_storage.py 87 87 0%
umap_narrative/polismath_commentgraph/utils/init.py 9 7 22%
umap_narrative/polismath_commentgraph/utils/converter.py 283 38 87%
umap_narrative/polismath_commentgraph/utils/group_data.py 332 279 16%
umap_narrative/polismath_commentgraph/utils/storage.py 616 486 21%
umap_narrative/reset_conversation.py 162 53 67%
umap_narrative/run_pipeline.py 561 173 69%
umap_narrative/topic_namer.py 178 8 96%
umap_narrative/topic_naming.py 159 9 94%
Total 26735 7419 72%

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