Skip to content

fix(sync, editor): retryable rejects resent, sync resumes after a lost pull, no double move, typing kept on remote changes, tagged blocks saved - #13909

Open
yuxi-liu-wired wants to merge 10 commits into
logseq:masterfrom
yuxi-liu-wired:fix/review-sync-editor

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Six fixes from a review of the sync client and the editor's save path, one commit each. Every test is in a new namespace and fails on master.

1. A reject the server marks retryable keeps the edit and sends it again

What the user sees. An edit (a new block, a paste, a property change) disappears from the page a moment after it was made. It is never uploaded and no other device gets it. When the server had in fact committed the tx, every inflight edit is rolled back locally and uploads stall until another client's change arrives.

Cause. On a failure that is not a data error (e.g. a storage error after a write), the server answers tx/reject with :retryable true; it sends "snapshot upload in progress" while a graph upload runs. The client never read the flag: handle-tx-reject! rolled back the failed tx, or every inflight tx when the reply carried no ids, and marked them failed, so they were never resent.

Change. A retryable reject (or "snapshot upload in progress") marks the txs the server confirmed as sent, keeps the others pending, clears inflight and sends them again: after a pull when the reject's t moved past ours, else after one second. Non-retryable rejects are handled as before.

Test. frontend.worker.sync.sync-recovery-test: retryable reject with a failed tx id, retryable reject after the server's commit, snapshot upload in progress. On master the edit is rolled back and marked failed.

2. A pull lost to a ws drop no longer stops sync until restart

What the user sees. After a network blip or a server-side socket close, sync silently stops: local edits pile up as pending, other devices' edits never arrive. Reconnecting, coming back online or showing the tab does not heal it; a graph switch or reload does.

Cause. request-pull! remembers the pull it sent in :pending-pull-since until pull/ok clears it. When the socket closed before the reply, the marker stayed and the reconnect reused the client map, so every later pull from the same t was taken for a duplicate and never sent; uploads wait for that pull.

Change. The marker is cleared when the socket closes (onclose and the stale-socket check) and when a new socket opens, before hello.

Test. frontend.worker.sync.sync-recovery-test: after a close, a changed sends the pull; the stale-socket check clears the marker. On master no pull is sent.

3. A pending tx the pull shows the server applied is not replayed

What the user sees. Move up (Alt+Shift+Up) pressed once during a network hiccup: after the reconnect the block has moved up two places, on every device.

Cause. The server applied the upload but its ack was lost with the socket, so the tx stayed pending. The next pull returned that tx, but handle-pull-ok! dropped the server's :tx-id, and apply-remote-tx-with-local-changes! reversed the pending tx, applied the pulled copy and replayed the pending tx on top. :move-blocks-up-down is relative, so the block moved again, and the replay was uploaded.

Change. handle-pull-ok! keeps each pulled tx's :tx-id. A pending tx whose id is among the pulled txs is reversed as before but not replayed, and is marked as sent.

Test. frontend.worker.sync.sync-recovery-test: pull/ok keeps the tx id; a pulled own move up is applied once and leaves nothing pending. On master the block ends up first and the move stays pending.

4. A remote change that keeps the editing block's title no longer resets the editor

What the user sees. Typing in a synced graph, the textarea reverts to the block's last saved text and the cursor jumps when someone adds a child under the block, sets a property on it, or edits a page it references. Everything typed since the last auto-save is lost.

Cause. A regression from fb1047d: the UI pipeline puts the editing block's title into the editor whenever a remote render delta carries the block. The delta also carries blocks whose children, properties or references changed, with the unchanged saved title. Before, only an added :block/title datom did this.

Change. invoke-hooks reads the editing block's rendered title before applying the delta and replaces the editor content only when the delta's title differs from it.

Test. frontend.modules.outliner.pipeline-editing-title-test: a delta with the saved title keeps the typed text; a delta with a new title still replaces it.

5. Auto-save blocks that hold a tag, and save the editor when the page is hidden

What the user sees. Editing a block that contains a hashtag (#task, a URL with #anchor), then reloading, minimizing, switching away or sending the mobile app to the background without leaving the block, loses everything typed in it.

Cause. The auto-save timer skipped every block matching #\S+ (meant to avoid a tag page for a half-typed tag), so a block holding a complete tag was never auto-saved, and nothing saved the editor when the page went away.

Change. The timer holds the save back only while a tag is being typed at the cursor (#ta, #[[my ta). The app saves the editing block, with the textarea's text, when the document becomes hidden (visibilitychange).

Test. frontend.handler.editor-unsaved-text-test: auto-save runs with a complete tag and with a URL anchor, not with a tag being typed; hiding the page saves with :flush-input? true.

6. An edit undone back to its start text is saved when leaving by paste or arrow

What the user sees. Block "foo": type "x", pause ("foox" is auto-saved), press Backspace, then within the auto-save delay paste blocks or press ArrowDown into the property row or comments. The block stays "foox".

Cause. paste-blocks and move-cross-boundary-up-down compared the editor text with the title in :editor/block, captured when editing started and not updated by later saves, so text equal to the start text looked saved.

Change. Both compare with the block's last saved title, as save-block-if-changed! does: a save still in flight, else the renderer snapshot.

Test. frontend.handler.editor-unsaved-text-test: paste after an edit undone back to the start text saves "foo". On master nothing is saved.

Test setup: the sync-recovery tests run on a graph that syncs

The graph in frontend.worker.sync.sync-recovery-test had no :logseq.kv/graph-remote?, so it was a local graph that happened to have a client-ops store. On master every local tx still gets a client-op row, but #13786 stops writing those rows for a graph that does not sync. With both PRs merged the deleted block's tx had no row, the reject carried no tx id, and three tests read an undefined row. A tx/reject only reaches a graph that syncs, so setup-parent-child now sets the remote flag, as upload and download do (7a38ffd). Test-only; the namespace passes on this branch alone and merged with #13786.


Devin Review

2b. A pull whose reply is lost on an open socket is sent again after 30 s

What the user sees. As in section 2, sync stops: the local t stays put while other devices' changes pile up on the server, until a restart. Reported on 2.0.2 in comments here (local t 252 for 20 minutes while the server went 317 to 553; the worker log shows four close/reconnect cycles in that time, which section 2 covers). The reporter reproduced the open-socket case on the installed 2.0.2 client with a server that withholds pull/ok: one pull, then none for over 31 s while changed kept arriving.

Cause. Section 2 clears the pending-pull marker when the socket closes or a new one opens. A reply lost while the socket stays open never closes it, so the marker stayed and every later pull from the same t was dropped as a duplicate.

Change. The client records when the pending pull was sent (:pending-pull-sent-at). Each sent pull schedules a check pull-reply-timeout-ms (30 s) later that sends it again if the same pull is still waiting, so it recovers also on a graph where no later changed arrives; a pull/ok or a newer pull turns the check into a no-op. request-pull! likewise sends a pull from the same t again once 30 s have passed. In node the timer is unref'd.

Test. frontend.worker.sync.pull-reply-timeout-test: the timer resends an unanswered pull and sends nothing once the reply came; a changed 31 s after an unanswered pull sends it again, 1 s after does not. The timer and expiry tests fail without the change (8c1d452, 620a530); sync-recovery-test still passes.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

Comment thread src/main/frontend/handler/editor.cljs Outdated
Comment on lines +2044 to +2045
(let [before-cursor (subs value 0 (min (count value) (or cursor-pos (count value))))]
(boolean (re-find #"#(?:\[\[[^\]]*|\S+)$" before-cursor))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 End-of-line URL fragments still defer auto-save

With the cursor after https://example.com/#anchor, typing-tag-at-cursor? matches #anchor and skips the timer save. The new visibility handler provides a separate save opportunity, but the claimed URL-fragment auto-save behavior needs checking.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

editor.cljs:2045 (URL fragment at the cursor). Right: typing-tag-at-cursor? matched any # before the cursor, so with the cursor right after https://example.com/#anchor the timer save was skipped. A tag begins at the start of the text or after whitespace, so the check now requires that; a # inside a word (a URL fragment) no longer holds the save back. The test auto-save-runs-in-a-block-that-holds-a-tag-test gains that case, and a tag being typed (task #proj, task #[[my proj) still holds it back.

@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/review-sync-editor branch 2 times, most recently from 82efb32 to 75092ef Compare November 3, 2026 12:02
@JaredStemper

Copy link
Copy Markdown

Observed on installed 2.0.2 / 533ac43: native status remained local-tx 252 for 20m27s while remote-tx advanced 317→553 and pending-server 65→301. Every capture reported ws-state open, last-error null and no pending local/assets; later checksums differed. Graceful desktop termination/relaunch reached 553/553, zero queues and matching checksums on both devices. This resembles section 2's user-visible symptom, but we have no proof of a lost pull marker or validation of this PR against the incident. Sanitized status timeline available.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Thanks, that timeline helps. With the socket open and no error the whole time, section 2 alone would not have healed it: it clears the pending-pull marker only when the socket closes or a new one opens, and a pull reply lost on a socket that stays open left the marker set, so every later pull from local-tx 252 was dropped as a duplicate until the relaunch. 8c1d452 (section 2b) records when the pending pull was sent and sends a pull from the same t again after 30 s without a reply; frontend.worker.sync.pull-reply-timeout-test covers it. If you have the timeline's websocket frames, a pull sent with no pull/ok after it would confirm this was the path.

@JaredStemper

Copy link
Copy Markdown

@yuxi-liu-wired Thanks for adding 8c1d452. I investigated the retained evidence and ran a controlled reproduction. I cannot recover a historical pull/pull/ok trace from the original captures, but I captured the unanswered-pull failure using the installed 2.0.2 client code. There is also an important correction: the original socket was not proven continuously open, and the worker log shows intervening closes/reconnects.

1. Original incident: status timeline, not a continuous transport trace

The stalled desktop was NixOS, with a macOS client on the same synced graph. The reported installed release/revision was 2.0.2 beta / 533ac43. The captures below came from the native worker's thread-api/db-sync-status, not renderer DevTools or a packet capture. All times are UTC on 2026-11-11.

Capture Local tx Remote tx Pending server Local/remote checksum equal
16:42:37.000 252 317 65 true
16:43:51.884 252 345 93 true
16:46:11.977 252 351 99 true
16:46:48.431 252 351 99 true
16:53:05.504 252 513 261 false
16:53:25.890 252 532 280 false
16:55:10.656 252 551 299 false
17:02:18.198 252 553 301 false
17:03:04.349 252 553 301 false

Every listed status snapshot reported ws-state: open, last-error: null, pending-local: 0, and pending-asset: 0. The observation interval was 1,227,349 ms (20m27.349s). Those are sampled observations; they do not establish continuous connectivity, receipt of transaction payloads, or successful application of remote transactions. The early checksum equality is just the returned field, not an independent consistency check while local/remote tx differed.

At 17:04:08.428, the identified NixOS desktop was gracefully terminated with SIGTERM and relaunched through its installed launcher using systemd-run. This was not a GUI close-button test. By 17:04:51.152, native status on both clients showed local-tx = remote-tx = 553, all three queues zero, last-error: null, and matching local/remote checksums across both devices.

2. Newly recovered worker log: closes/reconnects between the snapshots

I retrieved the original NixOS worker's retained db-worker-node-20261111.log. Its lifecycle entries include:

UTC time                  Event                 Retained log line
16:42:33.380               ws-closed             531
16:42:34.477               ws-reconnect          533
16:42:35.248               handle-hello          535
16:48:01.737               ws-closed             536
16:48:02.942               ws-reconnect          538
16:48:03.399               handle-hello          540
16:56:55.402               ws-closed             541
16:56:56.490               ws-reconnect          543
16:56:57.091               handle-hello          545
17:01:48.857               ws-closed             546
17:01:49.986               ws-reconnect          548
17:01:50.203               handle-hello          550
17:04:17.613               connect! after restart 559
17:04:18.197               handle-hello          560

The handle-hello entries above reported ws-open? true. The full retained daily log contains no recorded pull/pull/ok envelopes or pending-pull-since values, and no ws-handle-message-failed entry. Absence of those log records is not evidence that no pull/reply was exchanged: the installed send/onmessage paths do not ordinarily log every envelope.

This qualifies my earlier comment and the incident attribution in section 2b: “open at every capture” must not be read as “open and error-free throughout the whole interval.” Section 2's marker surviving a close/reconnect remains relevant to this incident; the available evidence cannot distinguish it from an unanswered pull during an open interval, or establish either as the cause. I have not established a server-side loss, a blocked receive queue, or another consumer failure. I am also not attributing this incident to co-occurring markdown-mirror errors or to a separate, later macOS TLS-trust failure.

3. Controlled reproduction using the installed compiled client

This was a new synthetic experiment on macOS, not recovered incident frames and not an end-to-end graph-sync test:

  • Executed the installed packaged worker member app.asar/js/db-worker-node.js, release 2.0.2 / 533ac43, under the installed Electron-as-Node runtime Node v24.15.0.
  • SHA-256 of that packaged JS member: 6531c797de1993fb4851a921f06d88701ac3ff27846068a3b6a1c76f3a7eb3e0.
  • Loaded the bundle into an isolated function context, skipping its CLI startup before graph admission/opening. Replaced only the local-tx getter with constant 252 and the RTC/UI broadcast with a no-op; created the client using the compiled client-state constructor and a real loopback ws connection.
  • The compiled entry points in this installed bundle were G9b (client-state construction), k8b (handle-message), f8b (request-pull), and g8b (clear pending pull). The isolation overrides were L2 (local tx getter) and $4 (RTC broadcast). The send queue, JSON parsing/schema coercion, transport/send, and pending-marker logic were otherwise the installed implementation.
  • The loopback server deliberately omitted pull/ok, kept the connection open, and sent further changed messages. Captured messages at both loopback endpoints, including server receipt of the outbound pull. These are decoded JSON WebSocket message envelopes, not RFC6455/TLS packet bytes.

The observed sequence, using elapsed milliseconds from the fixture's monotonic start:

+     9 ms  socket open, readyState=1
+    10 ms  server -> client  {"type":"changed","t":317}
+    11 ms  client -> server  {"type":"pull","since":252}
            server intentionally withholds pull/ok
+   143 ms  state: local=252, remote=317, pending-pull-since=252, readyState=1
+  1146 ms  server -> client  {"type":"changed","t":345}
+  1278 ms  state: local=252, remote=345, pending-pull-since=252, readyState=1
            no additional outbound pull
+ 32281 ms  server -> client  {"type":"pong"}
+ 32282 ms  server -> client  {"type":"changed","t":553}
+ 32412 ms  state: local=252, remote=553, pending-pull-since=252, readyState=1
            still exactly one outbound pull; no pull/ok received

            positive control follows:
+ 32415 ms  server -> client  {"type":"pull/ok","t":252,"txs":[]}
            compiled pull/ok handler clears pending-pull-since; asserted null
+ 32517 ms  server -> client  {"type":"changed","t":554}
+ 32519 ms  client -> server  {"type":"pull","since":252}
+ 32653 ms  socket closes normally, code=1000

Assertions passed: one initial pull, no resend after more than 31 seconds despite the subsequent changed, socket remained open until cleanup, marker stayed at 252, no handler/socket errors, and a second pull was emitted after the positive control cleared the marker. The positive-control pull/ok used t == local-tx and empty txs specifically to exercise marker clearing without invoking transaction application; it is not a simulated successful catch-up to 553.

This demonstrates the installed client's indefinite same-since suppression under the deliberately injected missing-reply condition. It does not establish that a reply went missing in the historical incident, nor why one would have been absent. No real graph, production sync server, graph credentials, E2EE payloads, TLS connection, persistence, or remote transaction application was exercised. I have not installed or executed PR head 8c1d452c6b, so this is not a failing-before/passing-after validation of that commit. From reading the change, I understand the 30-second expiry is checked on the next request-pull! trigger, rather than an independent timer callback.

4. Capture capability for another occurrence

In a separate isolated smoke, an explicit startup --require hook around Node's ws captured outbound send attempts and inbound messages before the application handler, plus open/close events. A strict metadata allowlist retained only type, direction, since/t, transaction count, byte count, socket identity, timestamps, and readyState; fictional URL tokens, graph identifiers, transaction bodies/IDs, checksums, and note contents were verified absent. NODE_OPTIONS=--require=... was blocked by the packaged Electron launch in this environment; the explicit --require flag worked in the isolated process.

That establishes a practical startup instrumentation path, not attachment to the existing worker or timing-neutral behavior on a live graph. No live worker was restarted or instrumented during this investigation. A future diagnostic capture would need to start before the relevant worker's first sync exchange and retain socket close/reconnect boundaries as well as pull, pull/ok, hello, changed, and handler errors/status. In particular, recording receipt before the receive queue would help distinguish an absent reply from one received but not processed.

Bottom line: the original incident still has an unconfirmed mechanism; intervening reconnects are now confirmed; and the installed-client unanswered-pull behavior has been reproduced with a captured message sequence. All evidence needed to interpret those distinctions is included above rather than linked to private/local files.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Thanks for the worker log and the reproduction against the installed client.

The four close/reconnect cycles change the reading: in 2.0.2 the pending-pull marker survives a close and the reconnect reuses the client map, so a pull lost with any of those sockets blocks every later pull from 252 until a restart. That is section 2's path. The relaunch healing it fits too, since it builds a new client map. 2b is the open-socket variant that your loopback run shows directly.

Your reading of 8c1d452 is right: the expiry was only checked on the next request-pull!, so a quiet graph with no later changed stayed stuck. 620a530 gives each sent pull its own 30 s timer, which resends it if that same pull is still waiting and does nothing once pull/ok or a newer pull came. pull-reply-timeout-test covers both the timer and the no-op; the timer tests fail on 8c1d452. Section 2b of the description now says this, and it credits your reproduction for the open-socket case without claiming it as the incident's mechanism.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 12, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 12, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 13, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 14, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 15, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 16, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 16, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 17, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 17, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 19, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.
…ds it again

An edit (a new block, a paste, a property change) disappeared from the page a moment after it was made when the sync server failed on a storage error while applying it. It was never uploaded, and no other device got it. When the server had in fact committed the tx and failed afterwards, every inflight edit was rolled back locally, and uploads stalled until another client's change arrived.

The server answers such failures with `tx/reject` and `:retryable true` (and `"snapshot upload in progress"` while a graph upload runs), but the client never read the flag: `handle-tx-reject!` rolled back the failed tx, or every inflight tx when the reply carried no tx ids, and marked them failed, so they were never resent.

A retryable reject now marks the txs the server confirmed as sent, keeps the others pending, clears inflight and sends them again: after a pull when the reject's t moved past ours (the server stored something), else after one second. A non-retryable reject is handled as before.

Test: `frontend.worker.sync.sync-recovery-test` (retryable reject with a failed tx id, retryable reject after the server's commit, snapshot upload in progress).
After a network blip or a server-side socket close, sync silently stopped: local edits piled up as pending and never uploaded, and other devices' edits never arrived. Reconnecting, coming back online or showing the tab did not heal it; only a graph switch or reload did.

`request-pull!` sends one pull per `since` and remembers it in `:pending-pull-since` until `pull/ok` clears it. When the socket closed before the reply, the marker stayed, and the reconnect kept the same client map. Every later pull from the same t (from `hello`, `changed` or a stale reject) was then taken for a duplicate and never sent, and uploads wait for the pull.

The marker is now cleared when the socket closes (`onclose` and the stale-socket check) and when a new socket opens, before `hello`.

Test: `frontend.worker.sync.sync-recovery-test` (ws close, stale socket close).
…ayed

The user pressed move up (Alt+Shift+Up) once while the network hiccuped. After the reconnect the block had moved up two places, on this device and on every other one.

The server applied the upload but its `tx/batch/ok` was lost with the socket, so the tx stayed pending. The next pull returned that same tx, but `handle-pull-ok!` dropped the `:tx-id` the server sends. `apply-remote-tx-with-local-changes!` then reversed the pending tx, applied the pulled copy, and replayed the pending tx on top. A relative op such as `:move-blocks-up-down` moved the block again, and the replay stayed pending and was uploaded, so the server applied the second move too.

`handle-pull-ok!` now keeps each pulled tx's `:tx-id`. A pending tx whose id is among the pulled txs is reversed as before, but not replayed, and is marked as sent.

Test: `frontend.worker.sync.sync-recovery-test` (pull/ok keeps the tx id, a pulled own move up is applied once).
…longer resets the editor

Typing in a block of a synced graph, the textarea suddenly reverted to the block's last saved text and the cursor jumped when a collaborator (or the user's other device) added a child under the block, set a property on it, or edited a page it references. Everything typed since the last auto-save was lost, silently.

Since fb1047d the UI pipeline puts the title of the editing block into the editor whenever a remote tx's render delta carries that block. The delta also carries a block whose children, properties or referenced entities changed; its title is then the unchanged saved title, which differs from the unsaved text in the editor. Before that commit only an added `:block/title` datom of the editing block did this.

`invoke-hooks` now reads the editing block's title from the renderer store before applying the delta, and the editor content is replaced only when the delta's title differs from it, i.e. when the tx changed the title.

Test: `frontend.modules.outliner.pipeline-editing-title-test`.
…en the page is hidden

Editing a block that contains a hashtag (`#task`, `#project`, a URL with `#anchor`), then reloading, minimizing, switching away or (on mobile) sending the app to the background without leaving the block first, lost everything typed in the block: when the user came back it held the text it had before editing started.

The auto-save timer skipped every block whose text matched `#\S+`, meant to avoid creating a tag page for a half-typed tag, so a block that already held a complete tag was never auto-saved. Nothing saved the editor when the page went away either.

The timer now holds the save back only while a tag is being typed at the cursor (`#ta`, `#[[my ta`); a tag elsewhere in the block no longer stops it. The app also saves the editing block, with the textarea's text, when the document becomes hidden (`visibilitychange`), which is when a mobile OS may kill the backgrounded app.

Test: `frontend.handler.editor-unsaved-text-test` (auto-save with a complete tag and with a tag being typed, save when hidden).
…ing by paste or arrow

Block "foo": the user typed "x" and paused, so "foox" was auto-saved, then pressed Backspace (the text is "foo" again) and within the auto-save delay pasted blocks or pressed ArrowDown into the block's property row or comments area. The editor moved on and the block stayed "foox": the deletion was lost silently.

`paste-blocks` and `move-cross-boundary-up-down` decided whether the editor held unsaved text by comparing it with the title in `:editor/block`, which is captured when editing starts and not updated by later saves. Text equal to the start text looked saved, so neither saved it, and the editor was switched without a save.

Both now compare the editor text with the block's last saved title, as `save-block-if-changed!` does: a save still in flight, else the renderer snapshot.

Test: `frontend.handler.editor-unsaved-text-test` (paste after an edit undone back to the start text).
…-save

The auto-save skips a block while a tag is being typed at the cursor, so a half-typed `#ta` does not become a tag. The check matched any `#` before the cursor, so a block ending in a URL with a fragment (`https://example.com/#anchor`) was never auto-saved while the cursor stayed there.

A tag starts at the beginning of the text or after whitespace; a `#` inside a word is not one. The check now requires that.

Test: `auto-save-runs-in-a-block-that-holds-a-tag-test` gains the URL-fragment-at-the-cursor case.
The retryable-reject tests in `frontend.worker.sync.sync-recovery-test` built their graph without `:logseq.kv/graph-remote?`, so it was a local graph that only happened to have a client-ops store. Today every local tx gets a client-op row anyway, but logseq#13786 stops writing those rows for a graph that does not sync (no remote flag, no remote graph id). With both changes, the deleted block's tx had no row: `pending-txs` was empty, the reject carried no tx id, and the tests read an undefined row (`Cannot read properties of undefined (reading 'pending')`).

A tx/reject only reaches a graph that syncs, so `setup-parent-child` now sets the remote flag, as upload and download do. The tests pass on this branch alone and merged with fix/db-page-delete-combined.
The pending-pull marker made every later pull from the same t a duplicate
until pull/ok cleared it. Section 2 of this PR clears it when the socket
closes, but a reply lost while the socket stays open kept it forever: the
local t stopped while the server's moved on, with the socket open and no
error, until a restart (a field report on 2.0.2: 20 minutes).

The client now records when the pending pull was sent, and a pull from the
same t is sent again once 30 s have passed with no reply.
The 30 s expiry of 8c1d452 was only checked when the next pull was
requested, so on a graph where no later `changed` arrives a lost pull reply
still left the local t behind. Each sent pull now schedules a check
pull-reply-timeout-ms later that sends it again while the same pull is still
waiting; a pull/ok or a newer pull makes the check a no-op. In node the
timer is unref'd so it does not keep the worker alive.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 19, 2026
The undo's render delta puts the undone text into the editor before the
undo's result reaches the history handler; the cursor restore then pulled
the block and called edit-block!, which loads it again, and moved the
cursor over whatever the user had selected in between: Mod+a then Backspace
right after Mod+z deleted one character
(cursor-boundaries-word-motion-and-kill-test, which fails the same way on
master under load).

The undo/redo snapshots the editing block, its text and selection before
the worker request. The restore edits the block only if the user did
nothing there meanwhile (the editor holds the snapshot, or the undone text
with the cursor at its end), checked after the pull and once more through
a one-time edit guard right before edit-block! moves the editor. The
edit-block! call is master's, unchanged.

This replaces 7095560, whose pipeline hold-back of the editing title
conflicted with logseq#13909's change to the same pipeline function.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants