Skip to content

Serialize batch state checkers per permission in dynamic distribution#25424

Merged
maliming merged 2 commits into
rel-10.3from
fix/distribution-batch-state-checker-projection
May 14, 2026
Merged

Serialize batch state checkers per permission in dynamic distribution#25424
maliming merged 2 commits into
rel-10.3from
fix/distribution-batch-state-checker-projection

Conversation

@maliming

Copy link
Copy Markdown
Member

RequireFeatures(...) and RequirePermissions(...) default to a shared batch state checker (AsyncLocal singleton) that holds models for many permissions. The serializer contributor pipeline only recognised the non-batch types, so the batch instance was silently dropped from PermissionDefinitionRecord during dynamic permission distribution. Consumers ended up with empty StateCheckers, the feature / permission gate disappeared on that side, and they disagreed with the publisher's in-memory verdict (typical symptom: a UI tab whose backing API rejects with 403 because the publisher still enforces the gate).

ISimpleStateCheckerSerializerContributor and ISimpleStateCheckerSerializer now have a state-aware overload. The Features and Permissions contributors look up the per-state model on the batch checker (matched with the same EqualityComparer<TState>.Default semantics the runtime uses) and emit a non-batch record. PermissionDefinitionSerializer threads the owning permission through. Includes a regression test pinning the equality contract.

Regression introduced in #25276. Reported in https://github.com/volosoft/volo/issues/22319.

- Add state-aware overload to ISimpleStateCheckerSerializer/Contributor
- Features and Permissions contributors recognise their batch checker and emit a per-state record
- PermissionDefinitionSerializer threads the owning permission through
- Pin equality semantics to match the batch runtime (default comparer)
Copilot AI review requested due to automatic review settings May 13, 2026 13:24
@maliming maliming requested review from EngincanV and yagmurcelk May 13, 2026 13:25
@maliming maliming added this to the 10.3-patch milestone May 13, 2026
@maliming

Copy link
Copy Markdown
Member Author

@yagmurcelk 10.4 test branch: test/distribution-batch-state-checker-projection-on-10.4
https://github.com/abpframework/abp/tree/test/distribution-batch-state-checker-projection-on-10.4

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

Fixes dynamic permission distribution losing StateCheckers when permissions/features use the default shared batch state checkers (AsyncLocal singleton). The serializer pipeline now becomes state-aware so it can emit per-permission/per-state non-batch records, keeping publisher and consumer gating consistent.

Changes:

  • Add state-aware serialization overloads and thread the owning PermissionDefinition through serialization.
  • Teach Features/Permissions serializer contributors to extract per-state models from batch checkers and serialize them as non-batch records.
  • Add regression tests (including equality semantics parity with runtime lookup).

Reviewed changes

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

Show a summary per file
File Description
modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/PermissionDefinitionSerializer_Tests.cs Adds regression coverage for default batch RequireFeatures/RequirePermissions serialization.
modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDefinitionSerializer.cs Passes the permission as “state” into state-checker serialization.
framework/test/Volo.Abp.Features.Tests/Volo/Abp/Features/RequireFeaturesSimpleBatchStateChecker_Tests.cs Pins EqualityComparer<TState>.Default semantics for model lookup.
framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeaturesSimpleStateCheckerSerializerContributor.cs Implements the new state-aware serializer contributor overload (delegating to existing logic).
framework/src/Volo.Abp.Features/Volo/Abp/Features/RequireFeaturesSimpleBatchStateChecker.cs Adds per-state model lookup API (GetModelOrNull).
framework/src/Volo.Abp.Features/Volo/Abp/Features/FeaturesSimpleStateCheckerSerializerContributor.cs Adds state-aware serialization that converts batch checkers into per-state JSON records.
framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/SimpleStateCheckerSerializerExtensions.cs Adds list serialization overload that accepts the owning state.
framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/SimpleStateCheckerSerializer.cs Adds state-aware Serialize(checker, state) pipeline.
framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/ISimpleStateCheckerSerializerContributor.cs Adds new state-aware contributor method (API surface change).
framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/ISimpleStateCheckerSerializer.cs Adds new state-aware serializer method (API surface change).
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/RequirePermissionsSimpleBatchStateChecker.cs Adds per-state model lookup API (GetModelOrNull).
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionsSimpleStateCheckerSerializerContributor.cs Adds state-aware serialization for permission batch checkers.
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/AuthenticatedSimpleStateCheckerSerializerContributor.cs Implements the new state-aware contributor overload (delegating to existing logic).

- Mirror _models with Dictionary<TState, ...> populated in AddCheckModels
- GetModelOrNull goes through the dict, matching IsEnabledAsync's first-wins
- Pin first-wins via a regression test

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

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

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

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.93220% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.78%. Comparing base (da37d5f) to head (340bd51).
⚠️ Report is 30 commits behind head on rel-10.3.

Files with missing lines Patch % Lines
...Management/PermissionDefinitionSerializer_Tests.cs 0.00% 46 Missing ⚠️
...Checking/SimpleStateCheckerSerializerExtensions.cs 62.50% 3 Missing ⚠️
...missionsSimpleStateCheckerSerializerContributor.cs 92.85% 0 Missing and 1 partial ⚠️
...sions/RequirePermissionsSimpleBatchStateChecker.cs 90.90% 0 Missing and 1 partial ⚠️
...FeaturesSimpleStateCheckerSerializerContributor.cs 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           rel-10.3   #25424    +/-   ##
==========================================
  Coverage     49.78%   49.78%            
==========================================
  Files          3609     3609            
  Lines        120714   120822   +108     
  Branches       9220     9232    +12     
==========================================
+ Hits          60099    60156    +57     
- Misses        58818    58859    +41     
- Partials       1797     1807    +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@oykuermann oykuermann requested review from oykuermann and removed request for yagmurcelk May 14, 2026 06:58
@maliming maliming merged commit da24e5e into rel-10.3 May 14, 2026
12 checks passed
@maliming maliming deleted the fix/distribution-batch-state-checker-projection branch May 14, 2026 08:12
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