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
I'll start by exploring the repository to understand the codebase and locate the relevant files. Let's first get an overview.
- Assistant
Let me search more specifically within the marimo source code, excluding the .venv directory.
- Assistant
Let me look at the watch-related code in marimo, since the issue is about
marimo edit --watch. - Assistant
Let me explore the file watcher integration code:
- Assistant
Now let's look at the file change handler, which is where the notebook gets updated when a file changes:
- Assistant
Let me look at the
reloadmethod in the file manager: - Assistant
Now let me look at how
_load_appworks to see how the file is parsed: - Assistant
Let me see the _load_app method:
- Assistant
Now let me look at load.load_app to understand how it handles parsing:
- Assistant
Now let me look at the serializer to understand what happens with conflict markers:
- Assistant
Let me look at the serializer to understand how it handles file content:
- Assistant
Now let me look at the
parse_notebookfunction to understand what happens when conflict markers are present: - Assistant
Let me search for the parse_notebook function:
- Assistant
Let me look at the parse_notebook function.
- Assistant
Now let me look at where
_unparsable_cellis used in the app: - Assistant
Let me check what happens when a file with merge conflict markers is parsed. Let me look at how conflict markers might be handled:
- Assistant
Now I understand the issue. Let me look at how files are loaded and where we could add a check for conflict markers. Let me create a test to reproduce the issue first:
- Assistant
Let me try a simpler approach - let me look at the code flow to understand where we need to add the check. First, let me check if there's already any conflict marker detection:
- Assistant
Now let me look at the file_watcher_integration.py to see how it reads the file:
- Assistant
Let me understand the flow better. The issue is that when
marimo edit --watchis running, it reads the file and reloads it. Let me trace through the code to understand the full flow:- File watcher detects a change
- Calls
handle_changeinFileChangeCoordinator - Calls
_handle_file_change_locked - Calls
session.app_file_manager.reload() - Which calls
_load_app()->load.load_app()-> reads file -> parses it
The fix should be in the
_load_apporload_appmethod to check for conflict markers before parsing. Let me check where the file content is first read:Let me understand the flow better by looking at
_load_app: - Assistant
Now let me look at how
load.load_appworks: - Assistant
Let me see the full
load_appfunction: - Assistant
Now I understand the issue. When
marimo edit --watchis running and a file with git merge conflict markers is modified, the watcher tries to reload it. The merge conflict markers cause parsing issues. The suggestion is to check for conflict markers before attempting to reload.The best place to add this check is in
_maybe_contentsor in theload_appfunction, or in the_handle_file_change_lockedmethod. Let me look at the_handle_file_change_lockedmethod: - Assistant
Let me look at how the file is read in the
_handle_file_change_lockedmethod to understand where to add the check. I need to see how the file content is accessed: - Assistant
Let me look at the
_maybe_contentsfunction more carefully: - Assistant
Let me search for _maybe_contents:
- Assistant
Let me look at the
_maybe_contentsfunction more carefully: - Assistant
Let me look at the storage interface:
- Assistant
Now I understand the issue fully. Let me look at what happens when a file with conflict markers is parsed:
- Assistant
Let me look at what
session.app_file_manager.pathrefers to: - Assistant
Now let me understand the full picture. I need to trace what happens when a file with conflict markers is reloaded. The best place to add a check would be in the file change handler. Let me also check if there's a method that reads the file content that we can leverage:
- Assistant
Now I understand the issue. When
marimo edit --watchis running and a file with git merge conflict markers is modified, the watcher tries to reload the file. The conflict markers cause the parser to createapp._unparsable_cellentries, which messes with conflict resolution tools.The fix should be to check if the file contains conflict markers before attempting to reload. Let me look at the tests to understand the existing behavior:
- Assistant
Let me look at the test file for file_change_handler:
- Assistant
Now I have a clear understanding of the issue. Let me check what tests exist for this scenario:
- Assistant
Now I have a clear understanding of the issue. Let me create a plan:
The issue is that when
marimo edit --watchis running and a file with merge conflict markers is modified (e.g., fromgit stash pop), the watcher detects the change and tries to reload the file. The conflict markers get parsed and cause issues - they get interpreted asapp._unparsable_cellentries, which messes with conflict resolution tools.The solution: We should detect merge conflict markers in the file content and skip the reload when they are present.
The best place to add this check is in the
_handle_file_change_lockedmethod inFileChangeCoordinator, right after checking if the content matches the last save. We need to:- Read the file content
- Check if it contains conflict markers (specifically
<<<<<<<at the beginning of a line) - If it does, skip the reload and log a warning
Let me first understand how to read the file content in the handler. Let me check the existing
file_content_matches_last_savemethod: - Assistant
Now let me look at the
pathproperty: - Assistant
Now I understand the issue. Let me implement the fix. The best place to add the check is in the
_handle_file_change_lockedmethod inFileChangeCoordinator. I need to read the file content and check for merge conflict markers before attempting to reload: - Assistant
Let me refine my test to handle the comment case correctly:
- Assistant
Wait, the docstring case is fine. The conflict markers are inside a multi-line string literal, which wouldn't be a real merge conflict scenario. Let me adjust my test:
- Assistant
Now let me implement the fix. I need to add the check in
_handle_file_change_lockedinfile_change_handler.py. Let me first understand the current flow better: - Assistant
Now let me implement the fix. I'll add a helper method to
AppFileManagerand use it in_handle_file_change_locked: - Assistant
Now I need to implement the fix. Let me look at the
_handle_file_change_lockedmethod more carefully and understand where to add the check. The best approach is to add a helper method to check for conflict markers, and call it in_handle_file_change_lockedbefore reloading. Let me implement this: - Assistant
Now let me implement the fix. I'll add a method to
AppFileManagerto check for conflict markers, and call it in_handle_file_change_locked. First, let me look at the current implementation of_handle_file_change_locked: - Assistant
Now I have a clear understanding. Let me implement the fix. I need to:
- Add a helper function to check for merge conflict markers
- Add a check in
_handle_file_change_lockedto skip reload when conflict markers are detected - Also consider adding a check in
AppFileManagerto expose whether the file has conflict markers
Let me implement this step by step. First, let me look at the
_handle_file_change_lockedmethod and understand the best place to add the check: - Assistant
Now let me implement the fix. I'll add a helper function to check for conflict markers and integrate it into the file change handler. The best approach is to:
- Add a helper function that checks if file content has merge conflict markers
- Add the check in
_handle_file_change_lockedbefore callingreload()
Let me first look at the current implementation of
_handle_file_change_lockedmore carefully: - Assistant
Now I have a clear understanding. Let me implement the fix. I'll add the check for merge conflict markers in
_handle_file_change_lockedright before attempting to reload. Here's my approach:- Add a helper function to check for merge conflict markers in the file content
- Add the check in
_handle_file_change_lockedafter checking for own writes but before reloading
Let me also look at the
_maybe_contentsfunction inload.pyto understand where the file is read: - Assistant
Now I have a thorough understanding of the issue and the codebase. Let me implement the fix. The issue is that when
marimo edit --watchis running and a file with merge conflict markers (like<<<<<<<) is modified, the watcher tries to reload the file and parses the conflict markers asapp._unparsable_cell.The fix should be to check for merge conflict markers in the file content before attempting to reload. The best place to add this check is in
_handle_file_change_lockedin theFileChangeCoordinatorclass.Let me implement this:
- Assistant
Now let me implement the fix. I'll add a helper function to check for merge conflict markers, and modify
_handle_file_change_lockedto skip reload when conflict markers are detected: - Assistant
Let me try using the replace command instead.
- Assistant
Let me use the replace command:
- Assistant
Let me navigate to line 216 first.
- Assistant
Now let me apply the edit to add the merge conflict check:
- Assistant
Now I need to add the
_file_has_merge_conflict_markersfunction. Let me add it at the module level: - Assistant
Now let me add the
_file_has_merge_conflict_markersfunction. I'll add it at the module level: - Assistant
Good, the changes look correct. Let me verify the full modified file looks correct by viewing the critical section:
- Assistant
Now let me run the existing tests to make sure they still pass:
- Assistant
Let me install the missing module or find a way to run the tests.
- Assistant
Now let me run the tests again:
- Assistant
Let me install the dependencies.
- Assistant
Now let me run the tests again:
- Assistant
The test failure is due to missing async test support. Let me install pytest-asyncio:
- Assistant
Let me try running the tests again with pytest-asyncio installed:
- Assistant
All 23 tests pass. Let me also run the file watcher integration tests:
- Assistant
All tests pass. Now let me create a test script to verify the fix works correctly with merge conflict markers:
- Assistant
Let me also test the full integration by simulating the actual scenario with
FileChangeCoordinator: - Assistant
The fix works correctly. Let me run the broader test suite to make sure I haven't broken anything:
- Assistant
Let me run the tests without the timeout flag.
- Assistant
Let me skip that test and run just the file change handler tests:
- Assistant
All 32 tests pass. Let me also run the notebook file manager tests:
- Assistant
All tests pass. Let me also run the AST tests:
- Assistant
Let me install inline_snapshot and run those tests too:
- Assistant
Let me also verify the final state of the changed file:
- Assistant
The diff looks clean and correct. Let me also clean up the temporary test files:
- Assistant
Let me also run the _ast tests that don't require inline_snapshot:
- Assistant
Let me check if that test failure is pre-existing (unrelated to my change):
- Assistant
Good, the test failure is pre-existing and unrelated to my change. Let me restore my changes:
- Assistant
Let me verify the final state of the change one more time:
- Assistant
Now let me verify the final file looks correct:
- Assistant
Let me view the full modified file:
- Assistant
Let me run the full test suite one more time to make sure everything is working:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.