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
{ "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
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me explore the marimo source directory.
Assistant
Let me explore the file manager to understand the reload logic.
Assistant
Let me look at how the file is loaded to understand the parsing.
Assistant
Now let me check how the file is parsed and where conflict markers might cause issues.
Assistant
Let me understand the file change handler more deeply to understand where I should add the check.
Assistant
Let me look at the file change handler more carefully to find the best place to add the conflict marker check.
Assistant
Let me look at existing tests for the file_change_handler to understand testing patterns.
Assistant
Let me write a script to reproduce the issue.
Assistant
I reproduced the issue. Now let me look at the storage interface to see how to read the file content.
Assistant
Let me also look at how the file content is read elsewhere to understand the convention.
Assistant
Let me check if there's a utility module for file-related helpers.
Assistant
Let me also look at the file watcher to make sure I understand the complete flow.
Assistant
Now I have a clear picture. Let me implement the fix. I'll add a check in the file change handler to skip the reload if the file contains merge conflict markers.
Assistant
Now let me make the changes to add the conflict marker check:
Assistant
Let me make the changes to the file_change_handler.py file. I'll add a helper function to detect git merge conflict markers, and use it in the _handle_file_change_locked method to skip the reload whenconflict markers are present.
Assistant
Let me look at where to best add the conflict marker check. I think adding it to
AppFileManagermakes the most sense sincefile_content_matches_last_save()is also there.Assistant
Let me now implement the fix. First, I'll add the helper method to
AppFileManager:Assistant
Now let me make the changes. I'll add a new method
has_merge_conflict_markers()toAppFileManagerand update the file change handler to use it.First, let me add the method:
Assistant
Now let me update the file_change_handler.py to use the new method:
Assistant
Now let me write a test script to verify the fix works:
Assistant
Let me fix my test assertion. The behavior is actually correct - "<<<<<<< not a real marker" does start with the marker prefix.
Assistant
All my tests pass. Let me also run the existing tests to make sure I haven't broken anything.
Assistant
All existing tests pass. Let me also run other related tests to make sure I haven't broken anything:
Assistant
The failure is unrelated to my changes. Let me skip this unrelated test and continue:
Assistant
All session tests pass. Let me also check related tests in the notebook directory:
Assistant
All notebook tests pass. Let me also run the broader test suite to make sure nothing else is broken:
Assistant
All AST tests pass. Now let me also write a test for the issue's exact scenario to make sure the fix works correctly:
Assistant
The fix works as expected. Let me verify my changes look clean:
Assistant
Let me check if there are any other places in the codebase where file changes are processed that might also need this check:
Assistant
These are all export endpoints, which are explicit user actions (clicking the export button), not file watch events. So they don't need the conflict marker check - they will likely fail gracefully anyway when trying to parse the file.
The main case is the file change handler triggeredby the watcher, which is what I've fixed.
Let me also verify by looking at the export.py to confirm those are user-triggered actions.
Assistant
These are explicit user-initiated export actions, not file watcher events. So they don't need to be modified.
Let me run all my tests one more time to confirm everything works:
Assistant
All 84 tests pass. Let me clean up the temporary test files:
Assistant
Let me verify the final state of the changes:
Assistant
Let me run a broader range of tests to confirm nothing is broken:
Assistant
All 340 session tests pass (only 1 unrelated kernel test was deselected). Let me also verify the changes once more by viewing the final state of both files:
Assistant
Let me also do a quick check by listing all the related tests:
Assistant
All 907 tests pass. The fix is working correctly.
Let me also verify the final solution by checking my changes once more:
Assistant
Let me make sure to check the checklist items:
Checklist:
-
"If an error was reported in the issue description, I have successfully reproduced it." - ✅ YES. I successfully reproduced the issue with a script that showed the cell code contained the conflict markers after a reload.
-
"If an error was reported in the issue description, I have confirmed that my fix resolves the error." - ✅ YES. After my fix, the file with conflict markers is no longer reloaded, preserving the original cell code. This was verified by my test scripts.
-
"I have thought about edge cases and made sure my fix handles them as well." - ✅ YES. Edge cases I considered:
- Empty files: Returns False (no conflict markers)
- Files without conflict markers: Returns False
- Files with
<characters in code (e.g., ): Returns False (only matches lines starting with )
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.