Skip to content

fix(editor): never save back a project's own file from the open dialog - #1097

Merged
EtienneLescot merged 1 commit into
mainfrom
fix/import-dialog-mcp-overwrite
Oct 10, 2026
Merged

EtienneLescot merged 1 commit into
mainfrom
fix/import-dialog-mcp-overwrite

Conversation

@EtienneLescot

@EtienneLescot EtienneLescot commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Opening a project's own file through the open dialog (or a drop) read it, then saved that content back as the project, so an MCP edit landing in between was overwritten. That was the gap left documented by #1040.

  • The dialog handlers now return storedProjectId when the file is a project's own file in the projects folder.
  • The editor then loads that project by id (a queued read like any other) instead of saving the file back. Any other file is imported as before.
  • The parse/migrate/save step the two open paths duplicated now lives in importProjectFile. beforeProjectFileRead is removed: with no save-back, the dialog's read needs no counting.
  • Doc: the known-gap bullet in mcp-server.md is gone.

Related issue

Follow-up to #1040 (CodeRabbit thread on document-service.ts).

Type of change

  • Bug fix

Release impact

  • Patch

Desktop impact

  • Not platform-specific

Testing

  • importProjectFile.test.ts: real DocumentService on a temp folder. The dialog reads a project's own file, an MCP edit is saved with saveProjectIfUnchanged, then the file is opened. The MCP edit survives; with the save-back restored the test fails (expected 'As read' to be 'Edited over MCP').
  • document-service.test.ts: storedProjectId names only files directly in the projects folder.
  • Both tsc configs, Biome, and the editor/MCP/document-service suites pass locally.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Opening a project’s own file no longer overwrites newer changes already made to that project.
    • Files opened from outside the projects folder continue to be imported as projects.

Opening a project's own file through the dialog (or a drop) read it, then saved that content as the project. An MCP edit landing between the read and the save was overwritten. The dialog now says when the file is a stored project's own file, and the editor loads that project by id instead of saving it back; any other file is imported as before.

The parse, migrate and save step the editor's two open paths duplicated now lives in importProjectFile. beforeProjectFileRead goes: with nothing saved back, the dialog's read no longer needs to count against MCP writes.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d68e467c-e0f7-423f-af4f-fccd2e7257f5

📥 Commits

Reviewing files that changed from the base of the PR and between fd8e6ce and d54feae.


📒 Files selected for processing (10)
  • electron/ai-edition/document-service.test.ts
  • electron/ai-edition/document-service.ts
  • electron/electron-env.d.ts
  • electron/ipc/handlers.ts
  • src/components/ai-edition/EditorEmptyState.tsx
  • src/components/ai-edition/NewEditorShell.tsx
  • src/components/ai-edition/importProjectFile.test.ts
  • src/components/ai-edition/importProjectFile.ts
  • src/native/contracts.ts
  • technical-documentation/architecture/mcp-server.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.



📝 Walkthrough

Walkthrough

Project-file loading now reports whether a file belongs to a stored project. A shared import helper handles migration, validation, and conditional saving. The editor’s file-picker and drag-and-drop paths use the helper to load the returned project.

Changes

Project File Import

Layer / File(s) Summary
Stored project identity
src/native/contracts.ts, electron/electron-env.d.ts, electron/ai-edition/document-service.ts, electron/ai-edition/document-service.test.ts, electron/ipc/handlers.ts
Load results now include an optional storedProjectId. DocumentService.storedProjectId returns an ID for supported files directly in the projects folder. The IPC loading paths return that ID and no longer call beforeProjectFileRead.
Shared project-file import
src/components/ai-edition/importProjectFile.ts, src/components/ai-edition/importProjectFile.test.ts
importProjectFile migrates and validates project data, then saves only when the document ID differs from storedProjectId. Tests cover preserving an intervening edit and importing an external document.
Editor import integration
src/components/ai-edition/EditorEmptyState.tsx, src/components/ai-edition/NewEditorShell.tsx, technical-documentation/architecture/mcp-server.md
The editor entry points use importProjectFile and load its returned project ID. NewEditorShell reports whether the import used the legacy path. The architecture documentation removes the open-dialog overwrite scenario from its known gaps.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Editor as Editor entry point
  participant IPC as Electron IPC
  participant DocumentService
  participant Importer as importProjectFile
  participant NativeBridge as Native save bridge
  participant ProjectStore as Project store

  Editor->>IPC: Load project file
  IPC->>DocumentService: Resolve stored project ID
  DocumentService-->>IPC: Return ID or undefined
  IPC-->>Editor: Return project and storedProjectId
  Editor->>Importer: Import project data and storedProjectId
  opt Project ID differs from storedProjectId
    Importer->>NativeBridge: Save imported project
    NativeBridge-->>Importer: Return save result
  end
  Importer-->>Editor: Return project ID and legacy flag
  Editor->>ProjectStore: Load project ID
Loading

Suggested reviewers: beetix


Merge Risk: ⚪ Minimal · up to d54fe

Opening a project's own file from the dialog or a drop now loads the stored project instead of saving the earlier read back over it. This prevents the overwrite of an intervening MCP edit. No merge-blocking risk was found.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 9 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main bug fix: preventing the editor from saving a project's own file back when opened through the dialog.
Description check Passed The description is complete and relevant. It includes the summary, related issue, bug-fix classification, patch release impact, desktop impact, and detailed testing information.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Full details: Docstring Coverage

Explanation

Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 9 files. (1 skipped: 1 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@EtienneLescot
EtienneLescot merged commit 3ee6a52 into main Oct 10, 2026
19 checks passed
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