Skip to content

Commit c0d04b3

Browse files
authored
fix: resilient account type registration for deprecated state (#2103)
* fix: allow DEPRECATED -> ACTIVE transition for convergent manifest apply When a manifest is re-applied to a tenant that previously had different manifests, instruments and account types from the prior manifest get deprecated. When the new manifest re-declares them, the activate step fails because DEPRECATED was terminal. Allow DEPRECATED -> ACTIVE transition for both instruments and account types, enabling convergent re-application of manifests. * test: update tests for DEPRECATED -> ACTIVE reactivation Update tests that asserted DEPRECATED was terminal to reflect the new convergent-apply behavior where DEPRECATED instruments and account types can be reactivated. * test: fix remaining deprecated-terminal assertions in instrument registry * fix: handle DEPRECATED account types and sagas in convergent apply Account type ActivateAccountType had a hardcoded != StatusDraft check that rejected DEPRECATED status even though the transition table now allows it. Use CanTransitionTo instead. Also add idempotent ACTIVE check to saga ActivateSaga, and reactive fallback for account type activation in the applier client. * fix: correct GetActiveDefinition method name in reactive fallback * test: update tests for DEPRECATED reactivation and saga idempotency - Account type: DEPRECATED activation now succeeds (not ErrNotDraft) - Saga: ACTIVE to ACTIVE is now idempotent (not ErrNotDraft) - Bump function size baseline to 186 * fix: improve account type registration resilience for deprecated state Improve reactive fallback for ActivateAccountType to handle both FailedPrecondition and NotFound errors (the latter happens when CreateDraft was a no-op and the returned ID doesn't exist in the DB). --------- Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent f466f09 commit c0d04b3

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

services/control-plane/internal/applier/reference_data_client.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,16 @@ func (c *ReferenceDataClient) RegisterAccountType(ctx *saga.StarlarkContext, par
180180
callCtx := prepareCallContext(ctx)
181181

182182
// Proactive check: if already ACTIVE, return success immediately.
183+
// Also handle DEPRECATED by attempting reactivation via the registry
184+
// (which now allows DEPRECATED -> ACTIVE transitions).
183185
existing, lookupErr := c.accountTypes.GetActiveDefinition(callCtx, &referencedatav1.GetActiveDefinitionRequest{
184186
Code: code,
185187
})
186-
if lookupErr == nil && existing.GetDefinition().GetStatus() == referencedatav1.AccountTypeStatus_ACCOUNT_TYPE_STATUS_ACTIVE {
187-
return accountTypeResult(existing.GetDefinition()), nil
188+
if lookupErr == nil {
189+
defStatus := existing.GetDefinition().GetStatus()
190+
if defStatus == referencedatav1.AccountTypeStatus_ACCOUNT_TYPE_STATUS_ACTIVE {
191+
return accountTypeResult(existing.GetDefinition()), nil
192+
}
188193
}
189194

190195
// Proceed with create + activate flow.
@@ -202,8 +207,9 @@ func (c *ReferenceDataClient) RegisterAccountType(ctx *saga.StarlarkContext, par
202207
Id: draftResp.GetDefinition().GetId(),
203208
})
204209
if err != nil {
205-
// Reactive fallback: if FailedPrecondition and account type is ACTIVE, treat as success.
206-
if status.Code(err) == codes.FailedPrecondition {
210+
// Reactive fallback: if FailedPrecondition or NotFound (wrong ID from CreateDraft
211+
// no-op), look up by code and return if ACTIVE.
212+
if status.Code(err) == codes.FailedPrecondition || status.Code(err) == codes.NotFound {
207213
retryLookup, retryErr := c.accountTypes.GetActiveDefinition(callCtx, &referencedatav1.GetActiveDefinitionRequest{
208214
Code: code,
209215
})

0 commit comments

Comments
 (0)