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
Let me start by exploring the repository structure to understand the codebase.
Assistant
Now let me search for the
--watchoption to understand how it works.Assistant
Now let me look at how the file is loaded to understand the parse error and how it interacts with conflict markers:
Assistant
Now let me see the file watcher manager and where the reload happens:
Assistant
Now let me check the
FileChangeCoordinatorand where reload happens:Assistant
Let me look at how the app.py handles unparsable_cell to understand the issue better:
Assistant
Now let me check how the file content is detected for conflict markers:
Assistant
Let me first set up a script to reproduce the bug:
Assistant
Now let me write a script to reproduce the bug:
Assistant
Let me try a different approach - install marimo from the directory:
Assistant
The bug is confirmed. The conflict markers are being incorporated as code inside the cell. Let me check what happens with markers at the start of a line in a more complex notebook:
Assistant
Let me see the scanner to understand how cells are being parsed with conflict markers:
Assistant
Now let me find the best place to add the conflict marker detection. Let me first look at how files are read:
Assistant
Now let me check the file content_matches_last_save to add the conflict marker detection:
Assistant
Now let me understand the file change handling flow more clearly:
Assistant
Let me look at the overall structure to find a good place to add the helper function:
Assistant
Now let me think about the design. The fix should:
- Detect if a file content contains git merge conflict markers (specifically
<<<<<<<at the beginning of a line) - Skip the reload when conflict markers are detected
Let me look at the best place to add the check. I think
file_change_handler.pyis the most appropriate place:- Detect if a file content contains git merge conflict markers (specifically
Assistant
Now let me write the fix. I'll add a helper function to detect git merge conflict markers and use it in the file change handler:
Assistant
Now let me understand the structure better and check the existing approach to add the fix:
Assistant
Now let me apply the fix. I will add a helper function that detects git merge conflict markers and modify the file change handler to skip reloading when such markers are present:
Assistant
Now let me make the changes. First, I'll add a helper function for detecting merge conflict markers, then modify the handler to skip reload when such markers are found:
Assistant
Now let me view the file to verify the change:
Assistant
Now let me modify the
_handle_file_change_lockedmethod to use this function. Let me first view the relevant section:Assistant
Now let me apply the fix to skip reload when merge conflict markers are detected:
Assistant
Now let me check the
read_filemethod onAppFileManager:Assistant
Good. Now let me write a test to verify the fix:
Assistant
Let me fix the test script:
Assistant
Let me update the test to use a real session:
Assistant
All tests pass. Now let me run the existing tests to make sure nothing is broken:
Assistant
The failures are due to pytest-asyncio not being installed. Let me install it:
Assistant
All existing tests pass. Let me also run the file watcher integration tests:
Assistant
Let me also test that the fix handles other edge cases properly:
Assistant
All edge cases pass. Now let me also check if there are similar reload paths that might have the same issue:
Assistant
These are explicit user actions (export) that wouldn't be impacted by the file watcher. The fix is correctly placed at the file watcher level.
Let me also run the existing notebook tests to make sure nothing is broken:
Assistant
All tests pass. Now let me also reproduce the original issue to confirm my fix actually addresses it:
Assistant
The fix works correctly. Let me also verify the fix from the actual user perspective:
Assistant
This confirms the original bug. The cell code gets polluted with the conflict markers. With my fix, the watcher will not call reload when conflict markers are present.
Let me also check the regex once more for a subtle issue. The issue is the
(?!<)negative lookahead is supposed to ensure that we match exactly 7<characters and not more:Assistant
Let me run all the session tests:
Assistant
The single failing test is unrelated to my changes - it's a kernel process kill test that fails due to a flaky test condition. Let me verify:
Assistant
The test fails even without my changes - so it's a pre-existing flaky test unrelated to my fix.
Let me also check the changes I've made:
Assistant
Let me check if there's a similar method we could leverage that doesn't re-read the file:
Assistant
Let me run the specific test suite that covers our changes one more time to confirm:
Assistant
All 32 tests pass. Let me also look at the final file to make sure it's clean:
Assistant
Now let me verify the final diff:
Assistant
Let me also run a broader test to make sure nothing is broken in the related areas:
Assistant
All 88 tests pass. Now let me also run the broader test for
marimo._ast.loadand related:Assistant
Good - that test failure also exists without my changes. My fix doesn't break anything.
Let me look at the final file once more:
Assistant
Let me clean up the temporary test files:
Assistant
Now let me check the final state of the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.