Skip to content

Fix JointFabricDatastore ownership, lifetime, and sync edge cases#71453

Open
vijs wants to merge 1 commit intoproject-chip:masterfrom
vijs:fix/0407
Open

Fix JointFabricDatastore ownership, lifetime, and sync edge cases#71453
vijs wants to merge 1 commit intoproject-chip:masterfrom
vijs:fix/0407

Conversation

@vijs
Copy link
Copy Markdown
Contributor

@vijs vijs commented Apr 8, 2026

Summary

Improves JointFabric Datastore memory safety and reliability by fixing ownership and lifetime bugs, tightening refresh and sync edge cases, and adding targeted unit tests to prevent regressions.

Changes

  • Fixed span-backed field ownership/lifetime handling for group key sets, names, and ICAC.
  • Fixed refresh and sync flow issues, including group key set fetch behavior and delete-pending payload handling.
  • Fixed binding and ACL sync edge cases, including ACL deduplication and delete behavior.
  • Added unit tests covering ownership, refresh/sync paths, and delete-pending payload correctness.

Testing

source activate.sh && ninja -C out/linux-x64-tests TestJointFabricDatastore

./out/linux-x64-tests/tests/TestJointFabricDatastore

@github-actions github-actions bot added documentation Improvements or additions to documentation examples platform linux app labels Apr 8, 2026
@pullapprove pullapprove bot added review - pending and removed documentation Improvements or additions to documentation examples platform linux app labels Apr 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant enhancements to the Joint Fabric Datastore and synchronization logic, including support for 'regular' device commissioning, improved in-flight command management, and more robust handling of ACL and Group Key Set data. The changes also include a major refactor of the unit tests to use a more descriptive tracking delegate. Key feedback items include critical safety concerns regarding iterator invalidation in asynchronous callbacks within JointFabricDatastore.cpp, misleading variable names in JFADatastoreSync.cpp, and inconsistent error status codes when resources are not found.

keySetWrite.groupKeySet.epochKey2 = cbContext->objectToWrite.Value().epochKey2;
keySetWrite.groupKeySet.epochStartTime2 = cbContext->objectToWrite.Value().epochStartTime2;

chip::Controller::ClusterBase groupsCluster(exchangeMgr, sessionHandle, kRootEndpointId);
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.

medium

The variable name groupsCluster is misleading here as it is being used to interact with the GroupKeyManagement cluster. Consider renaming it to groupKeyMgmtCluster.

                    chip::Controller::ClusterBase groupKeyMgmtCluster(exchangeMgr, sessionHandle, kRootEndpointId);

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

PR #71453: Size comparison from ad11a88 to cebf5f1

Full report (34 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section ad11a88 cebf5f1 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1090510 1090510 0 0.0
RAM 144858 144858 0 0.0
bl616 lighting-app bl616+thread FLASH 1101964 1101964 0 0.0
RAM 104280 104280 0 0.0
bl616+wifi+shell FLASH 1588876 1588876 0 0.0
RAM 98176 98176 0 0.0
bl702 lighting-app bl702+eth FLASH 1053644 1053644 0 0.0
RAM 108461 108461 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 892302 892302 0 0.0
RAM 105852 105852 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 775864 775864 0 0.0
RAM 103396 103396 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 788068 788068 0 0.0
RAM 108588 108588 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 734392 734392 0 0.0
RAM 97396 97396 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 717812 717812 0 0.0
RAM 97556 97556 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 559874 559874 0 0.0
RAM 204568 204568 0 0.0
lock CC3235SF_LAUNCHXL FLASH 592742 592742 0 0.0
RAM 204816 204816 0 0.0
efr32 lock-app BRD4187C FLASH 992164 992164 0 0.0
RAM 131268 131268 0 0.0
BRD4338a FLASH 794633 794625 -8 -0.0
RAM 243044 243044 0 0.0
window-app BRD4187C FLASH 1097676 1097676 0 0.0
RAM 130308 130308 0 0.0
esp32 all-clusters-app c3devkit DRAM 98460 98460 0 0.0
FLASH 1599064 1599064 0 0.0
IRAM 93514 93514 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 862116 862116 0 0.0
RAM 162094 162094 0 0.0
nxp contact mcxw71+release FLASH 738992 738992 0 0.0
RAM 67016 67016 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1711588 1711588 0 0.0
RAM 214028 214028 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1609356 1609356 0 0.0
RAM 210908 210908 0 0.0
light cy8ckit_062s2_43012 FLASH 1466876 1466876 0 0.0
RAM 197068 197068 0 0.0
lock cy8ckit_062s2_43012 FLASH 1499596 1499596 0 0.0
RAM 224820 224820 0 0.0
qpg lighting-app qpg6200+debug FLASH 842636 842636 0 0.0
RAM 127868 127868 0 0.0
lock-app qpg6200+debug FLASH 781252 781252 0 0.0
RAM 118816 118816 0 0.0
realtek light-switch-app rtl8777g FLASH 676960 676960 0 0.0
RAM 101516 101516 0 0.0
lighting-app rtl8777g FLASH 724504 724504 0 0.0
RAM 101956 101956 0 0.0
stm32 light STM32WB5MM-DK FLASH 475428 475428 0 0.0
RAM 141388 141388 0 0.0
telink bridge-app tl7218x FLASH 730852 730852 0 0.0
RAM 95924 95924 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 850306 850306 0 0.0
RAM 44340 44340 0 0.0
tl7218x FLASH 841712 841712 0 0.0
RAM 99724 99724 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 729992 729992 0 0.0
RAM 55904 55904 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 793218 793218 0 0.0
RAM 75080 75080 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 729936 729936 0 0.0
RAM 33388 33388 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 613142 613142 0 0.0
RAM 118396 118396 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 839846 839850 4 0.0
RAM 97432 97432 0 0.0

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 70.00000% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.27%. Comparing base (fdb31db) to head (58264e2).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
src/app/server/JointFabricDatastore.cpp 72.41% 24 Missing ⚠️
src/app/server/JointFabricDatastore.h 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #71453      +/-   ##
==========================================
- Coverage   54.31%   54.27%   -0.05%     
==========================================
  Files        1576     1576              
  Lines      108247   108317      +70     
  Branches    13401    13428      +27     
==========================================
- Hits        58796    58784      -12     
- Misses      49451    49533      +82     

☔ 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.


uint64_t JointFabricDatastore::GetEndpointStorageKey(NodeId nodeId, EndpointId endpointId) const
{
return (static_cast<uint64_t>(nodeId) << 16) | static_cast<uint64_t>(endpointId);
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.

NodeId is 64-bit already, so this loses the upper 16-bits.

We need a comment on why this is safe (I do not believe it is ...)

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.

also the static cast for nodeID is then not needed (otherwise it makes it seem like we upcast, but we do not)

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.

Simplified this logic to remove all casts and conversions. Please review the updated implementation.

@github-actions github-actions bot added documentation Improvements or additions to documentation examples platform linux app labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

PR #71453: Size comparison from 17a6004 to e03244d

Full report (34 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section 17a6004 e03244d change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1090510 1090510 0 0.0
RAM 144858 144858 0 0.0
bl616 lighting-app bl616+thread FLASH 1101988 1101988 0 0.0
RAM 104280 104280 0 0.0
bl616+wifi+shell FLASH 1588876 1588876 0 0.0
RAM 98176 98176 0 0.0
bl702 lighting-app bl702+eth FLASH 1053664 1053664 0 0.0
RAM 108461 108461 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 892362 892362 0 0.0
RAM 105852 105852 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 775888 775888 0 0.0
RAM 103396 103396 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 788092 788092 0 0.0
RAM 108588 108588 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 734416 734416 0 0.0
RAM 97396 97396 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 717844 717844 0 0.0
RAM 97556 97556 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 559874 559874 0 0.0
RAM 204568 204568 0 0.0
lock CC3235SF_LAUNCHXL FLASH 592742 592742 0 0.0
RAM 204816 204816 0 0.0
efr32 lock-app BRD4187C FLASH 992424 992424 0 0.0
RAM 131268 131268 0 0.0
BRD4338a FLASH 796297 796297 0 0.0
RAM 243364 243364 0 0.0
window-app BRD4187C FLASH 1098000 1098000 0 0.0
RAM 130308 130308 0 0.0
esp32 all-clusters-app c3devkit DRAM 98460 98460 0 0.0
FLASH 1599174 1599174 0 0.0
IRAM 93514 93514 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 862232 862232 0 0.0
RAM 162094 162094 0 0.0
nxp contact mcxw71+release FLASH 739016 739016 0 0.0
RAM 67016 67016 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1711700 1711700 0 0.0
RAM 214028 214028 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1609460 1609460 0 0.0
RAM 210908 210908 0 0.0
light cy8ckit_062s2_43012 FLASH 1466876 1466876 0 0.0
RAM 197068 197068 0 0.0
lock cy8ckit_062s2_43012 FLASH 1499596 1499596 0 0.0
RAM 224820 224820 0 0.0
qpg lighting-app qpg6200+debug FLASH 842668 842668 0 0.0
RAM 127868 127868 0 0.0
lock-app qpg6200+debug FLASH 781284 781284 0 0.0
RAM 118816 118816 0 0.0
realtek light-switch-app rtl8777g FLASH 680808 680808 0 0.0
RAM 101600 101600 0 0.0
lighting-app rtl8777g FLASH 724752 724752 0 0.0
RAM 101956 101956 0 0.0
stm32 light STM32WB5MM-DK FLASH 475452 475452 0 0.0
RAM 141388 141388 0 0.0
telink bridge-app tl7218x FLASH 730904 730904 0 0.0
RAM 95924 95924 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 850328 850328 0 0.0
RAM 44340 44340 0 0.0
tl7218x FLASH 841734 841734 0 0.0
RAM 99724 99724 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 730232 730232 0 0.0
RAM 55984 55984 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 793458 793458 0 0.0
RAM 75160 75160 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 730176 730176 0 0.0
RAM 33468 33468 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 613142 613142 0 0.0
RAM 118396 118396 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 839868 839872 4 0.0
RAM 97432 97432 0 0.0

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

PR #71453: Size comparison from d86a220 to 58264e2

Full report (34 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section d86a220 58264e2 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1090510 1090510 0 0.0
RAM 144858 144858 0 0.0
bl616 lighting-app bl616+thread FLASH 1101988 1101988 0 0.0
RAM 104280 104280 0 0.0
bl616+wifi+shell FLASH 1588876 1588876 0 0.0
RAM 98176 98176 0 0.0
bl702 lighting-app bl702+eth FLASH 1053666 1053666 0 0.0
RAM 108461 108461 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 892364 892364 0 0.0
RAM 105852 105852 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 775904 775904 0 0.0
RAM 103396 103396 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 788108 788108 0 0.0
RAM 108588 108588 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 734432 734432 0 0.0
RAM 97396 97396 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 717860 717860 0 0.0
RAM 97556 97556 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 559874 559874 0 0.0
RAM 204568 204568 0 0.0
lock CC3235SF_LAUNCHXL FLASH 592742 592742 0 0.0
RAM 204816 204816 0 0.0
efr32 lock-app BRD4187C FLASH 992512 992512 0 0.0
RAM 131268 131268 0 0.0
BRD4338a FLASH 796297 796297 0 0.0
RAM 243372 243372 0 0.0
window-app BRD4187C FLASH 1098000 1098000 0 0.0
RAM 130308 130308 0 0.0
esp32 all-clusters-app c3devkit DRAM 98460 98460 0 0.0
FLASH 1599174 1599174 0 0.0
IRAM 93514 93514 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 862232 862232 0 0.0
RAM 162094 162094 0 0.0
nxp contact mcxw71+release FLASH 739032 739032 0 0.0
RAM 67016 67016 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1711700 1711700 0 0.0
RAM 214028 214028 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1609460 1609460 0 0.0
RAM 210908 210908 0 0.0
light cy8ckit_062s2_43012 FLASH 1466876 1466876 0 0.0
RAM 197068 197068 0 0.0
lock cy8ckit_062s2_43012 FLASH 1499596 1499596 0 0.0
RAM 224820 224820 0 0.0
qpg lighting-app qpg6200+debug FLASH 842684 842684 0 0.0
RAM 127868 127868 0 0.0
lock-app qpg6200+debug FLASH 781300 781300 0 0.0
RAM 118816 118816 0 0.0
realtek light-switch-app rtl8777g FLASH 680824 680824 0 0.0
RAM 101600 101600 0 0.0
lighting-app rtl8777g FLASH 724768 724768 0 0.0
RAM 101956 101956 0 0.0
stm32 light STM32WB5MM-DK FLASH 475468 475468 0 0.0
RAM 141388 141388 0 0.0
telink bridge-app tl7218x FLASH 730906 730906 0 0.0
RAM 95924 95924 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 850332 850332 0 0.0
RAM 44340 44340 0 0.0
tl7218x FLASH 841738 841738 0 0.0
RAM 99724 99724 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 730236 730236 0 0.0
RAM 55984 55984 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 793462 793462 0 0.0
RAM 75160 75160 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 730180 730180 0 0.0
RAM 33468 33468 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 613142 613142 0 0.0
RAM 118396 118396 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 839872 839876 4 0.0
RAM 97432 97432 0 0.0

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants