Skip to content

fix(file-editor): preserve drafts and harden editing behavior - #7478

Open
waleedlatif1 wants to merge 3 commits into
stagingfrom
codex/file-editor-safety
Open

fix(file-editor): preserve drafts and harden editing behavior#7478
waleedlatif1 wants to merge 3 commits into
stagingfrom
codex/file-editor-safety

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Join a newly typed list item with a compatible neighboring list, preserving autoformat undo without bridging two pre-existing collaborative lists.
  • Improve Markdown fidelity, GFM-persistable table editing, toolbar keyboard handling, paste admission and asynchronous image insertion.
  • Preserve drafts across reload/streaming transitions; use version checks for stale saves and bounded recovery from rotated storage keys.
  • Retain the existing empty-middle-list behavior. A collaborative list-exit redesign and dependency upgrades are intentionally excluded.

Type of Change

  • Bug fix

Testing

  • 1,727 tests passed across 125 editor, collaboration, persistence and query suites.
  • All workspace type checks, lint, 45 repository audits including strict API validation, and docs-manifest validation passed.
  • Added 24 delayed-peer list cases across bullet, ordered and task lists, nested variants and both update orders; assert preserved content as well as convergence.
  • Added regression coverage for paused discard corrections, conflict-version ordering, storage-key recovery, session reset, frontmatter-aware paste and invalidated image-picker feedback.
  • Real two-peer image tests verify conservative anchor cancellation preserves intervening edits.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced in required checks
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 4, 2026 7:28am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR hardens file editing by preserving local drafts, adding version-aware saves and conflict recovery, and improving rich Markdown editing behavior.

  • Adds optimistic concurrency checks and an explicit save-conflict recovery interface.
  • Coordinates autosave, streamed content, storage-key rotation, reloads, and client cache state.
  • Improves list collaboration, Markdown round trips, table editing, paste handling, image insertion, keyboard behavior, and editor lifecycle synchronization.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/use-editable-file-content.ts Coordinates draft ownership, streamed content, save versions, conflict state, reloads, and storage-key recovery.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor-state.ts Adds reducer-level synchronization and stale-version protections for accepted baselines, drafts, and conflicts.
apps/sim/hooks/use-autosave.ts Strengthens queued draft persistence, discard correction, and recovery behavior.
apps/sim/hooks/queries/workspace-files.ts Adds version-aware content mutations, bounded stale-storage-key recovery, and related cache reconciliation.
apps/sim/app/api/workspaces/[id]/files/[fileId]/content/route.ts Passes validated content-version preconditions into the authorized file-update use case.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/extensions.ts Expands Markdown schema and serialization behavior for lists, tables, hard breaks, and structural empty paragraphs.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/image-upload.ts Introduces transaction-mapped placeholders for cancellable asynchronous image insertion.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/list-input-rules.ts Joins newly typed compatible lists while preserving undo and collaborative-list boundaries.

Sequence Diagram

sequenceDiagram
  participant User
  participant Editor
  participant Draft as Local Draft
  participant API as File Content API
  participant Store as Workspace Storage
  User->>Editor: Edit file
  Editor->>Draft: Preserve and autosave draft
  Editor->>API: Save(content, expectedUpdatedAt)
  API->>Store: Compare version and update
  alt Version matches
    Store-->>API: Updated content and version
    API-->>Editor: Save acknowledged
    Editor->>Draft: Mark draft saved
  else Version changed elsewhere
    Store-->>API: Conflict
    API-->>Editor: 409 conflict
    Editor-->>User: Preserve draft and pause saving
    User->>Editor: Download draft or reload latest
  end
Loading

Reviews (3): Last reviewed commit: "fix(file-editor): retain conflicts with ..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 67 files

Re-trigger cubic

Comment thread apps/sim/hooks/use-autosave.ts Outdated
Comment thread apps/sim/stores/file-viewer/store.ts
Comment thread apps/sim/hooks/queries/workspace-files.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 69 files

Confidence score: 4/5

  • In apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/image-upload.test.ts, the unrelated parametrized case inserts PEER well after the anchor range in another paragraph, so it may not validate the plugin’s handling of the intended edit interaction and could leave a regression undetected — align the peer insertion with the scenario the test is meant to cover.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/image-upload.test.ts">

<violation number="1" location="apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/image-upload.test.ts:52">
P2: In the `unrelated` branch of this parametrized test, the peer inserts `'PEER '` at `content.size - 1` (position 21), which is well after the anchor range 8–14 in a separate paragraph. Per the plugin's apply() logic, an insert entirely after the range maps `from`/`to` unchanged and keeps `doc.slice(from,to).eq(replacement)` true, so the anchor survives and `finishImageUpload` should return true — yet the test asserts `findImageUploadRange(...)` is null and `finishImageUpload(...)` is false for both `unrelated` values. This directly contradicts the sibling test 'maps a replacement through edits before it', which shows unrelated interrupts preserve the anchor. Either the implementation is silently cancelling a local pending upload when a collaborator edits an unrelated paragraph (a user-facing bug: the image upload is dropped), or this assertion is wrong and the case is not actually covering what its name claims. Resolve the discrepancy and make the two cases assert distinct, correct outcomes.</violation>
</file>

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

Fix all with cubic | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 69 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

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