Skip to content

Conversation

@anshulk-public
Copy link

@anshulk-public anshulk-public commented Jan 27, 2026

Add atomic rollback operation for failed fixes with suggestion updates

Summary

Adds a new rollbackFixWithSuggestionUpdates() method to FixEntityCollection that atomically rolls back a failed fix and updates all associated suggestions in a single DynamoDB transaction.

What Changed

  • Added rollbackFixWithSuggestionUpdates() method to FixEntityCollection (lines 283-400)
  • Added TypeScript type definition for the new method in fix-entity/index.d.ts
  • Added comprehensive unit tests covering all validation and transaction scenarios

Why This Change?

This method enables safe, atomic rollback of failed fixes by:

  1. Marking a FixEntity status from FAILEDROLLED_BACK
  2. Marking all associated Suggestion entities from ERRORSKIPPED

The atomic transaction ensures either all updates succeed or none are applied, preventing partial rollback states that could leave the system in an inconsistent state.

How It Works

The method uses ElectroDB's transaction.write() to perform the following atomically:

  • Update the fix status with a conditional check (must be in FAILED status)
  • Update all suggestions with conditional checks (each must be in ERROR status)
  • Fetch suggestion rank values upfront (required for GSI composite key updates)
  • Provide detailed error reporting if the transaction is canceled due to condition check failures

API Signature

async rollbackFixWithSuggestionUpdates(
fixEntityId: string,
opportunityId: string,
suggestionUpdates: Array<{suggestionId: string}>,
options?: {token?: string}
): Promise<{canceled: boolean, data: any[]}>### Parameters

  • fixEntityId - The ID of the FixEntity to roll back
  • opportunityId - The ID of the opportunity (required for partition key)
  • suggestionUpdates - Array of objects containing suggestionId for each suggestion to update
  • options.token - Optional client request token for idempotent operations (valid for 10 minutes)

Returns

  • canceled - Boolean indicating if the transaction was canceled
  • data - Array of transaction item results

Validation & Error Handling

  • ✅ All IDs must be valid UUIDs
  • ✅ At least one suggestion update is required
  • ✅ Transaction enforces status preconditions via DynamoDB conditional expressions
  • ✅ Detailed error messages on transaction cancellation
  • ✅ Throws ValidationError for input validation failures
  • ✅ Throws DataAccessError for transaction failures

Version Impact

This is a minor version feature addition (backward compatible).

Please ensure your pull request adheres to the following guidelines:

  • make sure to link the related issues in this description
  • when merging / squashing, make sure the fixed issue references are visible in the commits, for easy compilation of release notes

Related Issues

Thanks for contributing!

@github-actions
Copy link

This PR will trigger a minor release when merged.

@anshulk-public anshulk-public changed the title Rollback fix with suggestion updates feat: Rollback fix with suggestion updates Jan 27, 2026
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.

2 participants