Skip to content

[Bug]: JSON merge allocation test flakes under race instrumentation #25914

Closed

Description

@LeftHandCold

Summary

TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows can fail in the Ubuntu/x86 race-enabled UT even when the JSON merge implementation and its dependencies are unchanged. The allocation-only assertion therefore blocks unrelated pull requests as a false regression.

Root cause

The test in pkg/sql/plan/function/func_json_valid_test.go uses testing.AllocsPerRun(3, ...) around the complete JSON merge execution for 1 row and 8192 rows. That closure includes result-vector reset/growth, every merge-builder operation, every result append, and race-build-only vector checks; it does not isolate wrapper construction.

testing.AllocsPerRun derives its result from the process-wide runtime.MemStats.Mallocs delta. In the much longer 8192-row instrumented path, unrelated/instrumentation-dependent Go allocations are therefore attributed to the wrapper assertion. This is outside the production wrapper-allocation invariant that the test intends to protect.

The test was introduced by #25728 and passed that pull request's Ubuntu/x86 race UT. The affected package source remained unchanged, but the same test later failed in #25911 with one=1, many=45. On current main, repeated Darwin/arm64 runs report one=1, many=1 both with and without -race. This pass/fail history with unchanged source pins the defect to the test boundary, not to JSON merge or #25911.

Impact

Confirmed impact: unrelated pull requests can fail the required Ubuntu/x86 UT and require a rerun.

There is no confirmed production correctness or allocation regression in json_merge_patch.

Reproduction / evidence

Proposed fix

Keep all JSON merge functional tests in the race-enabled suite, but compile this allocation-statistics-only test only for non-race builds. Go defines the race build tag specifically so tests whose timing or instrumentation behavior is incompatible with the detector can be excluded: https://go.dev/doc/articles/race_detector#Excluding_Tests

No production code should change.

Acceptance criteria

  • The Ubuntu/x86 -race package test no longer executes the allocation-statistics-only assertion.
  • Non-race builds still execute TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows and retain its 1-row versus 8192-row invariant.
  • JSON merge functional tests continue to run in both race and non-race builds.
  • pkg/sql/plan/function passes targeted race, non-race, and package-level tests.

Activity

  1. added
    severity/s0
    and removed on Jul 21, 2026
  2. iamlinjunhong commented on Nov 4, 2026

    @iamlinjunhong
    Contributor

    Recurrence of the allocation-measurement failure class under non-race coverage instrumentation, recorded after independent PR/base checks. This comment does not reopen this issue or claim a new production regression.

    Stable signature:

    TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows
    func_json_merge_alloc_test.go:71
    Error: "12" is not less than or equal to "11"
    wrapper allocations must not grow with rows: one=1.000000 many=12.000000
    

    The complete failed-jobs log and complete root-job log were read. The summary has zero build failures and only this test plus its enclosing package failure. The failing command was go test -mod=readonly -count=1 -json -short -v -tags matrixone_test -timeout=20m -p 8 -covermode=set -coverprofile=... -coverpkg=... ${test_scope}, with CGO enabled on Linux/amd64, Go 1.26.4. This is a measurement assertion, with no compile/type/static/security failure or stable product error in the log.

    Independent non-PR flaky-candidate evidence:

    1. PR repetitions: on exact head 0fac11533824441409e5e36d276b91c0e4bc1125, the exact failing test passed 3 consecutive repetitions, no skips or failures. Used matrixone_test, CGO enabled, no race detector (matching the failing lane), covermode=set, and the same coverage selection policy from frozen CI revision 79c604b5c2c265427185271ab68629c9a464cbd0: discover repository packages, apply the CI package exclusions, then compact_coverage_profile.go -packages (438 instrumented packages).
    2. Causal exclusion: the entire PR diff only changes pkg/objectio/ioutil/sinker.go and its new executable ownership tests. The measured closure is PreExtendAndReset -> buildJsonMergePatch -> bytejson builder/vector append; it never calls Sinker or a spill path. Git tree/blob comparisons prove pkg/sql/plan/function, pkg/container/bytejson, pkg/container/vector, pkg/testutil, pkg/common/mpool, pkg/common/malloc, pkg/vm/process, go.mod, go.sum, and .github are identical between the official target and PR head. The changed Sinker file introduces no init/background work that could run during this measurement; its standalone tests run in a separate test binary.
    3. Clean target control: fetched official 4.2-dev, resolved to 7283f12d0eaf919e253dab4ed0d7dc0828c6ff8e. Temporarily detached the existing isolated task worktree at this exact commit, verified clean status, and ran the same command and coverage package list. The exact case passed 3 consecutive repetitions. Then restored the original task branch and exact PR head, with clean status. No baseline or PR source was edited. Failure absence on the clean control is the expected flaky-candidate result, not claimed as reproduction of the CI failure.
    4. Own change closure: reused unchanged-source validation at this exact PR head: ioutil normal and race package runs (78 roots each), build/vet, 17 focused ownership regression roots with 1,601 race repetitions, and TestS3Writer_SortAndSync all passed. The same head's Ubuntu/x86 UT job 126640087378 also succeeded.

    Reproduction/comparison command for both revisions, where cover_pkgs is the CI-policy-selected 438-package list:

    .agents/skills/mo-dev/scripts/mo-cgo-test -json -count=3 -short \
      -tags matrixone_test -covermode=set -coverpkg="$cover_pkgs" \
      -timeout=240s -run '^TestJsonMergePatchWrapperAllocationsDoNotScaleWithRows$' \
      ./pkg/sql/plan/function

    Local controls used Darwin/arm64 Go 1.27.1; they match the race/tags/CGO/coverage modes, but do not claim Linux/amd64 reproduction. Raw commands, JSON events, source comparisons, and full CI logs are retained outside the source repository in the task evidence directory.

    Disposition: non-PR flaky candidate, with all four required evidence categories checked. Reuse this issue solely as the tracking record; its closed state is not used as known-open-defect comparison evidence. No unrelated code or assertion threshold will be changed in #32164. Requesting one failed-jobs rerun of run 41849009910 after recording this evidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions