Skip to content

fix: make function-name token similarity advisory - #687

Open
egore wants to merge 1 commit into
bethington:devfrom
egore:pr/token-similarity
Open

egore wants to merge 1 commit into
bethington:devfrom
egore:pr/token-similarity

Conversation

@egore

@egore egore commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What this changes

rename_function no longer rejects a name just because its tokens are a subset of another function's tokens. That case is now an advisory warning, and the naming-quality checks and the Function ID check are still enforced.

Why

In enforce mode, rename_function rejected any name whose token set was a strict subset of an existing function's name in the same module prefix. Shared tokens don't mean two functions collide. They often mean related functions with different behaviour. A descriptive name such as GetNamedMatrixAlignmentTransformFlags was refused only because GetTransform already exists, and the same happened for a trailing-specifier name or a shorter related name.

Reproduction: in a program that has a function GetTransform, run rename_function with new_name="GetNamedMatrixAlignmentTransformFlags" and strict_mode="enforce". Before this change it returns status: rejected, error: name_collision, issue: token_subset_duplicate. Now the rename succeeds with a warning that names the similar function.

What changed:

  • FunctionService.renameFunctionByAddress: the token-subset check now adds an advisory warning in every mode. The rejection builder tokenSubsetCollisionRejection is gone.
  • Still enforced: the verb-tier / single-token / weak-noun quality rules, the Function ID gate, and Ghidra's own symbol validation.
  • strict_mode now only affects the naming-quality rejections. The tool and parameter descriptions say that token-subset similarity is advisory.
  • New FunctionServiceRenameTest covers descriptive supersets, trailing specifiers, shorter related names, and a name that must still be rejected on naming quality.

Behaviour change to be aware of: anything that relied on the name_collision / token_subset_duplicate rejection will no longer see it.

Tests you ran

  • uv run pytest tests/unit/ — Python unit tier, no Ghidra needed
  • ./gradlew test --tests 'com.xebyte.offline.*' "-PGHIDRA_INSTALL_DIR=<dir>"
    — offline Java tier, needs a Ghidra install but no running server and no
    Maven (mvn test -Dtest='com.xebyte.offline.*Test' is the Maven equivalent)
  • powershell -File tests\pester\Run-Tests.ps1 — only if you touched
    ghidra-mcp-setup.ps1
  • Live tier (pytest tests/ -m readonly, ./gradlew test) — needs Ghidra
    running on port 8089 with a program loaded
  • Could not run the live tier
Rebased on upstream/dev (8dbbb1f6), Ghidra 12.2, macOS.

pytest tests/unit  (excluding test_release_evidence.py and the gradlew
toolchain tests, which need gpg signing / a Windows-style environment)
-> 0 failed

./gradlew test --tests 'com.xebyte.offline.*' --tests 'com.xebyte.core.FunctionService*Test'
-> 1030 tests completed, 3 failed:
   SharedProjectLocatorTest.testResolveProjectDirOverrideIsContainmentChecked
   TreeRegistryTest.createIsIdempotentHoweverTheDefaultRootIsExpressed
   TreeRootTest.defaultsConfigRoundTripThroughExplicitRoot
   The same 3 fail on a clean upstream/dev checkout; this PR does not touch them.
   FunctionServiceRenameTest (new) passes on its own.

If you touched an @mcptool or @PARAM annotation

I changed only the description strings on /rename_function and its new_name parameter. No tool, parameter or path was added, removed or renamed.

  • mvn test -Dtest=RegenerateEndpointsJson -Dregenerate=true — Maven
    only
    ; Gradle cannot pass the -Dregenerate flag into the forked test
    JVM and exits BUILD SUCCESSFUL having regenerated nothing. No Maven? Say
    so here and leave the catalog alone — a maintainer will regenerate it.
  • python -m tools.audit_server_scope --write
  • python -m tools.gen_readme_api_reference --write
  • Not applicable — see below

No Maven here, so I left the catalog alone. tests/endpoints.json keeps its hand-authored description for /rename_function ("Rename function by name"), and the parity test and the Python catalog tests pass. tests/conformance/snapshots/mcp_schema.snap still holds the old tool and parameter description text. That file is recorded from a live server, which I couldn't run, so a maintainer may want to re-record it.

Checklist

  • Branched from dev and targeting dev
  • CHANGELOG.md updated, if this is user-visible
  • No unrelated reformatting mixed into the diff

Allow descriptive and related function names in enforce mode instead of
treating token subsets as symbol collisions. Keep naming-quality and
Function ID enforcement intact.

Add regression coverage for descriptive supersets, trailing specifiers,
shorter related names, and retained naming-quality rejection.

Validation: 102 targeted Java tests pass. Python unit suite: 1174
passed, 13 skipped, 1 default-branch assertion failure, and 17 fixture
errors due to GPG signing configuration.
@egore
egore requested a review from bethington as a code owner November 21, 2026 18:01
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@rahul05ranjan rahul05ranjan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Checked the gate matrix in FunctionService after the change: the Q1–Q5 quality gate and the Function ID gate still hard-reject in enforce mode (and downgrade to disabledEnforcementWarning otherwise), and the token-subset check is now advisory in every mode, added straight to enforcementWarnings regardless of strict_mode. The tests pin all three behaviors from both directions — superset/trailing-specifier/shorter-related names rename with setName(..., USER_DEFINED) and carry the advisory, while Get still rejects with name_quality and never().setName(...) proves the rejection path doesn't write. Also confirmed tokenSubsetCollisionRejection is fully gone with no dangling references, and the collision scan still lives inside the auto-generated-name exemption where it always was.

One small thing lost in the swap: the old rejection carried a concrete suggestion — add a distinguishing token like Broadcast, Local, ByIndex when the functions really are the same behavior. That was good guidance for a model-driven renamer, and it's exactly the case where the new advisory fires. Since the advisory now shows up for every superset/subset pair, keeping a one-line "if this is the same behavior, add a distinguisher" hint inside the advisory would preserve the useful part of the old text without bringing back the rejection.

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.

3 participants