Skip to content

feat(#501): Part B — narrowing routes answer only once the PDP enforces them - #56

Merged
PMQ9 merged 3 commits into
wiki-v2from
fix/501-narrowing-settle
Sep 23, 2026
Merged

PMQ9 merged 3 commits into
wiki-v2from
fix/501-narrowing-settle

Conversation

@PMQ9

@PMQ9 PMQ9 commented Sep 23, 2026

Copy link
Copy Markdown

TL;DR

A fork request that takes access away now responds only after the platform confirms the PDP enforces it, and says so in an Authz-Propagation: confirmed | pending response header. Fork half of wiki-v2 issue 501, Part B.

Context

A narrowing change (restrict, grant removal or downgrade, member removal or demotion, archive, move) commits in the fork DB first. It then reaches SpiceDB through the outbox → platform relay, and until then every decision still allows the old access. Before this change the response came back at once, so the actor would restrict a page and then paste the confidential text into it while the old readers could still see it (the Zanzibar "new enemy" problem). Design: ADR 0026 §4 in cccvu/wiki-v2.

Related issues

  • Refs cccvu/wiki-v2 issue 501 (Part B; the paired super PR closes it). Part A was PR 54.

What changed

  • authz/live-access/narrowing-settle.interceptor.ts (new APP_INTERCEPTOR, registered from the fork-owned CollabDisconnectModule, so no upstream file changes). Runs only in remote mode, on the routes in the table, and only after the handler succeeds:

    1. The fence P = the max COMMITTED outbox position.
    2. POST /sync/settle {position: P} on the platform.
    3. On confirmed, LiveAccessRevalidator.signal('narrowing'), awaited for at most 1.5 s.
    4. Sets the Authz-Propagation header.

    It never throws and never changes the status or body. Handler errors pass through untouched.

  • authz/live-access/narrowing-routes.ts: the table, keyed <Controller>.<handler>.

    • PageRestrictionController.{restrict, addPermission, removePermission, updatePermission}
    • PageController.{movePage, movePageToSpace}
    • SpaceController.{removeSpaceMember, updateSpaceMemberRole}
    • GroupController.removeGroupMember
    • ServiceSpaceController.{archive, addMember, changeMemberRole, removeMember}

    addPermission and addMember are upserts that can demote. narrowing-routes.spec.ts checks every entry against the static route scan.

  • service-bridge/authz-change-feed.service.ts: maxCommittedPosition(db), which reads with no xmin gate. It must never be head(): head is gated by the oldest open transaction, so while any unrelated transaction is open it sits before this request's rows. A settle fenced there would be a false confirmed. A real-PG spec pins this.

  • authz/http-authz.client.ts: settleProjection(position, waitMs). It resolves confirmed only on a well-formed 200 that says so. A 404 (a platform without the route), a timeout, a transport error or a malformed body resolves pending. Its deadline is the wait + 500 ms.

  • Budget.

    • AUTHZ_NARROWING_SETTLE_TIMEOUT_MS: default 3000, clamped to 5000. 0 = pass-through, which is the rollback switch.
    • The whole request is kept under 6 s, below the platform's 8 s relay and service-client timeouts. A slow handler leaves less wait, down to a single check.
  • Contracts.

    • authorization-service.openapi.json 1.1.0 adds /sync/settle as an OPTIONAL op. A 404 makes every narrowing response pending, so a third-party authorization service still works.
    • service-bridge.openapi.json 1.6.0 documents the header on archive and the member writes.
    • The contract README is updated.

How this was tested

  • npx jest src/authz src/service-bridge src/collaboration src/ws, with real Postgres (AUTHZ_TEST_PG_URL): 87 suites, 1019 passed.
  • New tests:
    • Interceptor spec (11):
      • confirmed and pending paths, a fence read failure, handler errors passing through;
      • the non-table, native-mode and =0 pass-throughs;
      • budget math, the bounded revalidation, and a reply already sent.
    • Route-table cross-check: 16 cases.
    • settleProjection (7): unit tests, plus 2 consumer-contract tests against the canonical OpenAPI example.
    • Real PG:
      • the fence covers a just-committed row while head() is still before it;
      • an empty outbox gives 0.0.
  • npx tsc --noEmit -p tsconfig.build.json is clean, and eslint is clean on the changed files.
  • The super scripts/check-upstream-boundary.sh passes on the committed HEAD (no upstream files touched).

AWS / infra apply

N/A for this PR. The paired super PR adds one CloudWatch alarm and its scripted apply.

Checklist

Scope

  • Complete and scoped to one logical concern — no unrelated drive-by changes (or follow-ups noted below).

Tests

  • New/changed behavior has appropriate tests — unit / integration / e2e / security / regression as applicable (or N/A, with why).
  • Existing tests pass, and any new tests pass.

Docs & contracts

  • Docs added/updated where needed (README / docs/ / an ADR), or N/A.
  • Any API/contract, config, migration, permission, or deployment impact is called out in this PR, or N/A.
  • Any AWS/infra apply is described precisely, scoped (no mass-apply), and captured in a reviewable one-time script — see "AWS / infra apply" above, or N/A.

Safety (this is a security-first, deny-by-default platform)

  • Security, authorization, data integrity, failure paths, and backward compatibility considered, or N/A.
  • Upstream boundary respected — no undocumented edits to Docmost-owned files (see UPSTREAM_MODIFICATIONS.md); proprietary/authz logic stays out-of-process.

Housekeeping

  • Related issue(s) linked above.
  • Known limitations, follow-ups, or intentionally deferred work identified below.

Known limitations / follow-ups

  • The fence is global on purpose. It can over-wait when someone else commits a bulk structural change during the request. The result is then pending, never a wrong confirmed. A per-request fence could under-wait; ADR 0026 §4 explains why.
  • confirmed is about the PDP. Only this node's live sessions get the bounded re-check. Other nodes rely on their sweep (≤ 60 s).
  • Paths outside the table stay eventual. That covers trash, deletes and deactivations; see the ADR 0026 table.
  • Merge order: merge this first with a MERGE commit, then re-pin the super gitlink.

🤖 Generated with Claude Code

PMQ9 and others added 3 commits September 23, 2026 10:26
… enforces them

A request on a route that takes access away (restrict + page grants, move / move-to-space,
native member remove / change-role, group-member remove, service-bridge archive + member
writes) now waits, after the handler succeeds, for the platform relay to project it:

- fence = the max COMMITTED authz_outbox position (`maxCommittedPosition`, ungated; never
  the xmin-gated head(), which sits before this request's rows while any older transaction
  is open — a real-PG spec pins it)
- `POST /sync/settle` on the platform (bounded; a 404 / timeout / malformed answer is pending)
- on confirmed, this node's live connections get a re-check (<= 1.5 s)
- `Authz-Propagation: confirmed | pending` on the response; status and body untouched,
  handler errors pass through, never throws

APP_INTERCEPTOR registered from the fork-owned CollabDisconnectModule (no upstream file
changes). Route table keyed <Controller>.<handler>, cross-checked against the static route
scan. Budget: AUTHZ_NARROWING_SETTLE_TIMEOUT_MS (default 3000, max 5000; 0 = pass-through
rollback switch), whole request kept under 6 s (below the platform's 8 s relay timeout).

Contracts: authorization-service 1.1.0 (optional /sync/settle op), service-bridge 1.6.0
(Authz-Propagation on archive + member writes).

Refs cccvu/wiki-v2#501

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…no-verdict pendings, report dropped rows

- interceptor: read the fence BEFORE the handler too; unchanged after it means the request committed no access
  change (a same-parent reorder, a no-op), so nothing is settled and no header is sent (Performance).
- a pending the platform gave NO verdict for (unreachable / no route / rejected / past the deadline) is logged here
  with the alarmed AUTHZ_PROPAGATION_PENDING (reason=settle-*); platform-answered pendings stay a plain warn.
- unrestrict (PageRestrictionController.removeRestriction) is a narrowing route: it drops every grant.
- settle margin 500 -> 1500 ms (the platform's confirm step can exceed 500 ms); a third-party reason string is
  sanitised before it is logged.
- feed: report `dropped` rows (known table, no event) so the platform dead-letters the batch and a settle cannot
  answer a false confirmed over an unprojected change (Correctness F2). service-bridge 1.6.0 schema + pin.
- contracts: positions/cursors order as an integer pair (xact_id, id), never as strings (Architecture).
- tests: fence skip + ordering, no-verdict alarm line, failing/capped live-session pass, non-HTTP, reason sanitising.

Refs cccvu/wiki-v2#501

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PMQ9
PMQ9 merged commit d6a4e09 into wiki-v2 Sep 23, 2026
@PMQ9
PMQ9 deleted the fix/501-narrowing-settle branch September 23, 2026 16:37
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