Skip to content

Clear scaleInfo when scaler is disabled (#12026) - #12409

Merged
carlydf merged 1 commit into
release/v1.32.xfrom
disable-scaler-bugfix
Oct 6, 2026
Merged

carlydf merged 1 commit into
release/v1.32.xfrom
disable-scaler-bugfix

Conversation

@carlydf

@carlydf carlydf commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What changed?

Clear scaleInfo when scaler is disabled

Why?

Not clearing scaleInfo meant that clients were still reading and writing based on scaleInfo.Read and scaleInfo.Write, even though target was cleared.

We want disabling the scaler to be a clean and complete break back to the mode of dynamic-config hard-coded partition counts.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

Note

Medium Risk
Changes partition read/write routing when managed scaling is turned off; backlog outside the former read range may remain unpolled until tasks time out, as noted in code.

Overview
Disabling managed partition scaling now fully resets client-visible scale state so workers stop routing on stale PartitionScaleInfo read/write counts.

When the scaler returns NewTarget: 0, scaleManager clears persisted/ephemeral backlog metadata (BacklogState, BacklogCounts, BacklogCap, private scaler state), forces a state update if leftover managed fields would otherwise be ignored as “no change”, and logs disabled managed scaling with the previous read/write counts. Scale-up from target 0 still seeds backlog bits from dynamic-config write partitions only on the prevTarget == 0 && target > 0 path.

Clients use PartitionCounts.Valid() (both Read and Write > 0) instead of checking write or read alone, so zeroed scale info after disable falls back to dynamic-config partition counts. Tests cover disabled-state cleanup and load-balancer partition count fixtures.

The partition scaler API docs now state that disabling scaling requires BacklogCap to be zero as well.

Reviewed by Cursor Bugbot for commit 89f912b. Bugbot is set up for automated code reviews on this repo. Configure here.

## What changed?
Clear scaleInfo when scaler is disabled

## Why?
Not clearing scaleInfo meant that clients were still reading and writing
based on scaleInfo.Read and scaleInfo.Write, even though target was
cleared.

We want disabling the scaler to be a clean and complete break back to
the mode of dynamic-config hard-coded partition counts.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes task-queue partition routing and persisted scale state when
scaling is disabled; incorrect behavior could misdirect polls/writes or
leave backlog unpolled until timeout (documented tradeoff).
> 
> **Overview**
> When managed partition scaling is turned off (`NewTarget == 0`), the
scale manager now **fully resets** managed state (backlog bits, counts,
cap, private scaler state) and publishes **zero read/write**
`PartitionScaleInfo` so clients stop routing on stale scale metadata and
fall back to dynamic-config partition counts.
> 
> `scaleStateToInfo` treats `Target == 0` as “scaling disabled” (zeros
everywhere), and the no-op path in `callScaler` still runs when target
is already zero but leftover managed fields need cleanup. Scale-up
backlog seeding only runs when re-enabling (`prevTarget == 0 && target >
0`), not on disable. Matching clients use **`PartitionCounts.Valid()`**
(read and write both &gt; 0) instead of checking write or read alone
when picking partitions.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
0007832. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@carlydf
carlydf requested a review from a team as a code owner October 5, 2026 20:49
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @carlydf's task in 1m 16s —— View job


Reviewed 5 files, 2 findings.

@@ -203,9 +203,15 @@ func (sm *scaleManager) callScaler() {
PrivateState: sm.scaleState.GetPrivateScalerState(),
})
backlogCapC8 := number.EncodeCompact8(int64(decision.BacklogCap))

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.

The rule "BacklogCap must be zero when NewTarget is zero" is only written down in the interface comments. Nothing in the code enforces it, and breaking it causes a write loop. If a scaler returns {NewTarget: 0, BacklogCap: N} after the state has been cleaned, then disabledStateNeedsCleanup is false and NewTarget == Target. But backlogCapC8 != 0, so the early return is skipped. The code then forces newState.BacklogCap = 0 and calls UpdateScaleState. That write repeats every cooldown period forever, with a new TargetVersion each time.

You could normalize the cap here instead. Then the no-op check always passes once the state is clean, the newState.BacklogCap = 0 line in the target == 0 block is no longer needed, and the doc changes in partition_scaler_interface.go can go:

Suggested change
backlogCapC8 := number.EncodeCompact8(int64(decision.BacklogCap))
var backlogCapC8 number.Compact8
if decision.NewTarget > 0 {
backlogCapC8 = number.EncodeCompact8(int64(decision.BacklogCap))
}

s.userData.EXPECT().SetPartitionScale(gomock.Any()).
Do(func(info *taskqueuespb.PartitionScaleInfo) { scaleInfos <- info }).Times(2)

initial := &persistencespb.PartitionScaleState{

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.

This test starts from Target: 0, so it only covers the cleanup of leftover state. The bug this PR fixes is the switch from an active managed target (Target > 0) to disabled, and no test covers that path. That path also checks the prevTarget == 0 && target > 0 change: mayHaveBacklog must not re-seed bits from dynamic config on disable. Please add a case that starts with, for example, Target: 4 and BacklogState bits 0–3. It should assert that the persisted state has a nil BacklogState and that the pushed info has Read == Write == 0.

@carlydf
carlydf merged commit 18cdcda into release/v1.32.x Oct 6, 2026
77 of 88 checks passed
@carlydf
carlydf deleted the disable-scaler-bugfix branch October 6, 2026 21:44
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.

2 participants