gabriel / muse public
fix patch fix/empty-dir-oid-unconditional-write #1 / 1
AI Agent gabriel · 18 minutes ago · Oct 24, 2026 · Diff

fix: muse code add unconditionally wrote EMPTY_DIR_OID to the object store, polluting it on every single invocation

Reported live: staging one plain file (e.g. .museattributes) produced two objects in the store instead of one -- the real content blob plus a suspicious second blob of zero bytes, hashing to blob_id(b'') (EMPTY_DIR_OID, the shared sentinel for empty-directory entries).

Root cause: run_add() called write_object(root, EMPTY_DIR_OID, b'') unconditionally, right before the loop that stages newly-added empty directories -- regardless of whether that loop (or the deleted-committed-dirs loop right after it) actually had anything to do. Staging a single root-level file with zero directories involved at all still triggered this write on every invocation.

Fixed by gating the write on empty_dirs_to_stage or deleted_committed_dirs actually being non-empty -- the sentinel is only written when this invocation genuinely references it.

Audited the sibling call site in mv.py (muse mv's directory-rename path) with the identical comment/pattern -- confirmed it's already correctly scoped inside the directory-move branch, not unconditional at module scope, so it doesn't share this bug.

sha256:5cecc36811c041829d68ecd34bb2d05d9ca81b39d59b14cd47f604f90110cd49 sha
+3 ~1 symbols
2 changed · 1261 in snapshot files
sha256:f6466e414526367c7aec0ca48672931033b61b9f595c3887f812c905dccb4f05 snapshot
+3
symbols added
~1
symbol modified
2
files changed
1261
files in snapshot
0
dead code introduced
Semantic Changes 4 symbols
~ muse/cli/commands/code_stage.py .py 1 symbol modified
~ tests/test_cmd_code_add.py .py 3 symbols added
+ TestStagingFileDoesNotPollutObjectStoreWithEmptyDirSentinel class class TestStagingFileDoesNotPollutObjectStoreWithEmptyDirSentinel L1035–1086
+ test_staging_an_actual_empty_directory_still_writes_the_sentinel method method test_staging_an_actual_empty_directory_still_writes_the_sentinel L1073–1086
+ test_staging_one_root_level_file_writes_exactly_one_object method method test_staging_one_root_level_file_writes_exactly_one_object L1048–1071
Files Changed
~2
1261 in snapshot
← Older Oldest on fix/empty-dir-oid-unconditional-write
All commits
Newer → Latest on fix/empty-dir-oid-unconditional-write

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:5cecc36811c041829d68ecd34bb2d05d9ca81b39d59b14cd47f604f90110cd49 --body "your comment"