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. Assistant
Let me understand the issue:
- When using
marimo edit --watch, if a file contains git merge conflict markers (like<<<<<<<,=======,>>>>>>>), marimo parses them asapp._unparsable_cell - This interferes with conflict resolution tools
- The suggestion is to avoid updating the notebook if the file contains conflict markers
Let me start by exploring the repository structure to understand how the codebase is organized.
- When using
Assistant
Let me explore the marimo source directory more specifically.
Assistant
Let me search for files related to file watching, parsing, and the
_unparsable_cellmentioned in the issue.Assistant
I need to explore the repository structure to understand where the file watching logic is and how to add conflict marker detection. Let me search for the watch-related code and the parsing/unparsable cell logic.
Assistant
I found the relevant files. Let me look at the file watching and file change handling code, particularly
_session/file_change_handler.pyand_session/file_watcher_integration.py.Assistant
Now let me look at the
app_file_manager.reload()method to understand how the file is loaded and parsed:Assistant
Now I see the key flow. The
reload()method calls_load_app()which parses the file. Let me look at the_load_appmethod and theloadmodule to understand how parsing works:Assistant
Now let me look at the
load.load_appfunction:Assistant
Now I understand the flow. When the file is reloaded in
reload(), it calls_load_app()which usesload.load_app(), which deserializes the notebook. If there are conflict markers, they get parsed asUnparsableCell.Let me look at where the file change handling happens to add the conflict marker check:
Assistant
So there's no existing handling for conflict markers. Let me check how the parsing/scanner handles things:
Assistant
The best place to add the conflict marker check is in the
file_change_handler.py, specifically in_handle_file_change_lockedbefore callingreload(). This way, we can detect conflict markers and skip the reload if they exist.Let me also check what the error handling looks like:
Assistant
Now I see where to add the conflict marker check. I should check if the file contains conflict markers before attempting to reload. Let me first look at what tests exist:
Assistant
Now I have a good understanding of the codebase. Let me create a test script to confirm the issue:
Assistant
I need to activate the virtual environment to run the test script.
Assistant
Interesting! The current behavior shows that when conflict markers are present, the file change handler catches a syntax error and returns
handled=False. But let me check if there's another code path where unparsable cells get created. Let me look at the parse module:Assistant
Let me check if there's a scanner fallback that handles syntax errors:
Assistant
I see! So when there's a syntax error, the parser uses a fallback scanner. Let me run my test again with the full flow to see the actual behavior:
Assistant
So the error is actually raised from the serializer handler level, not from the parse module. Let me trace back more carefully:
Assistant
Let me look at the
parse_notebookfunction more closely to trace the error:Assistant
So the scanner fallback also fails because the conflict markers are in the preamble (before the cells). This error propagates up. Let me check where this exception is being caught:
Assistant
I see! The scanner fallback has a
raisefor preamble errors on line 620:raise # Preamble errors are fatal. This means when conflict markers appear in the preamble (before the cells), the error is re-raised and propagates up.Now, looking at the issue description again, the user reports that conflict markers are parsed as
app._unparsable_cell. This might happen in a different scenario where the conflict markers are within cell code, not in the preamble. Let me test that:Assistant
Now I've confirmed the issue! When conflict markers are within a cell (not in the preamble), they get parsed as
UnparsableCell. This is the issue described by the user.The best solution would be to detect conflict markers in the file before attempting to parse/reload it. Let me implement the fix:
Plan:
- Add a helper function to detect if a file contains git conflict markers
- In
file_change_handler.py, check for conflict markers before callingreload()and skip the reload if they're found
Let me implement this:
Assistant
Now let me look at where to add the conflict marker check in
_handle_file_change_locked:Assistant
Now I'll add the conflict marker check. I'll add a helper function and use it in
_handle_file_change_locked. Let me first open the file:Assistant
I need to use the correct syntax for the open command.
Assistant
Now let me implement the fix. I'll add a helper function to check for conflict markers and use it before reloading:
Assistant
I need to use the
editcommand with proper syntax. Let me try again.Assistant
Let me first open the file and then use edit:
Assistant
Now I'll add a helper function to check for git conflict markers. Let me add it after the LOGGER definition:
Assistant
Good. Now let me add the helper function after the LOGGER definition (after line 26):
Assistant
Command
Assistant
Good! Now I need to add the helper function and update the
_handle_file_change_lockedmethod to check for conflict markers before reloading. Let me find the line numbers:Assistant
Now I'll add the conflict marker check after the "file_content_matches_last_save" check (after line 227) and before the "Reload the file manager" comment (line 228). Let me use sed to insert the new code:
Assistant
Let me verify the changes were applied correctly.
Assistant
The changes look good. Now let me test to make sure the fix works:
Assistant
The test shows that
handled=Falsewith no error, and the notebook is not corrupted (still has the original cell withx = 1andunparsable=False). This is exactly the behavior we want.Now let me also test that normal file changes (without conflict markers) still work correctly:
Assistant
Normal changes still work correctly. Now let me also test edge cases:
- Conflict markers only in comments (should still be detected)
- The
>>>>>>>or=======markers without<<<<<<<(should not trigger the skip) - Conflict markers in markdown files
Assistant
Command
The fix works correctly for all the test cases. Let me now run the existing tests to make sure I haven't broken anything:
Assistant
All 23 tests pass. Now let me also check if there are any other related tests I should run:
Assistant
All tests pass. Let me also run some broader tests related to session management and parsing to ensure nothing is broken:
Assistant
The only failing test is unrelated to my changes - it's about process killing (
test_try_kill_process_and_group_kills_grandchild), which is a flaky test related to OS-level process management.Let me verify by looking at the full file I modified to make sure everything is correct:
Assistant
I need to review the code I've modified and make sure everything is correct. Let me use the bash_terminal tool to verify the file content.
Assistant
The code looks correct. Let me run the tests one final time to confirm everything works, then submit.
Assistant
All tests pass. Let me verify the changes one more time and then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.