Repository navigation
fix(#493,#545): page-state read + database guards that keep restrictions (Release A) - #57
Merged
Merged
Conversation
…keep restrictions (Release A) Release A of ADR 0027 (wiki-v2): the fork side of the page lifecycle projection fix. - POST /api/service/authz/pages/state (pages:authz:read, own 6000/min window, contract 1.7.0): the pages' CURRENT placement, own restriction and lineage (the docmost#524 rule, includeSelf) by id / subtree / keyset. ONE SQL statement per response, so a row never mixes two committed trees; walks go through trashed and cross-space rows, stay in the workspace, and an unfinished walk reads as restricted. - PageRestrictionGuardInstaller (remote only): ccc_page_restriction_guard on pages (g1: no space change for a restricted page or section; g2: no parent change that strips an unrestricted page's last restricted ancestor) and ccc_page_access_guard on page_access (g0: space_id from the page). All take the cycle guard's per-workspace lock first, so restrict and move serialize. Idempotent: no DDL when current; lock_timeout 3s when it must change. - PageGuardConflictInterceptor (APP_INTERCEPTOR via ServiceBridgeModule): the guards' 23514 refusals (and the cycle guard's, a 500 until now) become 409 {message, code}; inner to the docmost#467 access audit, which records the 409. - ServiceAttachmentService.resolvePage: an attachment of a trashed or missing page is a 404 (trash will keep its PDP decision in Release B). - LIFECYCLE_MAX_DEPTH 256 -> 1024, the cycle guard's bound. Real-Postgres specs drive the REAL upstream movePageToSpace/movePage/ restorePage, two-connection restrict/move races, the marker == docmost#524 rule cross-check and a torn-read stress. Zero upstream-owned file edits. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… hot-scope rate windows, installer boot spec - g1 now runs on EVERY row an UPDATE sets pages.space_id on, changed or not (new trigger ccc_page_space_guard; g2 stays on real parent changes). Upstream movePageToSpace deletes every moved row's page_access, including a child already in the target space (stranded there by an earlier move that skipped it while trashed, then restored and restricted) — native-only declassification the old OLD<>NEW gate let through. pg spec drives it through the real paths; red with the old gate. - Per-scope rate-limit table: pages:read (the /v1 live-page resolve, every page-content request) gets its own 6000/min window beside pages:authz:read; every other scope stays on the shared 600. - Installer: page_access before pages (the outbox installer's lock order; they boot concurrently), accurate lock_timeout docstring; new unit spec for the fail-closed boot (red if the final throw becomes a return), retry, no-DDL-when-current and lock_timeout-before-DDL. - pages/state rejects an explicit null (it would widen subtreeRootId:null to a full scan). - Lock test fails fast under lock_timeout instead of hanging; uses CYCLE_LOCK_CLASS. - README: a refused restore-detach does not roll back the un-trash (issue 556). Co-Authored-By: Claude Opus 5.5 (1M context) <[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
This is the fork half of Release A of the page lifecycle projection fix for cccvu/wiki-v2 issues 493 and 545 (ADR 0027 there). It adds:
Context
Issue 493: the engine's own write paths remove restrictions in the database.
movePageToSpacedeletes the moved pages'page_accessrows and re-roots the page. A restore whose parent is trashed detaches the page to the space root, dropping an inherited restriction. A concurrent restrict can land with a stalepage_access.space_id, which a later space delete cascades away.Issue 545: the platform projects page events edge-triggered. It applies them in
(xact_id, id)order, which is not commit order, across three SpiceDB transactions each. A partially projected ancestor chain can therefore readlocked=falsewhile a page's DB lineage is restricted.The fix, in two releases:
lineage_restrictedmarker in the SpiceDB schema;ADR 0027 in cccvu/wiki-v2 has the design and a minimality proof: why the simpler "keep ancestry + atomic/add-before-remove" direction cannot satisfy the invariants.
Related issues
What changed
All changes are CCC-owned, under
apps/server/src/service-bridge/anddocs/integrations/. Zero upstream-owned file edits.POST /api/service/authz/pages/state(page-authz-state.service.ts, DTO, route onAuthzChangeController). New scopepages:authz:read, with its own 6000/min window (the platform reads it per page event).{pageIds≤500},{subtreeRootId, limit, after?}(descendants, keyset), or{limit, after?}(every page, trashed included). A mix of modes is a 400.{pageId, exists, spaceId, parentPageId, restricted, lineageRestricted, lineageComplete}.lineageRestrictedis exactly the fix: uuid7 for commentId docmost/docmost#524 rule,lineageRestricted(readPageLineage(includeSelf)).PageRestrictionGuardInstaller(remote only, fail-closed boot, like the fix: close space selection popover onClickOutside docmost/docmost#485 cycle guard):ccc_page_restriction_guard(BEFORE UPDATE OFspace_id, parent_page_idONpages):ccc_page_access_guard(BEFORE INSERT OR UPDATE ONpage_access): g0 setsspace_idfrom the page.lock_timeout 3sand retries.PageGuardConflictInterceptoris an APP_INTERCEPTOR registered byServiceBridgeModule. It maps exactly the guards' 23514 refusals, plus the cycle guard's (a 500 until now), to409 {message, code}with a fixed message. It is inner to the Docmost vs. Outline docmost/docmost#467 access audit, so the audit records 409.ServiceAttachmentService.resolvePage: an attachment of a trashed or missing page is a 404. After Release B a trashed page keeps its PDP decision.LIFECYCLE_MAX_DEPTH256 → 1024, equal to the cycle guard's bound and pinned by a spec.pages:authz:readin the scope list, and the guard 409 documented. README updated.How this was tested
AUTHZ_REQUIRE_PG=1 … jest --runInBand 'src/(service-bridge|authz)/.*\.pg\.spec\.ts$'): 15 suites, 175/175.page-authz-state.pg.spec.ts:lineageRestricted(readPageLineage(includeSelf))on a mixed forest;page-restriction-guard.pg.spec.tsdrives the real upstreamPageService.movePageToSpace/movePageandPageRepo.restorePage:jest src/authz src/service-bridge: 92 suites, 985 passed.page-guard-conflict.interceptor.spec.tsboots the app topology with the real Docmost vs. Outline docmost/docmost#467 audit interceptor; the audit records 409, and goes red with the order swapped.tscerrors (the 19 pre-existing ones are unchanged); eslint is clean on the new files./v1content smoke passes on a locally built stack from these branches (ALL CHECKS PASSED), including the new 10e leg. A native/api/pages/move-to-spaceof a restricted page returns409 {code: ccc_page_restricted_space_move}and the page does not move. The fork log showspage restriction guard installed.AWS / infra apply
N/A. The guards are installed by the fork at boot, like the cycle guard and outbox. No Terraform, no AWS.
Checklist
Scope
Tests
Docs & contracts
README/docs// an ADR), or N/A.Safety (this is a security-first, deny-by-default platform)
UPSTREAM_MODIFICATIONS.md); proprietary/authz logic stays out-of-process.Housekeeping
Known limitations / follow-ups
restorePageis two autocommit statements. When the guard refuses its detach, the un-trash has already committed: the page stays under its restricted, trashed parent (fails closed) but is live. This is cccvu/wiki-v2 issue 556; the pg spec pins the behaviour.docs/runbooks/cd.md.🤖 Generated with Claude Code