Repository navigation
feat(#485): page-lifecycle facts, trash roots, DB cycle guard, and snapshotBefore (wiki-v2 PR-B, fork half) - #53
Merged
Merged
Conversation
…and a DB page-cycle guard CCC-owned (service-bridge/ prefix, zero upstream edits). The platform's /v1 move, restore and trash routes decide from these facts; nothing here decides policy. - POST /api/service/pages/lifecycle-state (pages:read): a page's restriction lineage through TRASHED ancestors (trashing reaps the SpiceDB edges, so the PDP cannot answer this), its parent's state, and whether any descendant is restricted / trashed / in another space; with a would-be parent, that target's lineage, cycle membership and next sibling position. Every walk is cycle-safe and depth-bounded, and an incomplete walk reads as restricted (fail closed). - POST /api/service/pages/trash (content:read): the roots of trashed subtrees in a space, newest first, keyset (deletedAt ms, id), with every root under a restriction excluded IN SQL before the limit. deletedBy is a display name only. - PageCycleGuardInstaller: a BEFORE UPDATE OF parent_page_id trigger that refuses a self/descendant parent under a per-workspace advisory xact lock (closes the concurrent A<->B race and covers the engine's own move path). Remote-only, advisory-locked, idempotent, fail-closed on boot. - Contract: service-bridge.openapi.json 1.3.0 (2 paths, 5 schemas), provider contract rows, scope coverage. Real-Postgres spec incl. the concurrent race (18 cases). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…estore can be undone
An optional `snapshotBefore` on the CCC conditional-update route saves the page's current title +
content as a history version just before a content `replace` (after the edit check and the parse, so
a refused or malformed write saves nothing). Skipped when the write changes neither, or the newest
version already holds exactly this title + content. The response reports
`snapshot: { status: 'saved' | 'unchanged', historyId }`; the platform returns the id as the undo
handle (`previousVersionId`).
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… (PR 520 review, Testing L3) Native mode installs nothing; remote installs the guard function + BEFORE UPDATE OF parent_page_id trigger in one advisory-locked transaction (asserting the per-workspace lock the trigger takes before walking); a not-ready engine is retried; and a remote boot whose install never succeeds REFUSES TO START — so removing that throw (which would silently reopen the concurrent-move race) now fails a test. Mirrors authz-outbox.installer.spec. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…B branch; service-bridge contract -> 1.4.0 Both PRs bumped service-bridge.openapi.json to 1.3.0; per the agreement with docmost#486 the second to merge takes 1.4.0 (PR 52 merged first). The provider contract spec keeps both sides' rows (ShadowUserLookup + the docmost#485 lifecycle schemas). Fork lane 85 suites / 844 passed; real-PG lifecycle spec 18/18. 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
The fork half of agent page lifecycle (wiki-v2 issue 485, PR-B). It adds the facts the platform needs to decide a
/v1move or restore without ever changing who can see a restricted page, a space trash read, a DB cycle guard onpages.parent_page_id, and an opt-in pre-write snapshot so a version restore can be undone. All code is CCC-owned (service-bridge/,authz/page-write/); no upstream-owned file is touched.Context
The engine's native move and restore paths assume a human in the UI. Traced in wiki-v2 issue 485 (ADR 0024):
page_accessfor the whole subtree (G2);The platform (not this fork) now plans every move and restore and refuses those cases with
409 restricted_page/move_cycle. To do that it needs facts only the database has: trashing reaps a page's SpiceDB edges, so the PDP cannot see restriction lineage through a trashed ancestor. This PR serves those facts and nothing else. Policy stays out of the fork. Plan, progress and tradeoffs: https://github.com/cccvu/wiki-v2/issues/485#issuecomment-5782076140Related issues
Closes #485) merges.lockedbulk check).What changed
POST /api/service/pages/lifecycle-state(pages:read), inservice-page-lifecycle.service.ts. Workspace-filtered, trashed rows included. It returns:Given a would-be parent (
targetParentPageId: a uuid, ornullfor the root), it also returns that target's existence/space/trashed state, its restricted self-and-ancestors, whether it is the page itself or a descendant, and the next sibling position. Every walk is cycle-safe (path array) and depth-bounded (256), and an incomplete walk reads as restricted.nextPositionmirrorsPageService.nextPagePosition(COLLATE "C", live siblings only), because importingPageModulehere would pull in the collaboration/lib0 graph.POST /api/service/pages/trash(content:read): the ROOTS of trashed subtrees in a space, newest first.(date_trunc('milliseconds', deleted_at), id::text), limit + 1.deletedByis a display name, never a user id.PageCycleGuardInstallerinstallsccc_page_cycle_guard()as aBEFORE UPDATE OF parent_page_idtrigger. It refuses a self or descendant parent after takingpg_advisory_xact_lock(485485, hashtext(workspace_id)), and a walk that reaches its bound (1024) is refused too. This closes the race between two concurrent moves (A under B while B moves under A), which a platform pre-check alone cannot, and it covers the engine's own UI move. Same shape as the outbox installer: remote-mode only, advisory-locked DDL, idempotent, and a remote boot that cannot install it refuses to start.snapshotBeforeon the CCC conditional-update route (authz/page-write/conditional-page.controller.ts).replace, it saves the page's current title + content as a history version. It runs after the edit check and the parse, so a refused or malformed write saves nothing.snapshot: { status: 'saved' | 'unchanged', historyId }.PageHistoryRepois an optional appended constructor parameter.Contract:
service-bridge.openapi.jsongoes to 1.3.0 (2 paths, 5 schemas). The concurrent fork PR 52 (SMTP_SECURE docmost/docmost#486) also bumps to 1.3.0; whichever merges second takes 1.4.0.service-scope-coverageentries.How this was tested
pnpm exec jest src/authz src/service-bridge src/editor-compat(the CIdocmost-authzlane): 81 suites, 761 passed, 74 skipped (real-Postgres specs self-skip without a DB).service-page-lifecycle.pg.spec.tsagainst a throwaway Postgres 18 (AUTHZ_REQUIRE_PG=1): 18/18. It covers:nextPositionordering (valid fractional keys, trashed siblings ignored);conditional-page.controller.spec.ts(+10 cases): the snapshot is saved after the edit check and the parse and before the apply;unchangedwhen the newest version or the incoming write matches (title + content); saved when only the title differs; nothing on a refusal; never forwarded toPageService.update; boolean validation.npx tsc --noEmit -p tsconfig.build.json: clean.bash scripts/check-upstream-boundary.sh(super repo, against the committed fork HEAD): upstream boundary intact, and the brand guard passes.content-smokerun drives the new routes through the platform against this branch.AWS / infra apply
N/A. Fork code only; it ships with the release after the super-repo gitlink bump. The trigger installs itself at boot (idempotent). Rollback: a previous image leaves the trigger in place, which is harmless: it only refuses cycles, which the engine never intended. To remove it:
DROP TRIGGER ccc_page_cycle_guard ON pages; DROP FUNCTION ccc_page_cycle_guard();.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: the native UI restore / move-to-space paths still declassify (wiki-v2 issue 493). The trash read hides every root under a restriction, including ones that could legally be restored under a live parent.
🤖 Generated with Claude Code