Skip to content

fix(jdbc): warn when an existing store column is narrower than the DDL - #3920

Closed
jacksonw111 wants to merge 1 commit into
agentscope-ai:mainfrom
jacksonw111:fix/jdbc-warn-narrow-store-columns
Closed

jacksonw111 wants to merge 1 commit into
agentscope-ai:mainfrom
jacksonw111:fix/jdbc-warn-narrow-store-columns

Conversation

@jacksonw111

Copy link
Copy Markdown

AgentScope-Java Version

main @ abf3c35 (reproduces on 2.1.0-BETA1)

Description

Background. agentscope_store.item_key is VARCHAR(255) on 2.1.0-BETA1, while the keys written through JdbcStore are session journal paths built from base64-encoded ids. A freshly created managed session writes a key of about 260 characters, so the first Turn fails before the model is called:

IllegalStateException: JdbcStore putIfVersion (insert) failed
  Caused by: value too long for type character varying(255)

#3461 reports it; #3464 widens the DDL to VARCHAR(2048) for PostgreSQL and H2. That fixes new tables only.

The gap this PR closes. CREATE TABLE IF NOT EXISTS cannot widen an existing column, and the assembly-time schema check (TableSchemaValidator) compares column names only — a type change is deliberately not an error, because those belong to the user's own migrations. So on every deployment that predates #3464, the table keeps VARCHAR(255), start-up succeeds, and the failure appears at the first write with a message that names no column and no table.

What changes.

  1. TableSchemaValidator now compares declared VARCHAR(n) / CHAR(n) widths with the widths the database reports while it already validates an existing table. A column narrower than the current DDL produces one WARN per column, with the column name, both widths, and an ALTER TABLE example.
  2. The check stays advisory by design: assembly never alters a column, unbounded columns (TEXT, BIGINT, …) and drivers that report no size are skipped, and a missing/unreadable table does not add noise — so no existing deployment starts to fail because of this change.
  3. Docs (en + zh) for JdbcStore describe the warning.

How to test.

mvn -pl agentscope-extensions/agentscope-extensions-jdbc test

183 tests pass, including TableSchemaValidatorNarrowColumnTest, which covers four cases on H2: legacy VARCHAR(255) item_key → one warning that mentions the column, both widths and ALTER TABLE; already-wide column → silent; unbounded columns → silent; missing table → silent.

End-to-end, on the Docker Compose bundle with PostgreSQL 17, restoring the column to VARCHAR(255) reproduces the original failure, and the warning points at the exact ALTER TABLE that fixes it.

Relation to #3464. Complementary, not a replacement. #3464 sets the correct width for new tables; this PR makes an existing narrow table visible at start-up instead of at the first write. Both can land in either order.

Fixes #3461 together with #3464.

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 (e.g. links, examples, etc.)
  • Code is ready for review

CREATE TABLE IF NOT EXISTS cannot widen a column, and the assembly-time schema
check compares column names only. A table created before a width change keeps
the narrow column, and the framework then fails at write time instead of start
time. agentscope_store.item_key is the known case: declared VARCHAR(255) in
2.1.0-BETA1, while session journal keys reach about 260 characters, so the first
Turn of a managed session fails with "value too long for type character
varying(255)" behind "JdbcStore putIfVersion (insert) failed".

Compare declared VARCHAR/CHAR widths while validating an existing table and log
one warning per narrowed column, with the column name, both widths, and an ALTER
example. Keep it advisory: assembly does not alter the column, and unbounded or
unknown-width columns are skipped, so no existing deployment starts to fail.

Refs agentscope-ai#3461
@mintlify

mintlify Bot commented Nov 1, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 68ad3b2.

Approve preview

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jacksonw111

Copy link
Copy Markdown
Author

Withdrawn — #3464 already contains the fix for #3461, and it is the right place for that change.

This PR only added a start-up warning for deployments whose agentscope_store.item_key was created before #3464 (because CREATE TABLE IF NOT EXISTS cannot widen a column). Useful, but it is not the fix, and it does not justify a second open PR on the same defect. Closing to keep the queue clean.

The verification comment on #3464 stands: with that patch on main, a clean PostgreSQL 17 deployment creates item_key as VARCHAR(2048) and the first managed Turn completes.

If the maintainers later want the advisory width check, I can reopen this branch or send it as a follow-up after #3464 merges.

@jacksonw111 jacksonw111 closed this Nov 1, 2026
@jacksonw111
jacksonw111 deleted the fix/jdbc-warn-narrow-store-columns branch November 1, 2026 23:09
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]: dp.agentscope_store.item_key varchar(255) too short — every Managed Agent's first Turn fails before model invocation

2 participants