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
I'll start by exploring the repository structure and finding the relevant code for the
--watchfunctionality.Assistant
Now I need to look at the
reloadmethod in theapp_file_manager(file_manager.py) to understand how the file is parsed. Let me look at the file manager.Assistant
Now I need to understand the flow. The issue is that when
marimo edit --watchdetects a file change, it parses the file which may contain merge conflict markers, and these get parsed as_unparsable_cell. The suggestion is to avoid updating the notebook if the file contains conflict markers (<<<<<<<at the beginning of a line).Let me look at where the file change is handled and where the content is read. The best place to add the check would be in the
_handle_file_change_lockedmethod infile_change_handler.py, before callingreload(). Or in thereloadmethod infile_manager.py, before loading the app.Let me look at how the file content is read and check the
file_content_matches_last_savemethod. The check for conflict markers should happen beforereload().Let me check if there's already a utility for detecting conflict markers.
Assistant
No existing conflict marker detection. Let me understand the flow better and look at how the
reloadmethod works with the file content.Assistant
Now I have a good understanding. I'll add a method to
AppFileManagerto check for merge conflict markers, and use it in the_handle_file_change_lockedmethod infile_change_handler.pyto skip reload when conflict markers are present.Let me first look at the existing tests for the file change handler to understand the testing conventions.
Assistant
Now I understand the codebase well. Let me implement the fix. I'll add a method to
AppFileManagerto detect merge conflict markers and use it in the file change handler to skip reload when conflict markers are present.Assistant
The regex has a bug - the
||||||||part creates empty alternations. Let me fix and test properly.Assistant
The regex works correctly. Now let me check what utility modules exist for placement.
Assistant
Now I'll implement the fix. I'll add a utility function to detect merge conflict markers and add a method to
AppFileManagerto check for them. Then I'll use it in_handle_file_change_locked.Let me put the utility function in
marimo/_utils/strings.pysince it's a string utility, or maybe in a new file. Let me check what's in strings.py.Assistant
Now I'll implement the fix. I'll add a utility function to detect merge conflict markers in
strings.py, add a method toAppFileManager, and use it in the file change handler.Assistant
The import chain triggers marimo's full init. Let me test the function in isolation.
Assistant
The function works. Let me check if importing from
_utils.stringsworks in the test context since the marimo package init is involved.Assistant
There's a venv with dependencies. Let me check how to run tests properly.
Assistant
The function works with the venv Python. Now let me add a method to
AppFileManagerto check for conflict markers, and use it in the file change handler.Assistant
Now let me add the import and method. First, add the import:
Assistant
Now let me add a method to
AppFileManagerto check for conflict markers. I'll add it right afterfile_content_matches_last_save:Assistant
I need to fix the spacing - there should be two blank lines before the module-level function. Let me fix that:
Assistant
There's still only one blank line. Let me fix it to have two blank lines:
Assistant
Now let me add the check in the file change handler. Let me open the relevant section:
Assistant
Let me add a blank line before the comment for proper formatting:
Assistant
Now let me check the
pathproperty used in the file change handler to make sure my code is consistent:Assistant
Let me check the
file_watcher_integration.pyto see if there are other places where file changes are handled:Assistant
This delegates to
_on_change_callbackwhich is theFileChangeCoordinator.handle_change. Let me check where the callback is set to confirm it goes throughFileChangeCoordinator.handle_change.Assistant
All file change paths go through
FileChangeCoordinator.handle_change→_handle_file_change_locked, where I added the check. Now let me verify the changes compile and run the existing tests.Assistant
Now let me write a reproduction script to confirm the fix works:
Assistant
The fix works. Now let me run the existing tests to make sure nothing is broken:
Assistant
This test failure is unrelated to my change (it's about process group killing in the test environment). Let me verify it's pre-existing by stashing my changes:
Assistant
The test failure is pre-existing and unrelated to my changes. Let me run the rest of the session tests (excluding the unrelated failing test) and also the strings/file_manager tests:
Assistant
Let me also check tests for the file_manager and run any tests that test file watching:
Assistant
Let me reconsider edge cases. The
=======marker could appear as a markdown setext heading (e.g.,Title\n=======). Let me check if marimo supports markdown notebooks where this could be a false positive.Assistant
Let me check if marimo supports markdown (.md) notebooks, since
=======could be a setext heading in markdown.Assistant
Marimo supports markdown notebooks (.md, .markdown, .qmd). In a markdown notebook,
=======at the start of a line is valid setext heading syntax. Let me check how a markdown notebook is structured.Assistant
Important edge case: marimo supports markdown notebooks (.md, .markdown, .qmd), where
=======at the start of a line is valid setext heading syntax, and>>>>>>>could be a deeply nested blockquote. The issue specifically suggests detecting<<<<<<<at the beginning of a line, which is the canonical start-of-conflict marker and is unambiguous in both Python and markdown. Every git conflict block starts with<<<<<<<, so checking for it alone is sufficient and avoids false positives.Let me update the function to only check for
<<<<<<<at the start of a line:Assistant
Now let me update the docstring in
file_manager.pyto match the more targeted approach:Assistant
Now let me re-run the reproduction script and tests to verify everything still works with the updated approach:
Assistant
The markdown edge case (setext heading
=======and nested blockquote>>>>>>>) correctly does NOT trigger a false positive. Now let me test that an actual conflict in a markdown notebook IS detected:Assistant
Both edge cases pass. Now let me run the full test suite for the affected modules:
Assistant
All tests pass. Let me also run a broader test to make sure I haven't broken anything in the server/session_manager area:
Assistant
Now let me clean up the temporary test files and review the final diff:
Assistant
The diff looks clean. Let me verify linting passes (the project likely uses ruff):
Assistant
The ruff errors are pre-existing (property docstrings at lines 98-100 and 395-397 that start with "Get"), not related to my changes. Let me confirm by checking the full ruff output and verifying my added lines aren't flagged:
Assistant
Confirmed the original file already had 2 pre-existing ruff errors. My change added a third one. Let me find it:
Assistant
The third error is
unsorted-imports- my import isn't sorted. "scripts" should come before "strings". Let me fix the import ordering:Assistant
Now only the 2 pre-existing ruff errors remain (property docstrings at lines 100 and 397), and my changes introduce no new lint errors. Let me run the tests one final time to confirm everything is good:
Assistant
All tests pass. Let me do a final review of the complete diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.