stale-file: harden change detection beyond bare mtime equality #17
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Follow-up from the supervisor review of PR #15 (stale-file protection, #4). The stale check compares
disk_mtime != self._loaded_mtime(config_mtimereturnsPath.stat().st_mtime). Pure mtime equality can miss a concurrent external write when:A missed detection means BCC silently overwrites an external edit (e.g.
claude mcp addfrom a terminal) without showing the StaleDialog.Not a data-loss emergency —
write_configalways backs up the pre-write file first, so the external version is recoverable from.bcc_backups/. But the whole point of #4 is to prompt before clobbering, and mtime alone can skip the prompt.Proposed fix
Cheap hardening: pair mtime with file size (and optionally a content hash of just the server sections) captured at load and compared on save.
disk_mtime != loaded_mtime OR disk_size != loaded_sizecatches the same-second/equal-mtime case at negligible cost. A full content hash is the most robust but heaviest; size+mtime is the pragmatic middle.Acceptance criteria
config_mtimeor add a sibling helper).os.utime), assert the change is still detected.Relevant code
bcc_core.py::config_mtime,external_change_summarybcc.py::MainWindow._loaded_mtime, the stale check in the save pathFiled directly by the supervisor (Cowork) session.