Repository navigation
fix: idempotency in dreamsync adapter #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { Web3Adapter } from "web3-adapter"; | |
| import path from "path"; | ||
| import dotenv from "dotenv"; | ||
| import { AppDataSource } from "../../database/data-source"; | ||
| import { shouldProcessWebhook } from "../../context/OperationContext"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify that shouldProcessWebhook is implemented and exported. The import references Run the following script to verify the function exists and check its signature: 🏁 Script executed: #!/bin/bash
# Description: Verify shouldProcessWebhook function exists and check its implementation
# Check for shouldProcessWebhook export
rg -n -A 15 "export.*function shouldProcessWebhook" platforms/dreamsync-api/src/context/
# Also check if it handles entity name variations (singular vs plural)
rg -C 3 "shouldProcessWebhook" platforms/dreamsync-api/src/context/Length of output: 153 I need to search for the actual locations of the files and functions. Let me explore the codebase structure:The web search doesn't provide information about the specific codebase structure. Let me search the codebase directly to find the correct file locations: 🏁 Script executed: #!/bin/bash
# Find OperationContext file location
echo "=== Searching for OperationContext file ==="
fd -type f "OperationContext" platforms/
echo ""
echo "=== Searching for shouldProcessWebhook definition ==="
rg -n "shouldProcessWebhook" platforms/ -g "!node_modules"
echo ""
echo "=== Searching for subscriber.ts to verify path ==="
fd -type f "subscriber.ts" platforms/Length of output: 1022 Let me search for the OperationContext file with corrected commands: 🏁 Script executed: #!/bin/bash
# Find OperationContext file with correct syntax
echo "=== Searching for OperationContext file ==="
find platforms/ -name "*OperationContext*" 2>/dev/null
echo ""
echo "=== Searching for export of shouldProcessWebhook ==="
rg -n "export.*shouldProcessWebhook" platforms/
echo ""
echo "=== Broader search for shouldProcessWebhook definition ==="
rg -n "function shouldProcessWebhook|const shouldProcessWebhook" platforms/ -A 5
echo ""
echo "=== List src/context directory contents ==="
find platforms/dreamsync-api/src/context -type f 2>/dev/null | head -20Length of output: 202 Let me verify the directory structure more broadly: 🏁 Script executed: #!/bin/bash
# Check src directory structure
echo "=== Contents of platforms/dreamsync-api/src ==="
ls -la platforms/dreamsync-api/src/ 2>/dev/null
echo ""
echo "=== All directories in src ==="
find platforms/dreamsync-api/src -mindepth 1 -maxdepth 2 -type d 2>/dev/null | sort
echo ""
echo "=== Verify the import path in subscriber.ts ==="
head -20 platforms/dreamsync-api/src/web3adapter/watchers/subscriber.ts
echo ""
echo "=== Check if any context-related files exist anywhere ==="
find platforms/dreamsync-api -name "*context*" -o -name "*Context*" 2>/dev/nullLength of output: 1964 The import references a non-existent module and undefined function - must be implemented. Verification confirms that The 🤖 Prompt for AI Agents |
||
|
|
||
| dotenv.config({ path: path.resolve(__dirname, "../../../../../.env") }); | ||
| export const adapter = new Web3Adapter({ | ||
|
|
@@ -253,6 +254,12 @@ export class PostgresSubscriber implements EntitySubscriberInterface { | |
| private async handleChange(entity: any, tableName: string): Promise<void> { | ||
| console.log(`🔍 handleChange called for: ${tableName}, entityId: ${entity?.id}`); | ||
|
|
||
| // Check if this operation should be processed (only ConsentService operations for groups/messages) | ||
| if (!shouldProcessWebhook(entity?.id, tableName)) { | ||
| console.log(`⏭️ Skipping webhook for ${tableName}:${entity?.id} - not from ConsentService (protected entity)`); | ||
| return; | ||
| } | ||
|
Comment on lines
+257
to
+261
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify that blocking non-ConsentService webhooks doesn't break existing functionality. This guard blocks ALL webhook processing for protected entities (groups/messages) unless they originate from ConsentService. This is a significant behavioral change that could break other parts of the system that rely on webhooks for groups or messages. Run the following script to identify other code paths that might be affected: 🏁 Script executed: #!/bin/bash
# Description: Find other services or code that might create/update groups or messages
# Search for group creation/updates outside ConsentService
rg -n "createGroup|updateGroup|save.*group" platforms/dreamsync-api/src --type ts -g '!ConsentService.ts' -g '!subscriber.ts' -C 2
# Search for message creation outside ConsentService
rg -n "create.*message|save.*message" platforms/dreamsync-api/src --type ts -g '!ConsentService.ts' -g '!subscriber.ts' -C 2Length of output: 17274 I need to examine the 🏁 Script executed: #!/bin/bash
# Find shouldProcessWebhook function definition
rg -n "shouldProcessWebhook" platforms/dreamsync-api/src --type ts -A 10
# Also check imports/usage in subscriber.ts
rg -n "import\|shouldProcessWebhook" platforms/dreamsync-api/src/web3adapter/watchers/subscriber.ts -B 5 -A 5Length of output: 5102 🏁 Script executed: #!/bin/bash
# Find shouldProcessWebhook function definition
rg -n "shouldProcessWebhook" platforms/dreamsync-api/src --type ts -A 10
# Also check imports/usage in subscriber.ts
rg -n "import\|shouldProcessWebhook" platforms/dreamsync-api/src/web3adapter/watchers/subscriber.ts -B 5 -A 5Length of output: 5102 Length of output: 230 Length of output: 0 Length of output: 935 Length of output: 2291 The code references a non-existent module and will fail at runtime. The imports in This means:
Action required: Create the missing |
||
|
|
||
| // Handle junction table changes - DON'T IGNORE group_participants! | ||
| // @ts-ignore | ||
| const junctionInfo = JUNCTION_TABLE_MAP[tableName]; | ||
|
|
@@ -344,6 +351,12 @@ export class PostgresSubscriber implements EntitySubscriberInterface { | |
| return; | ||
| } | ||
|
|
||
| // Check if this junction table change should be processed (only ConsentService operations for groups) | ||
| if (!shouldProcessWebhook(parentId, junctionInfo.entity)) { | ||
| console.log(`⏭️ Skipping junction table webhook for ${junctionInfo.entity}:${parentId} - not from ConsentService (protected entity)`); | ||
| return; | ||
| } | ||
|
|
||
| const repository = AppDataSource.getRepository(junctionInfo.entity); | ||
| const parentEntity = await repository.findOne({ | ||
| where: { id: parentId }, | ||
|
|
@@ -408,6 +421,12 @@ export class PostgresSubscriber implements EntitySubscriberInterface { | |
| */ | ||
| private async sendGroupWebhook(data: any): Promise<void> { | ||
| try { | ||
| // Check if this group webhook should be processed (only ConsentService operations for groups) | ||
| if (!shouldProcessWebhook(data.id, "groups")) { | ||
| console.log(`⏭️ Skipping group webhook for ${data.id} - not from ConsentService (protected entity)`); | ||
| return; | ||
| } | ||
|
|
||
| // Skip groups with Match ID in description (already processed) | ||
| if (data.description && typeof data.description === 'string' && data.description.startsWith('Match ID:')) { | ||
| console.log(`🔍 Skipping group webhook - has Match ID in description: ${data.description}`); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify that the OperationContext module exists.
The import references
../context/OperationContext, but this module is not included in the files under review. Ensure thatwithOperationContextis implemented and exported from this module.Run the following script to verify the module exists and exports the required function:
🏁 Script executed:
Length of output: 31
The web search results are not related to the specific dreamsync-api project. Let me search the codebase to find if OperationContext exists anywhere and to understand the structure better.
🏁 Script executed:
Length of output: 1232
The OperationContext module is missing and will cause a runtime import error.
The import on line 8 references
../context/OperationContext, but neither thecontextdirectory nor theOperationContext.tsfile exist in the codebase. ThewithOperationContextfunction is called on line 27, but it has no implementation anywhere in the repository. Create the missing module with the required export, or remove/replace this import if it's not needed.🤖 Prompt for AI Agents