Skip to content

refactor: use semantic ops for both sync and undo/redo#12466

Merged
tiensonqin merged 92 commits intomasterfrom
refactor/sync-undo-semantic-ops
Mar 30, 2026
Merged

refactor: use semantic ops for both sync and undo/redo#12466
tiensonqin merged 92 commits intomasterfrom
refactor/sync-undo-semantic-ops

Conversation

@tiensonqin
Copy link
Copy Markdown
Contributor

@tiensonqin tiensonqin commented Mar 23, 2026

This PR refactors DB sync + undo/redo to be semantic-op driven and worker-owned, so rebase/undo/redo can preserve user intent instead of relying on raw tx replay.

It implements the architecture described in ADR 0010–0013 and includes follow-up bug fixes discovered during the migration.

What changed

1. Semantic history persistence for client ops

  • Persist canonical semantic history metadata on each client-op row:
    • :db-sync/forward-outliner-ops
    • :db-sync/inverse-outliner-ops
  • Keep normalized/reversed tx data for sync/compatibility/debugging, but make semantic ops the primary replay signal.

2. Worker-owned undo/redo

  • Added frontend.worker.undo-redo as the main undo/redo implementation.
  • Added worker thread APIs for:
    • record editor info
    • record UI state
    • undo / redo
    • clear history
    • debug-state retrieval
  • Main thread frontend.undo-redo is now a thin proxy to worker APIs.
  • frontend.handler.history now invokes worker undo/redo directly.

3. Op-driven rebase with legacy isolation

  • Rebase now replays canonical outliner ops for pending local actions.
  • Added canonical op construction in logseq.outliner.op.construct.
  • Isolated legacy tx-surgery compatibility logic into frontend.worker.sync.legacy-rebase.
  • Kept explicit transact fallback path ([[:transact nil]]) where needed.

4. Outliner op/canonicalization improvements

  • Expanded/normalized outliner op handling (including template and page/property flows).
  • Added :apply-template op path and related replay support.
  • Added/fixed behavior around move targets, save-block replay normalization, and entity id normalization.

5. Reliability fixes during migration

  • Fixed multiple undo/redo and rebase edge cases (indentation, page recycle/restore, hard delete page undo/redo, redo metadata binding, parser/outliner test regressions).
  • Added periodic cleanup of finished client-op history rows in worker (with protection for tx-ids still referenced by undo/redo stacks).

6. Dev tooling

  • Added (Dev) Undo/Redo right-sidebar debug panel for stack inspection and action replay debugging.

Docs

  • Added ADRs:
    • ADR 0010: Canonical op-driven client rebase
    • ADR 0011: Undo/redo semantic inverse-op persistence
    • ADR 0012: Worker-owned undo/redo
    • ADR 0013: Worker-owned undo/redo test ownership

Tests

Updated/added coverage across:

  • outliner op construction and replay behavior
  • worker undo/redo behavior and fallback paths
  • db-sync rebase/apply paths
  • db worker/listener integration
  • main-thread history coordination behavior

Key test files touched:

  • src/test/frontend/worker/undo_redo_test.cljs
  • src/test/frontend/worker/db_sync_test.cljs
  • src/test/frontend/worker/db_sync_sim_test.cljs

@tiensonqin tiensonqin merged commit 1cdceae into master Mar 30, 2026
24 checks passed
@tiensonqin tiensonqin deleted the refactor/sync-undo-semantic-ops branch March 30, 2026 09:27
@tiensonqin tiensonqin restored the refactor/sync-undo-semantic-ops branch March 30, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants