Skip to content

fuzzy_match: hoist the strategy table to module constants - #291

Merged
RecursiveIntell merged 1 commit into
mainfrom
rsi/patch-constants-hoist-20261130
Dec 1, 2026
Merged

RecursiveIntell merged 1 commit into
mainfrom
rsi/patch-constants-hoist-20261130

Conversation

@RecursiveIntell

@RecursiveIntell RecursiveIntell commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

What this does

Moves the patch tool's fuzzy-matching strategy table in tools/fuzzy_match.py from local variables inside fuzzy_find_and_replace to module-level constants:

  • MATCH_STRATEGIES: the ordered chain of nine (name, function) pairs, from exact to context_aware.
  • SIMILARITY_STRATEGIES: the frozenset {"block_anchor", "context_aware"} that replace_all refuses to use for multiple matches.

Order and contents are unchanged, and the dispatcher (fuzzy_find_and_replace) reads the constants at call time, so the refactor is behaviour-preserving by construction. It makes the matching chain readable and testable on its own, and is a step toward evaluating matcher changes without editing the dispatcher body.

One file changed (tools/fuzzy_match.py, +29/−22), no test files touched, single commit 839627c on top of main 6d072e1. To check order and contents directly, diff the strategy list and the similarity set in git show 6d072e1:tools/fuzzy_match.py against 839627c:tools/fuzzy_match.py.

Evidence

  • Equivalence (run locally before the commit): the before-module was read with git show HEAD:tools/fuzzy_match.py while HEAD was 2312f67; the after-module was the working tree that was then committed unchanged as 76b566e. The branch was later rebased onto main 6d072e1 (which changes no file this PR touches); the tools/fuzzy_match.py diff is byte-identical before and after the rebase, and the 116 patch tests pass again at 839627c. Both were loaded side by side and called with the same inputs, and the full return tuple (content, match_count, strategy, error) was compared. 0 differences across 14,114 cases:
    • 10,200 synthetic cases: 17 drift families × 300 cases, each run with replace_all=False and replace_all=True;
    • 3,914 random edits of real source text, drawn from 4,000 candidates with 86 skipped because the generated old_string was whitespace-only. Edits: indentation shifts, inserted blank lines, changed lines, tabs, truncated lines, and unmutated controls; 20% of files with CRLF line endings.
      This is a probe on one host, not a proof over all inputs; the construction argument above is the main warrant.
  • Existing patch tests (tests/tools/test_fuzzy_match.py, test_patch_multimatch_locations.py, test_patch_ws_diagnosis.py, test_patch_already_applied.py, test_patch_parser.py): 116 passed.
  • ruff check tools/fuzzy_match.py (ruff 0.15.10): All checks passed.

Scope and limits

  • No behaviour change is intended, and none was observed in the equivalence runs above.
  • This PR does not fix the matcher's reproduced safety issue. block_anchor matches a region whose first and last lines equal those of old_string after whitespace stripping and whose middle is similar enough; when the model's old_string has the same line count but a stale interior line, it is applied without an error and the real interior line is overwritten (reproduced on main). Strategy selection is unchanged here, so the issue is as reproducible after this PR as before.
  • Single-host local runs; any hosted CI results appear in this PR's checks.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-01T01:42:10.425961Z
We couldn’t complete this review. Comment @codex review to try again.
76b566e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

૮ >ﻌ< ა ci review

ran on 839627c — fuzzy_match: hoist the strategy table to module constants

⚠️ Warnings

OSV vulnerability scan · View job

320 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.

Behaviour-preserving refactor. The matching chain and the set of
similarity-based strategies were local variables rebuilt on every call to
fuzzy_find_and_replace; they are now module constants (MATCH_STRATEGIES,
SIMILARITY_STRATEGIES) defined after the strategy functions. Order and
contents are unchanged. This lets the strategy table be read, tested and
changed without editing the dispatcher body.

Equivalence: the pre- and post-change modules were loaded side by side and
compared on 10,200 synthetic cases (17 drift families x 300, replace_all
False and True) plus 3,914 random edits of real source: 0 differences in
the returned (content, count, strategy, error). Existing patch tests:
116 passed. ruff clean.
@RecursiveIntell
RecursiveIntell force-pushed the rsi/patch-constants-hoist-20261130 branch from 76b566e to 839627c Compare December 1, 2026 01:51
@RecursiveIntell
RecursiveIntell merged commit 3d3fa9d into main Dec 1, 2026
50 checks passed
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.

1 participant