Skip to content

feat(service-bridge): fork-owned authz change feed + snapshot (Group D R1, issue #171) - #14

Merged
PMQ9 merged 2 commits into
wiki-v2from
feat/standalone-group-d
Sep 4, 2026
Merged

PMQ9 merged 2 commits into
wiki-v2from
feat/standalone-group-d

Conversation

@PMQ9

@PMQ9 PMQ9 commented Sep 4, 2026

Copy link
Copy Markdown

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_outbox table + 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 the authz_outbox table + 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 enriches page_permissions with page_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). nextCursor advances past skipped rows; a cursor older than the retained window returns 409 {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, the page_access restriction idiom, the page_access_id -> page_id indirection). Reads camelCase payload keys because the fork's CamelCasePlugin recurses into the jsonb (verified via the spy compiler oracle).
  • ServiceScope.ChangesRead; both routes RemoteOnlyGuard then scoped ServiceAuthGuard.
  • 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 --noEmit clean; npx @redocly/cli lint clean; scripts/check-upstream-boundary.sh exit 0 (no file flagged; all additions are in excluded prefixes).

Notes / follow-ups

  • No consumer in this PR — the platform sync/ cutover onto the feed is R2 (the paired super PR), and dropping the platform's DOCMOST_DATABASE_URL is R3, after a soak.
  • The internal LISTEN is best-effort (postgres.js auto-reconnects); if it can't be established the feed degrades to poll latency, never an outage. This is a deliberate refinement of the "fail-closed" wording: the load-bearing part (table + triggers) fails the boot in remote; the latency optimization (LISTEN) does not.

🤖 Generated with Claude Code

PMQ9 and others added 2 commits September 4, 2026 13:50
…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]>
@PMQ9
PMQ9 merged commit ed96d1d into wiki-v2 Sep 4, 2026
@PMQ9
PMQ9 deleted the feat/standalone-group-d branch September 4, 2026 19:46
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.

1 participant