ISSUE DESCRIPTION marimo edit --watch messes with merge conflict markers Describe the…
- User
ISSUE DESCRIPTION
marimo edit --watch messes with merge conflict markers
Describe the bug
When cherry-picking commits, or
git stash poping, sometimes merge conflicts occur.If a notebook is open using
marimo edit --watchduring that time, it parses the git conflict markers asapp._unparsable_cell. This gets in the way of resolving the conflicts using conflict resolution tools likegit-mediateSuggestion: Avoid updating the notebook if the file contains conflict markers, recognizable by
<<<<<<<at the beginning of a line.Will you submit a PR?
- Yes
Environment
code{ "marimo": "0.23.6", "editable": false, "location": "/Users/yairchu/dev/soundradix/Drum3D/.venv/lib/python3.13/site-packages/marimo", "OS": "Darwin", "OS Version": "25.2.0", "Processor": "arm", "Python Version": "3.13.1", "Locale": "C/en_US", "Binaries": { "Browser": "140.0.7339.134", "Node": "v23.11.0", "uv": "0.7.12 (dc3fd4647 2025-06-06)" }, "Dependencies": { "click": "8.4.0", "docutils": "0.22.4", "itsdangerous": "2.2.0", "jedi": "0.19.2", "markdown": "3.10.2", "narwhals": "2.21.2", "packaging": "26.2", "psutil": "7.2.2", "pygments": "2.20.0", "pymdown-extensions": "10.21.3", "pyyaml": "6.0.3", "starlette": "1.0.0", "tomlkit": "0.15.0", "typing-extensions": "4.15.0", "uvicorn": "0.47.0", "websockets": "16.0" }, "Optional Dependencies": { "altair": "6.1.0", "anywidget": "0.11.0", "loro": "1.10.3", "pandas": "3.0.3" }, "Experimental Flags": {} }Code to reproduce
No response
Interface
Assistant
Let me explore the repository structure to understand how it's organized and find the relevant code for the
--watchfunctionality.Assistant
The key method is
_handle_file_change_locked. When a file change is detected, it callssession.app_file_manager.reload(). The issue is that when the file contains git merge conflict markers, the reload parses them as_unparsable_cellwhich corrupts the file.Let me look at the
file_manager.pyto understand the reload process.Assistant
The issue is that when a file change is detected with merge conflict markers, the file is reloaded and parsed, which corrupts the file. The suggestion is to avoid updating the notebook if the file contains conflict markers.
Let me look at the
_handle_file_change_lockedmethod again. The flow is:_handle_file_change_lockedis called- It checks
file_content_matches_last_save() - It calls
session.app_file_manager.reload()which calls_load_app(self.path)
The fix should be to detect merge conflict markers in the file content and skip the reload if found.
Let me check the middle portion of the file_manager.py that got truncated.
Assistant
Now I understand the flow. The fix should be in
_handle_file_change_lockedinfile_change_handler.py. We should check if the file content contains merge conflict markers before reloading.Let me also check the
file_watcher_integration.pyto understand the full flow.Assistant
Now I understand the architecture. The fix should be in
_handle_file_change_lockedinfile_change_handler.py. We need to detect merge conflict markers in the file content before reloading.Let me look at the existing tests for the file change handler.
Assistant
Now I understand the test structure and the code flow. Let me implement the fix:
- Add a helper to detect merge conflict markers
- Add a method to
AppFileManagerto check for them - Skip reload in
_handle_file_change_lockedwhen conflict markers are detected
Let me first add the helper and method to
file_manager.py:Assistant
Now let me add a
has_merge_conflict_markersmethod toAppFileManager:Assistant
Now let me add the
_has_merge_conflict_markershelper function at the module level. Let me find the_maybe_pathfunction:Assistant
The
<<<<<<<in the heredoc conflicts with the shell. Let me use a Python script to do the insertion instead:Assistant
Now let me update
_handle_file_change_lockedinfile_change_handler.pyto skip reload when conflict markers are detected:Assistant
Now let me add the merge conflict check between the "matches last save" check and the reload:
Assistant
Now let me write a reproduction script to verify the fix works:
Assistant
All tests pass. Now let me run the existing tests for the file change handler to make sure I didn't break anything:
Assistant
The failure is due to missing
pytest-asyncioplugin, not my change. Let me install it:Assistant
All 23 tests pass. Let me also run the file watcher integration tests and the file manager tests:
Assistant
All tests pass. Let me also verify there are no lint issues with my changes by checking if the codebase uses any linter:
Assistant
Let me also run a quick check on the ruff linter if available.
Assistant
Ruff isn't installed. Let me clean up the temp files and review the final diff:
Assistant
I notice there's a missing blank line between the new method and the
read_css_filefunction. Let me check:Assistant
I need to add the two blank lines between the method (end of class) and the module-level function:
Assistant
Now let me re-run the tests to confirm everything still passes:
Assistant
All 84 tests pass. Let me re-run the reproduction script once more to confirm the fix works end-to-end:
Assistant
Let me view the final diff one more time to confirm everything is clean:
Assistant
The diff is clean. Let me also run the resume_session test which references
FileChangeCoordinator:Assistant
Let me check if this test failure is pre-existing (unrelated to my change) by stashing my changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.