Repository navigation
Conversation
…tion instead of parsing slotKey
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
oss-maintainer
left a comment
There was a problem hiding this comment.
Review — Approved ✅
Clean, minimal fix for the SlotRef.parse() ambiguity when sessionId contains /.
What changed
userIdandsessionIdare now stored directly onCallExecutionas separate fieldssaveStateToSession()usesscope.userId/scope.sessionIddirectly instead of round-tripping through the concatenated slot keySlotRef.parse()is removed — no longer needed- Constructor updated to accept the original identity values
Assessment
- Correctness: Eliminates the root cause entirely. No more ambiguity from
lastIndexOf('/')splitting. - Scope: 12 additions / 13 deletions in a single file — well-contained.
- Backward compatibility: The
slotKeyfield is preserved onCallExecution(still used as map key), so no downstream breakage. - Suggestion: Add a regression test with a sessionId containing
/(e.g."cidLcMOzfRs62haqnq1NO8SxeYdmc/lO8bWyidOisoKAzM=") to verify state is stored and retrievable under the correct(userId, sessionId)pair.
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
|
@oss-maintainer noted on #2475 that "a regression test covering sessionId with Commit: gxgeek-n@c664ed09 (branch
Verified both directions:
The only case green on both is the plain-sessionId one, which the bug never touched — so the suite genuinely detects the regression rather than passing vacuously. The fixture uses a real DingTalk-style Feel free to cherry-pick
|
This comment was marked as abuse.
This comment was marked as abuse.
## AgentScope-Java Version 2.0.4-SNAPSHOT (main @ 9c8b10d) ## Description Fixes #2475. **Problem.** With an `AgentStateStore` configured, `saveStateToSession` recovered `(userId, sessionId)` by splitting the slot key `(userId or "__anon__") + "/" + sessionId` at its last `/`, while loads used the caller's real pair. For a sessionId containing `/` (e.g. a Base64 DingTalk `openConversationId`), saves and loads therefore addressed different pairs: - A trailing `/` split into a blank sessionId, so the save failed (`sessionId must not be blank`). - On stores that key user and session separately (InMemory, JsonFile, JDBC/MySQL/PostgreSQL, Mongo), each call started from an empty history, `getAgentState(uid, sid)` returned a fresh state, and state was written under made-up user ids such as `u1/cid...`, which also polluted per-user queries like `listSessionIds`. On versioning stores, every save from the second turn on also hit a spurious CAS conflict (the default OVERWRITE logs a warning; `FAIL` throws). - Redis/OSS/COS join user and session with `/`, so both pairs mapped to the same storage key and the history loss was masked there. **Fix.** `CallExecution` now carries the resolved `(userId, sessionId)` as final fields and derives `slotKey` from them. `saveStateToSession` passes that pair to the store. Every per-call save goes through this one method: normal completion, both structured-output paths, the failure path, user interrupt, and `streamEvents`. `SlotRef` and the unused 3-arg constructor are removed. The slot-key format is unchanged; it stays an opaque cache/serialization key. Identities without `/` still land on the same rows: saves now pass the caller's raw userId, so a blank or literal `"__anon__"` userId is no longer rewritten to `null`, and every in-repo store maps null, blank and `"__anon__"` to the same bucket. **Tests** (`ReActAgentPerSessionStateTest`): - Parameterized over `("u1", base64 id)`, `("u1", "tenant/chat/42")`, `("u1", "conv/")`, `(null, base64 id)`: state is readable under the caller's pair, and `agent_state` is written under exactly that pair. - Two turns on one session: no CAS conflict, and a rebuilt agent replays both turns. Without the fix, the new cases fail (4 failures, 1 error). **How to test:** `mvn -pl agentscope-core verify` **Out of scope (happy to follow up separately):** - The slot key is still not injective: `("u1/a", "b")` and `("u1", "a/b")` share a key. This needs a userId containing `/`. - Rows written under corrupted pairs before this fix stay orphaned on the stores that key user and session separately (plus the JPA store in agentscope-service). This may be worth a release note. Credit: same approach as #2476 by @waterWang; the regression-test idea comes from @gxgeek-n. ## Checklist - [x] Code has been formatted with `mvn spotless:apply` - [x] All tests are passing: agentscope-core `verify` (2491 tests) and agentscope-harness (1057 tests) locally; full repo left to CI - [x] Javadoc comments are complete and follow project conventions - [ ] Related documentation has been updated (N/A, no public API change) - [x] Code is ready for review --------- Co-authored-by: ”zhuzhiyu.zzy“ <[email protected]>
Fixes #2475
Problem
When
RuntimeContext.sessionIdcontains a/character (e.g., DingTalkopenConversationIdvalues likecidLcMOzfRs62haqnq1NO8SxeYdmc/lO8bWyidOisoKAzM=),ReActAgentpersists theAgentStateunder a corrupted(userId, sessionId)pair becauseSlotRef.parse()splits the concatenated slot key at the last/.Root Cause
SlotRef.parse()useslastIndexOf('/')to split the concatenated key, but this is ambiguous when sessionId itself contains/:Fix
userIdandsessionIddirectly onCallExecution— the original values are now carried through the per-call scope instead of being reconstructed from the concatenated slot key.saveStateToSession()to usescope.userId/scope.sessionIddirectly.SlotRef.parse()— no longer needed.Impact
getAgentState(userId, sessionId)now works correctly for any session whose id contains/.user_idvalues.listSessionIds(userId)return correct results.Testing
A regression test should verify: run a call with a sessionId containing
/and assert the state is retrievable from the store under the untouched pair, with no sibling slot appearing under a polluted userId.