Repository navigation
Promote edge to stable: Polis 2.46.0 - #3454
Merged
Merged
Conversation
…go and admitted again, publication is retried across polls, and a copied host identity no longer confirms a renewing attempt (#3452) * polis-jobs: a host-bound journal entry from another boot is confirmed only after its attempt's lease has expired The graph executor binds its retained journal to a host identity file. The binding is that file's contents, so a restored snapshot of the volume, or a copied or template-baked identity file, passes it on a second machine; the boot id then differs and the entry read as provably gone, so the copy recorded a live attempt's exit as confirmed while the original's child ran. Now, for a host-bound journal only, an entry written under another boot is confirmed once the database shows its attempt's lease over: while the attempt still holds the job, when its locked_until has passed by database time; once the job is no longer held by it, one whole lease after this daemon first read it so. A live original keeps renewing its lease, so it is never confirmed; an honest reboot waits at most one lease. Waiting entries are read again at the reaper cadence, before the reaper. The read is the existing pq_job_status together with the database clock, in one read-only statement; no SQL function or table changes. Daemons without a host binding (the full-pipeline shadow, the worker boxes) recover exactly as before. New graph_recovery reasons: another_boot_lease_live, another_boot_lease_expired. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * deploy: invalid graph executor settings refuse the graph executor only; the full-pipeline shadow still starts With DELPHI_SHADOW_GRAPH_ENABLED=1, the Delphi deploy checks the graph executor's composed settings (scripts/check-shadow-graph.py). A refusal used to stop both shadows, so a typo in an optional executor's setting also stopped the full-pipeline shadow. Now it refuses the executor alone: the full-pipeline shadow, whose own settings were read back first, starts as it would with the executor switched off. The message names what is not started. Nothing changes unless DELPHI_SHADOW_GRAPH_ENABLED=1 and the shadow are both selected. Two deploy-hook tests: valid settings start the executor before the shadow; invalid settings start the shadow without the executor. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * delphi shadow: an unclaimed graph is let go after ten minutes, publication is retried on later polls, and a held graph admission says why Three changes to the scheduler's graph path, which runs only for the conversations DELPHI_SHADOW_GRAPH_CONVERSATIONS lists (empty by default): - An admitted graph none of whose nodes is ever claimed (no graph executor running, unstartable, or refused at deploy) waited the whole job deadline (default four hours) per listed conversation, holding the full-pipeline shadow. After ten minutes with every node still queued and no attempt at all, its nodes are now cancelled with the existing fenced call, its scope is released by the existing reconciliation, it is counted failed, and the full pipeline goes on (graph_unclaimed). A graph any of whose nodes was claimed is waited for as before. - Publication of a finished graph was tried three times back to back, then counted failed. Now it is tried once per poll, up to three times, the count carried in the flight (in the state file, so a restart keeps it); a transient failure keeps the flight (graph_publish_retry). A given-up publication is counted failed once: recovery no longer takes the graph up again (which reset the count and counted the failure again every poll), and its snapshot is not remembered as seen, so a later build or change reconsiders the conversation and the same snapshot's admission answers with that graph, whose publication alone runs again. - While a deferred graph holds graph admission, the scheduler says so once, with the deferred graphs' ids (graph_admission_held, reason graph_deferred). With the list empty none of this runs and the state file is unchanged (the new fields are omitted when empty). The existing test of a transient publication failure now expects the retry on the next poll, as designed; its assertions on one success, two calls and one generation are kept. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * docs: the graph executor's recovery from another boot, its deploy refusal, an unclaimed graph and publication retries Describes, in the same-host graph executor section of the configuration docs, what the three preceding changes do and the lines they write, and that an older scheduler ignores the publication count and the given-up publications on a rollback. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * deploy: a refused graph executor starts the scheduler with its graph list blank, so no graph is admitted that nothing could claim With the graph executor switched on and its composed settings refused by the deploy check, the hook started the full-pipeline shadow with the scheduler's graph list as the environment document gave it. The scheduler then admitted each listed conversation's graph, which nothing could claim. Now the shadow's start is given one more Compose file, written by the hook (docker-compose.shadow-graph-off.yml), that composes the scheduler's DELPHI_SHADOW_GRAPH_CONVERSATIONS blank: the scheduler's existing off path, so it admits no graph for that deploy. The hook reads the composed list back first; should it not be blank, the shadow is not started at all, as when its own settings are refused. One line beginning "Error:" says which, naming the refused settings (the validator prints names only) and the list by key, never a value. The full-pipeline shadow starts as before. Nothing changes unless DELPHI_SHADOW_GRAPH_ENABLED=1 and the shadow are both selected and the executor is refused: the shadow's start otherwise runs the same command with the same files. Tests: the refused case starts the shadow with the file, reads the list back, writes one line and prints no value; a list that cannot be composed blank starts no shadow; the valid case writes no file; the read-back's jq program with the real jq. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * delphi shadow: a graph let go as unclaimed holds graph admission until the next build or an hour, doubling to a day, then its conversation is admitted again as a new graph A graph let go because nothing claimed it kept its snapshot remembered as seen, and the same snapshot's admission key answered with the cancelled graph, so an unchanged listed conversation was never admitted again, with no line saying so. Now, when a graph is let go as unclaimed (decided before its cancel, or found finished with every node cancelled and none ever claimed): - its conversation's snapshot is forgotten as seen and observed, and the graph is recorded per conversation in the scheduler state (graph_unclaimed), with the count of graphs let go in a row in that env; - no graph is admitted in that env until the next code version or the end of a hold of one hour, doubling with each let-go in a row up to a day, said once per hold (graph_admission_held, reason graph_unclaimed); - the next admission of that snapshot names the let-go graph in its key, so it is a new graph (and the same one again on a lost reply or a retried publication); every other admission keeps the key it always had; - a claim seen in that env resets the count (graph_unclaimed_cleared); - recovery no longer remembers as seen a snapshot whose graph had every node cancelled. The let-go line (graph_unclaimed) carries the reason, the count and the hold. The full-pipeline shadow goes on throughout; while held, the graph path makes no query. No SQL function, migration or Compose change. Tests, each seen failing on the previous code first: the let-go conversation is admitted again as a new graph after the hold, across a restart, with the full pipeline going on meanwhile; at the next build at once, with the hold doubling after a second let-go, and its given-up publication later found and only published; found cancelled or past the job deadline with no claim; a claim racing the cancel; the lines and their counts from the scheduler binary. And for the ten-minute rule: nothing is cancelled two seconds short of it; a graph whose claimed node was put back in the queue, and one with a node out of the queue and no attempt, are not let go; a re-admitted given-up publication leaves the given-up list and its nodes ran once. The held-admission test reads the scheduler's lines as they come instead of sleeping a fixed time. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * docs: a refused graph executor's blank list, the unclaimed hold and re-admission, the ten-minute constant, and what the copied-identity and publication-retry fixes do not cover The ten minutes are a constant, with what a slow box does. A refused executor starts the scheduler with its list blank. A graph let go as unclaimed holds admission for an hour, doubling to a day, or until the next code version, and its conversation is then admitted again as a new graph. Corrected: a copied identity still confirms an attempt whose original is alive but has stopped renewing for longer than a lease (writes stay fenced; the cost is a false exit record and the step computed twice); an honest reboot waits about one lease, up to a lease plus a reaper interval; a given-up publication is found and only published again only when the graph's specification is unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * delphi shadow: the admission-key comment no longer names the admission function The one-admitter check refuses any file outside the shared entry that names the SQL admission function; a comment added with the let-go key named it. Comment only. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs --------- Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…old and vote latency like for like (#3456) * polis-shadow: count what Logs Insights counts, and judge the copy's hold and vote latency like for like Logs Insights in the production account reads a condition on a field a line does not carry differently from the tests' evaluator: inside fields and stats, an `and` or `or` with an absent operand is absent, a sum with no value is left out of its row, and an empty string is no field. The evaluator now reads lines that way, and three counts it had hidden are fixed: - The stored comments read back. A would-serve line carries no `reason`, so `outcome = "would_serve" or reason = "strict_moderation"` counted only the strict hand-backs: 20 where 295 were read back. Named by `outcome` and `admitted` now, and the report withholds the read-back's judgement if a copy is ever handed back after admission for another reason. - A stored comment that differs. The same `or`, across fields a row that is not Node's own does not carry, so no row beside Node's 200 was not counted as a disagreement. Two counts that never overlap now. - The copies nginx answered itself. `n_copied = 0` is never true when the upstream status is empty, so a down shadow did not count against coverage. The logged copies less the copied ones now. Stop rule 2 judges an hour's p99 of the copy's hold only from 100 copies: below that the p99 is the hour's slowest copy, and one 20 ms copy in an hour of 41 stopped a week whose votes all agreed. Such hours are printed, not judged; every copy is still held to 60 ms, and the copies held above 10 ms in the window are counted beside the verdict. Stop rule 5 compares each hour's vote p99 with the median of the week before's hours of as many votes (20 to 99, 100 to 299, 300 to 999, 1,000 or more an hour), not with the same hour, which set quiet hours beside a surge. A band the week before has no hour in reads "no comparable baseline": neither a pass nor a stop. Votes slower at the same volume still stop. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * polis-shadow: judge a band from three hours and beside the same hour, judge quiet hours together, and count nothing by an unmeasured rule Rule 5, Node's vote p99. A band of the week before is a baseline only from three hours of it: the median of one hour is that hour, so one slow hour passed three busy hours at 500 ms where 142 ms is usual. A band with fewer has no comparable baseline, which is neither a pass nor a stop. Each hour is also set beside the same hour a week earlier when neither hour had more than twice the other's votes, and breaches on either: the band alone hid a rise at equal volume in an hour usually faster than its band. Quiet hours are still never set beside surge hours (ten times their votes). On the recorded week of 2026-11-12: 14 of 156 hours above, in no run longer than 2. Rule 2, the copy's hold. The hours of fewer than 100 copies are judged together: more than 1 % of their copies held above 10 ms is a p99 above 10 ms, and from 100 copies between them it stops. A shadow adding 30 ms to every vote in hours of 50 copies stops, and so does one holding every comment 50 ms. Rows that do not count those copies are not read. The copies nginx answered itself are the copies logged, less those with its status 204, less the copied ones: no count of a field other than `message` is tested against 0. The tests' evaluator reads each of the three rules of Logs Insights that no probe has measured (`false and <absent>`, `false or <absent>`, a sum of false and absent values) either way, chosen by POLIS_SHADOW_READING for a run; the suite passes under all eight readings, and one test requires every query of both routes to count the same under each. The test helper for Node's vote lines names the week it writes instead of taking a signed offset. Expectations that changed: the six golden vote reports, in the stop rule section only (rule 5's lines and the hours of fewer than 100 copies together); in the `classes` and `small` fixtures, and in two tests that add one hour of votes, the stop rule now reads "not evaluated" where it read "pass", because one hour of as many votes the week before is too few for a band's baseline. No verdict of a golden report changed. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs --------- Co-authored-by: Claude <noreply@anthropic.com>
…og line, a cancelled graph holds nothing, a lost let-go record is read back, and a check that runs the recovery proofs (#3457) * delphi-shadow: a graph found cancelled after a claim, with no record of its let-go, says so in an Error line and is admitted again under the hold A graph the scheduler lets go as unclaimed can lose its cancel's race with an executor's claim: the cancel wins, and the graph ends with every node cancelled and an attempt on record. If the scheduler's state file is then lost, the conversation's unchanged snapshot is admitted under its old key, answered with that cancelled graph, counted failed and remembered as seen: skipped until the snapshot changes, with no line saying so. Before building the admission key, the scheduler now reads the snapshot's newest graph whose every node is cancelled (one read on its read connection, ids only). When that graph was claimed and the record does not name it, it is let go under the same hold as a graph nothing claimed (graph_unclaimed, reason cancelled_after_claim), so the conversation is admitted again as a new graph when the hold ends or at the next code version; and the scheduler writes one line on standard error beginning "Error:" that names the graph, the conversation by its code in DELPHI_SHADOW_GRAPH_CONVERSATIONS (which may list only public conversations), the reason, the count and the hold. Only with the graph list set; with it empty no new statement runs. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * delphi-shadow: a let-go chain the scheduler's record lost is read from the database in one step The admission key of a let-go snapshot names the last graph let go, and the scheduler kept that graph only in its state file: one per conversation, at most 256 per env. When the record no longer named it (the state file lost, the conversation's entry dropped from the 256, or a snapshot that changed, was let go and came back), each cancelled graph of the chain was answered again and let go again, the env held once per link (one, three, seven, fifteen, thirty-one hours, then a day each) without the executor being given anything to claim. The same read the previous commit added (the snapshot's newest graph with every node cancelled) now also serves this case: a never-claimed graph there that the record does not name is the chain's end; the scheduler remembers it (graph_let_go_recovered) and the admission names it in its key, so it is a new graph at once. With no record of the env at all (a lost state file) the count of let-gos in a row is read from the database as well (the env's newest graphs, at most 32, while each had every node cancelled and none claimed), and no hold is in force until the next let-go, as after a new code version, because the build that let the last one go is not known; the hold after the next let-go follows the true count. The record's bound moves into one method of its own. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * docs: a let-go hold ends at a deploy of a new commit only; what resets the count The configuration document said the next deploy with valid settings admits graphs again, and the comment on the hold constants said a let-go conversation is admitted again "at the next deploy at once". The hold ends when DELPHI_SHADOW_CODE_VERSION changes, which the deploy hook sets to the deployed commit: a deploy of the same commit (the usual way a setting is corrected) waits the hold out, as does a restart. Both now say so. The document also said a claim on a graph admitted after the let-go resets the count; a claim seen on any graph the scheduler watches in the env resets it, the let-go graph itself included when an executor's claim lands before its cancel, and nothing else does (a new code version ends a hold but keeps the count). The comment on that reset said the same thing wrongly and is corrected with it. The document also describes the two previous commits: the let-go chain read from the database when the record does not name it, and the Error line for a graph found cancelled after a claim. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * delphi-shadow: tests for five conditions of the job graph that no test held Each of these could be removed with every test still passing: - a count of zero holds nothing: an executor's claim that beats the cancel of the let-go graph itself resets the count, and the next graph is admitted at once, though the let-go was a moment ago (the race is made real in the disposable database: the cancel's own call claims the node first); - the admission key names only the let-go graph of the same snapshot: a snapshot that comes back, after another snapshot of the conversation was let go, is answered with its own finished graph and nothing is computed again; - a graph cancelled after a claim while the scheduler watches it (here, by a person while its first node runs) is counted failed, not let go, and its snapshot stays seen; - the record of let-go conversations keeps 256 per env and never drops the one being let go (a unit test of the bound); - the deploy hook does not start the shadow when the read-back of the scheduler's composed graph list itself fails (Compose cannot render it, or jq cannot read it), as when the list is not composed blank. Tests only; the hook is unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * delphi-shadow: two recovery tests of the job graph that no test held - An admission error after the graph admission committed (the read that follows it fails once): no full-pipeline run is admitted in that cycle, the graph is taken up as the flight, and it is watched to its end. Removing the recovery after the error fails it. - A restart from a state file holding only the graph env, written before the first admission, with the graph list emptied: the graph is found and the full pipeline kept off its conversation until it ends. Not writing the env before the admission, or recovering only in the configured env, fails it. The third the earlier review asked for (no second graph while one is deferred) is held by an existing test, a_held_graph_admission_says_so_once_with_its_reason. Tests only. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * make check-shadow-graph-recovery: one entry point for the job graph's two Docker recovery proofs delphi/tests/shadow/graph_recovery.py (the graph executor killed mid-node, then its container replaced, the same container restarted, or its journal lost; a second daemon on one journal refused; no exit proof invented) and graph_scheduler_limits.py (the scheduler stopped with a graph in flight and restarted with the list cleared, under its deployed 256 MiB and quarter-CPU limits) were in the repository with nothing that ran them. ci/local/shadow-graph-recovery.sh runs both, each against its own database on one owned PostgreSQL 17 container with every migration applied and checked by polis-migrate, building the Delphi test image unless SHADOW_GRAPH_RECOVERY_IMAGE names one. Results go to a new run-<time> directory inside .ci-out/<project>, so the check can be run again with the same project; the container and any image it built are removed. A row and a paragraph in docs/local-checks.md. No hosted job runs it yet. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * docs: one small machine, with the graph stages' measured memory The configuration document named only the graph executor's memory ceiling. It now names both ceilings (DELPHI_SHADOW_CONTAINER_MEMORY for the full-pipeline daemon, DELPHI_SHADOW_GRAPH_CONTAINER_MEMORY for the graph executor) and the scheduler's, says the executor is optional and how to leave it off, and says what macOS needs for its host identity (DELPHI_SHADOW_GRAPH_HOST_ID_FILE). It gives the measured peak resident memory of each graph stage on the public biodiversity conversation (316 comments) and the conditions, from which a 3 GiB executor ceiling is measured to hold a conversation of that size; the full-pipeline daemon's peak was not measured and the document says so. delphi/tests/shadow/graph_stage_memory.py makes the measurement: each stage in a fresh container of a Delphi image under the executor's limits, through the stage adapter, on the previous stage's output; no vote is read. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * delphi-shadow: a graph cancelled after a claim is one Error line naming its list position, never a code; counted failed, not retried, no hold The Error line named a listed conversation by its code. A code is the conversation's address, and the scheduler's standard output and standard error go to the same log. The line now names the graph and the conversation's position in DELPHI_SHADOW_GRAPH_CONVERSATIONS ("entry 2"), as the list's parser names an entry it refuses. Every test of the Delphi shadow now ends by checking every line its scheduler wrote (in the test process, kept by the scheduler's two line writers for the thread that wrote them, and in every scheduler process the test started) for every conversation code the test created. A graph cancelled after an executor claimed it follows one rule, whether the scheduler watched it to its end or finds it in the database after a lost state file or a returning snapshot: one Error line, counted failed, its snapshot not admitted again until it changes, and no hold of the graph env. Such a graph is one whose claimed node was then cancelled, or a let-go graph whose cancel raced a claim, including one whose claimed node then ended before the next poll. No hold, because the hold exists for a graph nobody claimed and a claim proves an executor exists, and one conversation must not hold up every other listed one; no retry, because a person's cancel should stand and a graph cancelled at the job deadline would most likely overrun it again. A claim on record at a watched graph's end resets the count of let-gos in a row, and the let-go record drops the graph. Recovery's read of the snapshots that ran fills only what the state does not hold, so a cancelled snapshot is not said again at the next code version. The comment that a let-go graph always ends fully cancelled is corrected. Three tests change their expectation because of the rule: the claim that races the let-go, the claim that beats the cancel of the let-go graph, and the let-go whose cancel raced a claim before a lost state file. New tests: the person's cancel then a lost state file (the unrelated conversation is admitted in the same cycle), the claim that beats the cancel and whose node then dies, said once though an older snapshot ran, a claim ending the database's count, and the let-go record's bound for a conversation whose id sorts first. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * docs: a graph cancelled after a claim, the Error line's list position, Docker Desktop's machine id, and only what was measured The configuration page describes the one rule for a graph cancelled after a claim and the Error line that names a list position, never a code; what resets the count of let-gos in a row; that only Docker Desktop on macOS lacks /etc/machine-id for the executor (under Colima the bind resolves inside its Linux VM); and, for memory, only what was measured: each graph stage's peak resident memory, run alone, on 316 public comments under 2 CPUs (2.24 GiB, 0.85 GiB, 0.18 GiB, 23 MiB). The full-pipeline daemon was not measured. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * delphi-shadow: a let-go whose cancel raced an executor's claim is admitted again at once, not skipped When the scheduler let a graph go as unclaimed, watched it to its end, and an executor's claim raced the cancel, the cancel was the scheduler's own and the claim proves an executor exists. Neither reason for not retrying a graph cancelled after a claim (a person's cancel should stand; a deadline overrun would overrun again) applies, and not retrying skipped an unchanged listed conversation for good. Now the let-go record keeps the graph and the snapshot is not remembered as seen: the next admission is a new graph at once, with no hold, and one graph_let_go_raced line says so with the graph id and the conversation's position in the list, never its code. If the claimed node died before the next poll, it is an ordinary failure, as for any graph. When the claimed node ran, the let-go graph is not the snapshot's newest fully cancelled graph, so the chain-end read now also says whether the record's graph is newer, and the key names it; and recovery does not remember a snapshot the let-go record names as seen. The case found only in the database (that race, then a lost state file) cannot be told from a person's cancel, and keeps the one rule: one Error line, counted failed, not admitted again until its snapshot changes, no hold. A person's cancel of a watched graph and a deadline overrun are unchanged. Tests: the claim racing the let-go is again admitted again, now at once; the claim that beats the cancel is admitted again at once; the race then a lost state file is one Error line and not retried; a claimed node that died is an ordinary failure; a claimed node that succeeded is admitted again at once, though an older let-go of the same snapshot exists. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs --------- Co-authored-by: Claude <noreply@anthropic.com>
…ervation in flight, and answers a request head it cannot parse (#3455) * polis-api: on SIGTERM a dispatched vote commits and is answered, an undispatched one is handed back, and the process exits inside the stop window What changes for someone stopping the process (docker stop, docker compose down, the web deploy's teardown): - polis-api handled SIGINT only. As PID 1 in its container it ignored SIGTERM, so every stop waited the full 10 s and ended in SIGKILL (exit 137); outside a container SIGTERM killed it at once. Either way a vote inside its transaction got no answer. - Now SIGTERM and SIGINT are handled alike, installed before any startup work. The main role stops accepting connections, serves the connections the kernel had already completed, and waits until no request is being read or answered, no dispatched write is running and no notification is queued, at most 5 s. A vote, comment or wave write not yet dispatched when the stop begins is not dispatched: it is answered with the marked 502 hand-back nginx sends to Node. Blocking work still running afterwards is waited for at most 0.5 s, so a stop ends within about 5.5 s, inside Compose's 10 s. Two lines say what happened: polis_api_stopping (the signal) and polis_api_stopped (whether it drained, how long, what it left, and how many writes it handed back). - The shadow role stops at once on SIGTERM or SIGINT (it writes nothing) and prints shadow_stopping. - Nothing changes for any request while the process is not stopping: no new lock, pool, query or wait on a request; the wait reads counters and holds no database connection. Tests, written first and failing on the previous code (SIGTERM ended the process with no answer and no exit status), run the real binary against its own database (tests/stopping.rs): a vote held inside its transaction at SIGTERM commits and is answered while a vote still arriving is handed back and not written, and the process exits zero before its bound; a committed vote whose next-statement selection cannot finish is answered at its deadline, and the process waits the bound and exits zero in about 5.5 s; and both roles exit zero at once when idle. One existing test reads main.rs as text up to the `#[tokio::main]` attribute, which main no longer carries (it now builds the runtime itself so that blocking work is waited for at most 0.5 s at exit). Its anchor is now the start of `fn main`: the same span of source, the same keys. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * polis-api: a request head it cannot parse is answered with the marked 502 hand-back, never dropped, so a vote with such a head reaches Node What a participant would observe once POST /api/v3/votes is routed to polis-api: a vote whose request head polis-api could not parse was dropped with no answer, so nginx answered its own 502 and the vote was never recorded, where Node records it today. Two such heads reach polis-api through nginx: a header value that is not UTF-8 (a byte above 127) and more than 128 header lines; Node accepts both. Now the main listener answers every head it cannot parse with a 502 and closes the connection. On POST /api/v3/votes it carries the same X-Polis-Vote-Dispatch: not-started marker as the parser's other hand-backs (chunked and oversized bodies), and on POST /api/v3/comments the comment marker, so nginx's vote location gives the whole request to Node, which reads it with its own parser. Nothing is dispatched: no body is decoded and no handler runs. Any other path gets the 502 unmarked, which a read location's fallback sends to Node, as the dropped connection did. This covers every way a head fails in the parser: a value that is not UTF-8, more than 128 header lines, a control byte in a value, a header name that is not a token, a Content-Length that is not a number or two that differ, an unknown HTTP version, and a head longer than 1 MB. The log line for the refusal is unchanged. The shadow listener is unchanged: it still answers nothing and counts the refusal. A request whose head parses gets exactly what it got before. Tests in http.rs, written first and failing on the previous code (the reply was empty): every such head on the vote path gets the same bytes as the chunked-vote hand-back, and the handler never runs; on the comment path the comment marker; on any other path an unmarked 502 with Connection: close. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * polis-api: on SIGTERM the shadow waits for the observations in flight, and prints a stopped line for each one still in flight at its bound The shadow role exited as soon as SIGTERM arrived, so every deploy lost the observation line of each copy still being observed: a vote or comment copy prints its line only after its read-back of what Node stored, 2 s after the copy arrived, or 10 s after when Node's row is not there at the first look. Inside its container the old process ignored SIGTERM as PID 1 and the ten seconds before SIGKILL printed them; the change before this one lost them, the rarest class most of all, and counted nothing. Now, on SIGTERM or SIGINT, the shadow stops accepting copies and waits at most 7.5 s (shadow_stop.rs) for the observations it has begun. Each prints its own line as before. At the bound, each observation still in flight gets one line of its route, every key in its order, with outcome "stopped" and where it was in reason (in_handler, before_readback, before_retry), carrying nothing the observation had found: no would-be answer, admission, conversation, duration or read-back, as on a shed line. Then one shadow_stopped line gives the counts: kept, stopped by where, and connections still being read. Exactly one line per copy: the observation's own or its stopped line, whichever claims it first. A copy registered after the stop has printed its lines gets its stopped line at once. The window is Compose's default stop_grace_period, 10 s, which none of the three polis-api services changes, and the web deploy's teardown (--profile rust-api down) gives no other. 7.5 s leaves 2.5 s for the runtime's half second, the lines and a quarter CPU's scheduling. It keeps every copy whose Node row is there at the first look, and of those waiting for the second look the ones that arrived at least 2.5 s before the stop: three in four with copies arriving evenly. The wait holds no database connection: it reads two counters every 10 ms. A read-back marks the wait for its second look through a task-local; outside an observation it does nothing. A copy that completes normally prints the same line as before, byte for byte. Tests, written first against the previous binary (no line was printed for any copy in flight at SIGTERM): with the real binary, three votes and two comments read back at 2 s are all printed and the process exits about 1.5 s after the signal; a vote and a comment that arrived 3 s before the signal are kept at their 10 s look, and two votes and a comment that arrived 0.5 s before get stopped lines at the bound, exit zero inside the window. Unit tests of the registry (one line per copy under racing threads), the drain, and each route's stopped line against its line contract. Also the independent review's test that every connection queued in the kernel's backlog at SIGTERM is answered. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * polis-shadow: a stopped observation is counted in a bucket of its own, never as observed, covered or judged The shadow now prints a line with outcome "stopped" for a copy it was still observing when it was stopped, past its bound. The comparison tool read an outcome it did not know as nothing in the vote report (absent from the outcomes, yet counted as covered in the join) and as an unrecognised word in the comment report, which withholds the verdict. Now, for both routes: the join counts stopped copies on their own (stopped) and no longer as covered, so such a copy counts against coverage as a lost line would; no would-serve, hand-back, failure, admitted, read-back, pairing or disagreement class includes it. The vote report prints the stopped count and where they were when there are any; the comment route knows the word and its three reasons and prints them with the other outcomes. Reports over logs with no stopped line are unchanged, byte for byte (the six vote reports pinned as fixtures). Tests: the passing week with three stopped vote copies added, and the passing comment fixture with two, keep every criterion's mark and the verdict; the join's stopped count is the added copies and every other class is unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * polis-api: Treevite acceptances and topic-selection writes are counted by the stop, and the stop's tests each hold a stop of their own Two writers, both switched off in production and routed to polis-api by no nginx location, spawned their write as a detached task that the drain did not count: a Treevite acceptance or login (treevite_write.rs) and a topic selection's mutation (topic_selection_writes.rs). After their reply deadline (1 s and 1.1 s) such a write ran on with nothing to wait for it at a stop. Both now take the stop's count just before the spawn and hold it in the task, as votes, comments and waves do. A stopping process dispatches neither: the Treevite route answers 503 (polis_err_treevite_unavailable), its answer when it cannot take a dispatch; the topic-selection route answers 502, its answer before every mutation. Nothing is written either way. The wave route's stop answer is a 502 without the vote writer's hand-back marker, like its other answers before dispatch: no nginx location sends a wave POST to polis-api (the treeviteWaves location routes only GET and HEAD without a body), so a marker would be read by nothing. The commit that added the stop said otherwise; the code says so now. The stop is now a value: the process holds one, and a test holds its own (Stop::for_test, scoped), so a test can stop without handing back the writes of the other tests in its process. With it, the independent review's forced-interleaving tests run in the ordinary suite: a dispatch paused between its count and its read of the stop (the drain waits, the request is handed back), the other order (the drain waits for the dispatch), the swapped order as a mutant the harness detects, and a stress race (200 rounds of 4 threads by default; RACE_ROUNDS and RACE_THREADS raise it). And the review's test of the accept loop's sweep: every connection queued when the stop comes is answered, and one after it is refused. Nothing the process does changes. Tests, written first: against the handlers without this change, a stopping process accepted the invite (201, a participant written) and mutated the selection (200); now 503 and 502 and nothing written, and a dispatched acceptance is counted past its 202 until it commits, a dispatched mutation while it runs. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * polis-shadow: the stopped bucket counts without depending on how absent values are summed After the merge with the tool's corrected test evaluator, the stopped counts are taken from fields every line carries, the row helper refuses an unknown count name, and stale count names in the tests are renamed. No assertion is weakened. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs --------- Co-authored-by: Claude <noreply@anthropic.com>
…rmission can be recorded in Postgres, one new table, switched off (#3451) * migration 000048: one new table, delphi_entitlements, recording which accounts may use Polis 2 (not yet read) One table and nothing else: no existing table, column, index, constraint, function, trigger, rule or grant changes, and the file creates no function, trigger or rule. delphi_entitlements uid integer primary key, references users(uid) on delete cascade granted_at bigint not null, default now_as_millis() granted_by integer, references users(uid) on delete set null source text not null, check in ('auth0_role', 'site_admin') Nothing reads or writes it in this commit. The server reads it only under a setting that is off by default, added in the next commit. Locks, measured on PostgreSQL 17.11: the two foreign keys take SHARE ROW EXCLUSIVE on users until commit, 3 ms median and 6 ms at most over 20 runs. While it is held, reads of users, inserts into participants and writes to conversations went on without waiting; inserts and updates of users (a new anonymous participant's account, a first sign-in) waited for the commit. Beside an open transaction writing users the file waits its 5 s lock_timeout and fails with nothing changed, once, at the deploy. Nothing on the vote, comment or next-comment path reads the table. Declared additive (compat.txt, with its evidence in docs/migrations.md); listed in release.txt; the forward proof's additive ledger and the first-deploy report's release list include it, and the report is regenerated. The reversal, down/000048_drop_delphi_entitlements.sql, refuses while any row is stored; dropping the foreign keys takes ACCESS EXCLUSIVE on users until commit (milliseconds, 5 s at most). The coordinator schema census follows the new table: catalog.json measured by coordinator-rs/tools/schema_census.py on a fresh PostgreSQL 17.11 (the new table, its index and four constraints, and the file's checksum); the row type and table entry in rows.rs; 770 columns (was 766) in the census test, the mapping example and the README. The characterization schema catalog (server/characterization/catalog.json, read only when recording) is refreshed in its own change, as the recording rules require. Test: an integration test against the migrated test database checks the four columns, types, nullability and default; no trigger and no rule; a grant from each source; one row per account; a source outside the closed set, a missing source or time, and an absent account or granter refused; deleting an account deletes its row, deleting its granter keeps the row and clears granted_by. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * server: one function decides whether an account may use Polis 2, behind POLIS_DELPHI_ENTITLEMENT (default claim: unchanged); GET /api/v3/delphi/me answers it isDelphiEntitled (server/src/routes/delphi/entitlement.ts) answers whether an account may use Polis 2. The four routes that start Delphi work ask it first, in place of reading req.p.delphiEnabled themselves: POST /api/v3/delphi/jobs (routes/delphi/jobs.ts) POST /api/v3/delphi/batchReports (routes/delphi/batchReports.ts) POST /api/v3/collectiveStatement (routes/collectiveStatement.ts) GET /api/v3/reportNarrative (routes/reportNarrative.ts) and then apply the conversation-owner rule (generationOwner.ts) exactly as before. A refusal is the reply each route already gave a caller without the claim, byte for byte. POLIS_DELPHI_ENTITLEMENT (config.ts, delphiEntitlement) says where the answer comes from: - claim (unset or blank: the default): the token's delphi_enabled claim, as these routes always read it. The database is never read for this. - claim_or_db: the claim, or else a row for the account in delphi_entitlements (migration 000048). - db: a row only. Any other value stops the server at startup. Under claim_or_db and db the read is one SELECT by primary key (SELECT 1 FROM delphi_entitlements WHERE uid = ($1);) on the ordinary read-write pool, on these routes only; it holds its connection for that statement and nothing else. These routes never run in participation scope, so votes, comments and the next comment never make it and cannot wait on it. A failed read answers through each route's existing error reply and nothing starts. New route: GET /api/v3/delphi/me, signed-in callers only (hybridAuth: 401 without a token, as every such route), answers {"delphi_entitled": true|false} through the same function. Its path is made of words the client error reporters already know, so no client copy changes; no nginx Rust selector matches it (the /api/v3/delphi selectors are exact paths, and the one pattern is /api/v3/delphi/runs/<id>). The route census gains it (id 211). Not moved: the vote CSV import, POST /api/v3/votes-bulk (routes/votes.ts), still reads req.p.delphiEnabled directly under every value of the setting. A change to that handler is proposed separately. Documented in docs/configuration.md ("Polis 2 permission") and example.env. Tests (written first; on edge the new suites fail and the import's passes): - unit, delphiEntitlement.test.ts: the function under each value (no read of any kind under claim, whatever the claim; one read by primary key on the read-write pool otherwise; no read for an account number that is not one; a failed read throws; an unknown value answers as claim); the four routes under each value (under claim, the owner with the claim proceeds after only the owner read, and an account with a row but no claim gets today's refusal with nothing read; under claim_or_db and db, a row admits its owner and does not reach another's conversation, the claim alone is refused under db, a failed read starts nothing); the new route under each value. - unit, delphiEntitlementSetting.test.ts: blank and unset are claim; the three values are taken as written; anything else stops the server. - unit, votesBulkEntitlementUnchanged.test.ts: under every value the import refuses an account without the claim and admits a claim holder to its owner check, reading no entitlement. - integration, delphi-entitlement.test.ts, against the real stack: 401 without a token; under claim the claim decides and a row is ignored; under claim_or_db either one; under db the row decides, and an owner with a row starts a pipeline run while the same owner without it gets today's 403. The existing tests of these routes (delphiGenerationOwner, votesBulkOwner, the generation-owner and claim integration tests) are unchanged and pass. - The collective-statement mutation check: the mutation that drops the permission check in collectiveStatement.ts now finds the new line (its text moved; the same five cases fail), and a new mutation, ENTITLEMENT-DEFAULT, makes the function's default answer yes for everyone and fails the same five cases. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * polis-auth: the OIDC profile no longer carries the Polis 2 permission claim Profile (queue-rs/polis-auth/src/oidc.rs) mapped the namespaced delphi_enabled claim as request metadata. Nothing read it: no polis-api route calls Profile, and the only callers are this crate's own tests. It is removed, so no Rust route can be written that reads the claim; whether an account may use Polis 2 is recorded by Polis (the delphi_entitlements table), and a Rust route that needs it reads it there. A token that carries the claim is mapped exactly as before, minus that field. Test (written first; it failed on the previous source, naming oidc.rs): no source file of polis-auth, and none of polis-api, contains the claim's name. The claim-fallback test still feeds the claim and no longer reads it back. The README says the claim is not mapped. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs * migration 000048: wait at most 200 ms for the lock on users, not the runner's 5 s, so no vote or comment is refused while it waits Creating delphi_entitlements takes SHARE ROW EXCLUSIVE on users (its two foreign keys). While the migration waits for that lock, behind a session holding a conflicting lock on users (a transaction that wrote users, or a vacuum of it), every new writer of users queues behind it. A signed-in account's first request creates its users row in a transaction that gives up on a lock after 500 ms (server/src/db/pg-query.ts) and is then answered HTTP 500, and that request can be a vote or a comment. With the runner's 5 s, such a first vote sent during the wait was refused. The file now sets lock_timeout to 200 ms. On a busy instant the migration gives up after about 0.2 s with nothing changed (no table, no history row), the deploy stops on that box before any service is replaced, and it is run again. Nobody waits longer than that and nobody is refused. The table and both foreign keys are unchanged. The reversal (down/000048_drop_delphi_entitlements.sql), which takes ACCESS EXCLUSIVE on users, gets the same bound; a refused down changes nothing. The file header and its declaration in docs/migrations.md now say what it locks, for how long and why 200 ms (they said nothing was refused), and that the foreign keys add PostgreSQL's internal referential triggers. The coordinator schema census follows the new bytes (the checksum, re-measured on a fresh PostgreSQL 17.11, and the declaration pointers, seven lines lower), as does the first-deploy report. Test: server/__tests__/participation-pg/delphi-entitlements-migration.pgtest.ts, run by scripts/test-delphi-result-reads.sh. An open transaction writes users; the real runner's deploy waits on it; while it waits, a signed-in account's first vote, two anonymous first votes and, once they have queued, an existing participant's vote run the middleware of POST /api/v3/votes in order (onParticipationPools, the token step, ensureParticipant, handle_POST_votes), with the participation pools at 3 connections. Without the file's own bound (the runner's 5 s) the signed-in first vote is answered 500 and not recorded. With 200 ms every vote is answered and recorded, the migration fails with nothing changed, and the next deploy applies it. The reversal, under the same bound, gives up with nothing changed beside a transaction reading users, and drops the empty table once it can. Run against the 5 s file, the released case and the reversal case failed; with 200 ms all three pass. Measured on PostgreSQL 17.11, 20 runs with each file: with 200 ms every vote was answered, the longest after 0.27 s; with 5 s the signed-in first vote was answered 500 in all 20, and the anonymous first votes waited 5 s. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KvftUAdasWzxmMYdioZJWs --------- Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Contributor
Author
Delphi Coverage Report
|
colinmegill
marked this pull request as ready for review
November 20, 2026 01:56
This branch was successfully 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.
Release plan
Version: 2.46.0
Reason: new selected migrations
Previous stable:
8289aae6781cfdcaa9d78f1b2fe5aa11af37dcc3Candidate:
a4fe4c7a3b2c73c78f12c7fe1e039f8b5794556crelease.txt additions:
000048_create_delphi_entitlements.sqlMerge the reviewed version preparation into edge, then refresh this plan for the resulting edge SHA before merging the promotion with a merge commit.