fix: cap Session.Name to 255 chars to fix btree index on upgrade - #1601
Conversation
Session.Name was unbounded text, and some production sessions had AI-generated names up to 7654 chars (full prompts, <think> tags). Adding the search index in 2.6.0 fails because multi-byte characters push the byte size over PostgreSQL's 2704-byte btree limit. Adds a pre-migration truncation and size:255 constraint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code ReviewFound two bugs and two improvement areas: Bugs (should fix before merging)
Improvements (should consider)
VerdictNot safe to merge as-is. The WHERE condition bug (#2) means the migration will likely fail on the exact databases it's trying to fix — names between 256 chars and 2704 bytes won't be truncated, causing the ALTER COLUMN to error out. Combined with the swallowed error (#1), this could fail silently or loudly depending on the data. |
…ation - Fix silently swallowed Exec() error in migration (bug #1) - Fix WHERE condition: LENGTH(name) > 255 instead of OCTET_LENGTH > 2704 (bug #2) - Add Go-level name truncation in CreateSession, UpdateSession, UpdateSessionMeta, and UpdateSessionName to prevent cryptic GORM errors - Add 6 unit tests covering truncation for ASCII, multibyte (CJK), and boundary cases across all session name write paths Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The UPDATE sessions query fails when the sessions table doesn't exist yet (fresh database in CI). Guard with HasTable check since AutoMigrate creates the table after this step. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Session.Namewas unboundedtextand some production sessions had AI-generated names up to 7654 chars (full prompts,<think>reasoning). Adding the search index in 2.6.0 fails because multi-byte (CJK) characters push the byte size over PostgreSQL's 2704-byte B-tree limit.size:255constraint toSession.Nameso GORM createsvarchar(255)instead oftextUPDATEto truncate existing oversized names before AutoMigrate creates the indexTest plan
go build ./...passes in CI🤖 Generated with Claude Code