Skip to content

fix(postgresql): escape LIKE wildcards in listSessionIds - #4341

Merged
zouyx merged 2 commits into
agentscope-ai:mainfrom
shanuo0312:agent/fix-agentscope-4330-c61a3c178096
Nov 26, 2026
Merged

zouyx merged 2 commits into
agentscope-ai:mainfrom
shanuo0312:agent/fix-agentscope-4330-c61a3c178096

Conversation

@shanuo0312

Copy link
Copy Markdown
Contributor

This is by an automated agent, not a human.

Fixes #4329.

AgentScope-Java Version

2.1.0-SNAPSHOT (main)

Description

PostgresAgentStateStore.listSessionIds built its LIKE pattern by concatenating the raw
user segment, so user ids containing PostgreSQL wildcards (%, _) widened the prefix match
across users. For example, listSessionIds("user_1") also matched slots of userA1, and the
anonymous user __anon__ compiled to a run of single-character wildcards.

The pattern now escapes \, % and _ with PostgreSQL's default LIKE escape character
before appending the trailing %, mirroring the likePrefixPattern helper already used by
the JDBC state store (as suggested in the #3233 review).

Three regression tests cover %, the underscores in the anonymous user, and the escape
character 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
    PostgresAgentStateStoreTest cases.
  • mvn -B -T1C -pl agentscope-extensions/agentscope-extensions-postgresql spotless:check
    → BUILD SUCCESS.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated — not applicable: internal SQL pattern fix with
    no documented behavior change
  • Code is ready for review

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.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 07:18

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.

🟢 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 trailing LIKE wildcard.
  • 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 zouyx self-assigned this Nov 25, 2026
@zouyx
zouyx merged commit 31d3200 into agentscope-ai:main Nov 26, 2026
5 checks passed
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.

[Bug]: PostgresAgentStateStore.listSessionIds uses unescaped LIKE pattern, wildcard user ids list other users' sessions

3 participants