Repository navigation
feat(service-bridge): fork-owned authz change feed + snapshot (Group D R1, issue #171) - #14
Merged
Merged
Conversation
…D, issue docmost#171) Move the change-data-capture the platform's sync/ subsystem needs OUT of the platform (which reached into Docmost's DB) and INTO the fork, so the platform can later drop its Docmost DB credentials + DDL/NOTIFY privileges entirely. - AuthzOutboxInstaller: a mode-gated (remote-only), advisory-locked, idempotent boot installer of the authz_outbox table + authz_outbox_capture() AFTER triggers (moved from the platform). The trigger writes a change row inside Docmost's own write transaction (atomic + at-least-once) and enriches page_permissions with page_id. Fail-closed: refuses to boot in remote if it cannot establish the feed; installs NO CCC DDL in native. Superset-compatible with the platform's legacy outbox (keeps the notify channel + legacy columns) for the rollout window. - AuthzChangeFeedService: GET /api/service/authz/changes long-poll. The durable outbox is the source of truth (LISTEN/NOTIFY is wakeup-only); nextCursor advances past skipped rows; a stale cursor returns 409 {stale, head} so the platform rebaselines. Retention GC by age. - AuthzSnapshotService: GET /api/service/authz/snapshot, the full desired set as the same typed events, keyset-paginated on the IMMUTABLE row id (race-safe). - AuthzChangeEvent: typed domain events (owns all Docmost-schema knowledge, incl. the soft/hard-delete divergence + the page_access restriction idiom), so the platform is decoupled from Docmost's table/column names. Reads camelCase payload keys (the fork's CamelCasePlugin recurses into the jsonb). - ServiceScope.ChangesRead; both routes RemoteOnlyGuard then scoped ServiceAuthGuard. - Extend service-bridge.openapi.json (2 ops, typed-event schemas, changes:read) + README; provider-contract + scope-coverage specs updated; new unit specs for the mapper, feed (stale/cursor/long-poll), snapshot (phases), and installer. All under the boundary-excluded apps/server/src/service-bridge/ + docs/integrations/; zero upstream-owned edits. No consumer yet (the platform cutover is the paired super PR, Group D R2). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address the 7-lens /pr-review-comprehensive round 1 (0 blocking; the L3+ findings): - Security P3 (data minimization / write amplification): the capture trigger stored the FULL row via to_jsonb(NEW/OLD), so pages.content/ydoc landed in the retained outbox. Now stores ONLY the authz-relevant columns per table via jsonb_build_object (page_id enrichment preserved). - Security+Correctness P4 (latent, R2-facing): document the id>cursor commit-ordering at-least-once gap honestly (was overstated as "never lose an event"); the reconciler is the load-bearing backstop, and R2 MUST add a commit-safe watermark (xmin/low-watermark) before the feed is the sole live path (tracked docmost#171). - DevOps P3: correct the installer comment — ServiceBridgeModule IS reachable from the collab entrypoint (via DatabaseModule->AuthzModule), so the installer can run there too (dormant today; advisory-locked DDL + idempotent GC keep it safe). - Arch/DevOps/Correctness (R1 DDL co-existence): document that the fork + the legacy platform installer both create-or-replace the same capture function during the R1 window (benign, self-healing, retired at R2). - Testing P4/P3: make the installer retry bound env-configurable so the fail-closed path is testable; add specs for fail-closed-in-remote, retry-then-succeed, the page_permissions normal-DELETE branch, the empty-outbox stale-cursor branch, and the long-poll wake-on-NOTIFY early return. Column-scoped capture asserted. - Security P1 / Correctness nit: tighten the snapshot cursor to a strict UUID shape (400 not a 500 uuid-cast). - Architecture DOCS nit: add the missing 400 to the /changes OpenAPI op. Deferred (Level <=2, one follow-up issue): GC batching, the 3-query-per-getChanges round-trips, DRY event-shape parity, RETENTION/retry env docs, hardcoded sequence name, snapshot-phase SQL-compile breadth. Fork service-bridge 14 suites/87 tests + authz green; tsc + redocly + boundary clean. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Group D R1 (expand) of the standalone boundary epic (cccvu/wiki-v2#171, epic cccvu/wiki-v2#157): the fork now hosts a service-secret-guarded authz change feed + snapshot + outbox installer, so the CCC platform can stop reaching into Docmost's Postgres to capture and drain membership/page/restriction changes. No consumer yet, so this is behavior-preserving; the platform cutover is the paired R2.
Why
Today the platform installs an
authz_outboxtable + AFTER triggers in Docmost's DB,LISTENs on it, and reads six membership/page tables directly. That welds the platform to Docmost's exact schema and forces the platform to hold Docmost DB credentials + DDL/NOTIFY privileges. Group D moves the change-data-capture INTO the fork (which owns its schema); once the platform cuts over (R2) and the credential is dropped (R3), an upstream column rename is fixed only in the fork.What changed (all under the boundary-excluded
service-bridge/+docs/integrations/, ZERO upstream edits)AuthzOutboxInstaller— a boot installer of theauthz_outboxtable +authz_outbox_capture()AFTER triggers (moved verbatim from the platform). Mode-gated (installs NOTHING in native), advisory-locked (safe across replicas), idempotent, and fail-closed in remote (refuses to boot if it cannot establish the feed). The trigger writes the change row inside Docmost's own write transaction (atomic + at-least-once) and enrichespage_permissionswithpage_id. Superset-compatible with the platform's legacy outbox (keeps the NOTIFY channel + legacy columns) for the rollout window.AuthzChangeFeedService—GET /api/service/authz/changes, HTTP long-poll. The durable outbox is the source of truth; LISTEN/NOTIFY is wakeup-only (a missed wake is only latency).nextCursoradvances past skipped rows; a cursor older than the retained window returns409 {stale, head}so the platform rebaselines instead of skipping. Age-based retention GC.AuthzSnapshotService—GET /api/service/authz/snapshot, the full desired set as the SAME typed events, keyset-paginated on each row's immutable id (race-safe: no false orphan-delete on the platform under concurrent change).AuthzChangeEvent— typed domain events that own ALL Docmost-schema knowledge (soft/hard-delete divergence, thepage_accessrestriction idiom, thepage_access_id -> page_idindirection). Reads camelCase payload keys because the fork'sCamelCasePluginrecurses into the jsonb (verified via the spy compiler oracle).ServiceScope.ChangesRead; both routesRemoteOnlyGuardthen scopedServiceAuthGuard.service-bridge.openapi.json(+2 operations, typed-event schemas,changes:read) + README; provider-contract + scope-coverage specs updated; new unit specs for the mapper, feed (stale/cursor/long-poll), snapshot (phases), and installer.How this was tested
pnpm exec jest src/service-bridge— 14 suites / 81 tests green (incl. the new mapper/feed/snapshot/installer specs + the updated provider-contract + scope-coverage).pnpm exec jest src/authz— 22 suites / 219 tests green (regression).tsc --noEmitclean;npx @redocly/cli lintclean;scripts/check-upstream-boundary.shexit 0 (no file flagged; all additions are in excluded prefixes).Notes / follow-ups
sync/cutover onto the feed is R2 (the paired super PR), and dropping the platform'sDOCMOST_DATABASE_URLis R3, after a soak.🤖 Generated with Claude Code