Skip to content

cli: resolve numeric kg find-path IDs on integer-keyed graphs - #2186

Merged
pkupt merged 4 commits into
semantica-agi:mainfrom
charan-rathore:fix/2179-find-path-numeric-id
Nov 5, 2026
Merged

pkupt merged 4 commits into
semantica-agi:mainfrom
charan-rathore:fix/2179-find-path-numeric-id

Conversation

@charan-rathore

@charan-rathore charan-rathore commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Description

kg find-path --from 42 --to 7 fails on graph stores that key nodes by integer ID (Neo4j), because Click passes every option value as a string and _resolve_entity only ever compared the raw string token against node IDs. The command now retries a purely numeric token as an integer before falling back to name matching, so integer-keyed nodes resolve correctly.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Related Issues

Fixes #2179

Changes Made

  • _resolve_entity in semantica/cli.py: when the raw string token is not a node ID and token.isdigit(), retry membership as int(token) and return the integer ID on a hit.
  • Ambiguous-name error message now stringifies matched IDs before joining, so integer IDs render instead of raising a TypeError.
  • _resolve_entity guards the int() conversion so digit tokens it rejects (superscript digits, overlong digit strings) fall through to name matching and the documented unknown-entity error instead of raising ValueError.
  • Added tests/cli/test_cli_find_path.py (8 tests): numeric token resolves an integer node ID, string token still resolves a string node ID, name fallback unchanged, ambiguous-name error lists integer IDs, unknown token raises a clear error, superscript digit token falls through to the unknown-entity error, overlong digit token falls through to the unknown-entity error, superscript-containing name still resolves by name.

Testing

  • Tested locally
  • Added tests for new functionality
  • Package builds successfully (python -m build)

Test Commands

pytest tests/cli/test_cli_find_path.py -q   # 8 passed

Fail-before verified: on pristine main (only the test file added), exactly the 2 regression tests fail; on this branch all 8 pass. The 3 Unicode/long-digit tests were likewise verified failing before the int() guard (2 fail, the name-resolution one already passed).

Documentation

  • No documentation changes needed

Breaking Changes

Breaking Changes: No

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • Package builds successfully

Additional Notes

Baseline gaps on current main, not introduced or altered by this change:

  • semantica/cli.py is not black-clean on pristine main (166 reformat hunks). This diff adds none of its own: the hunk count is identical before and after the branch, and the new test file is black-clean.
  • tests/kg/test_community_hierarchy.py::TestCommunityHierarchyEdgeCases::test_builder_fallback_flag_resets_on_subsequent_builds fails on pristine main and is not listed in .github/full-suite-known-failures.txt. It is unrelated to this change (no shared code path with semantica/cli.py).

Click passes --from/--to as strings, but Neo4j-backed graphs key nodes
by integer ID, so _resolve_entity could never match a numeric ID
(semantica-agi#2179). Retry a numeric token as an int, keep name resolution
unchanged, and stringify IDs in the ambiguous-name error. Adds
regression tests for numeric IDs, string IDs and the ambiguous path.
Copilot AI balanced review requested due to automatic review settings October 31, 2026 07:37
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-31T07:38:40.940876Z
We couldn’t complete this review. Comment @codex review to try again.
7dc8517 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.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Resolve numeric find-path IDs on integer-keyed graphs

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Resolve numeric CLI tokens against integer-keyed graph nodes so find-path works with Neo4j IDs.
• Preserve string-ID and name lookup, and display integer IDs in ambiguous-name errors.
• Add regression tests for successful resolution and error cases.
Diagram

graph TD
  Token["CLI token"] --> Direct{"String ID exists?"} -->|yes| Result["Resolved ID"]
  Direct -->|no| Numeric{"Numeric ID exists?"} -->|yes| Result
  Numeric -->|no| Names{"Name matches?"} -->|one| Result
  Names -->|none or many| Error["Click error"]
Loading
High-Level Assessment

The localized lookup fallback is appropriate: it preserves existing string-ID precedence and name resolution while supporting integer-keyed graphs. Coercing all CLI inputs up front would risk changing how numeric string IDs are resolved.

Files changed (2) +54 / -2

Bug fix (1) +9 / -2
cli.pyResolve digit-only tokens as integer graph IDs +9/-2

Resolve digit-only tokens as integer graph IDs

• The entity resolver now checks an integer version of a numeric token after direct string-ID lookup and before name lookup. It also stringifies IDs in ambiguous-name errors so integer IDs can be listed.

semantica/cli.py

Tests (1) +45 / -0
test_cli_find_path.pyCover find-path entity resolution and errors +45/-0

Cover find-path entity resolution and errors

• Five tests check integer and string ID resolution, name fallback, unknown tokens, and ambiguous names with integer IDs.

tests/cli/test_cli_find_path.py

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Unicode-named entities crash path lookup ✓ Resolved
Description
_resolve_entity calls int(token) whenever token.isdigit() is true, although superscript
characters such as ² satisfy isdigit() but are not accepted by int(). A find-path request
using that name (or a long digit-only token) therefore exits through generic exception handling
before name fallback or the documented unknown-entity error.

Grey Divider

Tip of the day
💡 Did you know, you can turn these tips off under Display > Comment parts

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread semantica/cli.py Resolved
…tching

isdigit() accepts characters int() rejects (e.g. superscripts), and int()
caps digit-string length, so the numeric retry in _resolve_entity could
raise ValueError before the name fallback or the unknown-entity error.
Guard the conversion and add regression tests. Addresses review feedback
on PR semantica-agi#2186.
Copilot AI balanced review requested due to automatic review settings October 31, 2026 07:53

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@charan-rathore

Copy link
Copy Markdown
Contributor Author

Confirmed and fixed in ed8fbb4 (plus test formatting in d57498b). The numeric retry now guards the int() conversion, so tokens like ² or a 5000-digit string fall through to name matching and the documented unknown-entity error instead of raising ValueError. Three regression tests added: superscript digit token -> unknown-entity ClickException, overlong digit token -> unknown-entity ClickException, superscript-containing name still resolves by name. Verified fail-before (2 new tests fail on the previous head) and pass-after (8/8).

@pkupt pkupt added bug Something isn't working easy-fix Can be completed in less than one day labels Nov 2, 2026
Copilot AI balanced review requested due to automatic review settings November 5, 2026 03:24

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@pkupt pkupt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@charan-rathore thanks for this. I pulled the branch and ran it: tests/cli/test_cli_find_path.py gives 8 passed and tests/cli gives 36 passed. Swapping cli.py back to main turns exactly two tests red, the integer-node one and the ambiguous-name one, so both halves of the change are covered. LGTM.

One small thing, not blocking: isdigit() also accepts digits like ٣, and int() happily turns that into 3, so a name that looks numeric could resolve to a node instead of falling through to name matching. token.isascii() before isdigit() would close that if you think it is worth it.

@pkupt
pkupt merged commit 0edb7d5 into semantica-agi:main Nov 5, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working easy-fix Can be completed in less than one day

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] kg find-path cannot take a numeric node ID on Neo4j

3 participants