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
marimo edit --watchis running, it watches for file changes and reloads the notebook. - If git merge conflicts occur (e.g., during cherry-pick or stash pop), the file contains conflict markers like
<<<<<<<,=======,>>>>>>>. - The watcher parses these conflict markers and creates
_unparsable_cellcells, which interferes with conflict resolution tools.
The suggestion is: Avoid updating the notebook if the file contains conflict markers, recognizable by
<<<<<<<at the beginning of a line.Let me explore the repository structure to understand how the codebase is organized and find the relevant code.
- When
Assistant
Let me find the relevant code for the
--watchfunctionality and the file watcher.Assistant
Let me look at the key files related to file watching:
Assistant
Let me look at these files and also search for where
_unparsable_cellis referenced.Assistant
Now let me look at the file watcher and how it integrates with the notebook. The key files are:
marimo/_utils/file_watcher.py- the file watchermarimo/_session/file_watcher_integration.py- integration layer
Let me also look for where files are read before being processed.
Assistant
Now let me look at the file watcher integration to see how the callback handles file changes.
Assistant
Now I need to find where the
on_change_callbackis defined — the actual callback that handles file changes when watchingAssistant
Let me look at
session_manager.pyto understand how the file change is handled.Assistant
Let me look at
file_change_handler.pywhich contains the actual file change logic:Assistant
Let me look at the
reloadmethod in the app file manager:Assistant
Let me look at the
reloadmethod infile_manager.py:Assistant
Let me search for all callers of the
reloadmethod to understand the full scope of changes needed:Assistant
Let me check if there's already a utility for detecting conflict markers anywhere in the codebase
Assistant
Now I have a clear understanding of the code. Let me implement the fix. The issue is in
_handle_file_change_lockedinfile_change_handler.py. Before callingreload(), we should check if the file contains git conflict markers and skip the reload if it does.Let me open the file and add the check
Assistant
The open command requires a FILE and LINE_NUMBER. Let me try again.
Assistant
Let me try the open command differently.
Assistant
Let me scroll to the
_handle_file_change_lockedmethodAssistant
Now I'll implement the fix. I need to:
- Add a helper function to detect git conflict markers
- Add a check in
_handle_file_change_lockedto skip reload when conflict markers are present
Assistant
Now let me add the helper function after the LOGGER definition and before the TYPE_CHECKING block
Assistant
Now let me add the conflict marker check in
_handle_file_change_locked. Let me find the current lines:Assistant
Now I need to add the check after line 230 (
return FileChangeResult(handled=False)) and before line 232 (# Reload the file manager). Let me look at the exact lines:Assistant
Now I'll add the conflict marker check right after the
file_content_matches_last_saveblock and before the# Reload the file managercommentAssistant
The changes look good. Let me verify the entire file is correct:
Assistant
The file looks good. Now let me find and run the existing tests for file change handling:
Assistant
Let me look at the test file for file change handler:
Assistant
Let me run the existing tests to make sure they pass:
Assistant
Let me install the dependencies first
Assistant
Now let me run the tests again
Assistant
The async tests failed due to missing
pytest-asyncio. Let me install it and re-run:Assistant
Let me install the test dependencies from the project.
Assistant
Let me run the tests again.
Assistant
All 23 tests pass. Now let me write a quick script to verify my fix works correctly for the specific scenario described in the issue:
Assistant
Let me also run the file watcher integration tests
Assistant
All tests pass. Let me also run the broader set of session tests to make sure nothing is broken:
Assistant
Let me avoid that failing test and run only the relevant files
Assistant
All 36 tests pass. Let me verify my changes with git diff:
Assistant
The changes look perfect. Let me verify the logic one more time by looking at the full flow:
- When a file change is detected by the file watcher,
FileChangeCoordinator.handle_change()is called - This calls
_handle_file_change_locked() - My fix adds a check before the
reload()call: if the file contains<<<<<<<at the beginning of any line, the reload is skipped - This prevents marimo from parsing git conflict markers as
app._unparsable_cellcells - Once the user resolves the conflicts and saves, the file watcher will pick up the change and reload normally
Let me now run through the checklist:
Checklist:
- : The issue describes how parses git conflict markers as . I traced the code path: file watcher → → → → which parses the file. The markers get parsed as unparsable cells instead of causing an error. My fix adds a pre-check before reload.
- When a file change is detected by the file watcher,
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.