Repository navigation
Conversation
mejo-
force-pushed
the
fix/cleanup_steps
branch
from
November 10, 2026 09:30
27fb4bc to
c14224f
Compare
Member
Author
|
/backport to stable35 |
Steps were only removed once a document had no sessions at all. Sessions that pushed steps but were not closed cleanly are kept for 90 days, so documents in regular use never got there and oc_text_steps kept growing. Remove steps that are older than 7 days and part of the last saved version, except for the 200 steps before it that recovering clients receive along with the document state. A client that missed removed steps sends a sync query and recovers from the document state. Documents without a state file are skipped, as recovering clients get all of their steps. Adds a playwright test for recovering missing steps via document state. Fixes: #9080 Signed-off-by: Jonas <jonas@freesources.org> Assisted-by: ClaudeCode:claude-opus-5-5
Should speed up playwright tests in CI a bit. Signed-off-by: Jonas <jonas@freesources.org>
mejo-
force-pushed
the
fix/cleanup_steps
branch
from
November 10, 2026 16:49
c14224f to
b97c836
Compare
blizzz
reviewed
Nov 10, 2026
blizzz
left a comment
Member
There was a problem hiding this comment.
Two cases were found, the first one might be a blocker.
a stale client misses deleted steps without noticing, then its save overwrites other people's edits
Why the client doesn't notice:
- The client only asks for recovery when Yjs is left with
pendingStructs. The check is atsrc/services/y-websocket.js:53-63. When that happens, Yjs sends a SyncStep1 message while steps are being applied, andWebSocketPolyfill.ts:104-120turns that intosendRecoveryStep. - The 30-second resync timer (
y-websocket.js:347-351) also only fires when there arependingStructs. - Nothing else triggers recovery, and the server never checks for gaps. Both
syncandpushsimply returnfind(id > version)(ApiService.php:168,DocumentService.php:292).
Why there are no pending structs in this case:
- Each step row holds one client's push:
encodeStateAsUpdate(doc, sv(remote))aty-websocket.js:383-384. - B's insertions into paragraph 1 point to items in paragraph 1, so the stale client can apply them even without A's paragraph-2 items.
- If B deleted something A had written, that delete goes to
pendingDs. Nothing checkspendingDs.
Why the bad save is accepted:
- The stale client's version jumps to the newest step id (
WebSocketPolyfill.ts:91). - So the
outdatedcheck inautosave(DocumentService.php:420) passes, and the client writes both the.mdfile and the.yjsstate file without A's edit.
Why a client can be this stale:
- A session that pushed steps is never removed by
deleteInactiveWithoutSteps. OnlyremoveOldSessionsremoves it, after 90 days. getValidSession(SessionService.php:165-188) only checks that the session row exists. So a laptop that resumes after 8 days is still accepted.
Reproduction (manual): the same steps as before.
- S edits
a.md, then blocks/session/*requests in devtools. - A edits paragraph 2 and closes the tab.
- B makes more than 200 pushes in paragraph 1, and autosave runs.
- Run
UPDATE oc_text_steps SET timestamp = timestamp - 700000, thenocc background-job:execute <Cleanup id> --force-execute. - Unblock S. No request carries
recoveryAttempt, and A's text is missing. S types something, waits 10 seconds for autosave, then reload: A's edit is gone.
Reproduction (unit, Vitest, in the style of src/tests/yjs.spec.js; not run yet):
const base = new Y.Doc(); /* fragment with <p>one</p><p>two</p> */
const [s, a, b] = [0,0,0].map(() => { const d = new Y.Doc(); Y.applyUpdate(d, Y.encodeStateAsUpdate(base)); return d })
// A edits p2
const svA = Y.encodeStateVector(a); /* insert into p2 */ const updA = Y.encodeStateAsUpdate(a, svA)
Y.applyUpdate(b, updA)
// B edits p1 only
const svB = Y.encodeStateVector(b); /* insert into p1 */ const updB = Y.encodeStateAsUpdate(b, svB)
Y.applyUpdate(s, updB) // updA was "deleted" on the server
expect(s.store.pendingStructs).toBeNull() // → no recovery triggeredto consider: a costly query every 5 minutes, and unbounded deletes on the first run
A full table read every 5 minutes isn't new. The PR adds a second pass with a join and GROUP BY, and that pass can't stop early the way the orphan query's LIMIT 1000 can.
- First run: for each document,
deleteBeforeVersiondeletes every old saved step in one statement (StepMapper.php:119-126), with no batch limit and no time limit. A busy document with millions of rows means one long transaction, lock waits, and lag on replicas or Galera nodes. - New detail: documents without a state file still match the query on every run, and
DocumentService.php:527-531skips them. So they are fetched, and their app data looked up, again every 5 minutes forever. - Steady state: because of
lte(finding #4), once 2 more old steps age past the cutoff, a document matches again (HAVING > 200). Documents in active use are reprocessed every 5 minutes, a few rows at a time.
Reproduction:
- Seed about 10M steps across about 10k documents, with
timestampolder than 7 days andlast_saved_versionset to the newest step. - Run
EXPLAINon the SQL fromfindDocumentsWithSavedSteps. Expect a range or full read oftext_steps, a row lookup fortimestamp, and a temporary table for theGROUP BY. - Run Cleanup with
--force-executeand watch the slow log for singleDELETEstatements that remove 100k+ rows.
This branch has not been deployed
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.
Steps were only removed once a document had no sessions at all. Sessions that pushed steps but were not closed cleanly are kept for 90 days, so documents in regular use never got there and oc_text_steps kept growing.
Remove steps that are older than 7 days and part of the last saved version, except for the 200 steps before it that recovering clients receive along with the document state. A client that missed removed steps sends a sync query and recovers from the document state. Documents without a state file are skipped, as recovering clients get all of their steps.
Adds a playwright test for recovering missing steps via document state.
Fixes: #9080
Assisted-by: ClaudeCode:claude-opus-5-5
🏁 Checklist
npm run lint/npm run stylelint/composer run cs:check)🤖 AI (if applicable)