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 start by exploring the repository structure to understand the
Assistant
Let me look at the edit command and the watch functionality:
Assistant
Now let me look at the file change coordinator to understand how it parses:
Assistant
Now let me look at how the load mechanism works to understand where conflict markers might be parsed:
Assistant
Now let me look at the file watcher:
Assistant
Now I understand the architecture. The file change coordinator at
marimo/_session/file_change_handler.pyis the right place to add the merge conflict marker check. Let me trace where the file change is detected and where it gets reloaded:Assistant
Now I have a good understanding. The key place to check for conflict markers is in
_handle_file_change_lockedinmarimo/_session/file_change_handler.py. Let me look at the existing tests to understand testing patterns:Assistant
Now I have a great understanding. Let me look at the current
_handle_file_change_lockedmethod more carefully:Assistant
Now let me think about the best place to add the merge conflict marker check. The issue suggests checking if the file contains conflict markers (recognized by
<<<<<<<at the beginning of a line) before reloading. Let me look at where exactly to add this check.Let me look at the session_manager.py to understand the flow:
Assistant
Now let me look at the
file_change_handler.pymore carefully to determine where to add the conflict marker check:Assistant
Now let me create a quick reproducer to confirm the issue:
Assistant
successfully reproduced the issue. The conflict markers (
<<<<<<< HEAD,=======,>>>>>>> branch-a) are getting included in cell source code as if they were code. Let me also look at_unparsable_cell:Assistant
Let me also look at the editor flow to understand how the conflict markers end up in unparsable cells:
Assistant
Now let me look at how the conflict markers would cause unparsable cells. Let me reproduce the exact case the user mentioned:
Assistant
Let me look at what triggers the unparsable cell - perhaps a more extreme case:
Assistant
Hmm, in this case it doesn't trigger unparsable cells either. Let me look at how cells are parsed. Maybe the conflict markers in an unusual place cause issues:
Assistant
OK, now I see the actual issue - when merge conflict markers appear in the file, they cause cells to be created (or modified) with the conflict marker content. The user's mention of
app._unparsable_cellmight be a specific case. Let me check the case where the conflict markers are inside the @app.cell decorator:Assistant
Now let me design the fix. I'll add a check for git merge conflict markers in the
_handle_file_change_lockedmethod. Let me first see what other patterns exist in the codebase:Assistant
Now let me look at how the file_change_handler reads file content:
Assistant
Now let me design my fix. I'll add a helper function to detect merge conflict markers and modify the
_handle_file_change_lockedmethod to skip reloading when conflict markers are present.Let me first run the existing tests to make sure they pass:
Assistant
All tests pass. Now let me implement the fix:
Assistant
Now I'll implement the fix. I'll add a helper function
_has_merge_conflict_markersthat checks if a file contains conflict markers, and modify_handle_file_change_lockedto skip reloading when such markers are present:Assistant
Now I'll implement the fix. Let me modify the
file_change_handler.py:Assistant
Let me try a different approach and use
replace:Assistant
I need to use proper syntax with line ranges. Let me try using
editwith proper text replacementAssistant
Now I'll modify the file using a script:
Assistant
Now let me verify the changes:
Assistant
The fix looks good. Now let me write a test to verify it works:
Assistant
All my tests pass. Now let me also verify that existing tests still pass:
Assistant
All existing tests still pass. Let me also check the related tests:
Assistant
The failure is unrelated to my changes - it's a process killing test that's flaky. Let me run only the file change handler related tests:
Assistant
All tests pass. Now let me also test edge cases:
Assistant
implementation actually behaves correctly here - per the issue, we should only check for
<<<<<<<at the beginning of a line. Thelstrip()handles leading whitespace but not arbitrary characters before the marker. This is intentional and matches the spirit of the issue. Let me fix the test:Assistant
All edge case tests pass. Now let me also check if there's a watcher-related test or other places that might need this fix:
Assistant
These are explicit export operations triggered by user action, not automatic file watching. The user explicitly asks for the export, so we should still try to do it. Let me verify the fix is robust by checking the full file change handler:
Assistant
Let me check the storage interface to understand what
storage.readreturns:Assistant
Good. The storage interface's
readmethod returns a string. My fix uses the storage interface, which is the correct approach.Now let me also run the broader tests to make sure nothing is broken:
Assistant
The only failure is unrelated to my changes - it's a process killing test that fails because of timing issues. Let me also test the original reproducer scenarios:
Assistant
The fix works correctly. The notebook is preserved during conflicts, and once the conflicts are resolved, the normal flow resumes.
Now let me also check the lint/typecheck:
Assistant
Now let me also clean up the test files I created:
Assistant
Let me check the final state of my change:
Assistant
Let me also run the broader session tests to make sure everything still works:
Assistant
All 339 tests pass. Let me also run a wider set of tests to make sure nothing is broken:
Assistant
All 49 server tests pass. Let me also do a quick check on the imports to make sure everything is consistent:
Assistant
Let me also verify that the change does not interfere with the "save" operation, which is a user-initiated action that should always proceed:
Assistant
The fix only affects the file watching path (external file changes), not the save path (user-initiated saves). Let me also check the run mode reload:
Assistant
Let me verify the entire flow end-to-end works:
Assistant
All scenarios work correctly:
- Normal file changes trigger reload
- Files with conflict markers skip reload
- Once conflicts are resolved, reload resumes
- Indented conflict markers are also detected
- Own writes are still skipped
Let me check the final diff to confirm everything is good:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.