Skip to content

feat(counter): Add rollback support for SharedCounter#25771

Merged
scottn12 merged 6 commits into
microsoft:mainfrom
scottn12:counterRollback
Oct 31, 2025
Merged

feat(counter): Add rollback support for SharedCounter#25771
scottn12 merged 6 commits into
microsoft:mainfrom
scottn12:counterRollback

Conversation

@scottn12
Copy link
Copy Markdown
Contributor

@scottn12 scottn12 commented Oct 29, 2025

Description

This PR adds rollback support for the SharedCounter DDS.

Implementation

SharedCounter only has one type of op (increment), which will be reflected optimistically by incrementing the counter's value. To rollback we can simply call incrementCore() with opposite of the value that it was optimistically incremented with. This will also emit an incremented event with the amount that was rolled back and the new value of the counter.

This PR also adds additional bookkeeping for pending ops to ensure we handle local ops properly. This may not be technically necessary but can help catch bugs in the future and is more in line with how other DDSes handle local ops.

Testing

This PR adds the following testing:

  • UTs for Counter rollback scenarios
  • Enables rollback for existing Counter fuzz tests
  • Counter is now used in local server stress tests

Misc

AB#44705

@github-actions github-actions Bot added area: dds Issues related to distributed data structures area: tests Tests to add, test infrastructure improvements, etc dependencies Pull requests that update a dependency file base: main PRs targeted against main branch labels Oct 29, 2025
@scottn12 scottn12 closed this Oct 29, 2025
@scottn12 scottn12 reopened this Oct 29, 2025
@scottn12 scottn12 marked this pull request as ready for review October 29, 2025 20:22
Copilot AI review requested due to automatic review settings October 29, 2025 20:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds rollback support to the SharedCounter DDS to enable undoing optimistic operations when a transaction is rolled back.

Key changes:

  • Implements rollback functionality in SharedCounter by tracking pending operations
  • Adds comprehensive test coverage for rollback scenarios including multiple ops, partial rollbacks, and cross-client interactions
  • Enables rollback testing in fuzz tests by removing the rollbackProbability: 0 override
  • Integrates the counter model into local-server-stress-tests for broader stress testing

Reviewed Changes

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

Show a summary per file
File Description
packages/dds/counter/src/counter.ts Implements rollback support by tracking pending ops, modifying processMessage to handle local ops optimistically, and adding rollback method
packages/dds/counter/src/test/counter.spec.ts Adds comprehensive rollback test suite with 5 test cases covering various scenarios
packages/dds/counter/src/test/counter.fuzz.spec.ts Enables rollback in fuzz tests by removing rollbackProbability: 0 override
packages/test/local-server-stress-tests/package.json Adds counter package dependency
packages/test/local-server-stress-tests/src/ddsModels.ts Imports and registers baseCounterModel for stress testing
pnpm-lock.yaml Updates lockfile with new counter dependency
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment thread packages/dds/counter/src/counter.ts
Comment thread packages/dds/counter/src/counter.ts
Comment thread packages/dds/counter/src/counter.ts
Copy link
Copy Markdown
Contributor

@ChumpChief ChumpChief left a comment

Choose a reason for hiding this comment

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

Seems good! One suggestion but probably fine either way

Comment on lines +159 to +163
assert(
pendingOp !== undefined &&
pendingOp.type === op.type &&
pendingOp.incrementAmount === op.incrementAmount,
"local op mismatch",
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.

Consider calling submitLocalMessage with some unique localOpMetadata that is more-definitively matchable, rather than comparing the properties. Maybe just an incrementing number, or even the op itself and you could do object identity comparison.

Mostly just because normal use cases might increment by the same value (esp. +1) on every call and would otherwise be indistinguishable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in latest!

@scottn12 scottn12 requested a review from ChumpChief October 31, 2025 15:03
@scottn12 scottn12 merged commit 53af4b7 into microsoft:main Oct 31, 2025
33 checks passed
@scottn12 scottn12 deleted the counterRollback branch October 31, 2025 19:02
anthony-murphy-agent pushed a commit to anthony-murphy-agent/FluidFramework that referenced this pull request Jan 14, 2026
## Description

This PR adds rollback support for the `SharedCounter` DDS.

## Implementation

`SharedCounter` only has one type of op (`increment`), which will be
reflected optimistically by incrementing the counter's value. To
rollback we can simply call `incrementCore()` with opposite of the value
that it was optimistically incremented with. This will also emit an
`incremented` event with the amount that was rolled back and the new
value of the counter.

This PR also adds additional bookkeeping for pending ops to ensure we
handle local ops properly. This may not be technically necessary but can
help catch bugs in the future and is more in line with how other DDSes
handle local ops.

## Testing

This PR adds the following testing:
- UTs for Counter rollback scenarios
- Enables rollback for existing Counter fuzz tests
- Counter is now used in local server stress tests

## Misc


[AB#44705](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/44705)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: dds Issues related to distributed data structures area: tests Tests to add, test infrastructure improvements, etc base: main PRs targeted against main branch dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants