Skip to content
Loom Docs
Esc
↑↓navigate↵open⌘Jpreview
Product
View as Markdown
On this page

Document source push notifications

Needs LOOM_KNOWLEDGE_SOURCE_PUSH_ENABLED=true to request document source syncs from provider notifications.

Needs LOOM_KNOWLEDGE_SOURCE_PUSH_ENABLED=true to request document source syncs from provider notifications. Notifications never write document content or change the source’s access policy. The normal 15-minute poll remains enabled and is the recovery path for missed deliveries. Disabling push pauses setup, deliveries and renewal without preventing secret resealing or setup retirement.

Source entry points

  • server/knowledge/api/ops_source_push.py (OPERATIONS) declares admin setup, confirmation and status operations.
  • server/knowledge/app/source_push_routes.py (notification) bounds callback bodies and dispatches provider deliveries.
  • server/knowledge/app/source_push.py (receive, _fresh, _put, renew_drive, reseal_registry) authenticates hints and coordinates registry lifecycle writes.
  • server/knowledge/domain/source_push.py (fingerprint, verify_drive, verify_notion, verify_linear, IRRELEVANT_TYPES) binds setup, verifies provider proof and says whether a proven delivery requests a sync; server/knowledge/store/source_push.py (get, put) persists registry versions.
  • server/knowledge/app/sources.py (sources_lease, deactivate_namespace_sources) coordinates source lifecycle changes; server/erasure/store/steps_ledgers.py (delete_source_push_by_namespace) settles registry erasure.

Invariants

  • Authenticated deliveries request sync through the existing source path. Provider payloads cannot write content or widen source access.
  • A delivery must match the current source ID, setup generation and credential, item and configuration fingerprint. The source lease and sequential reads fence source replacement, retirement and late provider responses.
  • Push secrets use purpose-bound sealing. Only an admin can reveal a pending challenge; ordinary reads, audit subjects and idempotency replay omit it.
  • Registry writes and namespace erasure share a fenced writer lease. Erasure removes every stored version, and setup publication requires verified fleet support for that erasure step.

Registration and authentication

The push registry is separate from the source registry and sync cursors. A row binds an org, namespace, source ID, provider and random setup generation to a fingerprint of the source’s credential and items. Configuration is an admin operation. An explicitly configured HTTPS public base URL is required.

The callback URL puts the namespace, source ID and setup generation in the path and the exact organization in the required org query parameter. Query encoding preserves organization names that contain slashes or reserved URL characters. A callback re-reads the registry and current source under the namespace’s source lease before recording a sync request. A removed or replaced source, changed credential, changed item set, inactive namespace or retired generation refuses the delivery. Callback payloads and headers are not stored or logged.

  • Drive channels use independent random channel IDs and sealed channel tokens. A delivery must match the active channel ID, token and resource ID before its expiration. This is channel-token verification: Drive does not sign these deliveries. Early sync notifications are acknowledged without requesting work. Watch responses are activated only after rechecking the setup generation.
  • Notion setup captures one bounded, sealed verification challenge for a fresh generation. Only an admin can reveal it while setup is pending. After verifying the subscription in the provider’s UI, the admin confirms that exact generation and challenge fingerprint. An unsigned challenge cannot activate a subscription or request sync. Active deliveries require the raw-body HMAC and the configured workspace identity.
  • Linear setup first exposes a pending notification address. The admin creates its webhook there, then confirms the same generation with its signing secret. Deliveries require the raw-body HMAC, the signed body’s millisecond timestamp within one minute and the configured organization identity.

Provider identity is read using the source’s existing credential during setup. Notification bodies have a fixed size limit. Duplicate valid notifications coalesce with the existing pending sync request; a waiting full sync is preserved. Successful callbacks answer HTTP 200 within a four-second handler budget.

From a delivery to a turn

A proven delivery about the source’s documents records a sync request and marks it for the knowledge_source_requests worker, as knowledge.source.sync_now does (request_sync in server/knowledge/app/source_push.py, start_soon in server/knowledge/app/sources.py). What it costs depends on what it finds:

The delivery finds It reads It writes
The source’s marker reads pending The setup, the source, its namespace, the open erasures and the marker Nothing
No request waits The same, then the sync state One state row with requested_at and push_delivered_at, then the marker
A request waits with no marker: a turn runs on it, or it is left to the pass The same, then the sync state The marker only, where start_soon writes one

The first row is the path of a burst. It is answered before the namespace’s sources lease, because it writes nothing: a lease taken per delivery would queue the deliveries of one namespace behind each other and past the handler budget. The other two rows prove the delivery again under the lease, which fences their writes against a source removed, replaced or rotated meanwhile. A source’s sync state can be a megabyte, so the first row neither reads nor writes it. start_soon writes no marker for a source whose last turn did not end ok, an inactive namespace or a namespace an erasure will still run on: the request is recorded and waits for the sync worker’s pass, so a failing source gets no more turns than polling gives it.

push_delivered_at is what knowledge.source.push_status answers as last_delivery_at. It moves only in the second row. An exact time would cost a state write for every delivery of a burst.

A delivery during a turn is a new request. A turn’s start clears the marker, so a delivery that arrives while the turn runs finds a request with no marker and writes the marker again. When a complete turn ends with the request it started from still stored and the marker reading pending, it stores a fresh plain request in place of the one it served (_settle_request in server/knowledge/app/source_sync.py), and the request worker starts one more turn: after the gap when the turn wrote or retired a document, and after the hold below when it did not, since the same write then sets the hold. An edit the turn’s listing was too early for is read by that turn. A turn that ended incomplete or failed keeps its request anyway. A marker’s row is ordered by the ClickHouse servers’ clocks, like the sync state: a pending that sorts under an earlier clear leaves the request to the pass, and a clear that sorts under an earlier pending costs one more turn.

The hold. A turn that served a request, ended ok and complete, and neither wrote nor retired a document stores request_idle_at. The request worker starts the source’s next turn no earlier than LOOM_KNOWLEDGE_SOURCE_SYNC_REQUEST_GAP_SECONDS after its last turn and one sync interval after request_idle_at (prompt_not_before in server/knowledge/domain/sources.py), so deliveries that concern none of the source’s documents start one turn per sync interval. A turn that wrote or retired a document removes request_idle_at; every other turn leaves it. knowledge.source.sync_now, knowledge.source.update and loom knowledge sync --full clear it in the write that records their request, and a turn never sets it once another request was made while it ran, so a person’s request waits the gap only. The request worker reads a waiting marker again after one gap at most, which is how it sees that a person’s request ended a hold.

Deliveries that request a sync

A delivery to an active setup is refused when its proof fails, whatever type it announces; the type is read only after the proof. The proof is checked on the setup row alone, before the source, its namespace and the open erasures are read, so a request without one costs one point read and is answered by nothing else. A proven delivery requests a sync unless it cannot concern the source’s documents:

  • A linear or notion delivery requests none when its type is on its provider’s deny-list (IRRELEVANT_TYPES): Issue and Comment for linear, and comment.created, comment.updated and comment.deleted for notion. Every other type, and a delivery that names none, requests a sync.
  • A gdrive delivery requests a sync only when its resource state is change. A sync message says that a channel was created.

A delivery that requests nothing is answered 200. The receiver does not read the sync state for it and writes no row.

The list holds only types a source’s turn never requests. A linear source’s turn requests projects and their documents (server/knowledge/app/source_sync_linear.py), and a notion source’s turn pages, blocks, databases and data sources (server/knowledge/app/source_sync_notion.py). Neither requests an issue or a comment. The tracker feed that copies a team’s issues and comments (server/tracker/app/linear_feed.py) polls and takes no request from a delivery. A type about a document, a project, a page, a database or a data source is never on the list, and a type leaves the list in the change that makes a turn request it.

The list denies types and allows the rest. A type that is missing from it costs one sync request that finds nothing to write. A wrong value on an allow-list would drop every request of a kind without an error. A type that is wrongly on the list costs its source the turn a request starts and the head of the next pass, and loses no change: the pass (run_sync in server/knowledge/app/source_sync.py) reaches every source in rotation. A delivery about an item outside the source’s own items also requests a sync: the turn decides what is read, not the payload.

Each denied type has a delivery in tests/unit/fixtures/source_push_deliveries.json. tests/unit/test_source_push_proofs.py fails for a denied type without one.

Event types to subscribe to

A subscription needs only the events that announce something a turn reads:

Source kind Subscribe to What the requested turn does
linear Documents (Document) Writes a document’s body, title and address, and retires a removed document
linear Projects (Project) Reads each listed project’s documents; a project it cannot read fails the turn
notion page.content_updated Writes a page’s body
notion page.properties_updated Writes a page’s title
notion page.created, data_source.content_updated Writes a page added to a listed database or under a listed page
notion page.moved, page.deleted, page.undeleted Lists a page that is now in the source; leaves out one in the trash
notion The other database and data_source events Reads each listed database; one in the trash fails the turn
gdrive Nothing to choose: a channel reports every change in the account’s corpus as the state change Writes the changed files of the source’s folders

A payload is never evidence of a deletion: a turn decides what to retire from the provider’s API (syncing a source). A delivery requests an incremental turn, so a notion or gdrive document of a page in the trash or a removed file stays until the next complete full listing.

Drive coverage and renewal

A Drive user change channel does not cover every shared-drive change. Setup therefore creates channels for the user corpus and every shared drive the account belongs to, up to 19 drives. A complete, bounded membership listing avoids mistaking a directly shared file’s drive ID for membership: a nonmember’s directly shared items use the user log. Setup refuses an incomplete or over-limit corpus set rather than claiming complete push coverage. Moving a file to a new corpus may require setup again; polling still discovers the change.

A bounded, default-off worker renews channels before expiration. It creates a new unique channel, validates the response and source generation, then swaps it under the source lease. It stops the old channel best effort. A failed renewal leaves polling available and exposes the expired channel in setup status.

The configuration catalog controls the provider-work, per-channel stop, total cleanup and worker-pass deadlines. Their defaults are 40, two, five and 120 seconds. A pass stops starting renewals with enough time for one provider attempt and two cleanup windows. Configuration refuses provider work plus cleanup that could outlive the 48-second work window within the 120-second renewal lease, or a pass budget that leaves no time to start a renewal. The channel stop deadline cannot exceed the total cleanup window.

Lifecycle and storage

The registry is ordered by org, namespace and source ID, so namespace reads prune their physical key range. Maintenance scans advance in that same order. The registry stores the full identity tuple, server-stamped actor and derived provenance. Secrets use purpose-bound sealing and participate in resealing. Ordinary source reads and audit subjects never include tokens or challenges. The admin setup read bypasses idempotency replay storage, so a revealed pending challenge cannot be replayed from an ordinary cache after activation.

Source removal, credential rotation, item updates and namespace retirement retire push setup under the same source lease. Late external watch responses cannot revive retired setup. Namespace erasure removes every registry version through the existing settled erasure machinery. Configuration writes require a fleet that understands the registry’s erasure step; an unreadable fleet refuses. Before rolling back to a build without this registry, disable push, erase the registry rows with the current build and verify the namespace erasures complete. Provider channels that cannot be stopped expire; retired callbacks refuse them.

Alternatives

Putting push state in the source row would make every delivery contend with credential writes and risk carrying an old credential forward. Putting it in sync detail would mix sealed setup secrets with ordinary inspection output. Both are avoided by the separate registry. Notifications are hints, so a durable event queue, provider payload archive and a second ingestion path are unnecessary.

Provider contracts

Last updated on

Was this page helpful?