Skip to content

fix(watch): route graph.json replace through the atomic fallback on both incremental write sites - #3555

Closed
ayushcodes10 wants to merge 6 commits into
Graphify-Labs:v8from
ayushcodes10:fix-2689-watch-atomic-replace-fallback
Closed

ayushcodes10 wants to merge 6 commits into
Graphify-Labs:v8from
ayushcodes10:fix-2689-watch-atomic-replace-fallback

Conversation

@ayushcodes10

Copy link
Copy Markdown
Contributor

Fixes #2689.

Summary

On a VMware HGFS shared folder, os.replace(src, dst) raises PermissionError ([WinError 5] Access is denied) when dst was read earlier in the same process before being replaced — reproduced directly in the issue with a minimal snippet. graphify update and cluster-only do exactly that: read the existing graph.json for the merge/shrink-guard comparison, then replace the temp file onto it. On this filesystem the rebuild aborts at that point, GRAPH_REPORT.md/graph.html/manifest.json never get written, and the un-advanced manifest means every later run re-detects the same delta and fails at the same spot — incremental updates are permanently blocked.

graphify/paths.py already has os_replace_with_fallback (added in #3508, my own earlier PR) — it falls back to a copy-through-temp-and-rename-aside sequence on exactly this PermissionError/WinError-5 case, and export.py's clustered-path write already routes through it. watch.py's two incremental-rebuild write sites (the no_cluster fast path and the default clustered path) were both still using a plain Path.replace(), bypassing the fallback entirely — that's the actual gap this issue is hitting.

Changes

  • graphify/watch.py: both graph_tmp.replace(existing_graph) call sites now call os_replace_with_fallback(graph_tmp, existing_graph) instead.
  • tests/test_watch.py: two new regression tests (one per call site), each monkeypatching os.replace to always raise the simulated HGFS PermissionError and confirming the incremental rebuild still succeeds and lands the new content.
  • CHANGELOG.md: entry under 0.9.61 (unreleased).

Testing

  • python -m pytest tests/test_watch.py -k permission_error -q — 2 passed
  • Full suite: python -m pytest -q — 5487 passed, 68 skipped (pre-existing unrelated failures excluded: tests/test_ollama_retry_cap.py missing the optional openai module, and test_ts_normalizer_scales_linearly_on_large_files / test_hyperedge_convex_hull_js_is_geometrically_sound, both known environment-specific flakes unrelated to this change)
  • python -m tools.skillgen --check — OK

🤖 Generated with Claude Code

https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh

ayushcodes10 and others added 6 commits September 14, 2026 16:19
watch.py writes graph.json via a plain Path.replace() at two call
sites instead of the shared os_replace_with_fallback helper that
export.py, cache.py, and install.py already route through. This adds
the import with no behavior change yet; both call sites are switched
over in the next two commits.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
Fixes issue 2689 for the reconcile existing graph write site.

This site reads existing_graph a few lines earlier in the same
process, then replaced graph_tmp onto it with a plain Path.replace.
On a VMware HGFS shared folder, os.replace over a destination that
was read earlier in the same process raises PermissionError even
though src and dst are on the same drive; deleting then renaming
succeeds in that exact situation. os_replace_with_fallback already
implements that fallback for PermissionError generally, so this
switches the call over to it instead of duplicating the recovery here.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
Fixes issue 2689 for the main rebuild write site, the second of the
two watch.py call sites reported.

Same reasoning as the reconcile path: existing_graph was read a few
lines earlier in this same process for the same_graph comparison, so
a plain Path.replace can hit the VMware HGFS PermissionError this
issue reports. Both call sites in watch.py now route through the
shared os_replace_with_fallback helper that export.py, cache.py, and
install.py already use.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
Simulates the VMware HGFS PermissionError this issue reports by
monkeypatching os.replace to always raise it, then confirms an
incremental no_cluster rebuild still succeeds and lands the new
content instead of aborting the whole run.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
Same Graphify-Labs#2689 fallback requirement as the no_cluster test, exercised
against the default clustered rebuild path, the second of the two
watch.py call sites the issue reports.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Routes both incremental-rebuild graph.json write sites in _rebuild_code (no-cluster and clustered) through os_replace_with_fallback instead of a plain Path.replace, so graphify update/cluster-only no longer abort with [WinError 5] when the destination was read earlier in the same process on a VMware HGFS share. Adds tests that monkeypatch os.replace to raise PermissionError and assert both paths fall back and still land the new content.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 797 functions depend on the 611 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _rebuild_code() — 118 callers, 52 callees
  • new: dispatch_command() — 2 callers, 124 callees
  • new: watch() — 5 callers, 7 callees
  • new: _reconcile_graph_html() — 6 callers, 5 callees
  • new: _reconcile_existing_graph() — 1 callers, 8 callees
  • new: _reconcile_markdown_links() — 1 callers, 6 callees
  • new: test_poisoned_manifest_is_healed() — 0 callers, 6 callees

Verification — 797 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 623 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

275 of 275 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/test_affected_cli.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_build.py — full-run-safety
  • tests/test_build_merge_dedup_scope.py — full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — full-run-safety
  • tests/test_build_merge_shrink_guard.py — full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_cache.py — full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — full-run-safety
  • tests/test_chunking.py — full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cluster.py — full-run-safety
  • tests/test_codebuddy.py — full-run-safety
  • tests/test_community_hub_labels.py — full-run-safety
  • tests/test_community_labels_skill.py — full-run-safety
  • tests/test_confidence.py — full-run-safety
  • tests/test_corrupt_graph_json.py — full-run-safety
  • tests/test_cpp_nested_and_cli.py — full-run-safety
  • tests/test_cpp_objc_cross_file_calls.py — full-run-safety
  • tests/test_cpp_preprocess.py — full-run-safety
  • tests/test_cross_extension_reexport_self_cycle.py — full-run-safety
  • tests/test_cross_language_call_resolution.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • tests/test_cross_repo_shared_types.py — full-run-safety
  • tests/test_csharp_call_site_generic_args.py — full-run-safety
  • tests/test_csharp_enum_members.py — full-run-safety
  • … and 225 more

non-code file(s) changed (CHANGELOG.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (CHANGELOG.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

Could not verify: Could not verify \_rebuild\_code.

The verifier did not have enough to check \_rebuild\_code, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `watch_path` is annotated `Path` — outside the synthesizable primitive/collection set

· 7 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.62 (now on PyPI: uv tool install graphifyy==0.9.62). Your commits were cherry-picked with authorship preserved, so this shows up under your GitHub contributions. Thanks @ayushcodes10!

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.

update/cluster-only fail with os.replace WinError 5 on VMware HGFS shared folders (read-then-replace over existing graph.json)

2 participants