Skip to content

fix: fail early for incompatible Redisson state-store clients - #3112

Open
mvanhorn wants to merge 3 commits into
agentscope-ai:mainfrom
mvanhorn:fix/3063-redisson-state-store-compatibility-guard
Open

mvanhorn wants to merge 3 commits into
agentscope-ai:mainfrom
mvanhorn:fix/3063-redisson-state-store-compatibility-guard

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

In each existing Redisson constructor, resolve RScript.ReturnType.valueOf("LONG") into a final instance field and translate a missing constant into an actionable IllegalStateException explaining that this state-store integration requires the Redisson 4.x API, that 3.x is incompatible, and that the project currently manages 4.2.0. Preserve existing argument validation in the deprecated store, resolve the constant before any Redis operations, retain the original exception as the cause, and include the loaded Redisson API package implementation version when available with an explicit unknown fallback; capability detection, rather than parsing a nullable version string, decides compatibility. Use that stored return type in RedissonClientAdapter.evalScript and RedissonAgentStateStore.evalSave, covering both production script callers without a new helper, injectable resolver, static initializer, or INTEGER fallback.

The reporter encounters NoSuchFieldError: RScript$ReturnType.LONG when persisting agent state with AgentScope 2.0.3 and Redisson starter 3.52.0. The September 11 COLLABORATOR evaluation confirms the failure but corrects its cause: Redisson 3.x exposes INTEGER, while AgentScope's code targets the LONG constant introduced in 4.x; the evaluation reports no embedded org/redisson/** classes in the published aggregate. The local clone corroborates both LONG references and the BOM's Redisson 4.2.0 baseline, and its Redis extension already declares Redisson as a dependency. The thread proposes a construction-time guard and version documentation separately from an aggregate packaging decision, which remains pending.

Fixes #3063

Description

In each existing Redisson constructor, resolve RScript.ReturnType.valueOf("LONG") into a final instance field and translate a missing constant into an actionable IllegalStateException explaining that this state-store integration requires the Redisson 4.x API, that 3.x is incompatible, and that the project currently manages 4.2.0. Preserve existing argument validation in the deprecated store, resolve the constant before any Redis operations, retain the original exception as the cause, and include the loaded Redisson API package implementation version when available with an explicit unknown fallback; capability detection, rather than parsing a nullable version string, decides compatibility. Use that stored return type in RedissonClientAdapter.evalScript and RedissonAgentStateStore.evalSave, covering both production script callers without a new helper, injectable resolver, static initializer, or INTEGER fallback.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
    Not run: no test command resolved in this workspace, so nothing was executed to pass.
  • All tests are passing (mvn test)
    Not run: no test command resolved in this workspace, so nothing was executed to pass.
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@codecov

codecov Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ns/redis/state/redisson/RedissonClientAdapter.java 73.33% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@oss-maintainer oss-maintainer 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.

Summary

Converts the Redisson 3.x/4.x RScript.ReturnType.LONG linkage failure into an actionable IllegalStateException raised at construction time, resolved once into a final field and reused by both production eval callers, plus regression tests and EN/ZH docs. The approach is sound — capability detection via valueOf("LONG") instead of version-string parsing is the right call, and the "no Redis interaction before the check" assertions are valuable coverage. No blocking correctness issue found; my comments are about keeping the diagnostic and the guidance from drifting.

Findings

  • [Warning] RedissonClientAdapter.java:128 — getPackage() may be null and getImplementationVersion() is usually null for library jars, so the failure path can either NPE or print unknown; suggested a code-source fallback.
  • [Warning] RedissonClientAdapter.java:133 — 4.2.0 is hard-coded in a runtime message with nothing tying it to agentscope-dependencies-bom, so the guidance goes stale silently on the next bump.
  • [Warning] RedissonAgentStateStore.java:79-91 — the whole block including the message text is duplicated verbatim from the adapter; hoisting just the string constant respects the "no new helper" constraint while removing the drift risk.
  • [Info] RedissonClientAdapterTest.java:72 — the IllegalStateException surfaces from Builder.redissonClient(...), not build(); the new failure mode should be documented with @throws on the two public entry points.
  • [Info] docs/.../redis.md:27 — the same two paragraphs now live in four files, one of which is marked superseded.

Strengths

  • constructsWithoutContactingRedis / constructsAdapterAndUnifiedStoreWithoutContactingRedis pin the "fail before touching the network" contract, which is the part users actually care about.
  • validatesPrefixBeforeResolvingReturnType and validatesClientBeforeResolvingReturnType correctly lock the validation-before-capability-detection ordering, so argument errors stay IllegalArgumentException.
  • customAdapterDoesNotResolveRedissonReturnType guards against the check leaking into non-Redisson adapters, and saveIfVersionPreservesVersionAndConflictResults verifies the constant is resolved once at construction rather than per call.
  • Both call sites are covered and no remaining RScript.ReturnType.LONG reference exists in main sources, so the fix is complete for the reported stack trace.

Questions

  1. Is a String-code-source fallback acceptable for the "loaded Redisson API implementation version" field when the manifest omits Implementation-Version, or would you prefer it stay unknown and drop the code-source detail?
  2. Do you want the @throws IllegalStateException Javadoc in this PR, or tracked separately?

Automated review by github-manager-bot

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks, that is a much better diagnostic. All five addressed:

RedissonClientAdapter.java:128 - getPackage() is now null-checked, and when the manifest carries no Implementation-Version the message falls back to RScript.class.getProtectionDomain().getCodeSource() so the user can at least see which jar won. Same treatment in the RedissonAgentStateStore copy.

RedissonClientAdapter.java:133 - dropped the 4.2.0 literal. The message now points at "the Redisson version managed by agentscope-dependencies-bom", so a BOM bump cannot leave the runtime text stale.

RedissonAgentStateStore.java:91 - you are right that the message string is not a helper. It is now a single package-private RedissonClientAdapter.INCOMPATIBLE_REDISSON_API constant used by both constructors, and both tests assert equality against that constant rather than against re-typed prose. The control flow is untouched, as the spec asked.

RedissonClientAdapterTest.java:72 - added @throws IllegalStateException to both RedissonClientAdapter.of(...) and RedisAgentStateStore.Builder.redissonClient(...), with a sentence on the latter noting the check fires from the setter rather than from build().

docs/.../distributed/redis.md:27 - the full Redisson 4.x guidance now lives only on the EN/ZH distributed pages. The superseded session pages carry a one-line pointer instead, so there are two copies to maintain rather than four, and no version literal in either.

mvn -pl agentscope-extensions/agentscope-extensions-redis -am test is green: 18 tests, 0 failures, spotless clean.

@oss-maintainer oss-maintainer 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.

Summary

Re-review of 8dcda477 → 7ac7282. All five points from the previous round are addressed: getPackage() is null-guarded with a code-source fallback, the hard-coded 4.2.0 is replaced by a BOM reference, the duplicated message is hoisted into RedissonClientAdapter.INCOMPATIBLE_REDISSON_API, @throws IllegalStateException documents the early-failure boundary on redissonClient(...), and the redundant Redisson paragraphs are collapsed into a link from the superseded session pages to distributed/redis.md. The tests now assert the exact composed message instead of a substring, which is the stronger form of the same guarantee. No blocking issue found — approving; the three items below are optional cleanups.

Findings

  • [Info] RedissonClientAdapter.java:139 — code-source fallback prints null / a CodeSource blob where a version is expected.
  • [Info] RedissonAgentStateStore.java:86 — the version-resolution fallback is duplicated verbatim in the adapter and in both test helpers.

Strengths

  • Replacing the version-string literal with a BOM pointer removes the silent-staleness failure mode, and validatesPrefixBeforeResolvingReturnType / customAdapterDoesNotResolveRedissonReturnType keep the ordering and containment guarantees pinned.
  • The docs collapse is the right direction: one canonical compatibility page instead of four copies that drift independently.

Automated review by github-manager-bot

Additional notes (not anchored to a changed line)

  • [INFO] agentscope-extensions/agentscope-extensions-redis/src/main/java/io/agentscope/extensions/redis/state/redisson/RedissonAgentStateStore.java:416 — [Info] @throws IllegalStateException was added to RedisAgentStateStore.Builder.redissonClient(...) and RedissonClientAdapter.of(...), which is the right pair of entry points. RedissonAgentStateStore.Builder.build() throws the same way and its Javadoc is still silent — one line there would close the loop. (line outside diff)

- Null-check RScript.class.getPackage() and fall back to the code source
  when the manifest declares no Implementation-Version, so the failure
  path cannot NPE or print "unknown".
- Replace the hard-coded 4.2.0 literal with a pointer to the version
  managed by agentscope-dependencies-bom.
- Extract the message into a single package-private
  RedissonClientAdapter.INCOMPATIBLE_REDISSON_API constant used by both
  constructors and asserted by both tests.
- Document @throws IllegalStateException on RedissonClientAdapter.of and
  RedisAgentStateStore.Builder.redissonClient, noting the check fires
  from the setter rather than from build().
- Keep the Redisson 4.x guidance only on the EN/ZH distributed pages and
  leave a pointer on the superseded session pages.
Both optional cleanups from the review.

The code-source fallback interpolated String.valueOf(codeSource) into a
sentence promising a version, so it rendered either the literal "null" or a
"(file:/...jar <no signers>)" blob. It now degrades to omitting the version
clause rather than printing a meaningless one.

The package -> Implementation-Version -> code-source fallback was duplicated
verbatim in RedissonClientAdapter and RedissonAgentStateStore and repeated
again in both test classes. It lives in one place now and the callers and
tests use it.

No behavior change to the compatibility guard itself.

Signed-off-by: Matt Van Horn <[email protected]>
@mvanhorn
mvanhorn force-pushed the fix/3063-redisson-state-store-compatibility-guard branch from 7ac7282 to c19b7bc Compare September 21, 2026 17:27
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Both Info items done in c19b7bc, since they were quick.

The code-source fallback no longer interpolates a CodeSource blob or the literal "null" into a sentence promising a version; it drops the version clause when it cannot determine one. And the package to Implementation-Version to code-source fallback now lives in one place instead of being duplicated across the adapter, the store and both test classes.

No change to the compatibility guard itself, so your approval should still hold.

@oss-maintainer oss-maintainer 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.

Summary

Re-reviewed the delta since my previous approval (7ac72824 → c19b7bc0, "refactor: hoist Redisson version resolution and fix its fallback message"). It is exactly the two follow-ups I asked for, done well: the 4-line package/Implementation-Version/code-source fallback is hoisted into RedissonClientAdapter.loadedRedissonApiVersion() + incompatibleRedissonApiMessage(String) so the deprecated RedissonAgentStateStore no longer keeps a verbatim copy, and the diagnostic no longer interpolates a CodeSource blob or the literal "null" into a sentence — the version clause is simply omitted when the version is unknown. INCOMPATIBLE_REDISSON_API no longer ends in a dangling " ... version: ", which also removes the coupling of the user-facing text to a hard-coded 4.2.0. The stale BOM sentence in the docs is gone and the "this check reports the incompatibility, it does not repair dependency resolution" caveat is present in both the EN and ZH pages.

Tests: the duplicated private loadedRedissonApiVersion() helpers were removed from both test classes and replaced with direct coverage of the new contract — blank/whitespace/null all collapse to the base message, a known version is appended verbatim, and loadedApiVersionIsNeverACodeSourceLocation pins the regression (no <no signers>, no version: null, and a file: location can never be returned) while staying tolerant of whatever version the test classpath actually carries. assertFalse(...) on the construction-boundary tests guards against the old formatting silently coming back.

One optional, non-blocking thought left as an inline note at RedissonClientAdapter.java:190: the blank-version case is also the case where the classpath is most ambiguous, so a separately labelled code-source field could restore the "which jar won" signal without putting a location in the version slot. Fine to skip.

Verified on this head: license/cla = signed, Check License / Check Module Sync / build (ubuntu-latest) / build (windows-latest) / validate / codecov/patch all passing, mergeable=MERGEABLE, mergeStateStatus=CLEAN. Approving on c19b7bc0; merging is left to a maintainer.


Automated review by github-manager-bot

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for the re-review. I'm going to leave the optional code-source field at RedissonClientAdapter.java:190 out of this PR. The current message already says the API is incompatible and points at the BOM-managed version, and a labelled location field would be easy to add later on its own if someone hits the ambiguous-classpath case. From my side this is ready for a maintainer to merge at c19b7bc.

@jujn jujn added the P1 紧急不重要 label Nov 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 紧急不重要

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:Class org.redisson.api.RScript$ReturnType does not have member field 'org.redisson.api.RScript$ReturnType LONG'

3 participants