Skip to content

[4.1.2 Backport] CBG-5594: fix BackgroundManager.Stop transition - #8632

Merged
bbrks merged 1 commit into
release/4.1.2from
CBG-5594
Aug 27, 2026
Merged

[4.1.2 Backport] CBG-5594: fix BackgroundManager.Stop transition#8632
bbrks merged 1 commit into
release/4.1.2from
CBG-5594

Conversation

@torcolvin

@torcolvin torcolvin commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

CBG-5594

Unclean cherry pick of #8468 (CBG-5521) to 4.1.2

Stacked on #8631 (CBG-5743), which sits on #8660 (CBG-5752) and #8635 (CBG-5744).

Changes from main commit:

  • db/background_mgr_test.go — upstream's new tests are typed against MockProcessOptions, added by CBG-5653 (CBG-5653 switch backgroundmanager options to strong types #8490) which is not on 4.1.2. Applied against BackgroundManager[map[string]any] in six places, matching the rest of the file on this branch; no assertions changed. db/background_mgr.go is identical to upstream.

Integration Tests

🤖 Opened with the sync-gateway-backport skill in Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Backport of the upstream fix for a multi-node BackgroundManager.Stop() convergence bug where non-initiating nodes could incorrectly transition their local state to completed and overwrite the correct stopped cluster status.

Changes:

  • Replace the errBackgroundManagerStatusNotRunning sentinel with a typed error carrying the observed cluster state, and update call sites to use type-based matching.
  • Ensure poller nodes adopt the cluster’s terminal/stopping state locally before terminating, and only default to completed when the local state is still running at process completion.
  • Update existing unit tests to assert the new error type via require.ErrorAs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
db/background_mgr.go Fixes multi-node stop-state convergence by adopting cluster terminal state locally; refactors not-running error into a typed error; adjusts completion/state persistence logic and logging.
db/background_mgr_test.go Updates assertions to accommodate the typed errBackgroundManagerStatusNotRunning error.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread db/background_mgr.go
Comment thread db/background_mgr.go
Comment thread db/background_mgr.go
@bbrks

bbrks commented Aug 25, 2026

Copy link
Copy Markdown
Member

db/background_mgr_test.go — upstream's new tests (TestBackgroundManagerMultiNodePollingConverges, TestBackgroundManagerMultiNodeStopConvergesToStopped, TestBackgroundManagerConcurrentStopStartRace) not ported; they need the testing/require, testing/assert and testing/sgtest packages, which are not on 4.1.2

This doesn't seem like good justification for not porting over the tests and this has cropped up repeatedly now. The backport skills is just making the wrong choice here IMO.

Either we backport the testing packages to make the backports simpler to cherry pick - or we special case this and make the backport skill adapt the tests (which should only require minimal changes to make work with testify?)

@bbrks bbrks assigned torcolvin and unassigned bbrks Aug 25, 2026
@torcolvin torcolvin assigned bbrks and unassigned torcolvin Aug 26, 2026
bbrks
bbrks previously approved these changes Aug 26, 2026
stack merge was automatically disabled August 26, 2026 17:43

Pull Request is not mergeable

stack merge was automatically disabled August 26, 2026 17:48

Pull Request is not mergeable

@bbrks
bbrks force-pushed the CBG-5594 branch 2 times, most recently from ec13fe6 to 95f9d1a Compare August 26, 2026 18:09
stack merge was automatically disabled August 26, 2026 23:26

Pull Request is not mergeable

stack merge was automatically disabled August 27, 2026 09:02

Pull Request is not mergeable

Base automatically changed from CBG-5743 to release/4.1.2 August 27, 2026 13:23
Cherry-picked from 4ec1dd2 (CBG-5521, #8468).

db/background_mgr.go applies identically to upstream. One adaptation in
db/background_mgr_test.go: upstream's new tests are typed against
MockProcessOptions, introduced by CBG-5653 (#8490, "switch backgroundmanager
options to strong types"), which is not on 4.1.2. Applied against
BackgroundManager[map[string]any] with map[string]any{} options in six places,
matching the rest of the file on this branch. No assertions changed.

The import block keeps 4.1.2's github.com/stretchr/testify/{assert,require}
rather than the testing/{assert,require} wrappers, which the branch predates;
this commit's own import change, adding testing/sgtest, was applied.

Everything else applied unchanged, including the rename of
TestBackgroundManagerMultiNodePollingAvoidsOverwrite to
TestBackgroundManagerMultiNodePollingConverges with its CBG-5660 skip, the
errBackgroundManagerStatusNotRunning sentinel-to-type change with its
errors.AsType call sites, and TestBackgroundManagerConcurrentStopStartRace.

Co-authored-by: Tor Colvin <tor.colvin@couchbase.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@bbrks
bbrks merged commit 5d60e25 into release/4.1.2 Aug 27, 2026
43 of 64 checks passed
@bbrks
bbrks deleted the CBG-5594 branch August 27, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants