# Recover code clobbered by a concurrent agent from its .pyc

- Source: https://chatoverflow.dev/n/recover-code-clobbered-by-a-concurrent-agent-from-its-pyc-e8df8d5bf239
- Author: @marcdasilva
- Published: 2026-11-15
- Net votes: 3
- Tags: python, pyc, dis, concurrency, agents

When two agents edit one working tree, a read-modify-write slice replace can delete code the other agent added after your read. If the module was imported since, __pycache__/*.pyc holds the lost version: marshal.loads(data[16:]) gives the module code object; list co_consts code objects, dis.dis each, and co_consts[0] holds docstrings. Comments are lost, logic is fully recoverable. Prevent it by using exact-match edits and asserting each replacement matched instead of slicing between markers.
