memlog.py: concurrent writers lose entries and can truncate the log (shared .tmp name, no lock)

Aperta
#126 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Start with skills/bmad-eval-runner/scripts/memlog.py and compare the installed copy at _bmad/scripts/memlog.py; inspect the append read-modify-write path and its temporary-file handling. Reproduce the race with the provided parallel append commands, then verify that concurrent appends preserve every entry and do not leave invalid frontmatter.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

memlog.py (skills/bmad-eval-runner/scripts/memlog.py, also installed as _bmad/scripts/memlog.py) does read-modify-write with no lock, and every process writes the same temp file, <path>.tmp. One process can os.replace a temp file that another is still writing. So beyond lost updates, the log can be replaced with a partial file. That contradicts the docstring's claims that a crash never leaves a half-written entry and that nothing is ever removed.

Concurrent appends are realistic: parallel subagents, bmad-loop workers, or two sessions on the same skill.

Steps to reproduce

M=skills/bmad-eval-runner/scripts/memlog.py
python3 $M init --path .memlog.md
for i in $(seq 1 20); do
  python3 $M append --path .memlog.md --type note --text "a$i" &
  python3 $M append --path .memlog.md --type note --text "b$i" & wait
done
grep -c '^- ' .memlog.md      # 32 of 40 kept; 7 runs crashed with FileNotFoundError on .memlog.md.tmp

With 40 writers at once, 1 of 40 entries survived. Some writers failed with ValueError: .memlog.md has no frontmatter, because they read a half-written file that another writer had renamed into place.

Expected behavior

  • Use a unique temp file per write (tempfile.mkstemp(dir=path.parent)).
  • Hold an advisory lock (fcntl.flock / msvcrt.locking, or a .lock file with O_EXCL) across read-modify-write.
  • Optionally, append entries with O_APPEND and update updated: less often.

Environment

  • Model(s) used: n/a (deterministic script)
  • Agentic IDE used: n/a (scripts run directly)
  • BMad version: bmad-builder main @ d4a921c (v2.2.2 + #118)
  • Project language: Python 3.13, Linux
Lingua principale
Python
Stelle
220
Fork
54
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bmad-code-org/bmad-builder

Tutte le issue di bmad-code-org/bmad-builder

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.