Skip to content

fix(python-sdk): validate recall query and max_distance (#1248) - #1254

Merged
harrymove-ctrl merged 2 commits into
devfrom
fix/issue-1248-python-recall-validation
Oct 27, 2026
Merged

harrymove-ctrl merged 2 commits into
devfrom
fix/issue-1248-python-recall-validation

Conversation

@harrymove-ctrl

@harrymove-ctrl harrymove-ctrl commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This is the Python side of #1215/#1228 and #1212/#1227, which were fixed in TypeScript only.

  • MemWal.recall("") signed and sent an empty query, even though MemWalMock.recall("") raises ValueError: query cannot be empty.
  • max_distance=float("nan") or a negative value dropped every hit, because the filter keeps distance < max_distance. The empty result looks the same as an empty namespace. The mock had the same filter and the same problem.

Changes

  • recall() rejects a blank query with the mock's message (query cannot be empty) before signing. This covers both the positional and RecallParams call styles.
  • New memwal.utils.validate_max_distance, used by both MemWal.recall and MemWalMock.recall. It rejects NaN, ±inf, negative, bool and non-numeric values with ValueError("max_distance must be a non-negative finite number"), the same rule as the TypeScript maxDistance guard.

Tests

  • New tests/test_recall_validation.py: blank queries and bad max_distance values are rejected before signing in the client and in the mock. Valid thresholds still filter.
  • ruff check memwal/ tests/ and pytest tests/ -m "not integration" pass.

Estimate: 2 SP (incl. review)

Local results: ruff clean; pytest -m "not integration": 268 passed (new test failed 15/17 before the fix); mypy unchanged vs dev.

Fixes #1248

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

[P2] Include the Python release update with this SDK change.

The branch still carries Python 0.1.11, while current dev and main both carry 0.1.12 and that version is already on PyPI. This PR does not prepare a new release. After rebasing, keeping 0.1.12 makes release-python-sdk.yml skip stable publication, so users cannot receive this fix. Please prepare the next patch (currently 0.1.13), synchronize pyproject.toml, memwal/__init__.py, the package and docs changelogs, and the verifier pin. Re-evaluate the version if another unreleased patch lands first; use the manual release path.

Validation: 268 non-integration Python tests passed; Ruff clean. No new runtime regression found.

@harrymove-ctrl
harrymove-ctrl force-pushed the fix/issue-1248-python-recall-validation branch from 0468f41 to 5713271 Compare October 23, 2026 00:09
@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

@ducnmm rebased on dev (one conflict in recall(): kept dev's body dict and put the query and max_distance checks just before it) and prepared Python 0.1.13 (pyproject, __init__, both changelogs, verifier pin). Ruff is clean and tests pass.

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

[P2] Retarget the release to 0.2.1 after rebasing. dev and main now carry 0.2.0 (packages/python-sdk-memwal/pyproject.toml:7, memwal/__init__.py:131), and 0.2.0 is already the version on PyPI. This branch adds 0.1.13 (packages/python-sdk-memwal/CHANGELOG.md:3, docs/python-sdk/changelog.mdx:39) and calls it the latest release (docs/python-sdk/changelog.mdx:32), which is now below the current release; the PR is also CONFLICTING against dev. Keeping 0.1.13 would downgrade the SDK, and since 0.1.13 was never published, pip install memwal would continue to resolve 0.2.0, so users would not receive this fix. Please rebase and move the entry under a 0.2.1 section, updating pyproject.toml:7, memwal/__init__.py:131, and scripts/verify-manual-sdk-release.mjs:14 to 0.2.1.

@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

@ducnmm rebased onto dev (22556f92), kept _check_limit(limit) alongside the query and max_distance validation, and retargeted the Python SDK release metadata (pyproject.toml, memwal/__init__.py, and both changelogs) to 0.2.1. node scripts/verify-manual-sdk-release.mjs and pytest pass. Ready for another look.

@harrymove-ctrl
harrymove-ctrl force-pushed the fix/issue-1248-python-recall-validation branch from 5713271 to 22556f9 Compare October 26, 2026 08:48
@harrymove-ctrl
harrymove-ctrl requested a review from ducnmm October 26, 2026 08:48
@harrymove-ctrl
harrymove-ctrl force-pushed the fix/issue-1248-python-recall-validation branch from 22556f9 to 54be5f3 Compare October 26, 2026 23:38
@harrymove-ctrl harrymove-ctrl changed the title fix(python-sdk): validate recall query and max_distance (WALM-859) fix(python-sdk): validate recall query and max_distance (#1248) Oct 26, 2026
@harrymove-ctrl
harrymove-ctrl force-pushed the fix/issue-1248-python-recall-validation branch from 54be5f3 to 0ba6bc0 Compare October 26, 2026 23:56

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

Please address the findings below before merging.

Comment thread packages/python-sdk-memwal/CHANGELOG.md
@harrymove-ctrl
harrymove-ctrl force-pushed the fix/issue-1248-python-recall-validation branch from 0ba6bc0 to 51c8b3a Compare October 27, 2026 04:16
@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

@ducnmm Rebased onto origin/dev and bumped the Python SDK version to 0.2.2 in 51c8b3a:

  • Updated packages/python-sdk-memwal/pyproject.toml and packages/python-sdk-memwal/memwal/__init__.py to 0.2.2.
  • Moved the changelog entry into a new ## 0.2.2 (Unreleased.) section above ## 0.2.1 in both packages/python-sdk-memwal/CHANGELOG.md and docs/python-sdk/changelog.mdx.
  • Restored unchanged comments against origin/dev.

@harrymove-ctrl
harrymove-ctrl requested a review from ducnmm October 27, 2026 04:16

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

Re-reviewed the current head. Recall query/max-distance validation is consistent across the real client and mock, and the fix targets the unreleased Python 0.2.2 patch. Seventeen focused local tests passed. Current CI checks are successful or skipped.

recall() signed an empty query that MemWalMock.recall() already
rejects, and a NaN or negative max_distance dropped every hit because
the filter keeps distance < max_distance. Reject a blank query with the
mock's message, and reject a non-finite or negative max_distance in
both the client and the mock, matching the TypeScript guards from

Fixes #1248
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants