Repository navigation
delphi: a stored run gets its topic map with nothing recomputed (a derived job; migration 000050; everything switched off) - #3489
Merged
Merged
Conversation
… (migration 000050, switched off) A derived job reads one finished run's stored results and writes only what it adds; the first is a stored run's topic map. This gives it a lasting identity and a checked reference to the run it reads, and nothing else: no executor, route or scheduler yet. Migration 000050 (additive; no table, column or index): - the queue's closed lists gain stage delphi_derived, worker class derived and kind derived (CHECKs added NOT VALID: each is a superset of the validated list it replaces, so no rows are scanned), plus a CHECK binding stage and class. pq_claim, pq_reap and pq_class_depth admit the class; pd_enqueue, pd_queue_binding and pd_writer_admit admit the stage, each otherwise unchanged (pd_writer_admit's local variable is renamed). An existing daemon claims only delphi or large, so it never claims a derived job. - new pd_derived_admit (executor only): under a lock on a caller-made key, returns the existing job for the key whatever its state; refuses with one word unless the source is a succeeded job of the same env and conversation with a sealed output; otherwise admits through pd_writer_admit under its own scope, records the source in delphi_job_inputs and the key in delphi_job_aliases, whose primary key is the lasting uniqueness (the 24-hour request alias is not relied on). - down/000050 reverses it, refusing while any derived job exists. polis-topic-map gains derived.rs: the key is the SHA-256 of a canonical object of operation, operation version, env and source job id only; the specification stored with the job is read from the source's run record (inputs owned by the source, one batch, declared rule and hashes checked); POLIS_JOBS_DERIVED_ADMISSION=1 is required, otherwise nothing is admitted and the database is not touched. Tests against PostgreSQL 17: same key from eight simultaneous askers, other askers, a new connection, expired request aliases, a running and a dead job all return one job; wrong env, conversation, rule, hash, missing, unfinished or malformed source refuse with nothing written; the down file refuses with a derived job and reverses cleanly without one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… of its own (switched off) `polis-topic-map derived-worker` claims one job of class `derived` at a time, reads its source run's three stored families through a checked reader (the source named by the job's own record; every family's artifact, batch and SHA-256 compared with the job's record and with the source's record, and the received bytes hashed; one read-only repeatable-read transaction with statement, lock and idle timeouts, a whole-read deadline and byte caps), makes the map with the same function `from-run` calls, and stores only Delphi_TopicMapDocument in the derived job's own batch through the queue's fenced put, seal, exit proof and finalize. The document, gzip and digest are from-run's bytes; only the outer rows' job_id names the derived job (`stored::store_owned`). A source with nothing to draw stores its one no_map row and succeeds; a source that no longer matches the job's record ends dead with one word; a database or transport failure retries within the queue's three attempts. The worker spawns no process and links no model or pipeline. A restart is recovered with the daemon's own journal rule (another boot, or the pid dead); a lost journal parks the job exit_unconfirmed for an operator, as the daemon does. Off unless POLIS_JOBS_DERIVED_WORKER=1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…saved specification A request for a key that already has a job was returned that job without comparing the request's declared comment rule and input hashes with what the job was admitted with. The repeat, and the loser of a race, are now compared with the saved specification and refused on a mismatch. From independent review, with its two regression tests. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
Formatting only; no behaviour changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…made from it
GET /api/v3/delphi/topicMap still names runs, never the job that drew a
map. When the run a request resolves to (the served run, then the
shadow's; job_id, selection and source as before) stored no map family
of its own, the route looks up the derived topic map job made from that
run, by the run's derived key, and serves that job's stored map as the
run's map. Every row of that map must name the derived job, its
specification must name this run, and it must be in this conversation;
otherwise the map is refused as unreadable. The document is the stored
bytes, so its provenance and the X-Polis-Topic-Map-Job header name the
run its layout, clusters and names are from.
Observable changes, only for runs that have a derived map job:
- a map made by one carries X-Polis-Topic-Map-Made-By: <its job id>;
- while that job waits or runs, the answer is 200 no map with reason
map_pending and map_job_id; it is the served side's answer, so the
shadow is not read instead;
- a job that stored a reason instead of a map answers that reason, with
map_job_id; a job that failed answers map_failed with map_job_id, and
counts as nothing stored (a query naming no source reads the shadow);
- list=jobs marks such a run with map: {job_id, status:
stored|pending|failed}, and its current run is the one the read
answers. Derived jobs are never listed as runs.
A run with its own map, and every reply for a conversation without
derived jobs, is unchanged, header for header and byte for byte.
The lookup is one statement on the route's own connection, only when the
run has no map of its own (the list: one per side, for all its runs, and
one run record read for the current run's derived job). The route still
only reads: it never asks for a map to be made. No schema change; no new
pool, connection or lock.
The page says each state as text: the chooser adds "map made from this
run's stored layout (<short id>)" (or being made, or could not be made),
and a map being made or not made is a quiet line, never an error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A source read with a 100 ms deadline and a 50 ms statement bound stayed blocked for 800 ms until the relay closed. The read now ends at its deadline and closes its socket. From independent review, with its regression test. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…ne, with nothing kept on the box A derived job reads stored, digest-checked inputs and its only writes (put, seal, finalize) are fenced by owner, attempt, epoch and live lease. So the map worker keeps no journal, state file or directory, and gives no exit proof. Migration 000050 (unmerged) now exempts stage delphi_derived, and only it, from the exit-proof checks of five existing functions, each the earlier body with one stage condition added: - pq_claim does not wait on an unconfirmed old attempt; - pq_reap_one ends an expired attempt as an ordinary retry (lease_expired, one attempt of the budget) instead of parking it exit_unconfirmed; - pq_end_attempt takes no proof for fail, release or park and records none unless given (confirm_exit still requires it); - pd_release_scope does not wait on such an attempt; - pd_finalize does not require one. Provider checks still apply to derived jobs, and every other stage keeps its exit-proof and provider checks exactly: a database test parks a full-pipeline job without proof through the same functions. The down file restores the four added functions byte for byte; a test compares pg_get_functiondef of every public function after the down with a database at 000049 (two earlier restored bodies differ only in a local variable name and a comment word, and the test allows exactly those). The worker: no Journal, no recover, no confirm_exit; pq_fail without proof; an uncertain reply to the claim's COMMIT is settled by renewing the exact token with pq_heartbeat, and left to the reaper when that is not owned. The stored map's bytes, the derived key and admission, the route and the switches are unchanged. Tests on PostgreSQL 17: a worker vanishing after put, after seal and before finalize is retried by a second worker while the first's late put, seal and finalize are fenced and the repeat finalize is already_succeeded; a lost box and a restart on the same box; two workers racing; an abandoned committed claim; an uncertain claim committed and not; a spent budget and a permanent failure without proof; another stage still protected; the down file restores the functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds the independent review's test-only probes: a derived map under public moderation, a request naming the derived job itself (expected to fail until its provenance is fixed), the unchanged replies with no derived job, and the release chain through the real map worker to the route. The worker is built with the journal-free settings it now takes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y when derived reads are on The route found a run's derived map by matching its key against the conversation's job history, on every list and on every read of a run with no map of its own. It now computes the key as admission does, reads the one row of the job address table for it by primary key, then the job that row names by its (env, job id) index and its publication by the served pointer's primary key, with the scope strings passed in. A list of N runs is one statement of at most N such reads, bounded by the list's own bound. A new switch, POLIS_API_DELPHI_TOPIC_MAP_DERIVED_READS, off by default: off, the route makes no derived lookup of any kind and every reply is what it was before derived maps. A login that may not read the job address table finds no derived map (logged once per process) and keeps serving in-run maps; never a 500. A request naming the derived job itself is answered as the same request naming its source run: the run in the job header and the document, the derived job as maker, the run's selection; its source's address must name that very job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne, a few at a time, switched off The Delphi shadow's scheduler gains a backfill of derived topic maps, off by default (DELPHI_SHADOW_DERIVED_BACKFILL). Each cycle nothing pauses it and no full run is waiting or running, it reads one bounded range of the env's jobs of the conversations it looks at (the history index, from an in-memory cursor), finds the finished runs whose own batch holds the three stored inputs and no map, looks their derived keys up by the alias table's primary key, and asks the derived jobs' one admission call for at most DELPHI_SHADOW_DERIVED_PER_CYCLE of the rest, under its own daily cap (DELPHI_SHADOW_DERIVED_DAILY) and only while fewer than that many derived jobs are queued or running. Nothing is kept on the box: what was asked is the key's job in Postgres; a refusal is counted by its word and not asked again by the same process. Lines carry counts and closed words only; a whole pass with nothing owed logs that every stored run has a map or a recorded outcome, then rests (DELPHI_SHADOW_DERIVED_EVERY_SECONDS). The admission lives in polis-topic-map, which depends on this crate, so polis-delphi-shadow replaces itself with `polis-topic-map shadow-scheduler` (the same scheduler with the admitter) only when the switch is on. Off, nothing is read and every line is as before. No schema change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, and the migration's comments claim no durations From independent review, applied as delivered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
… map each use a database of their own From independent review, applied as delivered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…tion 000050 The report binds the sha256 of every numbered migration file. Migration 000050 was edited after the report was last generated (comment changes only), so the report check refused it as stale. Regenerated with server/bin/build-migration-report.py; only that one hash line changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d class Migration 000050 adds the stage delphi_derived and the worker class derived to the queue's closed lists, and a check that pairs them. The integration test pins each check's exact definition, so its two exact lists gain their new entries (with NOT VALID, as the migration adds them on purpose to avoid scanning existing rows), and the new pairing check pq_stage_derived is pinned exactly beside pq_stage_large. The expected strings are the ones PostgreSQL 17 prints after the migrations apply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… switched off A release can now carry derived topic map jobs with every switch off: - docker-compose.yml: a profile-gated delphi-derived-worker service (polis-topic-map derived-worker), the job queue's own login only, one CPU and a 1 GiB ceiling, the shadow's CPU weight and OOM score, a read-only root, no volume. No existing service names a derived key, so with them absent every existing service composes exactly as before. - docker-compose.derived.yml: the scheduler's backfill settings and the admission switch, added by the deploy hook only on the exact line DELPHI_SHADOW_DERIVED_BACKFILL=1 (with the shadow on). - after_install.sh: the worker starts on the Delphi box only on the exact line POLIS_JOBS_DERIVED_WORKER=1, after a read-back of its composed settings that refuses what cannot work (no queue login, TLS without a CA file, an env other than the shadow's, another login, a volume); it starts before the scheduler; with the backfill on and no worker started the scheduler's admission is composed off. Every Delphi deploy already removes a worker container left by an earlier one. - validate_service.sh: with the worker's line on, one line says whether it runs; it is optional work and never fails the deploy. Off, nothing. - delphi/Dockerfile: the image build checks that polis-topic-map carries both derived-worker and shadow-scheduler. - docs/configuration.md: Derived Topic Maps, the four switches in order, what each alone does, and the way back. Tests: the first deploy with no derived line on (or every derived line in a form that is not exactly on) makes exactly the calls it made before, for every role, with and without the shadow; the worker's start, refusals, start failure and removal; the backfill with and without a worker; the deploy check's report; the compose service and the hook's real jq program. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ling tests first Six database tests: three fail on purpose (refused asks are not bounded by the per-cycle limit; a stored derived map leaves the storage budget's total unchanged; admission switched off still reads sets at the full-run daily cap) and three pass (each pause reason holds the backfill, inventory paging over a large history, the scheduler entry as a process). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… its per-cycle limit DELPHI_SHADOW_DERIVED_PER_CYCLE counted only newly queued jobs, so a cycle whose asks were refused (or found a job already there) could call the admission for every candidate on its pages. Each call now spends an ask before it is made, whatever it answers; only a queued job spends the room for outstanding jobs and the day's room. The line gains `asked`. The daily cap now counts every derived job of the env created this UTC day, by any asker and for any conversation, instead of those of the conversations in the current sets, so a conversation leaving the sets no longer gives its jobs back to the day's room. A refused ask makes no job: it is bounded by the per-cycle limit, not the daily one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… nothing The scheduler checked the admission's switch only after the backfill's own pause read (the database signals) and, at the full runs' daily cap, after reading the roster and the current set, so a failed read logged `derived_unread` where `derived_held` `admission_off` was due. The switch is now checked first, before any read for the backfill. With either switch off the scheduler's other lines are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e budget A derived job's stored map left the scheduler's storage total unchanged, so the budget and the daily limit kept checking the full runs' bytes alone. With the backfill on, the scheduler now measures each terminal derived job of its env from the database by the same statement as a run (its attempts, then per attempt its result rows, families, embeddings and log lines, each with its indexes, plus the queue's own rows of the job), a few per cycle, and the storage pauses hold the full runs' bytes and the derived jobs' together; a derived job counts toward the day it completed. The derived bytes live in process memory only, never in the state file: a scheduler that starts lists the env's terminal derived jobs again (in completion order, looking back two minutes for completions that committed late) and admits nothing, full runs included, until it has measured them all, as it does for a fresh state file. To count nothing twice, the listing of a fresh state file leaves the env's derived jobs out while the backfill is on; with it off that listing is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…now are The settings say what the per-cycle and daily limits count and that the derived maps' bytes count against the storage budget; the module comment says the admission's switch is checked before any read; both say that the scheduler's own lines carry counts and closed words while the admission's line names the job ids, the env and the derived key's SHA-256. The process test's nested condition is collapsed, as clippy asks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From independent review, applied as delivered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
… allowlist From independent review, applied as delivered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
From independent review, applied as delivered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…ot a running total The derived jobs' bytes in the storage budget were measured job by job and held in process memory, so the total moved with the backfill switch's history (lost on, then off; doubled off, then on), a restart measured the whole history again twenty jobs a cycle while holding every full run, and a completion that committed late could be missed. Now one read-only statement sums what the env's terminal derived jobs have stored: 16 KiB of queue rows a job, each result family and log line exactly as a run's measure models them, and each result row modelled from its family's row count and wire length (above the row's real size). It is read at the first cycle and then every five minutes, whatever the admission switch; with the backfill off nothing is read. While no reading is known no derived job is asked for, and full runs are held to their own bytes. The fresh-state listing leaves this env's derived jobs out with the switch on or off, so they are never counted twice. Nothing is added to the state file. The review's switch, late commit and restart reproductions are tests; the restart case with 40,001 derived jobs reads them in one statement at the first cycle and holds no full run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts container is absent A release older than the first one that carries the derived worker cannot remove its container. The configuration docs say what must be done before such a downgrade, and the deploy check fails loudly if the worker is switched off and a container of it, running or stopped, is still present. From independent review, applied as delivered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…imes before failing With the derived worker off, the deploy check requires its container to be absent. The inventory call was tried once, so a momentary Docker error would fail the box's deploy. It is now tried three times, two seconds apart, and only after an error; a container found present still fails at once. Two tests cover the deploy check's filter for the report topic map's derived-reads switch. Proposed by one independent review, reviewed and delivered by another. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
…l runs' accounting is edge's again Two budgets that never mix. The full runs' storage accounting (ledger, state file, fresh-state listing, pauses, log lines, the graph's final checks) is what it is on edge, except that the fresh-state listing leaves out every job of kind 'derived' (`kind <> 'derived'`; kind is NOT NULL, so on a database without derived jobs the listing's rows and order are edge's). That listing and the scheduler's own runs are the only things that fill the ledger, so no derived job is ever measured, counted or logged as a run, whatever the switches were before. Derived maps get DELPHI_SHADOW_DERIVED_STORAGE_BYTES (default 1 GiB, 1 MiB..=1 TiB, refused at startup outside it), compared against one read-only reading of the database (the existing aggregate), made only with the backfill and the admission both on and only when an ask could follow, at most every five minutes. Over the budget, or with no reading (none yet, failed, timed out), no derived job is asked for; full runs are never held by it. The reading lives in the backfill's memory, never in the ledger. The estimate of a result row now counts the env's length (stored in the heap row and three index entries): a job that stored no map at the longest env was 344 bytes under before. It is stated as an estimate with its measured range, not a bound. The process log-parity test is ignored with the binary it needs named. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With admission off no derived storage reading is made; an older scheduler's saved ledger can hold a conservative excess that does not clear; the budget is per environment and read on a beat. Prose and comments only. From independent review, applied as delivered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
Generated by the repository's schema census tool on an empty PostgreSQL 17 built by the migrations: three widened checks and one new check on the job tables, all NOT VALID, and the migration inventory. Tables, columns and indexes are unchanged. No hand edits. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1
Contributor
Delphi Coverage Report
|
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.
Schema change: yes (migration
000050_add_derived_jobs.sql). Draft: not to be merged before the repository owner has read the migration.Observable changes
With every new setting absent, which is how a release carrying this deploys: none. Every existing Compose service renders byte for byte as before (measured on Compose v2.40.0 and v5.6.0, with a production-like env file and an empty one), and a deploy makes the calls it made before, plus one read-only container inventory on the Delphi box (tried up to three times).
At the deploy that applies the migration: three checks on two job tables are widened and one is added, all without reading existing rows; one admission function is added; and ten existing queue functions are replaced with bodies that differ only where the new stage, class and kind are named. No table, column or index is added (the regenerated schema census shows 108 tables, 770 columns and 209 indexes unchanged). Nothing on
conversations,votes,commentsorparticipantsis locked by it.What the four switches do, each off by default:
POLIS_JOBS_DERIVED_ADMISSION=1: a derived job can be admitted. A derived job reads a finished run's stored results and stores only what it adds. The first one is the topic map of a stored run, made from that run's stored UMAP positions, EVoC assignments and topic names. Embedding, UMAP, clustering and naming never run again. Asking for the same source run twice returns the same job, for good.POLIS_JOBS_DERIVED_WORKER=1: a small worker container on the Delphi box runs admitted derived jobs. It keeps nothing on the box: a job whose worker vanished is picked up again by any worker when its lease expires, and a late write from the old attempt is refused.DELPHI_SHADOW_DERIVED_BACKFILL=1: the shadow's scheduler finds every succeeded stored run that has no topic map and asks for its map job, a few per cycle, with a daily cap and a storage budget of its own, yielding to full runs.POLIS_API_DELPHI_TOPIC_MAP_DERIVED_READS=1: the report topic map route serves, for a run with no map of its own, the map a derived job made from it, and says which run it came from and which job made it. A run with its own map answers byte for byte as before.Participation path
Nothing on the vote, comment or next-comment path changes. The worker and the scheduler use the job system's own login and connections. The route gains no pool, lock or connection; a derived lookup is one read by primary key.
Downgrade
A release older than this one cannot remove the worker's container. The first deploy of this release must have every derived switch off; before deploying an older release, switch the worker off with this release, deploy, and confirm the container is absent (the deploy check fails loudly otherwise).
docs/configuration.mdhas the section.Tests and review
polis-topic-map from-runmakes from the same source (eight cases: both comment rules, replaced historical sources, fixtures of 154 and 3,948 comments).Not in this change
Turning anything on. The settings a deployment needs before each switch, and the checks to make first, are in
docs/configuration.md.🤖 Generated with Claude Code
https://claude.ai/code/session_01KvftUARCjBArGpuPBmjRZ1