Skip to content

feat: add durable document sessions and workspace polish - #25

Merged
Chefski merged 20 commits into
devfrom
codex/durable-document-sessions
Jul 24, 2026
Merged

feat: add durable document sessions and workspace polish#25
Chefski merged 20 commits into
devfrom
codex/durable-document-sessions

Conversation

@Chefski

@Chefski Chefski commented Jul 19, 2026

Copy link
Copy Markdown
Owner

What changed

  • Added durable shared document sessions with ordered updates, recovery, compaction, migration, and reconnect safety.
  • Kept document bodies out of generic offline replay while preserving metadata mutations.
  • Added page emoji editing, workspace feature gating, sidebar and page-browser polish, and safer async loading.
  • Added focused regression coverage across persistence, sync, navigation, settings, and editor behavior.

Checks

  • SwiftLint
  • iOS and macOS source typechecks
  • Changed test source typecheck
  • CRDT runtime tests and bundle build

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 82 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread docmostly/App/AppState+Management.swift Outdated
Comment thread docmostly/Features/Editor/NativeEditorCollaborationSyncDriver.swift
Comment thread docmostly/Features/PageTree/PageTreeNodeArray.swift Outdated
Comment thread docmostly/Features/PageTree/PageTreeView.swift
Comment thread docmostly/App/AppState+Management.swift Outdated
Comment thread docmostly/Features/Editor/DocumentSession.swift
Comment thread docmostly/Features/Editor/NativeEditorCRDTSyncCoordinator.swift Outdated
Comment thread docmostly/Features/Editor/NativeEditorJavaScriptCRDTDocumentEngine.swift Outdated
Comment thread docmostly/Persistence/DocumentLocalPersistencePeer.swift
@greptile-apps

greptile-apps Bot commented Jul 19, 2026

Copy link
Copy Markdown

Greptile Summary

This PR introduces a durable document session layer (DocumentSession, DocumentSessionRegistry, DocumentLocalPersistencePeer) that replaces ad-hoc CRDT state caching with ordered, sequenced updates backed by SwiftData. It also adds page emoji editing, workspace feature gating, sidebar polish, and expands regression coverage with ~600 lines of new architecture tests.

  • The persistence tier stores local and remote CRDT updates as sequenced StoredDocumentUpdate rows, compacts them into snapshots with recovery fallback, and handles migration of legacy offline mutations into the new schema.
  • The collaboration path is simplified: document body edits are driven entirely through the session (offline drafts are retained in the store, not the mutation queue), while the offline queue retains only metadata (title) mutations for replay.
  • UI additions include an emoji picker backed by the bundled emoji-16.0.txt catalog, a sidebar page-browser section replacing the old favorites/notifications links, and focus-after-split/merge fixes in the editor body view.

Confidence Score: 5/5

The durable session architecture is well-tested and the compaction, snapshot, and recovery logic is sound; the small issues found are quality concerns, not correctness defects.

The core document session, registry, and persistence peer all have direct test coverage (600-line architecture test suite) and CRDT idempotency protects the compaction path from its racy guard. The offline replay refactor correctly routes body mutations through CRDT sync and metadata mutations through a title-only queue, with a title-unchanged short-circuit preventing spurious API calls. No data loss or wrong-state scenario was found across the changed paths.

DocumentSession.swift (isCompacting guard) and DocumentLocalPersistencePeer.swift (silent retained-draft decode) warrant a second look before the session layer sees heavy production traffic.

Important Files Changed

Filename Overview
docmostly/Features/Editor/DocumentSession.swift New durable session layer: handles open/restore/retain-draft/compact/publish lifecycle. isCompacting guard is racy across await suspension points (benign due to CRDT idempotency).
docmostly/Persistence/DocumentLocalPersistencePeer.swift SwiftData-backed actor for sequenced updates, snapshots, and legacy migration. Silent try? for retained-draft decode risks silently losing unsynchronised user edits.
docmostly/Features/Editor/DocumentSessionRegistry.swift Session-per-key registry with generation-based invalidation and deduplication of concurrent creation tasks; logic looks correct.
docmostly/Persistence/DocumentStoreState.swift Four related value types grouped in one file, against project convention.
docmostly/App/AppState+OfflineQueue.swift Offline replay refactored: body mutations route through synchronizeQueuedDocument, title changes via replayPageMetadata with correct title==baseTitle short-circuit.
docmostly/App/AppState+EditorPersistence.swift updateCollaborativePageTitle now queues only metadata mutations; offline document body persistence delegated to the session layer.
Tools/CRDTRuntime/src/docmostly-crdt-runtime.js Adds validateUpdate and currentSnapshot; enqueueSnapshot title changed to null to align with session-owned title model.
docmostly/Features/Editor/NativeEditorCRDTSyncCoordinator.swift Coordinator now owns the committed-update stream with persistence-before-publish ordering guarantee.
docmostly/Features/PageReader/EmojiCatalog.swift Lazy static catalog parsed from bundled emoji-16.0.txt; tab-delimited parsing with group-header detection looks correct.
docmostly/Features/Spaces/SidebarRootView.swift Sidebar restructured with page browser section; task key correctly invalidates on space, scope, discovery, and favorite revision changes.
docmostlyTests/Persistence/DocumentSessionArchitectureTests.swift Comprehensive session-architecture tests covering ordering, deduplication, compaction, reconnect, two-window identity, and migration.

Sequence Diagram

sequenceDiagram
    participant VM as NativeRichEditorViewModel
    participant Reg as DocumentSessionRegistry
    participant Sess as DocumentSession
    participant Coord as NativeEditorCRDTSyncCoordinator
    participant Peer as DocumentLocalPersistencePeer
    participant Engine as NativeEditorCRDTDocumentEngine

    VM->>Reg: session(for:title:document:)
    Reg->>Engine: makeDocumentEngine(pageID:title:document:)
    Engine-->>Reg: engine
    Reg->>Sess: open(title:)
    Sess->>Peer: legacyMigrationCandidate(key)
    Peer-->>Sess: candidate?
    Sess->>Peer: commitLegacyMigration
    Sess->>Peer: load(key)
    Peer-->>Sess: DocumentStoredState
    Sess->>Engine: apply(snapshot)
    Sess->>Engine: apply(update) [per pending update]
    Engine-->>Sess: NativeEditorCRDTDocumentSnapshot
    Sess-->>Reg: session (open)
    Reg-->>VM: DocumentSession
    VM->>Sess: configureDocumentSession

    Note over VM,Coord: Normal edit cycle
    VM->>Coord: integrateLocalChange
    Coord->>Engine: integrateLocalChangeForCommit
    Engine-->>Coord: updates
    Coord->>Peer: append(update, origin:.local, key:)
    Peer-->>Coord: CommittedDocumentUpdate
    Coord->>VM: yield snapshot
    Coord->>Peer: "metrics -> compact if needed"

    Note over VM,Peer: Remote update
    Coord->>Engine: validate(update)
    Coord->>Peer: append(update, origin:.remote)
    Coord->>Engine: apply(update)
    Coord->>VM: publish(snapshot)
Loading

Reviews (2): Last reviewed commit: "test: cover unavailable CRDT attachment" | Re-trigger Greptile

Comment thread docmostly/Features/Editor/DocumentSession.swift Outdated
Comment thread docmostly/App/AppState+CollaborativeDraftResolution.swift Outdated
Comment thread docmostly/Persistence/DocumentLocalPersistencePeer.swift
Comment thread docmostly/Features/PageTree/PageBrowserScopeSwitch.swift Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 18b76e15ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docmostly/App/AppState+OfflineQueue.swift Outdated
Comment thread docmostly/Features/Editor/NativeRichEditorViewModel+Collaboration.swift Outdated
Comment thread docmostly/Features/Editor/NativeEditorCollaborationPresenceClient.swift Outdated
Comment thread docmostly/App/AppState+EditorPersistence.swift
@Chefski

Chefski commented Jul 23, 2026

Copy link
Copy Markdown
Owner Author

I love free runners

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 39 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread docmostly/App/AppState+EditorPersistence.swift Outdated
Comment thread docmostly/Features/Editor/NativeEditorCRDTSyncCoordinator.swift
Comment thread docmostly/Features/PageTree/PageTreeNodeArray.swift
Comment thread docmostly/Features/Editor/DocumentSessionRegistry.swift
Comment thread docmostly/App/AppState+OfflineQueue.swift Outdated
Comment thread docmostly/App/AppState+Management.swift Outdated
Comment thread docmostly/Features/PageTree/PageTreeViewModel.swift

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 21 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread docmostly/Features/Editor/NativeEditorCollaborationSyncDriver.swift Outdated
Comment thread docmostlyTests/Persistence/CacheRepositoryEditablePageTests.swift Outdated
Comment thread docmostly/Features/Editor/NativeEditorCollaborationPresenceClient.swift Outdated
@Chefski
Chefski merged commit 5c93f55 into dev Jul 24, 2026
7 checks passed
@Chefski
Chefski deleted the codex/durable-document-sessions branch July 24, 2026 07:22
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.

1 participant