#4820·cognee

Hackathon [Feature]: Add incremental sync to the Notion connector

Author: NMZivkovicCreated Aug 28, 2026Updated Sep 30, 2026
LabelsenhancementINTEGRATIONShackathon

Problem Statement

Unlike the other connector tickets in this batch, the Notion connector already exists — packages/connector/notion/ in cognee-community has a working DLT source (~290 lines), tests, an example, and a README. #4541 even points contributors at it as the reference implementation. Read it before you start; this is not a greenfield ticket.

Two things are missing.

1. Every sync re-reads the entire workspace. The source is a full snapshot (write_disposition="replace"), and _page_to_row calls _render_blocks for every page on every run. Unchanged pages are not re-cognified — the content-hash data_id already prevents that, so the LLM cost is fine — but the Notion API read cost is paid in full each time. On a large workspace that means thousands of block-children calls per sync, against Notion's rate limit, to rediscover text that did not change.

2. There is no OAuth flow. Auth is a single internal integration token (NOTION_API_KEY), which works for one workspace you control. A hosted "connect your Notion" experience needs Notion's public OAuth.

Proposed Solution

Incremental fetch, without breaking deletion. This is the interesting constraint and the reason the ticket is not trivial: forget-on-delete depends on the snapshot being complete. If you skip pages, orphan_cleanup reads their absence as deletion and forgets live pages from the graph. Any design must keep listing every visible page while skipping only the expensive part.

The shape that satisfies both:

  • Keep enumerating every page each run (cheap — search/database.query are paginated list calls), so the snapshot stays authoritative.
  • Compare each page's last_edited_time against the previous run's watermark.
  • Only call _render_blocks for pages that changed; reuse the stored content for the rest.
  • Preserve the existing failure semantics: a render error must still abort the run rather than yield a partial snapshot. The current code documents exactly why — a partial snapshot silently forgets memory.

Note the existing subtlety in _page_to_row: last_edited_time bumps on metadata-only edits that do not change text. Using it as a fetch filter is fine (worst case you re-render a page unnecessarily); using it as the data_id would cause churn, which is why the content hash exists. Do not replace the content hash with it.

OAuth can be a second PR, or a second contributor: add the public OAuth flow alongside the token path, keeping the token path as the default for local use.

Watch out for

  • Do not switch away from the full snapshot. It looks wasteful and is load-bearing. The module docstring explains why merge + hard_delete cannot work here — Notion omits trashed pages rather than flagging them.
  • Pages can be unshared rather than deleted; _is_gone already treats that as "forget", which is correct. Keep that behaviour.
  • Blocks nest, and _render_blocks recurses with a depth guard. Any caching must key on page id and handle child-block edits that do not bump the parent's last_edited_time.

Acceptance Criteria

  • A second sync with no upstream changes performs no blocks.children calls
  • Editing one page causes exactly that page to be re-rendered
  • Deleting, trashing, or unsharing a page still removes it from the graph on the next sync
  • A render failure mid-run still aborts without leaving a partial snapshot
  • Existing tests continue to pass, plus new tests for the watermark and the deletion path
  • README documents the watermark and where it is stored
  • (Optional, or a follow-up PR) Notion public OAuth alongside the existing token auth

Context

Part of the cognee hackathon connector push. Difficulty: Intermediate (M) — the code is small, but the snapshot/deletion interaction is the part to get right. Best suited to someone who wants a correctness puzzle rather than a fresh API integration.