Conversation
…n paths Add a formal state-transition matrix to the mutation storage layer that prevents illegal status transitions (e.g. success → error, idle → submitting). updateMutationOperation now validates every status change against the matrix and rejects violations, guaranteeing that terminal states (success, cancelled) are immutable and no partial state can persist. Key changes: - Add LEGAL_TRANSITIONS matrix and validateStateTransition() to mutationStorage - Guard updateMutationOperation to reject illegal transitions - Add migrationStatus option to createMutationOperation for historical reconstruction of legacy records that are already in terminal states - Fix migrateRecordToMutationSystem to use migrationStatus instead of illegally transitioning pending → success - Fix recoverOperation to transition idle → pending before setting error - Fix executeOperationAttempt to transition error/idle → pending before submitting (matrix requires error → pending → submitting) - Fix reset() to unlink legacy records without modifying terminal states 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a formal state-transition matrix to the mutation storage layer that prevents illegal status transitions, and fixes several migration/recovery paths that violated it.
Changes
src/lib/mutationStorage.tsLEGAL_TRANSITIONSmatrix: Formal definition of all legalMutationStatustransitions (idle → pending → submitting → success/error, with retry and cancel paths)validateStateTransition(): Validates transitions against the matrixupdateMutationOperation(): Now rejects illegal transitions — returns the unmodified operation and logs a warning instead of persisting unauthorized stateCreateMutationOptions.migrationStatus: New option oncreateMutationOperationthat allows creating operations directly in a terminal status (e.g.success) for migrating legacy records that are already completedsrc/lib/bondActionStorage.tsmigrateRecordToMutationSystem(): Fixed to usemigrationStatuswhen creating operations from legacy records with terminal states. Previously triedpending → successwhich is illegal; now creates directly in the target state.src/lib/mutationRecovery.tsrecoverOperation(): Now transitionsidle → pendingbefore settingerror(matrix requires it)executeOperationAttempt(): Now transitionserror/idle → pendingbeforesubmitting(matrix requireserror → pending → submitting)src/hooks/useEnhancedBondMutations.tsreset(): Unlinks legacy records (operationId,migratedToV2) without trying to modify terminal states in the unified systemState-Transition Matrix
Invariants Enforced
success,cancelled) are immutable — no code path can transition out of themmigrationStatusto bypass the normal lifecycleTesting
Bus error (core dumped)on Node v24.18.0 (jsdom compatibility); tests verified via extracted pure-logic test harness🤖 Generated with Codebuff
Co-Authored-By: Codebuff noreply@codebuff.com