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 explore the repository structure and understand how the file watching works in marimo.
Assistant
The
_handle_file_change_lockedmethod handles file changes. I need to add a check for merge conflict markers before reloading. Let me look at the file manager to understand the reload method.Assistant
Now let me understand the issue. The file change handler reloads the file when it changes. If the file has merge conflict markers (
<<<<<<<), it gets parsed as_unparsable_cell, messing up the conflict markers.The suggestion is to avoid updating the notebook if the file contains conflict markers, recognizable by
<<<<<<<at the beginning of a line.Let me add a check in
_handle_file_change_lockedfor merge conflict markers. I'll read the file content and check for<<<<<<<at the beginning of a line.Let me look at how the file is read. I can use
session.app_file_manager.read_file()but that might raise an exception if unnamed. Let me check the storage layer. Actually, I'll use a more direct approach - read the file content directly.Let me check what's available. The
file_pathis astr(absolute path). I could read it directly. Let me check what imports are available.Actually, let me look at the approach. The cleanest way is to add a helper function to check for conflict markers and read the file content. Let me add a check before calling
reload().Assistant
Now let me add the merge conflict check in the file change handler. I'll add a helper function and use it in
_handle_file_change_locked.Assistant
No existing conflict marker handling. Let me add it. Let me add a helper function and use it in
_handle_file_change_locked.Assistant
Now let me add the merge conflict detection. I'll add a helper function and use it in
_handle_file_change_locked.Assistant
Now I'll add a helper function for detecting merge conflict markers and add the check before reloading.
Assistant
I accidentally duplicated the LOGGER line. Let me fix that.
Assistant
Now let me add the helper function and the check in
_handle_file_change_locked. Let me add a module-level function:Assistant
There's a duplicate
FileChangeResultclass. Let me remove the duplicate.Assistant
Now let me add the check in
_handle_file_change_locked. Let me find the exact lines.Assistant
There are duplicate lines from the edit. Let me fix lines 250-251 and 269-270.
Assistant
The file looks clean now. Let me verify the top part too and run a syntax check.
Assistant
Now let me check if there are existing tests for the file change handler.
Assistant
Let me run the existing tests to make sure my changes don't break anything.
Assistant
All tests pass. Now let me write a temporary test to verify the new behavior works as expected.
Assistant
The async test isn't recognized because the asyncio mode config isn't being picked up. Let me check the pyproject.toml.
Assistant
The config is in pyproject.toml, but my test file is in /tmp. Let me put the test in the marimo directory so it picks up the pyproject config. Or I'll run the async one directly with asyncio.run.
Actually the 3 non-async tests passed (mode auto would handle async if run from the marimo dir). Let me run the test from the marimo directory.
Assistant
All tests pass. Let me clean up the temporary test file.
Assistant
Let me run the related tests one more time to be thorough.
Assistant
The failure is in
test_save_configwhich seems unrelated to my change (a 500 error on the index page). Let me verify it fails without my change by temporarily stashing.Assistant
The
test_save_configtest fails even without my change — it's a pre-existing failure unrelated to my change (an environment issue with a 500 error). My changes are good.Let me do a final review of the diff.
Assistant
Let me also check the file_watcher_integration.py to see if there's another path that handles file changes.
Assistant
This delegates to a callback. Let me find where the callback is set to confirm it uses
FileChangeCoordinator.handle_change.Assistant
All paths funnel through
FileChangeCoordinator.handle_change, so my fix covers both the file watcher and the file-explorer rename paths. The fix is complete and centralized.Let me do a final verification of the full file change handler test suite.
Assistant
All tests pass. Let me verify the module imports cleanly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.