Skip to content

Conversation

@coodos
Copy link
Contributor

@coodos coodos commented Oct 19, 2025

Description of change

Issue Number

Type of change

How the change has been tested

Change checklist

  • I have ensured that the CI Checks pass locally
  • I have removed any unnecessary logic
  • My code is well documented
  • I have signed my commits
  • My code follows the pattern of the application
  • I have self reviewed my code

Summary by CodeRabbit

Release Notes

  • New Features
    • Implemented operation context tracking system to monitor and control database operation origins
    • Enhanced webhook processing with consent-based security controls to protect sensitive entity interactions and prevent unauthorized notifications

@coodos coodos merged commit fafe04b into main Oct 19, 2025
0 of 3 checks passed
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 19, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR introduces a request-scoped operation context system to track database operation origins and control webhook processing. It adds a singleton OperationContextManager with automatic expiry, integrates context wrapping into ConsentService, and gates webhook processing in subscriber.ts based on active operation contexts.

Changes

Cohort / File(s) Summary
Operation Context Infrastructure
platforms/dreamsync-api/src/context/OperationContext.ts
Introduces OperationContextManager singleton with context creation, expiry tracking (30s), and cleanup. Exports withOperationContext decorator and shouldProcessWebhook helper for gating protected operations (groups, messages) unless ConsentService context is active.
Consent Service Integration
platforms/dreamsync-api/src/services/ConsentService.ts
Wraps processConsentResponse in withOperationContext with unique operationId per run. Moves error handling inside the context wrapper while preserving existing functional behavior.
Webhook Processing Gates
platforms/dreamsync-api/src/web3adapter/watchers/subscriber.ts
Adds shouldProcessWebhook checks across three code paths (handleChange, handleJunctionTableChange, sendGroupWebhook) to skip webhook processing for protected entities outside ConsentService context. Adds early returns and logging for skipped webhooks.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ConsentService
    participant OperationContextManager
    participant Subscriber
    participant Webhook
    
    Client->>ConsentService: Request consent response
    ConsentService->>OperationContextManager: createContext('ConsentService', operationId)
    OperationContextManager->>OperationContextManager: Store context with 30s TTL
    
    ConsentService->>ConsentService: processConsentResponse()
    ConsentService->>Subscriber: Trigger data changes
    
    Subscriber->>OperationContextManager: shouldProcessWebhook(entityId, 'groups')
    OperationContextManager->>OperationContextManager: Check if ConsentService context active
    alt Context Active
        OperationContextManager-->>Subscriber: true
        Subscriber->>Webhook: Send webhook
    else No Active Context
        OperationContextManager-->>Subscriber: false
        Subscriber->>Subscriber: Skip webhook (log)
    end
    
    ConsentService->>OperationContextManager: removeContext() [on completion]
    OperationContextManager->>OperationContextManager: Clear context entry
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

The PR introduces a new context management system with integration across three distinct files. While individually straightforward, the review requires understanding the singleton pattern, context lifecycle, automatic expiry mechanics, and how the gating logic correctly handles edge cases (protected tables, ConsentService bypass). The changes are cohesive but not repetitive, warranting moderately careful examination.

Possibly related PRs

Poem

🐰 A context is born with each operation's grace,
Thirty seconds to live in its temporal space,
Gating the webhooks with careful precision,
Protecting our groups with each wise decision,
The manager cleans up what time leaves behind,
A safer DreamSync, thoughtfully designed.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/idempotency-logic-on-dreamsync-adapter

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62a1329 and 33c95fa.

📒 Files selected for processing (3)
  • platforms/dreamsync-api/src/context/OperationContext.ts (1 hunks)
  • platforms/dreamsync-api/src/services/ConsentService.ts (3 hunks)
  • platforms/dreamsync-api/src/web3adapter/watchers/subscriber.ts (4 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coodos added a commit that referenced this pull request Nov 4, 2025
* fix: idempotency in dreamsync adapter

* chore: add file
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