Skip to content

feat(#501): re-check live realtime connections after narrowing access changes (fork, Part A) - #54

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

PMQ9 merged 3 commits into
wiki-v2from
fix/501-live-access

Conversation

@PMQ9

@PMQ9 PMQ9 commented Sep 23, 2026

Copy link
Copy Markdown

TL;DR

The fork now re-checks every live collab editor and notifications socket against the PDP after a narrowing access change (and on a per-node sweep), closing or narrowing the ones that lost access. It also fixes a lost-wakeup / xmin stall in the authz change feed. Fork half of wiki-v2 issue 501, Part A.

Context

Upstream authorizes a collab socket (onAuthenticate) and a notifications socket (ws.gateway) once, at connect. A restrict, a space-member removal or demotion, an archive or a group-grant removal never reached an open editor (it kept syncing) or an open notifications socket (it kept its space-* rooms and received tree titles and comment bodies). The only eviction was the per-page force-disconnect, which covered a user's page-grant removal and re-checked view only. Design: ADR 0026 in cccvu/wiki-v2.

Related issues

  • Refs cccvu/wiki-v2 issue 501 (Part A; Part B closes it). Paired super PR: cccvu/wiki-v2 fix/501-live-access.

What changed

  • authz/live-access/collab-access.decision.ts: a pure four-state mirror of onAuthenticate (deny | read | write | unknown); collab-access-parity.spec.ts drives the REAL extension and the mirror over the same facts (a mutation made it red).
  • authz/live-access/live-access.revalidator.ts: re-checks every resident collab connection (close on deny, or read on a writable connection) and every local socket.io socket (leave each space-* room it can no longer view; disconnect a missing/disabled user). Uses only tryCheckBulk (failure = unknown, no action; closed after 3 consecutive unknown passes). Never widens (static spec). Coalesced (one running + one queued pass), trailing pass 2 s after a signal, sweep on every node (LIVE_ACCESS_SWEEP_INTERVAL_MS, default 60 000, 0 = off, remote mode only).
  • POST /api/collab/revalidate (empty body, RemoteOnlyGuard + CollabServiceSecretGuard, bounded 5 s wait) replaces POST /api/collab/force-disconnect.
  • Seams: collaboration.gateway.ts gains getResidentDocuments() (#3g); the per-page forceDisconnectUserFromPage wrapper (#3a) and forceDisconnect handler (chore(wiki-v2): promote #57 platform-admin entry seam onto the durable branch #2) are removed. ws.gateway.ts: comment corrected (its forceDisconnectUser is cluster-wide).
  • page-restriction.service.ts: restrict invalidates the socket.io "space has restrictions" cache.
  • authz-change-feed.service.ts: a wake counter captured before the first read closes the lost-NOTIFY race; while committed rows are withheld by the xmin gate the long-poll re-polls every 250 ms instead of sleeping 25 s; LISTEN re-subscribe re-wakes.
  • service-bridge.openapi.json 1.5.0 (+ contract README / architecture notes).

How this was tested

  • npx jest src/authz src/service-bridge src/collaboration src/ws — 85 suites, 871 passed (pg specs skip without a DB).
  • Real Postgres (AUTHZ_TEST_PG_URL, throwaway container): authz-outbox-commit-safety.pg.spec.ts + page-restriction.pg.spec.ts — 22 passed; the new withheld-row case FAILS on the old feed code and passes on the new one.
  • npx tsc --noEmit -p tsconfig.build.json clean; scripts/check-upstream-boundary.sh (super) green on the committed HEAD; eslint/prettier: no new findings in changed files.

AWS / infra apply

N/A for this PR (the paired super PR adds CloudWatch alarms).

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

  • Contract: /api/collab/force-disconnect is removed; its only caller is the platform in the same task (the paired super PR switches to revalidate), and the ALB denies /api/collab/*.
  • Merge with a merge commit (not squash) so the super PR can re-pin its gitlink to it.
  • Residuals and follow-ups are listed in ADR 0026 and the paired super PR.

🤖 Generated with Claude Code

PMQ9 and others added 3 commits September 23, 2026 00:06
… access changes

Upstream authorizes a collab editor socket and a notifications/tree socket once, at
connect. A restrict, a space-member removal or demotion, an archive or a group-grant
removal therefore never reached an open editor (it kept syncing) or an open
notifications socket (it kept its space rooms: tree titles and comment bodies). The
only eviction was the per-page force-disconnect, which covered a user's page-grant
removal and re-checked view only.

- authz/live-access: LiveAccessRevalidator re-checks every live connection on this
  node against the PDP and only narrows. Collab: a mirror of onAuthenticate
  (decideCollabAccess, pinned by a parity spec against the real extension); deny,
  or read on a writable connection, closes it. socket.io: leave each space room the
  user can no longer view; disconnect a missing/disabled user. A PDP failure is
  "unknown" (no action) until 3 consecutive passes. Never widens (static spec).
- POST /api/collab/revalidate (empty body, service secret, remote only) replaces the
  per-page POST /api/collab/force-disconnect; a trailing pass 2 s later, and a sweep
  on every node (LIVE_ACCESS_SWEEP_INTERVAL_MS, default 60 s).
- Seams: collaboration.gateway getResidentDocuments() (#3g); the per-page
  forceDisconnectUserFromPage wrapper and forceDisconnect handler are removed.
- Restrict invalidates the socket.io "space has restrictions" cache.
- Change feed: a wake counter captured before the first read closes the lost-NOTIFY
  race; rows withheld by the xmin gate re-poll every 250 ms instead of sleeping the
  whole 25 s wait; LISTEN re-subscribe re-wakes. Real-Postgres spec included.
- service-bridge.openapi.json 1.5.0.

Refs cccvu/wiki-v2#501

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… connection; unknown cap is time-bounded

- page-editor seam (169) + features/editor-ux/collab-access: a per-document server
  CLOSE on a live socket reconnects so the server re-decides; a non-expiry refusal
  stops editing and shows the connection-lost status; a read-only authentication
  (demoted user) stops editing. Upstream's editor ignored the close entirely.
- LiveAccessRevalidator: narrow on unknown only after UNKNOWN_CAP passes spanning
  UNKNOWN_GRACE_MS (120 s) — a pass count alone collapsed to seconds under a burst
  of fast-path signals and could evict every editor on a PDP blip. That narrowing
  now logs LIVE_ACCESS_REVALIDATE_FAILED (the I/O-failure case never threw).
- Specs: burst-during-blip never narrows (mutation-checked), consecutive-only
  reset, the alarm token; realistic controller failure case; client unit tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…reopen on disconnect, not a timer

- The auth-failed handler decoded the token captured at mount; a refresh only
  updates remote.configuration.token. In a tab open past the token's life every
  later refusal read as an expiry: refetch -> reconnect -> refused, forever, never
  reaching the lost state. Now currentCollabToken + isCollabTokenExpired (fork-owned,
  unit-tested) judge the token the provider actually sends.
- The forced reconnect after a server close re-opens on the socket's own
  'disconnect' event: disconnect() keeps the status Connected until the browser's
  close event and connect() is a no-op while it reads Connected, so the 100 ms timer
  could strand the editor. Also never reconnects after unmount.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PMQ9

PMQ9 commented Sep 23, 2026

Copy link
Copy Markdown
Author

Heads-up from wiki-v2 issue 524 (fork PR 55). Once that PR merges, decideCollabAccess no longer mirrors the connect path for one class of page.

  • What PR 55 changes. PdpPagePermissionRepo.canUserEditPage no longer passes the PDP's view=false, locked=false straight through. That is the PDP's answer for a page it has not placed: trashed, or not yet projected. The repo walks the fork's own lineage and returns restricted-with-no-access when the lineage is restricted, or when the walk cannot finish. So onAuthenticate now refuses a page in a restricted section in that state.
  • Why the revalidator diverges. It builds pagePerms from raw PDP view/edit/locked answers. For the same page it takes the unrestricted branch and keeps a live socket open (read).
  • Why the parity spec may not catch it. collab-access-parity.spec.ts may stay green if its fixture never has an unplaced page in a restricted section.
  • Suggested direction (not prescriptive). Derive pagePerms through the repo's canUserEditPage, or share its lineage check (service-bridge/page-lineage.ts). Then add a parity case: a trashed page under a restricted parent, with the PDP answering all-false.
  • Merge order. Whichever of the two PRs merges second needs to take this into account.

@PMQ9
PMQ9 merged commit 6d81cd3 into wiki-v2 Sep 23, 2026
@PMQ9
PMQ9 deleted the fix/501-live-access branch September 23, 2026 14:18
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