Skip to content

emrg: fix flaky install-info.json read — guarded parse + atomic write - #569

Merged
argszero merged 2 commits into
argszero:masterfrom
pm25coder:feature/install-info-atomic-write
Aug 8, 2026
Merged

emrg: fix flaky install-info.json read — guarded parse + atomic write#569
argszero merged 2 commits into
argszero:masterfrom
pm25coder:feature/install-info-atomic-write

Conversation

@pm25coder

Copy link
Copy Markdown
Contributor

Fixes a flaky test: test_build_prompt_with_project intermittently failed with json.decoder.JSONDecodeError in the full suite (1 failure observed, passes in isolation and on re-run).

@argszero argszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle

Verified locally: both new tests pass (corrupt-read negative state + atomic-write positive state), the previously-flaky test_build_prompt_with_project passes, and the full tests/test_git_utils.py module is green (27 passed). The guarded read matches the existing _cached_tool_path pattern (same exception tuple), and the tmp + os.replace write is atomic on the same filesystem (tmp lives in the same dir).

Minor non-blocking nit: README.cn.md still says 597 — the #511 CI guard only checks README.md/Agent.md so CI won't fail, but the bilingual docs should stay in sync.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle 20260808-100707

Second independent review of the full diff (4 files, +56/−6 on top of master 047b37b):

  • Root cause is real: _cache_tool_paths read INSTALL_INFO non-atomically while the live daemon rewrites the shared install-info.json — a concurrent reader can catch a partial write → JSONDecodeError flake (observed as test_build_prompt_with_project failing intermittently mid-suite).
  • Fix is correct and narrow:
    • Read side: guarded json.loads (catches OSError/JSONDecodeError/AttributeError) → degrades to {} instead of raising — consistent with _cached_tool_path's existing guard.
    • Write side: temp file + os.replace — atomic on POSIX and Windows, so concurrent readers never see a partial file.
  • Verification both states (#455): I ran the suite on the branch — 599 tests pass (597 + 2 new). Also manually confirmed the negative state: an already-corrupt/truncated cache file is tolerated (no raise) and rewritten atomically with no .tmp leftover.
  • Blast radius: only _cache_tool_paths; the except OSError: pass outer guard still covers replace failures.

Ready to merge once a third independent ✅ lands.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle 20260808-101021

Third independent review. Head-change audit (f074d87 on top of previously-reviewed 4cf87e5): the only delta is the README.cn.md test-count sync 597→599 (addressing the nit raised in the first review) — the four reviewed files are byte-identical, so prior LGTMs remain valid. CI on the new head is green (run 31234374076 SUCCESS). Merge gate satisfied: 3 consecutive ✅ from different cycles, no ❌ in between.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants