Repository navigation
Starts a child for every pass of a loop - #302
Merged
Merged
Conversation
A durable subchart inside a loop started only its first child. Every pass of the same <invoke> element asked for the one id Linkage.child_execution_id/3 derives, so the second pass adopted the first pass's finished child and the parent waited on it for good. A single child is now read for before it is created. The first pass keeps the old id. A child found there that has not ended is adopted, as before; one that has ended belongs to an earlier pass, and this pass creates its own under Linkage.child_execution_id/4, the old id plus "@" and Linkage.invocation/1 of its invoke effect (the parent's macrostep and round). Those counters are the same on a re-drive and differ on any later pass, so a re-drive of a pass adopts its child. The exit's cancel spares a later pass's child at or after its own counters, so a re-drive of a loop's exit and entry does not cancel the child it is about to adopt. Reading first also lets a re-drive on Postgres adopt its child, which the refused insert used to abort. Records the design as an ADR-0008 Amendment at proposed. A fan-out keeps its ids. Tests prove two passes and a re-drive on the in-memory adapter, on Postgres and on SQLite with the linkage columns on. Refs: sp-5pfj
Every pass of a loop shares the invoke id, and the parent's door read liveness by invoke id alone. So a duplicate answer of an earlier pass, delivered after the next pass started, was taken as the next pass's answer, and a later pass's child created by an interrupted drive could answer the pass before it. A single child's answer is now delivered only when that child is the current pass's: the newest of the invocation's children the parent's stored position could have started, read inside the parent's step. Any other is discarded, as an answer to an invocation that is no longer live is. A later pass's child that ended before its pass was re-driven is adopted and answers that pass from its record. The ADR-0008 Amendment states the routing decision and the cases exactly, the first pass's crash window included, whose cost is that the child's work runs twice. Refs: sp-5pfj
The rule that a later pass's child counts only while its macrostep is after the parent's stored one did not hold: macrostep numbers are reused after a lost drive, so once another event was persisted a stray child left by that drive counted, and the waited-on pass's genuine answer was discarded. A single child's answer now reaches the parent when the invoke id reads live and the child is the newest of the invocation's children. That is exact wherever a child's create commits with the parent's step, as on Postgres under AdapterLock, where a lost drive leaves no child behind. On a store where the two commit apart, a stray from a lost drive ranks newest; ruled by the operator, 2026-11-22, that is a named known limit of this release, and exact routing on every store needs the position to record each live invocation's counters, a later change. The ADR-0008 Amendment states the rule, where it is exact, the limit and the cases. Tests pin the limit on the in-memory adapter and show on Postgres that a lost drive leaves no child. Refs: sp-5pfj
The named limit of newest-child routing left out one consequence. On a store where a child's create and the parent's step commit apart, when no other step of the parent comes between a lost drive and the stray child's answer, that answer is taken for the waited-on pass, the step it drives re-uses the lost macrostep and round, and the next pass adopts the same stray and takes its answer again. One answer then satisfies both passes. The ADR-0008 Amendment, the changelog and two driver comments now say so, and a test pins it on the in-memory adapter. No behaviour changes: this is the known limit ruled by the operator, 2026-11-22. Refs: sp-5pfj
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.
What
A durable subchart inside a loop started only its first child. Every pass of the same
<invoke>element asked for the one idLinkage.child_execution_id/3derives, so the second pass found the first pass's finished child, took it for an at-least-once re-drive, adopted it, and the parent waited on it for good.This PR gives every pass a child of its own and keeps the re-drive adoption, and records the design as an Amendment to ADR-0008 at proposed. Ruled by the operator, 2026-11-22: the fix lives in statifier_persistence, with the record in the same PR as the code, and no statifier_blocks change.
How
Linkage.invocation/1(new) writes"<macrostep>.<round>"from the invoke effect the interpreter emitted. Both counters are in the parent's persisted position, so a re-drive of the step stamps the same token and any later pass a different one.child_execution_id/3's id, so a fresh single child outside a loop is stored under the id it always was. A later pass's child takesLinkage.child_execution_id/4(new): that id, then@, then the token.existing/2,create_child/6,first_child/2,later_pass/5indriver.ex). At the first id: nothing found creates there; a child of this parent and invocation that has not ended is adopted, as before; one that has ended belongs to an earlier pass, and the pass goes to its own id, where a child found is adopted (the token makes that exact). Rows written by 0.26.0 read by the same rule, so nothing is migrated.answer_parent/3or the automatic answer) is now delivered only when the invoke id reads live and the child is the newest of the invocation's children (current_pass?/3, read inside the parent's step): the first pass's child is the oldest, and later passes are ordered by token. Any other answer is discarded:answer_parent/3returns{:discarded, execution}, as it does for an invocation that is no longer live. A later pass's child that ended before its pass was re-driven is adopted by the re-drive, which delivers its recorded answer (adopt_later/2).AdapterLocka lost drive leaves no child behind, so every stored child is one the parent started. On a store where the two commit apart, such as the in-memory adapter, a lost drive can leave a later pass's child the parent never started. That child ranks newest, so the waited-on pass's answer is discarded until it ends, and its answer is then taken for that pass. When no other step of the parent comes between the lost drive and that answer, the step the answer drives re-uses the lost macrostep and round, so the next pass adopts the same child and takes its answer again: one answer satisfies both passes, and the waited-on pass's own answer is never taken. If it had already ended, the parent waits until the host delivers that child's answer again. Ruled by the operator, 2026-11-22: this is a named known limit of this release. Exact routing on every store needs the parent's persisted position to record each live invocation's counters, which is a later change outside this package.{:cancel_invoke, _}arm now spares a later pass's child whose token is at or after the cancel effect's own counters (started_before?/3), throughExecutions.cascade_cancel_where/4, which is@doc false.cascade_cancel/3is unchanged.in_failed_sql_transaction.start_child_at/6) is unchanged: same ids, same create-then-adopt order, same settlement.What a host sees, all in
changelog.d/sp-5pfj.md: two new functions (Added); more adapter calls in[:statifier_persistence, :adapter, :call](Changed): a:fetch_executionper single child start, which answers:execution_not_foundfor a fresh child, and a:list_executions_by_metadataper single child answer while the invocation is live; and three fixes (Fixed): the routing, the loop, and the Postgres re-drive.Provenance
Engineering choices made for this PR, each recorded in the Amendment:
linkage_columns: true.test/support/looping_subchart.ex. Its examples are library loan renewals.Direction check of the record text
Every claim in the Amendment about code that predates this change was read on
mainat46746e4, and each is cited by function and file. The code this change adds is cited by name only, with no SHA. The statifier facts (the effect's counters,generate_invoke_id/3,Position.to_binary/1,begin_macrostep/1) were read in the locked statifier 2.15.0. The reference embedder's id derivation was read in statifier_examples at44e6f4a.git diff origin/main -- docs/adr/shows zero removed lines.Tests
driver_subchart_loop_test.exs(in-memory): two passes in order, then the parent goes on; a re-drive of the second pass adopts its child; a loop left mid-pass twice cancels the first pass's child and then a later pass's; a duplicate answer of an earlier pass changes nothing; a later pass's child that ended before the re-drive answers the pass that adopts it; the known limit, pinned twice: with another persisted step after the lost drive (the first pass's answer is discarded, and the stray's answer is later taken for that pass while a fresh child starts the next), and with none (the stray's one answer satisfies both passes, and the parent ends inrenewed_allwith both children completed).driver_subchart_ecto_test.exs(Postgres,AdapterLock): two passes; a re-drive of the second pass; a single child's re-drive; the duplicate answer; the ended later-pass child. The two re-drive cases start from a stored state built by putting the parent's record back, because a lost drive cannot leave that state on this store.ecto/loop_lost_drive_test.exs(Postgres, live): a drive of the second pass inside a transaction that rolls back leaves no child behind, and the first pass's answer delivered again is taken.ecto/sqlite_migrations_test.exs(SQLite,linkage_columns: true): two passes; a re-drive of the second pass, driven by re-delivering the event the lost step processed.execution_linkage_test.exs: the two new functions.Each new test has a sabotage note above it. Every mutation in those notes was run and restored from a copy, and the restore was checked byte-equal.
Full
mix qualitywas green locally on the committed tree, with the gate lock and a machine slot held from that run through the commit: 1,494 tests, 95.7% coverage, credo and dialyzer clean.