Skip to content

fix(install): stop install/uninstall data loss when no matching heading follows a section - #3803

Open
ayushcodes10 wants to merge 13 commits into
Graphify-Labs:v8from
ayushcodes10:fix-3791-install-eof-fallback-data-loss
Open

ayushcodes10 wants to merge 13 commits into
Graphify-Labs:v8from
ayushcodes10:fix-3791-install-eof-fallback-data-loss

Conversation

@ayushcodes10

Copy link
Copy Markdown
Contributor

Fixes #3791.

Summary

Since 0.9.66 (#3741, itself a fix for #3668), _replace_or_append_section and _remove_marker_section fell through to end of file whenever no boundary_prefix heading followed graphify's marker, replacing or deleting everything below it. This is a regression I introduced in that earlier fix.

The H1 skill registration marker (# graphify) hits this on nearly every real CLAUDE.md, since user content there conventionally uses H2 headings, which never match an H1 boundary_prefix. One report lost 217 lines this way after a routine reinstall printed only Done..

Fix

Both functions now write and look for an explicit end marker (<!-- graphify-section-end -->) as the primary way to find a section's real end, regardless of its own internal structure. This is close to the reporter's own suggested fix.

Boundary detection now tries, in order:

  1. The exact end marker line, written by this function on a prior call.
  2. The next boundary_prefix heading, for content written before this fix (keeps the existing Graphify not improving token efficiency in Claude Code sessions #580 upgrade-in-place guarantee).
  3. Neither exists, but nothing that looks like an ATX heading of any level appears anywhere in the trailing content either: safe to treat as more of graphify's own unmarked prose and fall through to EOF.
  4. Neither exists, and something heading-shaped does follow: the end is not knowable (this is the exact install --platform claude deletes all CLAUDE.md content below the graphify block when no later H1 exists (regression in 0.9.66, #3741) #3791 shape — a user's own ## My own rules after an H1 marker). Treated the same as no marker at all: a fresh, clearly-bounded copy is appended and the old block is left in place, orphaned, rather than guessed away. The fresh copy's own end marker means every later call finds it precisely via (1), so this only happens once per legacy file.

While building this I also found and fixed a related idempotency bug: claude_install, gemini_install, codebuddy_install, _agents_install and vscode_install bypassed _replace_or_append_section entirely on a file's first write, so that first write carried no end marker and a second install call couldn't recognize its own prior output. All five now route through the same helper unconditionally.

Testing

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 3 advisory finding(s) below merit a look before merge.


Graphify review — findings

Fixes a data-loss regression in graphify install/uninstall where a marker-bounded section with no following heading of the expected level fell through to EOF and silently deleted the user's own trailing content in CLAUDE.md/AGENTS.md/GEMINI.md/etc. Sections written from this fix onward end with an explicit _SECTION_END_MARKER comment that later calls in _replace_or_append_section and _remove_marker_section locate exactly; absent that, they fall back to the next boundary_prefix heading, then to EOF only when nothing heading-shaped follows at all. When something that looks like a heading of any level does follow an unmarked legacy section, the end is treated as unknowable: replace appends a fresh bounded copy leaving the old block orphaned, and remove stops at that occurrence rather than deleting to EOF.

Worth a look

  • vscode_install prints truncated/incomplete output and never writes file — graphify/install.py · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • End marker search can skip an earlier section boundary and delete following sections — graphify/install.py:655 · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • _has_heading_before_eof matches the graphify H1 marker's own boundary_prefix subheadings — graphify/install.py · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 666 functions depend on the 370 functions this change touches.

Health — this change adds coupling hotspots:

  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: install() — 13 callers, 11 callees
  • new: codebuddy_install() — 20 callers, 5 callees
  • new: gemini_install() — 11 callers, 7 callees
  • new: claude_install() — 19 callers, 4 callees
  • new: _copy_skill_file() — 12 callers, 6 callees
  • new: claude_uninstall() — 17 callers, 4 callees
  • …and 15 more — each is listed as a finding

Verification — 666 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: 512 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

300 of 300 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 — impact, full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — impact, 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 — impact, 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_cargo_missing_manifest.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 — impact, 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_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — impact, 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_external_call_guards.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • … and 250 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.

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

@ayushcodes10

Copy link
Copy Markdown
Contributor Author

Addressing the three advisories:

"vscode_install prints truncated/incomplete output and never writes file" — not accurate. Ran it directly against a temp dir: the file is written, the printed messages are complete, and the content round-trips correctly. Pasting the actual output for the record:

  references       ->  /tmp/.../home/.copilot/skills/graphify/references
  skill installed  ->  /tmp/.../home/.copilot/skills/graphify/SKILL.md
  /tmp/.../proj/.github/copilot-instructions.md  ->  graphify section added

VS Code Copilot Chat configured. Type /graphify in the chat panel to build the graph.
Note: for GitHub Copilot CLI (terminal), use: graphify copilot install
FILE EXISTS: True

The full expected section content is in the file, ending with the end marker. I don't see a path where this doesn't write or truncates — happy to look again at a specific repro if one exists.

"End marker search can skip an earlier section boundary and delete following sections" (install.py:655) — could not reproduce, added a defensive test anyway. I traced several constructions by hand: two marker occurrences with only the later one sentinel-bounded, an orphaned legacy generation from a prior tier-4 append sitting alongside real user sections both before and after it, duplicate headings with unrelated content interleaved. In every case the search correctly anchors on the last occurrence (starts[-1]) and never reaches backward past it, so an earlier boundary (sentinel or heading) is never in scan range to begin with. Added test_an_orphaned_legacy_generation_never_swallows_user_content_around_it to lock in the specific shape I think this finding is describing (orphan + user content on both sides, checked through both install and uninstall). If there's a concrete input that reproduces the loss, I'd like to see it — happy to fix it once I can see what actually breaks.

One related, pre-existing edge case I did find while checking this, distinct from what's described: a user who writes their own heading with text that happens to be textually identical to the marker (e.g. a note titled literally "# graphify") can have that heading picked up as "the section" by the existing exact-heading-match design — this predates #3791 entirely (see this function's own "last one is used" note from #1688) and isn't something this fix changed either way, so I've left it alone as out of scope here.

"_has_heading_before_eof matches the graphify H1 marker's own boundary_prefix subheadings" — not applicable to the current template, now documented. _skill_registration()'s own body (3 lines: heading, one bullet, one sentence) has no heading-shaped line in it, checked directly. Added a comment right at that function noting the invariant explicitly, so a future edit that adds a heading-shaped line there would at least be a documented, deliberate tradeoff (a needless but harmless duplicate append on a legacy file) rather than a surprise.

Full install-suite (266 passed) and skillgen --check are green with these changes.

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.


Graphify review — findings

Fixes a data-loss regression in graphify install/uninstall where marker-bounded section replacement fell through to end-of-file and destroyed the user's own trailing content in CLAUDE.md/AGENTS.md/etc. (hundreds of lines lost in one report). Sections written from now on carry an explicit _SECTION_END_MARKER HTML comment so their end is found exactly on later runs; a legacy section without one is only replaced/removed to EOF when nothing heading-shaped follows at all (_has_heading_before_eof), and otherwise a fresh clearly-bounded copy is appended while the old block is left orphaned rather than guessed away. _remove_marker_section applies the same rule and halts at the first ambiguous occurrence, so uninstall is either fully cleaned or provably untouched from that point.

Worth a look

  • Replacement can consume unrelated later sections by preferring any later sentinel over an earlier boundary — graphify/install.py:663 · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • _has_heading_before_eof matches the marker heading's own body headings — graphify/install.py · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 668 functions depend on the 372 functions this change touches.

Health — this change adds coupling hotspots:

  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: install() — 13 callers, 11 callees
  • new: codebuddy_install() — 20 callers, 5 callees
  • new: gemini_install() — 11 callers, 7 callees
  • new: claude_install() — 19 callers, 4 callees
  • new: _copy_skill_file() — 12 callers, 6 callees
  • new: claude_uninstall() — 17 callers, 4 callees
  • …and 15 more — each is listed as a finding

Verification — 668 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: 514 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

300 of 300 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 — impact, full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — impact, 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 — impact, 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_cargo_missing_manifest.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 — impact, 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_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — impact, 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_external_call_guards.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • … and 250 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.

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

@ayushcodes10

Copy link
Copy Markdown
Contributor Author

Good catch — real bug, fixed. The end marker is an HTML comment, invisible in a markdown preview, so a user who adds their own section by editing the file directly can easily insert it above the marker instead of below it. The search looked for the sentinel across the whole rest of the file before ever considering a boundary_prefix heading, so it preferred a later, misplaced sentinel over an earlier legitimate heading regardless of position — confirmed this directly:

```python
before = (
"## graphify\nregistration content\n\n"
"## User Section\nimportant user content\n\n"
"\n\n"
"## Another Section\nmore content\n"
)
after = _replace_or_append_section(before, "## graphify", "## graphify\nNEW content\n")

pre-fix: "important user content" is gone -- swallowed into the replaced section

```

Both `_replace_or_append_section` and `_remove_marker_section` now scan forward from the marker a single time and stop at whichever of the two (the sentinel, or a boundary_prefix heading) is reached first, instead of always preferring the sentinel. A well-formed section written by this fix is unaffected, since its own sentinel always sits immediately after its content, before any later heading could be reached.

On the second finding (`_has_heading_before_eof` matching the marker's own body headings): same as last round, not applicable to the current templates, already documented in the code.

Regression test added reproducing the exact scenario above, confirmed to fail against pre-fix code. Full install suite (267 passed) is green.

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Formal verification. 1 change(s) alter behavior, breaking input(s) attached.

Behavior changes: \_replace\_or\_append\_section changes behavior, here is the input that shows it.

The verifier found a concrete input on which \_replace\_or\_append\_section behaves differently before and after the change. If that change is intended, ship it; if not, this is your bug.

Guarantee: This difference was REPRODUCED, the verifier actually ran both versions on that input and saw them disagree. It is real, not an artifact.

Evidence: On input \{"content":"'a longer string'","marker":"'a'","new\_section":"'='","boundary\_prefix":"'h\\u00e9llo w\\u00f6rld'"\}, the old code produced 'a longer string\\n\\n=' but the new code produces 'a longer string\\n\\n=\\n\<\!\-\- graphify\-section\-end \-\-\>\\n'. Paste that input straight into a regression test.


Graphify review — findings

Fixes graphify install/uninstall silently deleting a user's trailing content in CLAUDE.md/AGENTS.md/etc. when the marker-bounded replace found no following heading and fell through to EOF. Sections written by _replace_or_append_section now end with an explicit _SECTION_END_MARKER, and the boundary scan stops at whichever of that sentinel or the next boundary_prefix heading comes first; a legacy section without a marker is only replaced/removed to EOF when _has_heading_before_eof confirms nothing heading-shaped follows, otherwise a fresh bounded copy is appended and the old block left orphaned. _remove_marker_section follows the same first-reached, leave-in-place-when-uncertain logic on uninstall.

Worth a look

  • H1 replacement swallows lower-level user headings before an end marker — graphify/install.py:675 · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 670 functions depend on the 374 functions this change touches.

Health — this change adds coupling hotspots:

  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: install() — 13 callers, 11 callees
  • new: codebuddy_install() — 20 callers, 5 callees
  • new: gemini_install() — 11 callers, 7 callees
  • new: claude_install() — 19 callers, 4 callees
  • new: _copy_skill_file() — 12 callers, 6 callees
  • new: claude_uninstall() — 17 callers, 4 callees
  • …and 15 more — each is listed as a finding

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

Health delta baseline: last indexed commit 4000de1 (diverged from this PR's base — delta is approximate).

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: 516 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

300 of 300 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 — impact, full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — impact, 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 — impact, 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_cargo_missing_manifest.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 — impact, 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_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — impact, 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_external_call_guards.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • … and 250 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

Behavior changes: \_replace\_or\_append\_section changes behavior, here is the input that shows it.

The verifier found a concrete input on which \_replace\_or\_append\_section behaves differently before and after the change. If that change is intended, ship it; if not, this is your bug.

Guarantee: This difference was REPRODUCED, the verifier actually ran both versions on that input and saw them disagree. It is real, not an artifact.

Evidence: On input \{"content":"'a longer string'","marker":"'a'","new\_section":"'='","boundary\_prefix":"'h\\u00e9llo w\\u00f6rld'"\}, the old code produced 'a longer string\\n\\n=' but the new code produces 'a longer string\\n\\n=\\n\<\!\-\- graphify\-section\-end \-\-\>\\n'. Paste that input straight into a regression test.

Could not verify: Could not verify \_agents\_install.

The verifier did not have enough to check \_agents\_install, 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: no capturable inputs from the test suite; property tier: not verifiable: all 200 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly NameError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify claude\_install.

The verifier did not have enough to check claude\_install, 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: no capturable inputs from the test suite; property tier: not verifiable: all 10 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly NameError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify codebuddy\_install.

The verifier did not have enough to check codebuddy\_install, 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: no capturable inputs from the test suite; property tier: not verifiable: all 10 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly NameError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify gemini\_install.

The verifier did not have enough to check gemini\_install, 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: no capturable inputs from the test suite; property tier: not verifiable: all 10 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly NameError — names the real obstacle, not a sampling gap)

Verification did not run: Verification did not run for \_remove\_marker\_section.

The verification could not execute (an environment/toolchain issue, not a statement about the code).

Guarantee: No guarantee, the check itself did not complete.

Note: Detail: harness produced no verdict (rc=124): timeout after 30s

No difference found (not proven): No behavior difference found in \_skill\_registration (not a proof).

The verifier ran both versions of \_skill\_registration on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: concolic exploration (CrossHair). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify vscode\_install.

The verifier did not have enough to check vscode\_install, 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: no capturable inputs from the test suite; property tier: not verifiable: all 10 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly NameError — names the real obstacle, not a sampling gap)

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

@ayushcodes10

Copy link
Copy Markdown
Contributor Author

Good catch — real gap in last round's fix, confirmed and fixed.

"H1 replacement swallows lower-level user headings before an end marker" (install.py:675) — real, fixed. Last round's fix stopped the scan at whichever of an exact `boundary_prefix` match or the end marker came first, but for an H1 marker (`boundary_prefix="# "`) a user's own H2 heading never starts with `"# "`, so the scan still skipped right over it looking for something that matched exactly, and a later, misplaced sentinel could still swallow it:

```python
before = (
"# graphify\nregistration content\n\n"
"## User Section\nimportant user content\n\n"
"\n\n"
"## Another Section\nmore content\n"
)
after = _replace_or_append_section(before, "# graphify", "# graphify\nNEW\n", boundary_prefix="# ")

pre-this-fix: "important user content" is gone again, same mechanism as last round's finding

```

Fixed by recognizing that an H1 (top-level) marker's own body is documented to never contain a heading-shaped line at all — there's nothing shallower for internal structure to nest under — so for that specific marker level, ANY heading (not just an exact `boundary_prefix` match) unambiguously ends the section. A deeper marker (H2+) keeps the narrower same-level-only check, since its body can legitimately contain a deeper heading as nested content.

This also strictly improves two existing test cases that used to fall back to the more conservative "ambiguous, leave alone" or "append a duplicate" behavior for this exact shape — both now resolve cleanly, updated the assertions accordingly.

On the formal-verification note (behavior change on a fuzzed input with marker `"a"`/no real heading match): confirmed intended — that's the "no marker found, append with sentinel" path, and every appended section carrying a sentinel from now on is the fix's whole point.

Regression test added for the new finding, confirmed to fail against pre-fix code. Full install suite (268 passed) is green.

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.


Graphify review — findings

Fixes graphify install/uninstall silently deleting a user's own trailing content in CLAUDE.md/AGENTS.md/GEMINI.md when graphify's section had no later same-level heading after it and the marker-bounded replace fell through to EOF (up to hundreds of lines lost). Sections written from now on end with an invisible _SECTION_END_MARKER HTML comment so _replace_or_append_section finds the exact boundary on later runs; the scan stops at whichever of the end marker or a boundary_prefix heading comes first, and for H1 markers treats any heading level as a section boundary. A pre-marker legacy section is only replaced/removed to EOF when nothing heading-shaped follows at all (_has_heading_before_eof); otherwise a fresh, marker-bounded copy is appended and the old block is left in place rather than guessed away.

Worth a look

  • Top-level section replacement can split fenced code blocks on inner headings — graphify/install.py · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • _replace_or_append_section may leave marker section unremoved when heading-shaped content follows — graphify/install.py · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 672 functions depend on the 376 functions this change touches.

Health — this change adds coupling hotspots:

  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: install() — 13 callers, 11 callees
  • new: codebuddy_install() — 20 callers, 5 callees
  • new: gemini_install() — 11 callers, 7 callees
  • new: claude_install() — 19 callers, 4 callees
  • new: _copy_skill_file() — 12 callers, 6 callees
  • new: claude_uninstall() — 17 callers, 4 callees
  • …and 15 more — each is listed as a finding

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

Health delta baseline: last indexed commit 4000de1 (diverged from this PR's base — delta is approximate).

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: 518 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

300 of 300 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 — impact, full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — impact, 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 — impact, 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_cargo_missing_manifest.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 — impact, 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_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — impact, 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_external_call_guards.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • … and 250 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.

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

@ayushcodes10

Copy link
Copy Markdown
Contributor Author

Good catch — real bug, both findings share the same root cause, fixed together.

Confirmed directly: a "#"-led shell/Python comment line inside a fenced code block (an example in the marker's own body, or in the user's trailing content) matches the same ATX-heading pattern the boundary scan and `_has_heading_before_eof` use, without any awareness that it's inside a fence:

```python
before = (
"# graphify\nregistration content\n"
"```python\n# a comment that looks like a heading\nx = 1\n```\n\n"
"## User Section\nimportant user content\n"
)
after = _replace_or_append_section(before, "# graphify", "# graphify\nNEW content\n", boundary_prefix="# ")

pre-fix: the fence gets split in two -- the opening ```python line and "registration

content" are treated as replaced, the comment line + rest of the fence + closing

``` end up orphaned in the kept tail with no matching opener

```

This is exactly "Top-level section replacement can split fenced code blocks on inner headings." The flip side ("may leave marker section unremoved") is the same mechanism from the conservative-fallback direction: a fenced comment in trailing content could make `_has_heading_before_eof` see a false heading and refuse to resolve a case it safely could have.

Both `_replace_or_append_section` and `_remove_marker_section` (plus the shared `_has_heading_before_eof`) now track fence state while scanning forward and skip the heading/boundary checks entirely while inside a fence, toggling on any line that opens or closes one. The end-marker sentinel check itself is untouched — a literal HTML comment matching that exact text inside a fence isn't a realistic concern the way an ordinary comment line is.

Regression tests added for both directions, confirmed the direct repro fails against pre-fix code. Full install suite (270 passed) is green.

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.


Graphify review — findings

Fixes graphify install/uninstall silently deleting a user's own trailing content in CLAUDE.md/AGENTS.md/etc. when no heading of the expected level follows graphify's section: _replace_or_append_section now writes an explicit _SECTION_END_MARKER at the end of every section it inserts and stops the boundary scan at whichever of that sentinel, a boundary_prefix heading, or (for top-level markers) any ATX heading comes first. For legacy sections that predate the marker, it only replaces/removes to EOF when nothing heading-shaped follows via _has_heading_before_eof; otherwise it leaves the stale block in place and appends a fresh, marker-bounded copy. Both the end-marker scan and the heading check ignore #-led lines inside fenced code blocks so example comments aren't mistaken for section boundaries.

Worth a look

  • Fence tracking closes on the wrong fence delimiter — graphify/install.py:708 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • boundary_prefix matched via lines[j].startswith (raw) vs stripped for other checks — graphify/install.py · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 676 functions depend on the 380 functions this change touches.

Health — this change adds coupling hotspots:

  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: install() — 13 callers, 11 callees
  • new: codebuddy_install() — 20 callers, 5 callees
  • new: gemini_install() — 11 callers, 7 callees
  • new: claude_install() — 19 callers, 4 callees
  • new: _copy_skill_file() — 12 callers, 6 callees
  • new: claude_uninstall() — 17 callers, 4 callees
  • …and 15 more — each is listed as a finding

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

Health delta baseline: last indexed commit 4000de1 (diverged from this PR's base — delta is approximate).

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: 522 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

300 of 300 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 — impact, full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — impact, 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 — impact, 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_cargo_missing_manifest.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 — impact, 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_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — impact, 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_external_call_guards.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • … and 250 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.

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

@github-actions github-actions Bot added the needs:title PR title should follow the conventional-commit format label Oct 11, 2026
@ayushcodes10

Copy link
Copy Markdown
Contributor Author

Investigated both findings from this round (matching b603ad0), both real, fixed in 44f0cd7.

  • "Fence tracking closes on the wrong fence delimiter": the scan toggled a single in_fence boolean on ANY fence line, backtick or tilde, treating the two as interchangeable. CommonMark closes a fence only on a line of the SAME character it opened with, so a tilde fenced example that itself demonstrates a backtick fence as literal documentation text had that backtick line wrongly treated as closing the outer fence. A heading line still logically inside the tilde fence would then end the scan early — exactly the data loss shape this file exists to prevent. Added a small _toggle_fence helper that tracks which character opened the current fence and only closes on a matching one.

  • "boundary_prefix matched via lines[j].startswith (raw) vs stripped for other checks": confirmed, the boundary_prefix check matched the raw line while the ATX heading regex right beside it in the same condition matched the stripped line. A sibling heading indented by a couple of spaces is still a real ATX heading per CommonMark, so the raw line check missed it as a boundary even though the stripped check would have caught the exact same line a moment later. Switched it to match the stripped line, consistent with every other check in the same scan.

Both fixes verified against the pre-fix code first (confirmed each new regression test actually fails without the fix, not just that it passes with it), with the fence test specifically needing an unbalanced single inner fence line rather than a balanced pair — a balanced pair's toggle parity happens to cancel out and masks the bug even on the old code.

@github-actions

Copy link
Copy Markdown

Thanks @ayushcodes10! One small thing: our changelog and release notes are built from PR titles, so we use the conventional-commits format, for example:

fix(python): resolve a bare stdlib import correctly

Prefixes we use: feat, fix, docs, chore, refactor, test, perf, build, ci. Editing the PR title clears this automatically. This is just a nudge and does not block review.

@ayushcodes10

Copy link
Copy Markdown
Contributor Author

Rebased on current v8. The rebase itself surfaced a new, genuine bug at the five call sites that conflicted with v8's newline preserving read/write refactor: each site's fresh file branch set new_content straight from the always on template instead of routing it through _replace_or_append_section, so a fresh install never wrote _SECTION_END_MARKER, and the very next install misjudged the section's end and appended a duplicate copy. Fixed in a separate commit, with new byte for byte idempotency regression tests for the gemini, agents, and vscode fresh install paths, since the existing idempotent tests for those only assert the heading count and did not catch this.

@ayushcodes10 ayushcodes10 changed the title Fix install/uninstall data loss when no matching heading follows a section fix(install): stop install/uninstall data loss when no matching heading follows a section Oct 23, 2026
@github-actions github-actions Bot removed the needs:title PR title should follow the conventional-commit format label Oct 23, 2026
…ction

_replace_or_append_section and _remove_marker_section used to fall through
to end of file whenever no boundary_prefix heading followed the marker,
replacing or deleting everything below it. For the H1 skill registration
marker this happened on nearly every real CLAUDE.md, since user content
there conventionally uses H2 headings, which never match an H1
boundary_prefix. One report lost 217 lines this way after a routine
reinstall printed only "Done."

Both functions now write and look for an explicit end marker
(_SECTION_END_MARKER) as the primary way to find a section's real end,
falling back to a boundary_prefix heading for legacy content written before
this fix. When neither is found, the trailing content is only treated as
safe to consume to EOF if nothing that looks like a heading of any level
appears in it at all; if something heading shaped is there, it is assumed
to be the user's own separate section and is left untouched, with a fresh,
clearly bounded copy appended instead of an unbounded replace.

claude_install, gemini_install, codebuddy_install, _agents_install and
vscode_install previously bypassed this helper entirely on a file's first
write, so that first write carried no end marker and a second install call
could not recognize its own prior output, defeating the fix above and
breaking idempotency. All five now route through the same helper
unconditionally.

Fixes issue 3791.
Covers issue 3791 directly: an H1 registration marker followed by the
user's own H2 heading must survive both _replace_or_append_section and
_remove_marker_section, since an H2 line never matches an H1
boundary_prefix and previously caused everything below it to be
destroyed. Also covers that legacy content with no heading of any level
after the marker is still safely consumed to EOF (the existing issue
580 upgrade in place guarantee), and that a freshly written section and
a subsequent reinstall of the same content produce byte identical
output, guarding the idempotency regression introduced and caught
while building this fix.

Confirmed against pre fix code via git stash: the two direct issue 3791
reproduction tests fail there and pass only with the fix applied.
Review finding: whether the sentinel search could reach past the last
marker occurrence and wrongly consume or skip a boundary belonging to
a different, earlier generation of the section. Traced several
constructions by hand and could not reproduce data loss, but the
scenario is worth locking in directly: an orphaned legacy generation
plus real user sections both before and after the active one, across
both a reinstall and an uninstall.

Also documents, right where the H1 registration body is built, the
invariant _has_heading_before_eof already relies on: that body must
never contain a line shaped like an ATX heading, or a legacy copy of
it without an end marker yet would be judged ambiguous and appended
fresh rather than replaced in place, a needless if harmless
duplicate. Not applicable to the current three line template, which
was already checked to contain no headings.
Both _replace_or_append_section and _remove_marker_section searched
for an exact end marker line across the whole rest of the file before
ever considering a boundary_prefix heading, rather than stopping at
whichever of the two came first. The end marker is an HTML comment
that renders invisibly in a markdown preview, so a user who adds
their own section by editing the file directly can easily insert it
above the marker rather than below it. Since the search always
preferred a later sentinel over an earlier heading regardless of
position, a heading and its content inserted before a stray or
misplaced end marker was swallowed into the replaced or removed
section along with the marker's own content instead of ending the
section where it should have.

Both functions now scan forward from the marker a single time and
stop at the first of either kind reached, so an earlier heading
always wins over a later sentinel. A well formed section written by
this fix is unaffected, since its own sentinel always sits
immediately after its content, before any later heading could be
reached.

Fixes review finding on PR 3803.
Covers the review finding directly: a user's own heading and content
inserted between the marker's body and its end marker, the kind of
edit an invisible HTML comment invites, must survive both a replace
and a removal instead of being swallowed along with the marker's own
content. Confirmed against pre fix code by restoring the prior
version of install.py directly, the test fails there and passes only
with the fix applied.
The previous fix stopped the boundary scan at whichever of an exact
boundary_prefix match or the end marker came first, but a user's own
lower level heading under an H1 marker never starts with the H1
boundary_prefix, so the scan skipped right over it and a later,
misplaced end marker could still swallow it along with the marker's
own content.

An H1 marker's own body is documented to never contain a heading
shaped line at all, since nothing shallower exists for internal
structure to nest under, so for that specific marker level any
heading, not just an exact boundary_prefix match, is unambiguously a
separate section. A deeper marker keeps the narrower same level only
check, since its body can legitimately contain a deeper heading as
its own nested structure.

Two existing tests asserted the old, more conservative fallback
behavior for this exact shape, either leaving an ambiguous removal
untouched or appending a duplicate registration rather than
replacing it in place. Both are updated to expect the now correct,
complete result instead.

Fixes review finding on PR 3803.
Covers the review finding directly: a user's own H2 heading under an
H1 marker, followed by a misplaced end marker further down, must
survive both a replace and a removal instead of being swallowed
along with the marker's own content. Also updates the two existing
tests whose old assertions described the prior, more conservative
fallback for this exact shape, since the fix now resolves them
completely instead of leaving them ambiguous or duplicated.

Confirmed against pre fix code by restoring the prior version of
install.py directly, the new test fails there and passes only with
the fix applied.
The end marker search and the any heading rule for a top level marker
both matched a bare hash prefixed line anywhere in the trailing
content, including inside a fenced code block. A shell or Python
comment line in an example fence matches the same pattern a real
heading does, so a top level marker whose own body contained an
example with a commented line got its fence split in two on that
inner line, replacing only part of it and leaving the closing fence
orphaned with no matching opener in the kept tail.

Both functions now track fence state while scanning forward and skip
the heading and boundary prefix checks entirely while inside a fence,
toggling on a line that opens or closes one. The end marker sentinel
check itself is unaffected, since a literal HTML comment matching
that exact text inside a fence is not a realistic concern the way an
ordinary hash prefixed comment line is.

Fixes review finding on PR 3803.
Covers both review findings directly: a top level marker whose own
body has an example fence with a hash prefixed comment line must have
that fence replaced whole rather than split on the inner comment, and
a legacy section followed by real user content whose own example
fence contains a similar comment must still resolve to a clean
removal rather than being left ambiguously untouched. Confirmed
against pre fix code by restoring the prior version of install.py
directly, the direct repro test fails there and passes only with the
fix applied.
A review round pointed out two gaps in the heading boundary scan.

First, fence tracking toggled on ANY fence line, a bare backtick or
tilde, as if the two were interchangeable. CommonMark closes a fence
only on a line of the same character it opened with, so a tilde
fenced example that itself shows a backtick fence as literal text
(documenting how to write one) had that backtick line wrongly
mistaken for closing the outer fence. A heading line still inside the
tilde fence would then end the scan early, the exact data loss shape
this file exists to prevent. Tracks which character opened the
current fence and only closes on a matching one.

Second, the boundary prefix check matched the raw line while the ATX
heading check right next to it matched the stripped line. A sibling
heading indented by a couple of spaces is still a real ATX heading
per CommonMark, so the raw line check missed it as a boundary even
though the stripped check beside it would have caught the exact same
line. Switched it to match the stripped line too, for consistency
with every other check in the same scan.
Pins a tilde fenced example that shows a backtick fence as literal
text no longer closes early on that backtick line, and a sibling
heading indented by a couple of spaces is still recognized as a
boundary. Both were verified to fail against the prior code before
the fix, using an unbalanced single fence line for the first test so
the bug's toggle parity actually surfaces instead of canceling out.
The two existing idempotent tests for agents and gemini only assert
the heading appears once, which does not catch the end sentinel
duplicating underneath an unchanged heading count, so they stayed
green while the previous commit's bug was live. Adds a stricter check
for agents, gemini, and vscode: the sentinel appears exactly once
after the first, fresh install, and a second install produces byte
for byte identical output.
@ayushcodes10
ayushcodes10 force-pushed the fix-3791-install-eof-fallback-data-loss branch from 9f9cd8e to 348e8cc Compare November 22, 2026 12:12

@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 review View in Graphify

Review before merging · Merge confidence 4/5

2 bugs (1 preexisting) · 6 possible issues to check · High impact

P2  A marker shown in a code sample can truncate the section · install.py:1160

P2  Shorter backtick lines can split fenced sections · install.py:921

6 possible issues we couldn't confirm

They don't change the score.

What this review covered
  • We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
  • 4 of 4 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 1196 functions depend on this change
  • 1 function became more coupled. gemini_install() (15 callers).
  • 613 of 613 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 348e8cc · Full report in the Graphify check

Comment thread graphify/install.py
Comment on lines +1157 to +1160
fence_char: str | None = None
for j in range(start + 1, len(lines)):
if lines[j].startswith(boundary_prefix):
stripped = lines[j].strip()
if stripped == _SECTION_END_MARKER:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2  A marker shown in a code sample can truncate the section

Updating or uninstalling can stop at a code sample’s literal end-marker line and leave the rest of the managed section behind.

Check whether the scanner is inside a fenced block before matching _SECTION_END_MARKER in both section scanners.

Evidence · checked against the code

Expected: The marker is treated as sample text, and the actual section boundary is used.
Actually: The marker ends the scan even inside the fence, so update or uninstall leaves the rest of the managed section in the file.

  • Independent source review: Reviewed the fence-related tests: they check headings or comments inside fences, but do not place the exact end-marker line inside a fenced block. They do not refute this path.
  • Also reported as: End-marker examples can leave part of a section behind
Prompt to fix with AI
In graphify/install.py, _remove_marker_section (lines 1157-1160):
Problem: A marker shown in a code sample can truncate the section
Expected: The marker is treated as sample text, and the actual section boundary is used.
Actually: The marker ends the scan even inside the fence, so update or uninstall leaves the rest of the managed section in the file.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

Comment thread graphify/install.py
Comment on lines +920 to +921
def _toggle_fence(stripped: str, fence_char: str | None) -> str | None:
"""Advance fence state by one line; returns the new ``fence_char``.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2  Shorter backtick lines can split fenced sections

Installing or uninstalling can mistake a three-backtick line inside a four-backtick code block for the block’s closing fence, then treat a heading in the example as a section boundary.

Track the opening fence run length in _toggle_fence.

Evidence · checked against the code

Expected: The shorter run does not close the fence, so the heading-looking line remains inside the managed section.
Actually: Fence tracking treats any matching-character run as a close; the heading can become the section boundary, leaving the rest of the fenced content outside the updated or removed span.

This was already on the base branch; the change keeps it.

  • Independent source review: The reviewed tests cover a fence of the other character and headings inside fenced content, but not a shorter matching-character run. Neither mitigates the run-length mismatch. The install caller passes file content to the section helper and writes its result.
Prompt to fix with AI
In graphify/install.py, _toggle_fence (lines 920-921):
Problem: Shorter backtick lines can split fenced sections
Expected: The shorter run does not close the fence, so the heading-looking line remains inside the managed section.
Actually: Fence tracking treats any matching-character run as a close; the heading can become the section boundary, leaving the rest of the fenced content outside the updated or removed span.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

This branch has not been deployed

No deployments
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.

install --platform claude deletes all CLAUDE.md content below the graphify block when no later H1 exists (regression in 0.9.66, #3741)

1 participant