Repository navigation
fix(postgresql): escape LIKE wildcards in listSessionIds - #4341
Merged
zouyx merged 2 commits intoNov 26, 2026
Merged
Conversation
listSessionIds built its LIKE pattern from the raw user segment, so user ids containing '%' or '_' widened the prefix match across users: e.g. listSessionIds("user_1") also returned sessions of "userA1", and the anonymous user "__anon__" compiled to a run of single-character wildcards.
Escape '\', '%' and '_' with PostgreSQL's default LIKE escape character before appending the trailing '%', mirroring the likePrefixPattern helper already used by the JDBC state store.
Regression tests cover '%', '_' (anonymous user) and the escape character itself.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change to escape literal user prefixes in PostgreSQL session-listing queries.
No open issues 🎉
What changed in this PR
Fixes #4329 by escaping literal user prefixes in PostgreSQL session-listing queries, preventing % and _ in user IDs from matching other users’ sessions.
Changes:
- Adds a helper that escapes
\,%, and_before appending the trailingLIKEwildcard. - Adds three regression tests for percent signs, anonymous-user underscores, and backslashes.
| File | Description |
|---|---|
agentscope-extensions/agentscope-extensions-postgresql/src/test/java/io/agentscope/extensions/postgresql/state/PostgresAgentStateStoreTest.java |
Verifies escaped query parameters for all three special characters. |
agentscope-extensions/agentscope-extensions-postgresql/src/main/java/io/agentscope/extensions/postgresql/state/PostgresAgentStateStore.java |
Escapes the user prefix used by listSessionIds. |
Review effort: Balanced
zouyx
approved these changes
Nov 25, 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.
This is by an automated agent, not a human.
Fixes #4329.
AgentScope-Java Version
2.1.0-SNAPSHOT (
main)Description
PostgresAgentStateStore.listSessionIdsbuilt itsLIKEpattern by concatenating the rawuser segment, so user ids containing PostgreSQL wildcards (
%,_) widened the prefix matchacross users. For example,
listSessionIds("user_1")also matched slots ofuserA1, and theanonymous user
__anon__compiled to a run of single-character wildcards.The pattern now escapes
\,%and_with PostgreSQL's defaultLIKEescape characterbefore appending the trailing
%, mirroring thelikePrefixPatternhelper already used bythe JDBC state store (as suggested in the #3233 review).
Three regression tests cover
%, the underscores in the anonymous user, and the escapecharacter itself.
Verification
mvn -B -T1C -pl agentscope-extensions/agentscope-extensions-postgresql -am test→ BUILD SUCCESS; PostgreSQL module: 151 tests, 0 failures, 0 errors, including the three new
PostgresAgentStateStoreTestcases.mvn -B -T1C -pl agentscope-extensions/agentscope-extensions-postgresql spotless:check→ BUILD SUCCESS.
Checklist
mvn spotless:applymvn test)no documented behavior change