fix: encode dynamic URL path segments#5963
Merged
Merged
Conversation
VectorPeak
force-pushed
the
fix/encode-url-path-segments
branch
from
June 30, 2026 03:05
84403b3 to
c92cea4
Compare
Contributor
Author
|
Hi @kartik-mem0, sorry to bother you again. The previous PR for this fix had already received an LGTM, but I accidentally deleted the fork branch before it could be merged, so GitHub could no longer complete the merge from that branch. I opened this new PR to address the same issue with the same intended fix. When you have a chance, could you please help review this one as well? Thank you very much for your time and help. |
Widen the Python CLI helper's parameter hint from str to Any to match the SDK's _encode_path_segment. Both bodies coerce via quote(str(value), safe=""), so the str hint was misleading — the helper intentionally accepts non-str ids (int, UUID). No behavior change.
Fixes the TypeScript SDK CI build failure: `prettier --check .` rejected the new test file's line wrapping (build_ts_sdk lint step). No logic change.
kartik-mem0
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Fixes #5893. Re-submitted after fork recovery; original PR #5818 was closed because the fork was deleted.
Description
What Problem This Solves
Several hosted SDK and CLI methods build API paths by directly interpolating caller-provided IDs into URL path segments:
Those values are identifiers from the SDK or CLI caller's perspective, but
/,?, and#are structural URL characters. If an ID contains one of those characters, the request no longer targets the intended single path segment.For example, deleting a user/entity named:
can construct a path like:
That can be parsed as an extra path segment plus query/fragment syntax instead of one literal entity identifier. The intended request path is:
This keeps the identifier as a single URL path segment and lets the server receive the literal ID value after decoding.
Change
This PR adds local path-segment encoding helpers and uses them where dynamic IDs are inserted into hosted API paths.
urllib.parse.quote(str(value), safe="")so/is encoded instead of being preserved byquote()'s default behavior.encodeURIComponent(String(value))for the same single-segment encoding behavior.Affected hosted API paths include:
Conflict Resolution
This branch has been updated on top of the current
mainbranch. The conflicts came from related CLI fixes that landed after the original PR:entity delete, not just the last #5936: Python CLI now preserves everydelete_entitiesresult instead of returning only the last one.entity delete, not just the last #5970: Node CLI now preserves everydeleteEntitiesresult instead of returning only the last one.The resolution keeps both fixes: entity delete results remain keyed by entity type, and
entity_type/entity_idare still encoded before constructing/v2/entities/.../.../paths. The Node CLI test file also keeps both the result-preservation tests frommainand the path-encoding regression tests from this PR.Evidence
Representative encoded request examples:
Validation after resolving conflicts:
Results:
Node/TypeScript tests were not re-run in this conflict-resolution pass because this checkout does not have
node_modulesinstalled, but the affected Node CLI conflict was resolved by keeping both existing test groups.Type of Change
Breaking Changes
N/A
Test Coverage
Regression coverage is included for:
tests/test_client.pycli/python/tests/test_platform_backend_paths.pymem0-ts/src/client/tests/memoryClient.crud.test.tsandmem0-ts/src/client/tests/memoryClient.users.test.tscli/node/tests/platform-backend.test.tsChecklist