Skip to content

Conversation

@jcortes
Copy link
Collaborator

@jcortes jcortes commented Aug 20, 2025

WHY

Resolves #18102

Summary by CodeRabbit

  • New Features

    • Respects settings to include or exclude new pages when emitting change events.
  • Bug Fixes

    • More reliable detection of property changes for existing pages.
    • Consistent tracking of property values for all pages, eliminating inconsistent handling of new pages.
  • Chores

    • Bumped Notion component version to 0.9.1.
    • Incremented Updated Page module version to 0.1.11.

@jcortes jcortes self-assigned this Aug 20, 2025
@vercel
Copy link

vercel bot commented Aug 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
pipedream-docs Ignored Ignored Aug 20, 2025 5:32pm
pipedream-docs-redirect-do-not-edit Ignored Ignored Aug 20, 2025 5:32pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 20, 2025

Walkthrough

Version bumps applied to Notion components. The updated-page source refactors new-page detection to a page-level check, tracks property values for all pages, and gates emissions based on includeNewPages. Events now emit on property changes for existing pages and optionally for new pages.

Changes

Cohort / File(s) Summary
Notion package version
components/notion/package.json
Bumped version 0.9.0 → 0.9.1. No other metadata changes.
Updated Page source logic
components/notion/sources/updated-page/updated-page.mjs
Bumped version 0.1.10 → 0.1.11. Refactored page-level existence check, removed inner-loop redefinitions, persisted property values for all pages, and gated emissions based on includeNewPages and property change status.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant P as Scheduler/Poller
  participant N as Notion API
  participant U as UpdatedPage Source
  participant E as Event Stream

  P->>U: Invoke run()
  U->>N: Query database pages
  N-->>U: Pages with properties

  loop For each page
    U->>U: pageExistsInDB = propertyValues[page.id] != null
    alt Existing page
      loop For each property
        U->>U: Compare current vs stored
        alt Changed
          U->>E: Emit change event
        else Not changed
          U->>U: No emit
        end
        U->>U: Update stored value
      end
    else New page
      U->>U: Ensure propertyValues[page.id] initialized
      loop For each property
        U->>U: Store current value
        alt includeNewPages == true and Changed
          U->>E: Emit change event
        else Gate emission
          U->>U: No emit
        end
      end
    end
  end

  U-->>P: Complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Emit events when a page is updated in the database (#18102)
Emit events for new pages when configured (includeNewPages) (#18102)
Prevent “Waiting” state by ensuring trigger produces event data (#18102) Depends on external runtime behavior and polling cadence; not verifiable from code alone.

Poem

I twitched my whiskers at the queue’s long wait,
Now pages hop with changes, up to date!
New kits or elders, we log each trace,
If flagged, we thump—events in place.
Version bumps tucked in my cozy burrow—
Onward we scamper, no more idle furrow. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-notion-sources-not-emiting-events

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
components/notion/sources/updated-page/updated-page.mjs (2)

79-84: Potential crash when state is absent or from older deployments (inflate undefined/legacy JSON).

on cold starts or migrated sources, this.db.get("propertyValues") can be null/undefined or contain legacy (uncompressed) JSON. Calling Buffer.from(compressed, "base64") and inflateSync will throw, preventing runs and emissions.

Harden _getPropertyValues to:

  • Return {} if the key is missing.
  • Try deflate/base64 first, then fall back to direct JSON parse for backward compatibility.

Apply this diff:

   _getPropertyValues() {
-      const compressed = this.db.get("propertyValues");
-      const buffer = Buffer.from(compressed, "base64");
-      const decompressed = zlib.inflateSync(buffer).toString();
-      return JSON.parse(decompressed);
+      const compressed = this.db.get("propertyValues");
+      if (!compressed) return {};
+      try {
+        const buffer = Buffer.from(compressed, "base64");
+        const decompressed = zlib.inflateSync(buffer).toString();
+        return JSON.parse(decompressed);
+      } catch (err) {
+        // Backward compat or corrupted state: attempt direct JSON parse; otherwise, start fresh
+        try {
+          return typeof compressed === "string" ? JSON.parse(compressed) : {};
+        } catch {
+          return {};
+        }
+      }
   },

133-140: Early return should precede state load to avoid unnecessary (and potentially failing) reads.

If LAST_EDITED_TIME is null (e.g., right after deactivation or before first activation completes), we should skip without touching propertyValues. Currently, _getPropertyValues() is called before the guard, which can still throw if state is missing.

Apply this diff:

   async run() {
     const lastCheckedTimestamp = this._getLastUpdatedTimestamp();
-    const propertyValues = this._getPropertyValues();
-
-    if (!lastCheckedTimestamp) {
+    if (!lastCheckedTimestamp) {
       // recently updated (deactivated / activated), skip execution
       console.log("Awaiting restart completion: skipping execution");
       return;
     }
+    const propertyValues = this._getPropertyValues();
🧹 Nitpick comments (1)
components/notion/sources/updated-page/updated-page.mjs (1)

67-69: Log says “clearing states” but only timestamp is cleared; consider clearing cached property snapshots too.

Small consistency nit. Either update the message or clear propertyValues so state is fully reset on deactivate. Clearing avoids stale snapshots and reduces storage.

Apply this diff to clear the cache:

   async deactivate() {
     console.log("Deactivating: clearing states");
     this._setLastUpdatedTimestamp(null);
+    // Clear cached property snapshots to force a re-sync on next activation
+    this.db.set("propertyValues", null);
   },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c376b6c and ef27314.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • components/notion/package.json (1 hunks)
  • components/notion/sources/updated-page/updated-page.mjs (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: GTFalcao
PR: PipedreamHQ/pipedream#15376
File: components/monday/sources/name-updated/name-updated.mjs:6-6
Timestamp: 2025-01-23T03:55:15.166Z
Learning: Source names in Monday.com components don't need to start with "New" if they emit events for updated items (e.g., "Name Updated", "Column Value Updated") rather than new items. This follows the component guidelines exception where the "New" prefix is only required when emits are limited to new items.
🧬 Code Graph Analysis (1)
components/notion/sources/updated-page/updated-page.mjs (1)
components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs (1)
  • isNewPage (74-74)
🔇 Additional comments (6)
components/notion/package.json (1)

3-3: Version bump aligns with PR scope.

Increment to 0.9.1 is appropriate to publish the updated source behavior.

components/notion/sources/updated-page/updated-page.mjs (5)

12-12: Version bump acknowledged.

Increment to 0.1.11 reflects functional changes in the source.


169-172: New-page detection via presence in persisted state looks correct.

Using propertyValues[page.id] != null for existence is robust and fixes per-iteration re-declarations.


196-212: Tracking properties for new pages while gating emission via includeNewPages is sound.

This ensures we always seed state for new pages (preventing future false positives) and only emit when configured.


215-219: Emission gating is correct and matches expected behavior.

Emits for existing pages on changes, and for new pages only when includeNewPages is true.


165-167: Confirmed descending sort; early break is safe.

The lastUpdatedSortParam method (in components/notion/sources/common/base.mjs) sets direction: constants.directions.DESCENDING. Pages are fetched in descending order of last_edited_time, so once you encounter a timestamp older than lastCheckedTimestamp, it’s correct to break.

Copy link
Collaborator

@GTFalcao GTFalcao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@vunguyenhung vunguyenhung merged commit deb2971 into master Aug 22, 2025
10 checks passed
@vunguyenhung vunguyenhung deleted the fix-notion-sources-not-emiting-events branch August 22, 2025 05:07
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.

Notion: New or Updated Page in Database is not emitting events

4 participants