Repository navigation
delphi shadow: a named run reuses a finished run's map and only names it, so two runs of one conversation can differ only in who named the topics - #3481
Draft
colinmegill wants to merge 18 commits into
Draft
colinmegill wants to merge 18 commits into
colinmegill wants to merge 18 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
…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
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
…of), so two namers of one conversation differ only in their names A run whose configuration carries `names_of` (a finished keyword run of the same conversation under participant_visible/1) and a model namer takes that run's layout and clusters instead of making its own. Before its child starts, polis-jobs reads the source's run record and its positions and assignments families from the stored results in Postgres (pd_run_record, pd_result_artifact_wire), checks each against the batch and digest the record names, and writes them into the attempt directory. The child copies the two families row for row into its own batch, recomputes keywords and sample comments over that layout, and names it. No embedding, UMAP or EVoC. Every unusable source is the job's recorded outcome before a child starts: missing, not succeeded, of another conversation or comment rule, itself a named run, without its own two families in one batch, or with its stored families removed. A source comment the run's own selection no longer keeps sends nothing to the model: the keyword names stay, with the reason. The admission (shadow::plan::names_admission) keys a named run by its conversation, source and namer, in a scope of its namer's own, so it is never its source's duplicate, two namers are two jobs, and the same request asked again is the same job. Nothing calls it yet: no production admission, list or setting changes. No schema change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…nnet namings, through the stored map Bowling Green 2050 from the public fixtures: a keyword run, then two runs that name its topics (names_of), one by claude-haiku-5-5 and one by claude-sonnet-5-5, each through run_pipeline's own writes, naming step, execution record and stored-map step, drawn by the real polis-topic-map. The model is the naming tests' stand-in replaying the saved replies; no call, no key. Only the embedding, UMAP and EVoC of the keyword run (replaced by the fixture's layout) and the conversation read are not the pipeline's. The three stored maps have the same points (ids, positions, order, topic per level), levels and topics (ids, levels, clusters, sizes, centres, parents, colours); the named runs hold the keyword run's positions and assignments byte for byte; the names are the keyword labels and exactly each saved reply's; provenance.models.topic and run.topicModel name none (a run without a namer, as the shadow records it), claude-haiku-5-5 and claude-sonnet-5-5. A named run whose namer fails stores the source's keyword names, recorded as keywords with the outcome and its reason. Also a unit test of the seam between the namer's record and the names rule: the record's model_clusters are kept as the model wrote them only when the naming named, and a failed naming lists none. No change to what any run does; no schema change. 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
…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
Brings the naming step's review fix round into the named-run branch: the
naming record goes to run_delphi.py over a pipe before any label is
written, a scratch-file failure is an outcome that keeps the keyword
labels, and the step's scratch directory lives in the attempt directory
and is emptied once read. Also brings the naming program's corrections
(its fixtures and its cost bound counted in bytes).
One conflicted hunk, in delphi/umap_narrative/run_pipeline.py
(_process_conversation, where the naming step's arguments are built):
- This branch had changed the line that starts the naming record so a
run naming another run's topics, whose layout holds a comment its own
selection no longer shows, starts with {"source_refused": ...}.
- The fix round had added naming_record_fd to the arguments passed to
process_layers_and_create_visualizations.
- Resolved by keeping both: the record starts as this branch made it,
and the arguments carry the pipe as the fix round made them. Taking
either side alone would either lose the refusal (a named run would send
a hidden comment's text to the model) or lose the pipe (a named run's
record would never reach the manifest).
Merged without a conflict and checked by reading: _name_with_namer now
pops the refusal before anything else, records namer_failed with that
reason without building the hierarchy, touching the scratch directory or
starting the program, and then follows the fix round's order of writes
(the record sent first, the labels after), so a refused named run sends
its keyword record on the pipe like any other outcome.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…see nothing left behind After the naming step's review fix round, a run's naming record reaches run_delphi.py over a pipe before any label is written, and the step empties its scratch directory once read. The named-run tests ran without the pipe, so they no longer proved that a run naming another run's topics keeps those properties. Now: - The end-to-end test of one conversation's keyword, Haiku and Sonnet runs gives each named run the pipe as run_delphi.py does, and checks that the record sent (once, "named") names the same model as the stored map, and that the naming directory is empty afterwards. - The failed-namer test checks the record sent says http_429 with the reason, and names keywords. - A new end-to-end test: a named run whose model answered but whose record could not be sent stores the source's keyword names, recorded as keywords with the reason record_unsent, and its record keeps the call's token counts. - A new test of the refusal for a comment the run no longer shows, through the naming step itself: its keyword record goes on the pipe, the program never runs and no scratch directory is made. No production code changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…a record needs its final newline Two narrow corrections to the naming step: an OSError reading names.json is reported as scratch_unavailable (malformed JSON keeps its own reason), and receive_record ignores a final line without its newline, as the framing says. Each with a test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…t image In the image the tests live at /app/tests, so the checkout two levels up is /, and the topic map's Bowling Green layout and the saved Sonnet reply were not there: the names_of tests and the end-to-end test of a keyword, a Haiku and a Sonnet run failed on a missing file. They now resolve the checkout as the other tests do (, else the checkout), and ci/local/delphi-python.sh copies the two inputs into that root, so the end-to-end test runs in the same shard on our boxes and hosted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…pped run stops its pipeline What a named run stores and what its manifest records now agree on every failure of the record between the pipeline and run_delphi.py: - receive_record raises when the pipe cannot be read, instead of reading that as the end of the data; run_delphi.py's receive_naming returns the reason a record was not received (unreadable, missing, or only part of one), and such a run fails: the pipeline may have stored the model's names, so no manifest is written that could name another naming; - a record not sent whole is sent again once under keyword labels for any outcome, not only after a named one; - the call's token counts are in the pipeline's own log line (topic_names_call facts and one log line), whatever becomes of the record. A run given a namer is stopped as a whole: step_log.run_child stops and reaps the pipeline (SIGTERM, then SIGKILL after 30 s) when run_delphi.py is interrupted, with the step log on or off, and the pipeline exits through Python on SIGTERM so the naming's program is stopped and waited for before the scratch directory is removed. The module docstring states exactly when that directory is removed and when not (a hand run sent SIGKILL; the daemon's recovery path), and why what can be left is not state. A run without a namer is started and waited for exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
Contributor
Delphi Coverage Report
|
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.
A Delphi run can name another run's topics, so two namers of one conversation differ only in their names
What anyone will observe: nothing. No run asks for this yet. No production admission, list, setting or schedule changes, and every existing run's arguments, frame and results are what they were. No schema change and no migration. No Node change.
The test this change is for: one conversation, three jobs, one map, three sets of names
delphi/tests/test_named_runs_of_one_conversation.pytakes Bowling Green 2050 from the public fixtures and makes three runs of it, each carried throughrun_pipeline.py's own writes, keywords, naming step, execution record and stored-map step, and drawn by the realpolis-topic-map:participant_visible/1, set up as the shadow runs it (Anthropic named with modelnoneand no key, so every layer keeps its keyword labels);names_ofthat keyword run and the namerclaude-haiku-5-5;claude-sonnet-5-5.The model is the naming tests' stand-in for
polis-topic-names, replaying the saved replies of the November 2026 naming study (Haiku:bg2050_names_haiku.json; Sonnet:queue-rs/polis-topic-names/tests/fixtures/replies/bg2050/sonnet-default-r1.json). No call is made and no key is read. Only two things are not the pipeline's own: the keyword run's embedding, UMAP and EVoC are replaced by the fixture's layout (3,162 comments, four layers, 185 topics), and the conversation's comments are given instead of read from Postgres. The named runs read the keyword run's two families from the files the job's frame names, as the daemon writes them from the stored batch.It asserts, on the three stored documents:
Delphi_UMAPGraphandDelphi_CommentHierarchicalClusterAssignmentsbyte for byte, with the same digests in each map'sprovenance.inputs, and none of them embedded, laid out or clustered;<layer>_<cluster>: <name>); every model name differs from its topic's keyword label, and the two models differ on most topics (they agree on a few: both call one topic "SKyPAC Performances and Bookings");provenance.models.topic(andrun.topicModel, from the names rows) isnone,claude-haiku-5-5,claude-sonnet-5-5; the execution record'salgorithms.topic_namesgives each layer's model, outcome and the clusters the model wrote;http_429) stores the source's keyword names, with the same map, recorded askeywordswith the outcome and the reason, never under the model it asked for.A unit test in
polis-topic-map/src/stored.rspins the seam between the namer's record and the names rule: the clusters the record lists as the model's are kept as written only when the naming named; a failed naming lists none, so its labels are taken by their shape.A run without a namer records
none(the shadow'sANTHROPIC_TOPIC_MODEL), notkeywords. This change keeps that as it is; whatever lists a job's namer reads both as keyword-named.What it makes possible
EVoC gives different topics from run to run, so two independent runs of one conversation, one named by Claude Haiku and one by Claude Sonnet, would differ in their topics as well as their names. With this change, a run whose configuration carries
names_of(a finished keyword run of the same conversation) and a model namer reuses that run's layout and clusters:pd_run_record) and its two families,Delphi_UMAPGraphandDelphi_CommentHierarchicalClusterAssignments(pd_result_artifact_wire), from the stored results in Postgres with the queue login. It checks each family against the batch and digest the record names and writes them into the attempt directory. The frame names them undernames_of(polis-jobs.names-of/1). Nothing is read from a file an earlier run left on a machine.Two named runs of one keyword run therefore hold the same positions and clusters, and differ in their names and in the model their map's provenance names.
Refusals
Each of these is the job's recorded outcome before any child starts. None is a crash, and none falls back to a fresh clustering.
names_ofthat is not a job id (names_of_not_a_job), or given without a model namer (names_of_without_namer), or given to a run under any rule other thanparticipant_visible/1(names_of_selection_not_named).names_of_source_missing);names_of_source_unfinished);names_of_source_other_conversation);names_of_source_other_rule);names_of_source_named);names_of_source_incomplete);names_of_source_removed).names_of_source_unreadable, the only one an attempt may retry.At run time, if any comment in the source's layout is no longer kept by the run's own selection (moderated out since, for example), nothing is sent to the model. The run keeps the keyword names and records the reason
source_comment_not_shown. A naming failure never fails the run, as before.Identity
shadow::plan::names_admission(zid, source, source_config, naming)builds the admission. Nothing calls it yet; the scheduler's list is a later change.shadow:names:<zid>:<source job, no dashes>:<namer>, where the namer is for exampleclaude-haiku-5-5.p1.default. Scope:delphi:names:<namer>.existing).The admission refuses a source under another comment rule, a source that is itself a named run, and a namer that the child does not run.
Tests
Rust unit tests (
queue-rs/src/jobs/names_of.rs,queue-rs/src/shadow/plan.rs): every refusal, the wire checks, the files and the frame value, and every identity case.A PostgreSQL 17 test with the release migration chain (
polis-topic-map/tests/from_run_database.rs,--features db-tests):pd_writer_admit, and asking again returns the same job;Python (
delphi/tests/test_names_of.py):The end-to-end test above (
delphi/tests/test_named_runs_of_one_conversation.py), and the seam test inpolis-topic-map/src/stored.rs. The end-to-end test needspolis-topic-maponPATHor named byDELPHI_TOPIC_MAP_BIN, as the topic map step's tests do; without it, it is skipped.Not covered: the real child started by the daemon for a queued named job (the frame
task.rswrites, read by the child in its own process). The end-to-end test builds that frame the same way, and the database test covers the read that fills it.The participation path
This work runs in the Delphi job process and its child, on the queue login's own short connection and the attempt's directory. It uses no web-server pool, takes no lock that a vote, comment or next-comment request could wait on, and holds no connection across the model call.
🤖 Generated with Claude Code