Repository navigation
fix(collab): harden persistence lifecycle against silent write loss (#345) - #41
Merged
Merged
Conversation
…ocmost#345) Grouped robustness defects in the collaborative persistence lifecycle: - Post-store side effects (broadcast / contributors / mention+AI+history queue enqueues) now run in per-effect try/catch (`runPostStoreSideEffect`) so `onStoreDocument` can NEVER reject. Hocuspocus's debouncer leaves a rejected store resident in `runningExecutions` and re-throws it on every later store, so one post-commit blip (a Redis/DB hiccup) would otherwise permanently wedge persistence for that document (silent data loss) and return a false 503 on the settle/flush path. This de-poisons every store path (debounce, flush, conditional write, updatePageContent, comment marks). - Flip `unloadImmediately: true` (Docmost had overridden the upstream default to false). With false, the last client disconnecting with a pending debounced store neither flushes nor unloads and waits out the 10s/45s timer, so a restart in that window loses unsaved edits and graceful shutdown can't drain. Unload still fires only after the store completes, so the settle invariant holds; destroy() stays unbounded on purpose (a mid-store timeout would abandon an in-flight commit). - Change-origin guards on the three reactive appendTransaction mutators (TrailingNode, Indent via an injected filterTransaction option; AutoJoiner via a direct isChangeOrigin check), mirroring UniqueID. An open browser no longer rewrites content that arrived over the collaboration sync (API/MCP/another client): trailing paragraph, list auto-join, indent normalization now act only on LOCAL edits. - Resolve @docmost/editor-ext to source in Vitest so tests exercise the code that ships (production Vite already uses the source/module field), not the gitignored stale dist that masked the guards above. Regression tests: post-commit throw does not reject the hook and one failing side effect doesn't skip the rest; gateway pins unloadImmediately:true; a change-origin transaction no-ops each of the three mutators while a local one still acts. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…eject; pin guard wiring (docmost#345 review) Round-1 review findings on PR #41 (post-store lifecycle hardening): - Emit COLLAB_POST_STORE_FAILED (from the fork's authz/ collab-drift-log) when a best-effort post-commit side effect fails, so a systematic failure (wedged Redis/BullMQ, broken queue) pages via a CloudWatch alarm instead of only landing in the logs. Content is already durable, so it is a distinct token from COLLAB_STORE_FAILED (data-durability). [devops L3] - Add an outer try/catch backstop around the whole post-commit block so "onStoreDocument never rejects post-commit" is STRUCTURAL, not merely per-callsite — it also covers syncTransclusion's own guard and any FUTURE unwrapped await on the linchpin path. [architecture/correctness/testing] - Add a source-level regression test pinning that extensions.ts actually wires filterTransaction: (t) => !isChangeOrigin(t) into TrailingNode + Indent, so an upstream merge that drops the wrapper reds CI instead of silently reintroducing the docmost#345 content-rewrite bug (the behavioral tests configure their own guard and cannot catch this). [testing L3] - Strengthen the post-store isolation specs to assert the alarm token fires, named per side effect. Co-Authored-By: Claude Opus 4.8 <[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
Fork half of super-repo cccvu/wiki-v2#345 — grouped robustness defects in the collaborative
persistence lifecycle that can silently lose writes or return misleading status. Fast-follow to docmost#282/docmost#390
(ADR 0019). This PR must merge FIRST; the super-repo PR carries the gitlink re-pin.
The linchpin
Hocuspocus 3.4.4's debouncer (
useDebounce.run) deletes itsrunningExecutionsentry only on success,and
storeDocumentHooksre-throws any hook error with a.message— with nofinally. So ifonStoreDocumentever rejects, the rejected promise stays resident and every later store for that documentre-throws it before running → persistence is permanently dead until restart (silent data loss), and the
flushPageContentsettle path returns a false 503 for a write that committed.persistence.extensionis theonly hook that does work, so making it never reject fixes every store path (debounce / flush / conditional /
updatePageContent/ comment marks) at once.What changed
persistence.extension.ts). The effects that run AFTERthe row commits (broadcast, contributors, mention/AI/history queue enqueues) are each wrapped in
runPostStoreSideEffect(try/catch + log), mirroring the isolationsyncTransclusionalready has. Onefailing effect no longer skips the rest, and none can wedge the debouncer. (Defect 2 — highest severity;
subsumes the residual of Defect 1, whose in-txn half Revert "fix: Add alignment styles for task list items" docmost/docmost#390 already handles.)
unloadImmediately: true(collaboration.gateway.ts). Docmost had overridden the upstream default tofalse, under which the last client disconnecting with a pending debounced store neither flushes norunloads (it waits out the 10s/45s timer) — so a rolling deploy / scale-in / crash in that window loses the
edits, and graceful
destroy()can't drain. Unload still fires only after the store completes, so thesettle's "not resident ⇒ row authoritative" invariant holds and RedisSync releases the lock as designed.
destroy()is deliberately left unbounded — a mid-store timeout would abandon an in-flight commit(Postgres rolls back on connection drop); the only infinite-hang was debouncer poisoning, which the change
above removes. (Defect 3)
appendTransactionmutators —TrailingNode+Indent(editor-ext, via an injected
filterTransactionoption) andAutoJoiner(client, directisChangeOrigin),mirroring
UniqueID. An open browser no longer rewrites content that arrived over the collaboration sync(API/MCP/another client): trailing-paragraph insert, list auto-join, and indent normalization now act only
on local edits. (Defect 5 + two same-class bugs the adjacent-path audit found.)
@docmost/editor-extto source, not its gitignored (possibly stale)dist/— whichhad masked the two editor-ext guards in tests while production Vite uses source.
Every upstream-owned file touched is documented in
UPSTREAM_MODIFICATIONS.md(docmost#122/#3/#59 updated;docmost#155–docmost#159 new);
scripts/check-upstream-boundary.shis green.Tests
pnpm exec jest src/authz src/editor-compat(414) + clientpnpm test(315). New: a post-commit throw doesnot reject
onStoreDocumentand one failing effect doesn't skip the rest; the gateway pinsunloadImmediately: true; a change-origin transaction no-ops each of the three mutators while a local onestill acts.
Out of scope (tracked separately)
updatePageContenthas no try/catch (30s cross-node reply-hang on a genuine pre-commit throw; needs apage.servicechange + the docmost#344 false-200 tradeoff); RedisSynccustomEventStartreply-on-throw;movePageToSpaceenqueue insideexecuteTx; upstream Hocuspocus debouncerno-finally.🤖 Generated with Claude Code