Repository navigation
fix(jdbc): warn when an existing store column is narrower than the DDL - #3920
jacksonw111 wants to merge 1 commit into
Conversation
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
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
|
|
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 The verification comment on #3464 stands: with that patch on If the maintainers later want the advisory width check, I can reopen this branch or send it as a follow-up after #3464 merges. |
AgentScope-Java Version
main@abf3c35(reproduces on2.1.0-BETA1)Description
Background.
agentscope_store.item_keyisVARCHAR(255)on 2.1.0-BETA1, while the keys written throughJdbcStoreare session journal paths built from base64-encoded ids. A freshly created managed session writes a key of about 260 characters, so the firstTurnfails before the model is called:#3461reports it;#3464widens the DDL toVARCHAR(2048)for PostgreSQL and H2. That fixes new tables only.The gap this PR closes.
CREATE TABLE IF NOT EXISTScannot 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 keepsVARCHAR(255), start-up succeeds, and the failure appears at the first write with a message that names no column and no table.What changes.
TableSchemaValidatornow compares declaredVARCHAR(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 oneWARNper column, with the column name, both widths, and anALTER TABLEexample.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.JdbcStoredescribe the warning.How to test.
mvn -pl agentscope-extensions/agentscope-extensions-jdbc test183 tests pass, including
TableSchemaValidatorNarrowColumnTest, which covers four cases on H2: legacyVARCHAR(255)item_key → one warning that mentions the column, both widths andALTER 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 exactALTER TABLEthat fixes it.Relation to #3464. Complementary, not a replacement.
#3464sets 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
mvn spotless:applymvn test)