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
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 usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /marimo, current file: none) bash-$
Assistant
Let me start by understanding the issue. The problem is that when using
marimo edit --watch, if a file contains git merge conflict markers (like<<<<<<<), marimo parses them asapp._unparsable_cell, which interferes with conflict resolution tools.The suggestion is to avoid updating the notebook if the file contains conflict markers, recognizable by
<<<<<<<at the beginning of a line.Let me first explore the repository structure to understand how it's organized and find the relevant code.
Assistant
Let me look at the marimo source directory to understand the structure.
Assistant
Let me search for the watch functionality and where file parsing happens:
Assistant
I need to focus on the file watching functionality, particularly related to the
--watchflag and how it handles file changes. Let me look at the file watcher and file change handler.Assistant
Let me look at the file change handler since that's likely where the file reload happens:
Assistant
Now let me look at the
app_file_manager.reload()method to understand where the file is parsed:Assistant
Now let me look at the
_load_appmethod to see how the file is loaded and parsed:Assistant
Let me look at the
load.load_appfunction:Assistant
Now I understand the flow. When a file changes:
file_change_handler.pycallssession.app_file_manager.reload()file_manager.pycalls_load_app()which usesload.load_app()- The file is parsed and if it contains conflict markers, they're treated as unparsable cells
The fix should be to check for conflict markers before reloading the file. Let me look at the
reloadmethod infile_manager.pymore closely and find where to add the check:Assistant
end
Assistant
There's no existing handling for git conflict markers. Let me look at the
file_change_handler.pymore closely to understand where I should add the check:Assistant
I see. The best place to add the check for conflict markers would be in the
_handle_file_change_lockedmethod infile_change_handler.py. Before reloading the file, we should check if the file contains conflict markers and skip the reload if it does.Let me also check what tests exist for this functionality:
Assistant
command>
<tool_call> <function=bash_terminal> <parameter=command> cat /marimo/tests/_session/test_file_change_handler.py </tool_call>
Assistant
Let me try again to read the test file.
Assistant
Now I understand the codebase. Let me create a test script to confirm the issue and then implement the fix.
Assistant
The user seems to have sent an empty message. Let me continue with my work on solving the issue. I was in the process of testing the conflict marker issue. Let me continue running the test.
Assistant
Let me use the virtual environment that's already set up in the repo:
Assistant
Good, this confirms the issue! When a file contains git conflict markers, the parser fails with a SyntaxError. Now let me understand how the file reload works and where to add the check. The issue states that conflict markers get parsed as
app._unparsable_cell, but from the error it seems like it's actually throwing a SyntaxError in some cases.Let me look at the error handling in the file change handler again:
Assistant
The user seems to have sent an empty message. Let me continue with my work. I was in the middle of investigating the issue and need to open the file_change_handler.py file to understand where to add the conflict marker check.
Assistant
Let me use the correct syntax for opening a file:
Assistant
Now I understand the issue. The
_handle_file_change_lockedmethod already has error handling for syntax errors, but conflict markers might be parsed asapp._unparsable_cellin some cases, which still updates the notebook state and interferes with conflict resolution tools.The fix should add a check before reloading to detect git conflict markers and skip the reload if they're present. Let me implement this:
Assistant
I'll add a helper function to check for conflict markers and use it in the
_handle_file_change_lockedmethod. The best place to add this check is right after the "content matches last save" check.Assistant
Let me try a different approach to edit the file:
Assistant
Now I need to add the actual check in the
_handle_file_change_lockedmethod. Let me find the right place to add it:Assistant
Now I need to add the conflict marker check after the "content matches last save" check and before the reload. Let me add it:
Assistant
Now let me verify the changes look correct:
Assistant
The code looks good. Now let me write a test script to verify that the fix works:
Assistant
The pattern works correctly. Now let me run the existing tests to make sure I didn't break anything:
Assistant
All existing tests pass. Now let me create a temporary test script to verify the new functionality works correctly:
Assistant
Let me debug the issue - it seems like the conflict markers aren't being detected:
Assistant
The pattern works when I test it directly. Let me check if the import is working correctly in the actual module:
Assistant
Interesting! The direct pattern search works, but
_has_conflict_markersreturnsFalse. There must be an issue with how the function is reading the file. Let me check:Assistant
That works too. There might be an issue with how the module imports
Path. Let me check the actual module code:Assistant
Hmm, this works. Let me check the actual function in the module - there might be an issue with the
Pathimport since it's only inTYPE_CHECKING:Assistant
That's the issue!
Pathis only imported insideTYPE_CHECKING, which means it's not available at runtime. I need to add a proper import forPathat runtime.Assistant
Now let me verify the changes:
Assistant
Good, now
Pathis imported at runtime. TheTYPE_CHECKINGimport is redundant now, but it won't hurt anything. Let me run my test again:Assistant
Now the function works. Let me run the full test script again:
Assistant
Excellent! All my tests pass. Now let me run the existing tests again to make sure I didn't break anything:
Assistant
All 23 existing tests pass. Let me also think about edge cases and verify that the fix handles them properly:
- Conflict marker only at start of line: ✅ The regex uses
^<<<<<<<withre.MULTILINE, so it only matches at the beginning of a line. - Conflict marker in the middle of a line: ✅ Should not match because of the
^anchor. - Empty file: ✅ Returns
Falsesince there's nothing to match. - Non-existent file: ✅ Returns
Falsedue to the try/except block. - Different encodings: The function uses UTF-8 encoding, which is the standard for Python files.
Let me also run any other related tests to make sure nothing is broken:
- Conflict marker only at start of line: ✅ The regex uses
Assistant
All 69 file-related tests pass. Let me view the final state of the modified file to make sure everything looks clean:
Assistant
Let me clean up the redundant
Pathimport in theTYPE_CHECKINGblock since we now import it at runtime:Assistant
There's an empty line left after removing the
Pathimport. Let me clean it up properly:Assistant
Now let me verify the imports look clean:
Assistant
Now let me run all the tests one more time to make sure everything still works:
Assistant
All tests pass. Let me also run my test one more time to confirm the fix works:
Assistant
Let me also view the diff to see exactly what changes I've made:
Assistant
The changes look clean and minimal. Let me clean up the temporary test file and verify the solution one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →