mesh-delivery-gate: apply each event and call whole, one at a time, so no record loses its delivery time (issue 721) #749

Merged
mesh-tools merged 2 commits from fix/gate-records-race into main 2026-11-23 14:54:31 +00:00
Member

Fixes issue 721 note 11 (main.493 failed on TestAGateWholeTakesAMergeCallAndWatchesTheHeadsOverARealBus: Records.End read the in-memory record before the running event's outcome was stored, because mesh-sdk's stdio runs each event and call on its own goroutine).

  • Every event (take) and every tool call (applied, its answer marshalled under the lock) is applied under one unexported lock Holder.applying, taken before every other lock.
  • A bus-test guard fails any bus test whose gate process reports a data race under -race.
  • One unit test, TestWhatIsHeardWhileAnEventIsWrittenWaitsUntilItIsApplied, cites 721/AC1.

Quick or thorough: the quick fix (a lock around End and Outcome only) was not taken; one event's several writes would still interleave with another's. Thorough: one lock for every event and call.

Proof: TestAGateWhole -race -count=50 passed 50/50 with 0 races (trunk: 13 races in 30 runs); unit suite plain and -race, both vets, gofmt, 33 checks.

Bent rule (rules-are-weighed): playbook 08 asks the What exists today and Acceptance criteria notes older than the first commit; note 15 (14:51:52Z) came after cc1140ba (14:28Z) and before fe2bed92. The search was run and matches (reviewer, round 1 and 2); rewriting the branch would buy nothing.

Merged at once, without waiting for the pull request's check, by the operator's temporary rule until design 47 is delivered.

Reviewed-by: mesh-code-reviewer@shanks for lead-47@shanks at fe2bed92e6

Fixes issue 721 note 11 (main.493 failed on TestAGateWholeTakesAMergeCallAndWatchesTheHeadsOverARealBus: Records.End read the in-memory record before the running event's outcome was stored, because mesh-sdk's stdio runs each event and call on its own goroutine). - Every event (`take`) and every tool call (`applied`, its answer marshalled under the lock) is applied under one unexported lock `Holder.applying`, taken before every other lock. - A bus-test guard fails any bus test whose gate process reports a data race under -race. - One unit test, `TestWhatIsHeardWhileAnEventIsWrittenWaitsUntilItIsApplied`, cites 721/AC1. Quick or thorough: the quick fix (a lock around End and Outcome only) was not taken; one event's several writes would still interleave with another's. Thorough: one lock for every event and call. Proof: TestAGateWhole -race -count=50 passed 50/50 with 0 races (trunk: 13 races in 30 runs); unit suite plain and -race, both vets, gofmt, 33 checks. Bent rule (rules-are-weighed): playbook 08 asks the What exists today and Acceptance criteria notes older than the first commit; note 15 (14:51:52Z) came after cc1140ba (14:28Z) and before fe2bed92. The search was run and matches (reviewer, round 1 and 2); rewriting the branch would buy nothing. Merged at once, without waiting for the pull request's check, by the operator's temporary rule until design 47 is delivered. Reviewed-by: mesh-code-reviewer@shanks for lead-47@shanks at fe2bed92e68e3c3420556e5a42b52359a6d9e862
mesh-tools added 2 commits 2026-11-23 14:54:23 +00:00
The runtime hands each event and each tool call to a goroutine of its own (mesh-sdk stdio), and the gate
applied them to the same in-memory records with no lock: Records.Outcome writes the ledger and only then
memory, so a pipeline-wanted heard once a running's outcome was in the ledger ended the record before
memory held that running, and timesAtEnd found no running: the record ended with no delivery time and
no class (main.493's failure of TestAGateWhole...). The race detector names it: 9 reports in 30 runs on
main, the running's Records.Outcome (record.go:759) against pipeline-wanted's timesAtEnd (movers.go:67).

The fix, the thorough one for the kind (events and calls applied concurrently to one in-memory state):
- take applies every event under Holder.applying; the ledger write and the memory write of an entry
  happen under it, so whatever is heard after the write lands waits until memory holds it too.
- Holder.applied runs every tool call under the same lock and takes its answer (marshalled) under it,
  so a view of a kept record is never written out while the next event writes the record.
- The bus test's bundle log fails the test on a data race the bundle reports under -race, a guard for
  every bus test of the gate.
The quick fix, a lock around Records.End and Records.Outcome alone, was not taken: it leaves an event's
several writes (pipeline-ended, take-in) interleaved with another's and the calls reading half-written
records.

Test: TestWhatIsHeardWhileAnEventIsWrittenWaitsUntilItIsApplied hears pipeline-wanted, and calls show,
as the running's write lands; each of the three parts removed fails a row.

Fixes: issue 721 note 11
Builds: design 47 H2 §810
The review of cc1140ba found the new test cited no acceptance; issue 721's note 15 gives it 721/AC1.
The test's comment now names it. No code changes.

Fixes: issue 721 note 11
Acceptance: 721/AC1
Builds: design 47 H2 §810
mesh-tools merged commit 51a6ac3461 into main 2026-11-23 14:54:31 +00:00
mesh-tools deleted branch fix/gate-records-race 2026-11-23 14:54:31 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: novox/mesh-catalog#749