Skip to content

Commit 6d41b71

Browse files
committed
fix: guard reconcileOrganization against subscribeToStoreOnDataLayer falsy return
Bugbot flagged an inconsistency introduced by af06a65: governance sync now correctly treats both a thrown exception and a falsy return from subscribeToStoreOnDataLayer as a failure, but V1/V2 reconcileOrganization still only guarded thrown exceptions. subscribeToStoreOnDataLayer in src/datalayer/persistance.js returns false (without throwing) on the two most common failure paths: - No storeId provided - getSubscriptions() RPC failure (datalayer unreachable) Without the falsy-return check, the dominant datalayer-unreachable failure slips past the try/catch, and the subsequent getDataLayerStoreSyncStatus call (which also fails when the store is not subscribed) produces a misleading "not yet synced" log instead of a clear "could not subscribe" message. Mirrors the subscribe-first pattern af06a65 added to governance sync. Both subscribe-first and the falsy-return guard are no-ops in simulator mode (wrapped in !USE_SIMULATOR for V2, skipped entirely for V1 via the function's top-level simulator guard).
1 parent af06a65 commit 6d41b71

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/models/organizations/organizations.model.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,23 @@ class Organization extends Model {
834834
// before entering the blocking subscription flow. If either the org store or
835835
// its derived singleton store is not yet synced, return early so the periodic
836836
// task retries on the next run rather than waiting up to 10 minutes.
837+
//
838+
// subscribeToStoreOnDataLayer returns falsy on the common failure paths
839+
// (no storeId, getSubscriptions RPC failure) and also throws on unexpected
840+
// errors, so guard on both. Without the falsy-return check, the dominant
841+
// datalayer-unreachable failure would slip past the try/catch and the
842+
// subsequent "not yet synced" skip log would be misleading.
837843
try {
838-
await datalayer.subscribeToStoreOnDataLayer(orgUid);
844+
const subscribed = await datalayer.subscribeToStoreOnDataLayer(orgUid);
845+
if (!subscribed) {
846+
logger.warn(
847+
`[v1]: reconcileOrganization: could not subscribe to org store ${orgUid}. Skipping reconcile, will retry on next task run.`,
848+
);
849+
return;
850+
}
839851
} catch (error) {
840852
logger.warn(
841-
`[v1]: reconcileOrganization: could not subscribe to org store ${orgUid}, skipping reconcile: ${error.message}`,
853+
`[v1]: reconcileOrganization: could not subscribe to org store ${orgUid}: ${error.message}. Skipping reconcile, will retry on next task run.`,
842854
);
843855
return;
844856
}

src/models/v2/organizations-v2.model.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,12 +1857,24 @@ class OrganizationsV2 extends Model {
18571857

18581858
// Subscribe to org store first so it begins syncing, then check sync status
18591859
// before entering the blocking subscription flow.
1860+
//
1861+
// subscribeToStoreOnDataLayer returns falsy on the common failure paths
1862+
// (no storeId, getSubscriptions RPC failure) and also throws on unexpected
1863+
// errors, so guard on both. Without the falsy-return check, the dominant
1864+
// datalayer-unreachable failure would slip past the try/catch and the
1865+
// subsequent "not yet synced" skip log would be misleading.
18601866
if (!USE_SIMULATOR) {
18611867
try {
1862-
await datalayer.subscribeToStoreOnDataLayer(org_uid);
1868+
const subscribed = await datalayer.subscribeToStoreOnDataLayer(org_uid);
1869+
if (!subscribed) {
1870+
loggerV2.warn(
1871+
`[v2]: reconcileOrganization: could not subscribe to org store ${org_uid}. Skipping reconcile, will retry on next task run.`,
1872+
);
1873+
return;
1874+
}
18631875
} catch (error) {
18641876
loggerV2.warn(
1865-
`[v2]: reconcileOrganization: could not subscribe to org store ${org_uid}, skipping reconcile: ${error.message}`,
1877+
`[v2]: reconcileOrganization: could not subscribe to org store ${org_uid}: ${error.message}. Skipping reconcile, will retry on next task run.`,
18661878
);
18671879
return;
18681880
}

0 commit comments

Comments
 (0)