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
I’ll trace the
--watchfile-change path, identify where notebook source is parsed and written back, then reproduce the conflict-marker behavior before making a narrowly scoped guard. I’ll also inspect nearby tests and run the relevant suite after the change. - Assistant
ripgrepis unavailable in this environment, so I’ll use recursivegrepto locate the watch implementation and parser handling. - Assistant
The relevant path appears to be the session-level watcher rather than the generic runtime
mo.watch.file. I’ll inspect that extension, the callback supplied by the session manager, and tests around file reload/save behavior to determine the safest layer for the guard. - Assistant
The extension only routes events; the coordinator owns reload semantics and likely distinguishes edit/run behavior. I’ll inspect the complete handler and coordinator/reload strategies before deciding whether conflict detection belongs in the coordinator or edit reload strategy.
- Assistant
I found the dedicated
file_change_handlerabstraction. I’ll review it and its tests in full enough to understand stale-hash suppression and ensure ignored conflict events don’t disrupt later valid reloads. - Assistant
The coordinator reloads directly after only a last-save hash check, so conflict text reaches
AppFileManager.reload()and is normalized into an unparsable cell. A pre-reload content guard here would preserve the in-memory notebook and avoid all strategy notifications. I’ll examine coordinator test fixtures and file I/O conventions to implement this without blocking markers that merely occur inside indented code or strings—the requested recognition is specifically<<<<<<<at the beginning of a line. - Assistant
The locked helper is synchronous because reload itself is synchronous, so the simplest race-safe guard is a small source predicate plus reading the same file immediately before reload.
Path.read_text()could introduce encoding assumptions that differ from the loader; I’ll inspectAppFileManager.reload()and loading utilities so the guard uses the exact source-reading behavior where possible. - Assistant
AppFileManagercan use alternate storage, while the watcher supplies a filesystem path. Since this guard is specifically for filesystem watch events, checkingfile_pathin the coordinator is appropriate. However, to avoid a time-of-check/time-of-use window and duplicate reads, I’ll inspect loader APIs for loading from source; if unavailable, the lock still serializes marimo events and a direct read immediately before reload is acceptable for external Git writes. - Assistant
There is already an
AppFileManager.read_file()abstraction, which is preferable and matches its storage encoding behavior. I’ll inspect its exact contract and then add a pure marker predicate plus an early coordinator return. The predicate will usesplitlines()so it recognizes LF, CRLF, and a marker on the first or any later line, while not matching leading whitespace or embedded occurrences. - Assistant
Before editing, I’ll run a small temporary reproduction against the current coordinator: initialize a valid notebook, replace a cell body with Git conflict markers, and verify that the event is currently handled and the in-memory cell becomes unparsable.
- Assistant
The system Python lacks repository dependencies (
msgspec), so I’ll rerun the reproduction through the project’s lockeduvenvironment rather than altering the environment or source. - Assistant
The reproduction confirms the harmful reload/notification (
handled=True, strategy called), though the manager-wideunparsableflag is not the right observable for scanner-fallback cells. I’ll inspect the resulting cell code/serialization to confirm the marker was converted into an_unparsable_cell, then implement the guard. - Assistant
The second reproduction shows the exact corruption: the conflict region is loaded as cell code and would serialize as
app._unparsable_cell. I’ll now add a focused helper and skip beforereload(), logging at info level so watch users can understand why no update occurred. Read failures remain handled by the existing reload error path. - Assistant
The guard is in place and preserves the existing result semantics (
handled=False, no error) used for ignored own writes. I’ll run the targeted session tests plus formatter/linter checks, then rerun the reproduction and verify that a later resolved edit reloads normally and that indented marker-like text does not trigger the guard. - Assistant
All 32 targeted tests and lint checks pass; only the formatter requested a line compaction, which prevented the chained reproduction from running. I’ll apply the repository formatter, inspect the resulting diff, and rerun formatting plus the post-fix behavioral checks.
- Assistant
The post-fix reproduction now confirms all key behavior: conflict content is ignored without mutating cell code or notifying the reload strategy; once markers are resolved, the next event reloads; CRLF markers are recognized; and indented marker-like text remains reloadable. I’ll run the broader session test suite as a final regression check and inspect repository status to ensure only the intended source file changed.
- Assistant
The broad suite completed with 340 passes and one unrelated process-group teardown failure in
test_kernel.py(the grandchildsleepremained visible after SIGTERM); the changed file’s tests all passed within that run. Because the failing command stopped before status checks, I’ll now verify no test artifacts or unintended files were created and review the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.