Skip to content

comment scores: the program in the Delphi image, its Compose service and its start on the Delphi box (off) - #3614

Merged
colinmegill merged 11 commits into
edgefrom
week/4-scores-compose
Dec 3, 2026
Merged

colinmegill merged 11 commits into
edgefrom
week/4-scores-compose

Conversation

@colinmegill

@colinmegill colinmegill commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

This branch contains two drafts that are not on edge yet: PR #3613 (the comment scores program) and PR #3607 (the math worker's Compose service), joined by a merge commit. Until both are on edge this page shows their changes too. What is new here is the last two commits, git diff 964695764..7432fcdf9.

What a person would observe

Nothing. No page, route, number or label changes, and the next comment is chosen as before. With none of the new settings present, every box starts and replaces exactly the services it does today, and make start runs the same command.

When an operator later sets one line, the Delphi box also runs a program that stores comment scores nothing reads, and the deploy log says whether it is up.

What changed

  • The Delphi image holds polis-routing-jobs beside polis-jobs, built in the same stage by a cargo command of its own. In one command with the others, cargo would compile their shared dependencies with this crate's features as well, and all four existing programs came out different; built apart, they are compiled by the same command as before, with the same features.
  • docker-compose.yml, the service scores-worker: the math worker's hardening, restart rule, CPU weight and OOM score; 1 CPU and 512 MiB (measured on a document of 10,000 comments: 0.25 s a job, a peak of 179 MB).
    • Its own: the profile, the switch POLIS_JOBS_ROUTING_WORKER, POLIS_JOBS_ROUTING_CONVERSATIONS, POLIS_JOBS_ROUTING_RULES and POLIS_JOBS_ROUTING_EVERY_UPDATES (default 1).
    • The math worker's: the login (POLIS_MATH_QUEUE_DATABASE_URL), the queue env (POLIS_MATH_QUEUE_ENV), the TLS settings and the label's source. Either service runs without the other.
  • scripts/after_install.sh: selection on the Delphi role and the exact line, the release's image, the read-back of the composed settings, the start and the look ten seconds later, as for the math worker.
    • The start and the look are now one function for the two. The math worker's commands and messages are unchanged, and so are its tests of them.
    • The read-backs stay two. Each refuses a login or a queue env any other service has, with one exception each: the other of these two workers.
    • A refusal of one leaves the other as it is. The old containers are gone before a new one starts, by the Delphi role's existing removal.
  • A job lost and then refused is done again by a new build (queue-rs/polis-math-routing/src/due.rs). A job whose process died is done again once by the same build. When that repeat was refused, its chain had no result to name the build, so a release that mends the refusal waited for the next vote. The repeat's source id already names the builds that did it, and the due rule now reads it there. It cannot loop: a build named there never does it again, and at most eight are named. A refused first job of a conversation that has no result yet still waits for the next vote, as before.
  • Makefile, docker-compose.dev.yml, example.env, docs/configuration.md ("Comment Scores Worker"), the crate's README: as for the math worker.
  • The participation load test. The math worker's series is now a function that can run a second program through its loaded windows; its own test and its bounds are unchanged. polis-math-routing/tests/participation_load.rs includes that file and runs the real program there at its cap, its notices counted. The memory and the connections it prints are samples taken about once a second, so they can miss a peak. Ignored by default.

Schema

None. No migration, grant, role, function or index.

Participation path

Not touched. The service runs on the Delphi box, which serves no participant, on connections of its own (at most five, beside the math worker's three), never a web pool. It reads no vote; its reads of math_main are plain SELECTs under a 2 s statement timeout. The load test runs votes and next comments against both workers at their caps on a conversation of a million votes. In one short run on a busy box (45 s windows) it passed:

95th percentile, ms alone both workers at their caps bound
vote, 4 connections, paced 6.3 5.8 26.3
next comment, 2 connections, paced 10.7 10.0 30.7
vote, 24 connections, no pause 33.8 52.5 53.8
next comment, 24 connections, no pause 47.3 63.1 67.3

No vote was refused or lost. The last two rows are close to the bound; other work was running on that box (load average 25 on 14 cores), and the workers and the database share it, which in production they do not. The run before it kept every latency bound too, but counted 12 paced requests over their 50 ms period, which the test also refuses (that run failed, on a check of mine that took the program's ordinary last line for an error). The quiet series of longer windows is still to run.

Vote sign

Not touched. The new program reads no vote. The load test's votes go through the code that was there.

Identity and deploy mechanics

  • One login, two programs. The programs check it at start (exit 2 on one that holds more), and the hook refuses one a third service uses. The docs create it with CONNECTION LIMIT 20. The two programs hold at most eight on one box (seven was the most in the load test's samples), and a second Delphi box, or a replaced one while the server still holds the lost box's connections, needs eight more. A deploy has no overlap, since both old containers are removed first. A connection refused at the limit is tried again at a start, but one refused during a job can end that job.
  • One container, never scaled, the old one stopped before the new one starts: two builds side by side do each other's work again. Each Delphi box runs one and the boxes deploy one at a time, so exactly one Delphi box is to be in service when it is turned on.
  • The rule setting is JSON. It is written in the env document as it is, without quotes. Compose passes it through unchanged (run), and the hook refuses a value that is not a JSON object naming its rule. A value in double quotes whose inner quotes are not escaped, or whose last quote is missing, makes every Compose command fail on every box, web boxes included, before the hook can refuse it; the docs now say so.
  • The first deployment of a release that carries this service must have the line off, unless the release it could go back to already carries the math worker's service, whose hook removes a container it does not know by its labels.
  • The queue worker boxes (off by default) load the whole env document into polis-jobs. That daemon reads none of the new settings, and starts with all of them present (run), so the docs' warning about those boxes stays the math worker's alone.
  • The program's code identity changes, because the crate's Cargo.toml gains two test dependencies and the due rule changes. Nothing is listed anywhere, so nothing is done again.

Checks (local build box)

What Result
bash scripts/test-deploy-hooks.sh (the entry point CI uses, with the real jq) 929 passed
The same with the two sibling exceptions taken out and a refused scores worker started anyway 119 fail
docker build --target polis-jobs with the old and the new Dockerfile with a shared build cache, the four existing programs identical; polis-routing-jobs runs, and exits 0 when off. Clean builds without a cache gave polis-jobs, polis-delphi-shadow and polis-topic-map in one of two forms, with the old Dockerfile as with the new one
cargo fmt --all --check; clippy with -D warnings on polis-math-routing (with and without jobs-integration) and on the queue package ok
cargo test --locked -p polis-math-routing --features jobs-integration 23 + 29 + 26 + 1 passed, 2 ignored
The same with the new condition of the due rule taken out; with every refused job done again; with a build allowed to do it twice 2, 8 and 7 tests fail
cargo test --locked --features jobs-integration --test math_participation_load 1 passed, 1 ignored
cargo test --locked -p polis-api --test no_rule_evaluation_crate, and its cargo tree check 2 passed; no rule crate
The loaded test, 45 s windows, twice the first failed as said above; the second passed
The real service from docker-compose.yml with the development overlays and a migrated Postgres, started by the hook's own function alone: logged in, one job admitted, stored and its notice sent; a row in the view math_routing_weights; read-only root, no mount, 512 MiB, 60 s to stop. Then beside the math worker; then the math worker removed and this one still running. A bad rule and a superuser login: not up, exit 2. Two rules in one env line. A stop: exit 0
Real docker compose config with a production-shaped env file through both jq programs nothing wrong named
make -n start with the switch 0 and 1 the profile only when 1
make check-nginx-upstreams, make check-vote-sign-lint ok; 0 new

Not run, or not in full:

  • The full local table, and the quiet load series.
  • The whole Delphi image (only the Rust stage, and the two programs copied into a recent test image).
  • Compose v2.40.0, the version on the boxes. The box here has v5.6.0.
  • A TLS connection from this service, and a wrong password (the development database trusts its own network). The hook's tests cover what it then says.
  • A Docker daemon or box restart.

Turning it on

Until it is on, it is not done.

  1. Release and deploy this with the line absent, and let the deployment of the workers succeed, not only the web one.
  2. The math worker's login exists (docs/configuration.md, Math Worker, "Its login"), with CONNECTION LIMIT 20; nothing more is granted to it. Exactly one Delphi box is in service.
  3. The env document gains POLIS_JOBS_ROUTING_WORKER=1, POLIS_JOBS_ROUTING_CONVERSATIONS (numeric ids, comma-separated) and POLIS_JOBS_ROUTING_RULES={"rule":"stored-weights/1","params":{},"terms":[]}, and POLIS_MATH_QUEUE_DATABASE_URL (a secret) if the math worker has not put it there.
  4. Deploy again (the same release will do). The hook writes the env file, so a restart of the box is not enough.
  5. It is seen working when:
    • the Delphi box's deploy log says The comment scores worker is up 10 seconds after its start, logged in to its database;
    • the Delphi log stream shows polis_jobs math admitted routing_weights job ... and then polis_jobs math job ... notice sent for the same job;
    • the view math_routing_weights holds an active row for each listed conversation, at the number of math-python's newest update or just behind it.

Nothing deletes old results yet, so a busy conversation waits for that, or is listed with a larger POLIS_JOBS_ROUTING_EVERY_UPDATES.

To turn it off, remove the line and deploy. The results stay stored.

🤖 Generated with Claude Code

colinmegill and others added 11 commits December 2, 2026 16:24
…ntil one line is set

docker-compose.yml gains math-worker: polis-jobs as worker class math_compute
(PCA, k-means and representativeness, each its own job) with a login, queue
env and conversation list of its own, a read-only root, no volume, 1 CPU and
2 GiB, restarted at most ten times, behind its own profile.

The deploy hook starts it on the Delphi box only, on the exact line
POLIS_JOBS_MATH_WORKER=1, after reading its composed settings back and naming
what is wrong without a value. Ten seconds later it says in the deploy log
whether the worker is up and logged in. Nothing about it fails a deploy, and
every Delphi deploy with the line off removes its container.

make start starts it when the env file has the switch at 1; the development
overlay gives it the Postgres container's network.

Nothing serves its results. math-python, its lock and its settings are
unchanged. No schema change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… with Python's document, one log line (off with the worker)

Right after a representativeness job's finishing transaction has committed as
succeeded, the math worker reads the update's three results, its capture and
its chains' last facts in one bounded read-only transaction, releases, compares
them with the Python engine's own document, and logs one JSON line
(math_shadow_observation): agrees, differs_in_window, differs or not_compared.

Discrete values are compared exactly (clusters as sets of participants, never by
id), floats within the tolerance of the replay step comparer (1e-6 + 0.01 of the
Python value), centres through the crate's one axis function. A difference is
expected only when a named reason read from Postgres covers the field or one it
is computed from; the table is in src/math/compare.rs. Whatever goes wrong in
the comparison becomes a line and never reaches the job, its chain or the loop.
The line carries no participant, comment, vote, coordinate or conversation.

No schema change, nothing served, no new switch, and no stored byte changes: the
steps' code identity covers neither new file.

The recorder gains --documents (the engine's whole captured document per update,
representativeness and consensus included) and five recordings made with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…vice it does not know

- The Delphi role's removal of the services it does not name falls back, only
  when Compose's own removal fails, to removing those services' containers of
  this project by their labels, stopped first. Compose refuses the whole list
  for one name its file does not have, so a rollback to this release from a
  later one would have failed after it had taken Delphi down. A container that
  still cannot be removed fails the deploy, as before.
- math-worker restarts unless stopped, like the box's other daemons: it comes
  back after a restart of the box or of Docker, and a refused setting is tried
  again about once a minute. The deploy log's line for a worker that is not up
  says so.
- make names the math-worker profile from the last POLIS_JOBS_MATH_WORKER line
  in the env file, the one Compose uses.
- Docs: not together with the queue worker boxes, whose daemon refuses two of
  the settings; a password of letters and digits only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tested

A reason in the line now excuses only what it can cause, for as long as it can
cause it.

- A chain's first update that equals Python's is agrees_at_seed, not agrees:
  the chain had just started from Python's document of that same update.
- Each line has judged (1 or 0) and first_chain, the root job of the
  conversation's oldest PCA chain, which stays the same when a chain is seeded
  again. One log query over them shows the conversations that were never judged.
  The lookup is one step down math_job_results_newest; a test holds the plan at
  10,000 chains.
- An update passed over excuses the in-conversation set only when the chain
  began with fewer than 7 comments or 15 participants in conversation.
- What only the k-means chain did excuses no PCA component and no order. Older
  start vectors excuse no order either.
- Another column order excuses a representativeness difference only among
  comments of exactly equal rank, and a consensus tie needs the same comments
  with the same counts.
- The PCA's centre and the representativeness and consensus statistics are held
  to 1e-6 + 0.0001 * |python|, as the retirement's stage comparer held them.
- A float field with nothing to compare is null, not equal.

New database tests: updates arriving in bursts, an update passed over in a
conversation that is not small, and a finish whose COMMIT went unanswered. No
schema change, and no stored byte changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on the math worker's loop (off)

The math worker's loop takes what it runs as a Program: its steps, its
admission pass and what it does after a committed success. polis-jobs runs
the same three steps and admission as before through it.

polis-routing-jobs (polis-math-routing) runs that loop with the routing step:
it reads the admission manifest, the stored capture and the chain's previous
result by their digests, builds the plan from the capture alone and stores
its stored form with a run record naming every input. One attempt per job; a
failure stops the chain with its reason. Off unless
POLIS_JOBS_ROUTING_WORKER=1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ld when new scores are stored (off)

A routing weights job that ended because it was lost (its process died, its
lease ended, the database went away) is due once more for the same update
under the same build, the chain's first job included; a new build does a lost
first job again too. An input the step refused waits for the next update, as
before. The due query reads which it was from two stored facts, the queue's
state of the job and the chain's last_failure_reason, and the repeat is
bounded by the new job's source id, which names the builds that did it again.

After a job has committed as succeeded, an uncertain commit that turns out to
have happened included, the program sends one NOTIFY on the draw crate's
channel with its notice type, as a transaction of its own. A refused notice or
a lost connection is one log line and changes nothing about the job.

Tests added for what the review of the previous change found untested: the
result names the running build, and nothing runs after a lease the heartbeat
found lost. The README says why two builds must not run side by side and how
to deploy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The one conflict is a paragraph of queue-rs/README.md: both sides are kept
(the routing weights job's own program, and the Compose service that runs
this binary).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t on the Delphi box, off until one line is set

polis-routing-jobs is built into the Delphi image by a cargo command of its
own, so the four programs already there are byte for byte what they were.
scores-worker runs it with the math worker's hardening, login and queue env
and its own switch, list, rule and memory ceiling. The deploy hook reads its
settings back, starts it and says whether it is up, as it does for the math
worker: the start is now one function for the two, and each read-back lets
the other worker, and no third service, have its login and queue env.

The participation load test's series can run a second program through its
loaded windows; the scores crate's test runs the real program there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ild, and the shared login's connection limit is 20

A routing weights job whose process died is done again once by the same
build. When that repeat was refused, its chain had no result to name the
build that made it, so a later release that mends the refusal waited for the
next vote. The repeat's source id already names the builds that did it; the
due rule now reads it there. A build named in it never does it again, so each
build still does it at most once, eight builds at most.

Docs: the login the two workers share is created with CONNECTION LIMIT 20
(room for two Delphi boxes); what a rule written in unescaped double quotes
does to every deploy; one Delphi box in service before the turn-on.

The loaded test says that its resident size and connections are samples.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Edge carries this branch's first parts (the math worker's service and the
comparison with Python) as squashed merges with the same content; merged
from that state, with no conflict. The web side's draw comes in from edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 3, 2026

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 5 96%
polismath/delphi_storage/writer.py 200 12 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/embedding_reuse.py 104 7 93%
polismath/job_child/input_bundle.py 106 7 93%
polismath/job_child/names_of.py 89 7 92%
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 7 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 9 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 1000 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/rust_producer.py 242 126 48%
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 143 26 82%
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 27 90%
umap_narrative/polismath_commentgraph/utils/group_data.py 332 279 16%
umap_narrative/polismath_commentgraph/utils/storage.py 616 342 44%
umap_narrative/reset_conversation.py 162 53 67%
umap_narrative/run_pipeline.py 681 217 68%
umap_narrative/topic_namer.py 289 289 0%
umap_narrative/topic_naming.py 159 9 94%
Total 27417 7736 72%

@colinmegill
colinmegill marked this pull request as ready for review December 3, 2026 16:39
@colinmegill
colinmegill merged commit 50016e5 into edge Dec 3, 2026
66 of 68 checks passed
@colinmegill
colinmegill deleted the week/4-scores-compose branch December 3, 2026 16:39
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