Prove a write by compare-and-set loses no update under contention, on a real bus (hq research 042)
mesh/delivery-group group feat/a-counter-by-compare-and-set checking: 0 of 2 member(s) ready
mesh/merge-gate pass: builds mesh-tools, node-tools → ace, g14, novox, shanks; no bus step; every machine composes with the change as it did without (4 of …
mesh/repo-check pass: THE CHANGE ALTERS ITS OWN CHECK (merge-check.sh): main's version judged it; the change's judges the pull requests after it merges; it…
mesh/delivery superseded: a newer head of the same pull request

The issues module will hand out numbers through mesh/state.create and update. Two writers incrementing one
counter a thousand times each through the module's bus now end at two thousand with every number handed out
once; a stale, zero or future revision is refused with the lost-write code and writes nothing; a deleted key
can be created again; and the lost-write code reaches a bundle wrapped or not, and no other refusal carries it.
Both runtime tests run in the check's bundleless list, so mesh/repo-check runs them.

Part of the issue tracker decision, hq research 042.
This commit is contained in:
jochen
2026-10-10 12:31:06 +02:00
parent 83c1994183
commit 1eaa1abbe9
3 changed files with 233 additions and 2 deletions
@@ -0,0 +1,30 @@
package launch
import (
"errors"
"fmt"
"testing"
)
type lostWrite struct{}
func (lostWrite) Error() string {
return "issues.numbers.issue: the key was written by another writer first"
}
func (lostWrite) ErrorCode() int { return CodeChanged }
// A lost compare-and-set is answered to a bundle with its own code, wrapped or not, and the SDK tells it by
// that code alone (mesh-sdk's stdio.CodeChanged); every other refusal is the general code, never that one.
func TestALostWriteIsAnsweredWithItsOwnCodeAndNothingElseIs(t *testing.T) {
if CodeChanged != -32010 {
t.Fatalf("the lost-write code is %d; mesh-sdk tells it by -32010", CodeChanged)
}
for _, err := range []error{lostWrite{}, fmt.Errorf("asked by issues: %w", lostWrite{})} {
if got := errorCode(err); got != CodeChanged {
t.Errorf("%v is answered %d", err, got)
}
}
if got := errorCode(errors.New("issues keeps no state numbers")); got == CodeChanged || got != -32000 {
t.Errorf("a plain refusal is answered %d", got)
}
}