Repository navigation
fix(go): a coalesced leader keeps a value returned with an error - #277
Conversation
Since the leader runs its work in a goroutine, it read its result as a follower and dropped a value that the loader returned together with an error. v0.27.0 and the uncoalesced path return both. The leader now returns the value with the error again; followers still get only the error.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #277 +/- ##
=======================================
Coverage 94.76% 94.77%
=======================================
Files 84 84
Lines 13168 13171 +3
Branches 805 805
=======================================
+ Hits 12479 12483 +4
+ Misses 623 622 -1
Partials 66 66
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
lan17
left a comment
There was a problem hiding this comment.
Agent: Review of head d5887b0 (one commit on main 22c1f50) in report mode. Lanes: correctness, tests, contracts, simplicity and holistic. The holistic lane made an independent pass first, then audited the findings. Concurrency, reliability, performance, security and architecture do not apply: the change is a 6-line return path that reads the settled flight after f.done. This is a comment review. It does not approve and does not request changes.
Verdict: no blocker, no high and no medium. 1 low test gap. The code meets the PR's goal. The correctness, contracts and simplicity lanes found no issue.
| ID | Severity | Tag | Location | Fix |
|---|---|---|---|---|
| R5-F1 | low | V | go/flight_lifetime_test.go:576 |
Add a leader-and-follower test: the leader gets (7, err) and the follower gets (0, err), for Policy{} and Policy{RequestLocal: true}. |
Tag V: we ran it or read the code at the head. R5-F1 has an inline comment.
What we checked:
TestCoalescedLeaderKeepsAValueReturnedWithAnErrorfails at22c1f50(leader = (0, partial result)) and passes atd5887b0.- With a gated loader that returns
(7, err)and a follower that joins before release, the head gives leader(7, err)and follower(0, err), for both process and request-local coalescing. This matchesgo/v0.27.0, where the leader ran the work inline and returned both values. - A request-local leader keeps the value only when its request also led the process flight. When it joins another request's process flight, it gets
(0, err), as a follower does. This also matches v0.27.0. - The caller's own cancellation still wins before the new branch. A timeout, a panic and a stale recovery are unchanged: zero value with the error, or the stale value with no error. An error result still fills no cache.
- Every
go/engine.gobeforeanchor informal/catalogs/mutations.jsonoccurs exactly once ingo/engine.goat the head.
Not re-run here: the replay and effects conformance tests (Node is not installed in our sandbox), the Mutations run (pending on the final head by design) and make check-go, formal-go and audit. We take those as reported.
— Levicus Connecto 🤖
| ctx, done := f.cache.Enable(context.Background()) | ||
| defer done() | ||
| failed := errors.New("partial result") | ||
| if v, err := f.get(ctx, func(context.Context) (int, error) { return 7, failed }); v != 7 || !errors.Is(err, failed) { |
There was a problem hiding this comment.
Agent: R5-F1 (low, V). No test checks that followers still get only the error.
This test makes one call, so it covers the leader only. The other tests with a loader error return a zero value, so they cannot tell a follower's (0, err) from (7, err). A mutant where followerResult also returns the value with the error passes every Go test that runs in our sandbox. The test below catches it (follower=(7, partial result)). The code at the head is correct: this test passes for both policies.
func TestCoalescedFollowerGetsOnlyTheErrorOfAValueWithAnError(t *testing.T) {
for _, policy := range []Policy{{}, {RequestLocal: true}} {
synctest.Test(t, func(t *testing.T) {
f := newLifetimeFixture(policy)
ctx, done := f.cache.Enable(context.Background())
defer done()
failed := errors.New("partial result")
release := make(chan struct{})
load := func(context.Context) (int, error) { <-release; return 7, failed }
type result struct {
v int
err error
}
leader, follower := make(chan result, 1), make(chan result, 1)
go func() { v, err := f.get(ctx, load); leader <- result{v, err} }()
synctest.Wait()
go func() { v, err := f.get(ctx, load); follower <- result{v, err} }()
synctest.Wait()
close(release)
l, fo := <-leader, <-follower
if l.v != 7 || !errors.Is(l.err, failed) || fo.v != 0 || !errors.Is(fo.err, failed) {
t.Fatalf("leader = (%d, %v), follower = (%d, %v); want (7, err) and (0, err)", l.v, l.err, fo.v, fo.err)
}
})
}
}Low, because followerResult does not change in this PR. The test guards the leader and follower split against a later change.
— Levicus Connecto 🤖
lan17
left a comment
There was a problem hiding this comment.
Agent: Rollout-safety review of head d5887b0 (report mode, comment only; the PR is a draft). Scope: the code commit only.
Verdict: no blocker. The change is safe to merge and to release. I found one low test gap and two gates that are not code defects.
Why it is safe
- The new branch runs only for the leader, only after its own context check, and only when the work failed (
go/engine.go:279-291). Followers still go throughfollowerResult(go/engine.go:292). - The value is the leader's own work result. The flight goroutine writes
f.valueandf.errfromcallSafely[T]beforeclose(f.done)(go/engine.go:260,:272). So the read is race-free, the type is alwaysT, and a panic gives the zero value. - Only a loader's own pair reaches this branch.
traversereturnsv, errfrom the source before any fill (go/engine.go:442-450). Timeouts, context errors and panics carry zero values. - I measured with a scratch test under
-race. With coalescing on: the leader gets(7, err), the follower gets(0, err), and the next call runs the source again with no remote write of 7. With coalescing off, both callers get(7, err). With request-local coalescing, the leader gets(7, err)and the follower(0, err). This matches v0.27.0, where the leader returnedvalue, errfrom its inline run. - No release exists after v0.27.0, so released callers see no change.
- Every Go
beforeanchor inmutations.jsonmatches the head exactly once (82), M20 included. - Local, Go 1.27.1,
-race: the new test fails at 22c1f50 ("leader = (0, partial result)") and passes at the head. The lifetime tests and./internal/testsuitepass with-count=3, and the nativego test -race .tests andgo vet ./...pass.
Findings
| ID | Severity | Tag | Where | Issue | Fix |
|---|---|---|---|---|---|
| T1 | low | V | go/flight_lifetime_test.go:570-579 |
The test pins only the leader. Nothing pins the PR's claim that followers get only the error, or that a value returned with an error is not cached. A mutant where followerResult also returns the value passes every native Go test. |
Add the follower test in the inline comment. It passes at the head with -race -count=3 and fails on that mutant ("follower = (7, partial result)"). |
| G1 | gate (CI) | V | CI run 43361613506, jobs typescript and python / native (3.14) |
Both jobs' tests passed, but the Codecov upload failed: "gpg: no valid OpenPGP data found", then "Could not verify signature". So the required test check is red on d5887b0. The rust job on #274 failed the same way in run 43324223350, so this failure repeats. |
Re-run: gh run rerun 43361613506 --failed. If it fails again, a separate tooling change can stop the Codecov upload from failing the job. |
| G2 | gate | V | formal/catalogs/mutations.json (M20) |
The PR edits the mutation catalog, so the Mutations tier must pass before the PR leaves draft. No formal-full.yaml run exists for this branch yet. The description already plans one on the final head. |
Run formal-full.yaml in mutations mode on the final head. |
Note: with request-local coalescing, a request whose work joins another request's process flight is a follower there, so its leader gets only the error. This matches the follower rule and needs no change.
— Levicus Connecto 🤖
| }) | ||
| } | ||
|
|
||
| func TestCoalescedLeaderKeepsAValueReturnedWithAnError(t *testing.T) { |
There was a problem hiding this comment.
Agent: T1 (low, V). This test pins only the leader. Suggested companion test: it pins that followers get only the error, and that a value returned with an error is not cached. It passes at d5887b0 with -race -count=3. It fails on a mutant where followerResult also returns the value ("follower = (7, partial result), want (0, partial result)"), and no native test catches that mutant today.
func TestCoalescedFollowerGetsOnlyTheErrorAndNothingIsCached(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
f := newLifetimeFixture(Policy{LocalTTL: time.Minute})
ctx, done := f.cache.Enable(context.Background())
defer done()
failed := errors.New("partial result")
gate := make(chan struct{})
load := func(context.Context) (int, error) { f.calls.Add(1); <-gate; return 7, failed }
leader := make(chan int, 1)
go func() { v, _ := f.get(ctx, load); leader <- v }()
synctest.Wait()
var fv int
follower := make(chan error, 1)
go func() { v, err := f.get(ctx, load); fv = v; follower <- err }()
synctest.Wait()
close(gate)
if v := <-leader; v != 7 {
t.Fatalf("leader value = %d, want 7", v)
}
if err := <-follower; fv != 0 || !errors.Is(err, failed) {
t.Fatalf("follower = (%d, %v), want (0, %v)", fv, err, failed)
}
if v, err := f.get(ctx, func(context.Context) (int, error) { f.calls.Add(1); return 9, nil }); v != 9 || err != nil || f.calls.Load() != 2 {
t.Fatalf("next call = (%d, %v) after %d source calls; want (9, nil) after 2: a value returned with an error is not cached", v, err, f.calls.Load())
}
})
}— Levicus Connecto 🤖
The leader test covered one caller. Followers of a value returned with an error still get only the error, and the value is not cached, for process and request-local coalescing.
Problem
A Go loader can return a value together with an error. Without coalescing,
GetOrLoadreturns both. With coalescing on, the caller that leads the flight now gets only the error: since the leader runs its work in a goroutine (#255), it reads the settled result the same way a follower does, andfollowerResultdrops the value when there is an error. v0.27.0 returned both to the leader. Reported in the Follow-ups of #274. The other item there, a dark-shadow fill after an invalidation, needs no change:futureBufferMs ≥ Dmaxcovers it, as it covers a normal refill, and TypeScript behaves the same.Change
Bug fix (restored behavior). After its wait, the leader returns the value that its work returned together with the error. Followers still get only the error, as in v0.27.0. A value of another type under the same key still gives the zero value. No design record and no docs change: the behavior returns to v0.27.0.
Mutant M20 is re-anchored to the new leader code with the same fault, and the
go/engine.gopins ingo-parity.jsonare re-pinned (the TypeScript mapping is unchanged: TypeScript throws and returns no value with an error).Ports
ResultValidation
Head:
df05cc6TestCoalescedLeaderKeepsAValueReturnedWithAnErroringo/flight_lifetime_test.go, for process and request-local coalescing: the leader gets(7, err), a follower gets(0, err), and the value is not cached. It fails at22c1f50(the leader gets(0, err)) and on a mutant where followers also get the value, and passes atdf05cc6(-race -count=3).d5887b0: no blocker; both asked for the follower test above, added indf05cc6.make check-go,make formal-generateandmake formal-goatd5887b0: pass (df05cc6changes only the test).make auditatdf05cc6: pass.go/flight_lifetime_test.gounder-race: pass.df05cc6: every check passes (a Codecov upload failure was re-run).formal-full.yamlinmutationsmode atdf05cc6: run 43485734239, pass, 37 of 37 jobs (replay in all four ports, symbolic lane, and the TypeScript, Go and Rust mutation campaigns).Not run: none.
Follow-ups
None.