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
2 Commits
Author SHA1 Message Date
jschoubben fe2bed92e6 mesh-delivery-gate: name the acceptance the race test holds (issue 721, 721/AC1)
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
2026-11-23 15:53:07 +01:00
jschoubben cc1140ba36 mesh-delivery-gate: apply each event and call whole, one at a time, so no record loses its delivery time
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
2026-11-23 15:28:11 +01:00