[#4] Stale-file protection #4

Closed
opened 2026-07-02 00:49:42 -04:00 by the_og · 0 comments
Owner

Problem

There is no check for whether the config file changed on disk since BCC loaded it (e.g. Claude itself rewrote it, or a second BCC window is open, or claude mcp add ran in a terminal) before write_config() overwrites it. This is the same class of bug as the "config got clobbered" complaints — silent loss of concurrent changes.

Proposed solution

  1. In load_config(), record the file's mtime and content hash at load time (store in the returned structure or via a parallel _file_stamps dict keyed by path).
  2. In write_config(), re-stat the file before writing. If mtime or hash changed, do not overwrite — instead raise a StaleFileError (or return a sentinel) with a diff of what changed externally.
  3. In bcc.py, catch this and show a dialog: "File changed externally — reload and reapply your edits, or overwrite anyway."

Acceptance criteria

  • Editing in two BCC windows simultaneously and saving from both no longer silently loses one set of changes.
  • claude mcp add running between a BCC load and save is caught.
  • The overwrite-anyway escape hatch works.
  • Core stamp logic has unit tests (no real file races needed — test with a temp file modified between load and write).

Relevant code

  • bcc_core.py::load_config (line 135)
  • bcc_core.py::write_config (line 226)
## Problem There is no check for whether the config file changed on disk since BCC loaded it (e.g. Claude itself rewrote it, or a second BCC window is open, or `claude mcp add` ran in a terminal) before `write_config()` overwrites it. This is the same class of bug as the "config got clobbered" complaints — silent loss of concurrent changes. ## Proposed solution 1. In `load_config()`, record the file's `mtime` and content hash at load time (store in the returned structure or via a parallel `_file_stamps` dict keyed by path). 2. In `write_config()`, re-stat the file before writing. If `mtime` or hash changed, do not overwrite — instead raise a `StaleFileError` (or return a sentinel) with a diff of what changed externally. 3. In `bcc.py`, catch this and show a dialog: "File changed externally — reload and reapply your edits, or overwrite anyway." ## Acceptance criteria - Editing in two BCC windows simultaneously and saving from both no longer silently loses one set of changes. - `claude mcp add` running between a BCC load and save is caught. - The overwrite-anyway escape hatch works. - Core stamp logic has unit tests (no real file races needed — test with a temp file modified between load and write). ## Relevant code - `bcc_core.py::load_config` (line 135) - `bcc_core.py::write_config` (line 226)
the_og added the P0 label 2026-07-02 00:49:42 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: the_og/better-claude-config#4