Skip to content

[Bug]: putIfVersion discards the underlying SQLState and message, so JDBC store failures are undiagnosable #3948

Open

Description

@lianYeah

Describe the bug

When JdbcStore.putIfVersion fails for a reason other than a duplicate-key violation, the thrown
exception discards the underlying SQLException's SQLState and message. The operator sees only:

java.lang.IllegalStateException: JdbcStore putIfVersion (insert) failed

Any SQLException whose SQLState is not 23xxx (integrity constraint violation) takes this path
(JdbcStore.java:134-138). That includes common, individually-diagnosable failures:

  • 22001 value too long for type character varying(N)
  • 42P01 undefined table
  • 42703 undefined column
  • 08006 connection failure
  • 40001 serialization failure

The message names no SQLState, no column and no table, and reads like a logic error rather than a
schema/storage error.

Why this matters (not hypothetical)

This is a diagnostics issue, reported separately from the key-length defect that surfaced it. Three
independent reports of the same item_key overflow (#3461, the independent confirmation comment in
#3461, and ours) all had to identify the cause without any help from this message. In our case the
DDL and the real key length only became visible after enabling PostgreSQL statement logging with
log_parameter_max_length_on_error = -1.

#3920 mitigates the pre-existing-narrower-column case with a start-up warning, but the runtime
exception itself is still information-free on main.

To Reproduce

  1. Use a table where item_key is VARCHAR(255) (e.g. dp.agentscope_store on 2.1.0-BETA1).
  2. Call putIfVersion(namespace, key, value, 0) with a key longer than 255 characters.
  3. The thrown exception reports only JdbcStore putIfVersion (insert) failed, with no indication
    that the cause is a value-length error.

Expected behavior

The exception should include the underlying SQLState and message, preserving the original
SQLException as the cause.

Suggested fix

throw new IllegalStateException(
        "JdbcStore putIfVersion (insert) failed [SQLState="
                + e.getSQLState() + "]: " + e.getMessage(),
        e);

Same treatment for the update path. The parallel throw sites (all still information-free on main)
are:

  • agentscope-extensions-jdbc/src/main/java/io/agentscope/extensions/jdbc/store/JdbcStore.java:138 and :148
  • agentscope-extensions-mysql/src/main/java/io/agentscope/extensions/mysql/store/JdbcStore.java:209 and :222
  • agentscope-extensions-postgresql/src/main/java/io/agentscope/extensions/postgresql/store/PostgresBaseStore.java:265 and :278

A broader improvement would be to stop converting SQLException into a generic
IllegalStateException (or to introduce an exception type that preserves the SQLState), but adding
the two fields to the message is a strictly better baseline than today.

Environment

  • AgentScope-Java Version: 2.1.0-BETA1 (tag agentscope-service/service-controlplane/v2.1.0-BETA1, commit 5451c73); the same code is present on main
  • Java Version: 17
  • OS: Windows 11 host with Docker Desktop; Service containers are Linux
  • Store: agentscope-extensions-jdbc against PostgreSQL 17 (official compose file)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions