Skip to content

fix: stop counting a failed distributed operation as a success - #276

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/operation-success-accounting
Aug 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/operation-success-accounting

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

The three consistency executors each reported failure in OperationResult.Success and returned a
nil error. ClusterManager.DistributeOperation classified on the error — the ordinary thing to do
in Go — so an operation that failed on every node incremented SuccessfulOps.

The counters are what an operator reads to decide whether coordination is working. A cluster where
every operation fails while the success count climbs is worse than one with no metrics: it actively
argues against investigating.

The fix

ExecuteOperation now returns an error whenever the result is unsuccessful, carrying the result's
own failure text so the two representations cannot drift.

Reconciled at that one choke point rather than in each executor, because it is the single point
every consistency level passes through: a fourth level added later cannot reintroduce the
disagreement, and no executor has to remember to report one fact in two places. The contract is now
stated in doc.go — a failed operation is reported both ways, and checking either is sufficient.

The test gap in the same change

The -tags=distributed suite that surfaced this was asserting against a misconfiguration. It never
injected a backend, so executeLocally took its c.backend == nil arm and every operation failed
with no backend configured — which is how TestConcurrentOperations came to print both of these
in the same run:

Failed 10 out of 10 concurrent operations
Concurrent test completed - Total ops: 10, Successful: 10, Failed: 0

Those tests now use a real S3 backend against an in-process substrate endpoint, seed the keys they
read, and check the returned bytes rather than only the success flag. A real backend rather than a
mock, per the harness note in CLAUDE.md: a mock on the far side of this seam would agree with the
coordinator by construction, which is how the defect was missed.

TestClusterManager_DistributedOperation also executes a GET of an absent key, so the tagged suite
can now fail if the reconciliation is removed — the assertion its counters could not make while
every operation failed for the same reason.

Verification

Three mutations, each caught:

mutation caught by
reconciliation removed (the original defect) TestDistributeOperation_FailedOperationCountsAsFailed, TestDistributeOperation_ErrorAndSuccessNeverDisagree (3 failing subtests), and TestClusterManager_DistributedOperation under -tags=distributed
error returned unconditionally TestDistributeOperation_SucceededOperationCountsAsSuccessful, …NeverDisagree (3 passing subtests)
cause dropped from the error text TestDistributeOperation_FailedOperationCountsAsFailed

…ErrorAndSuccessNeverDisagree asserts the invariant itself — result.Success == (err != nil) must
be false — across all three consistency levels and both outcomes, rather than the two counters that
happen to read it today.

Gates: build, vet, gofmt clean; full -race suite green; coverage gate 35 packages at or above
floor with internal/distributed 73.4% → 73.9%; golangci-lint --new-from-merge-base=origin/main
0 issues; gosec unchanged (the two pre-existing G404 at consensus.go:856,859).

Two further defects found while fixing this

Filed as #275, not fixed here. Confirmed by probe rather than by reading:

  • A single-node cluster never elects a leader. startElection sets voteCount = 1 and the
    majority check lives only in handleVoteResponse, which is reached only when a peer replies.
    With one node there is no peer, so a node that has already satisfied the majority never evaluates
    it, and the term increments forever.
  • GetStats reports zero nodes for the first five seconds after Start, because nothing
    computes the statistics before updateStats' hardcoded ticker first fires — while GetNodes
    correctly reports one.

Both are why three tests in the -tags=distributed suite have been failing unobserved. No CI job
builds that tag (#240).

Closes #269

The three consistency executors each reported failure in OperationResult.Success
and returned a nil error. ClusterManager.DistributeOperation classified on the
error — the ordinary thing to do in Go — so an operation that failed on every node
incremented SuccessfulOps.

The counters are what an operator reads to decide whether coordination is working.
A cluster where every operation fails while the success count climbs is worse than
one with no metrics: it actively argues against investigating.

ExecuteOperation now returns an error whenever the result is unsuccessful, carrying
the result's own failure text so the two representations cannot drift. Reconciled at
that one choke point rather than in each executor, because it is the single point
every consistency level passes through: a fourth level added later cannot
reintroduce the disagreement, and no executor has to remember to report one fact in
two places.

The -tags=distributed suite that surfaced this was asserting against a
misconfiguration. It never injected a backend, so executeLocally took its
c.backend == nil arm and every operation failed with "no backend configured" —
which is how TestConcurrentOperations came to print "Failed 10 out of 10" and
"Successful: 10, Failed: 0" in the same run. Those tests now use a real S3 backend
against an in-process substrate endpoint, seed the keys they read, and check the
returned bytes rather than only the success flag. A mock on the far side of this
seam would agree with the coordinator by construction, which is how the defect was
missed. TestClusterManager_DistributedOperation also executes a GET of an absent
key, so the tagged suite can now fail if the reconciliation is removed — the
assertion its counters could not make while every operation failed for the same
reason.

Three mutations checked: removing the reconciliation fails the failure-path tests,
returning an error unconditionally fails the success-path tests, and dropping the
cause from the error text fails the test that reads it.

Two further defects found by probe while fixing this and filed as #275: a
single-node cluster never elects a leader, because the majority check lives only in
the inbound-vote handler, and GetStats reports zero nodes for the first five
seconds after Start, because nothing computes the statistics before the ticker
first fires. Both are why three tests in that suite have been failing unobserved.

Closes #269
@scttfrdmn scttfrdmn added type: bug Something isn't working as expected priority: high Important issue that should be addressed soon area: distributed Distributed coordination and consensus labels Aug 3, 2026
@scttfrdmn scttfrdmn added the area: tests Test infrastructure and test suite label Aug 3, 2026
@scttfrdmn
scttfrdmn enabled auto-merge (squash) August 3, 2026 17:27
@scttfrdmn
scttfrdmn merged commit 81fbd4c into main Aug 3, 2026
28 checks passed
@scttfrdmn
scttfrdmn deleted the fix/operation-success-accounting branch September 20, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: distributed Distributed coordination and consensus area: tests Test infrastructure and test suite priority: high Important issue that should be addressed soon type: bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClusterManager.DistributeOperation counts a failed operation as successful

1 participant