Repository navigation
Description
Problem
Multiple interconnected issues with how the ORM handles dates, pagination, and indexing.
1. Dates stored as TEXT, not native TIMESTAMP
All @DateField decorated fields are stored as TEXT columns containing ISO 8601 strings. This sorts correctly by accident (ISO is lexicographically sortable), but is fragile:
- Any code that writes
Date.now()(unix ms integer) to the same column breaks sort order - Mixed formats in one column = wrong ordering
- No database-level date operations (BETWEEN, date math)
Locations:
workers/continuum-core/src/orm/sqlite.rs—"created_at TEXT NOT NULL"workers/continuum-core/src/orm/postgres.rs— hasTIMESTAMPTZinpg_type_from_field_type()but only for schema-defined fields, not dynamic ones
2. Cursor pagination defined but NEVER implemented
query.rs defines Cursor, CursorDirection, ComparableValue types. StorageQuery has a cursor: Option<Cursor> field. But zero query code in sqlite.rs or postgres.rs ever reads it. All pagination is OFFSET-based, which gets slow on large tables.
3. Composite indexes declared but never created
@CompositeIndex decorator collects metadata via getCompositeIndexes(), but no ORM adapter calls this function or creates the indexes. Example:
@CompositeIndex({
name: 'idx_chat_messages_room_timestamp',
fields: ['roomId', 'timestamp'],
direction: 'DESC'
})
export class ChatMessageEntity extends BaseEntity { ... }This index would massively speed up chat room pagination queries but it's never created.
4. Widget-level cache may have its own sort issues
The chat widget (EntityScroller, chat-widget) maintains its own message cache. If the cache sorts by string representation of dates rather than actual Date comparison, ordering would be wrong even if the DB returns correctly ordered results.
Fix Strategy
These should be addressed at the Rust ORM layer (single source of truth):
- Date columns: Use
TIMESTAMPTZ(Postgres) / store as ISO but validate format on write (SQLite). Consider integer unix ms for SQLite (native integer comparison). - Cursor pagination: Implement keyset pagination using the existing
Cursortypes —WHERE timestamp < ? ORDER BY timestamp DESC LIMIT 50 - Composite indexes: Have
ensure_table_existsread@CompositeIndexmetadata and CREATE INDEX - Widget cache: Audit EntityScroller sort comparators
Impact
- Chat message ordering may be wrong in edge cases
- Pagination performance degrades on large tables (OFFSET scanning)
- Missing indexes = full table scans on common queries
🤖 Generated with Claude Code
Activity
joelteply commentedon Mar 25, 2026
Investigation Results (2026-03-24)
1. Dates stored as TEXT — NOT A BUG
TIMESTAMPTZcolumns forcreated_at/updated_at.DateTime<Utc>passed as native typed parameter. All date operations work correctly at the DB level.chrono::Utc::now().to_rfc3339(). Lexicographic sort = chronological for zero-padded UTC ISO dates. No code path writes non-RFC-3339 formats through the ORM.2. Composite indexes — MOSTLY WORKING
Verified in Postgres:
chat_messages: 4 indexes (includingidx_chat_messages_room_createdcomposite) ✅memories: 4 indexes ✅timeline_events: 4 indexes ✅cognition_state_snapshots: 2 indexes ✅Some low-traffic tables (
skills,academy_benchmark_results) missing composite indexes becauseensureSchemaruns lazily on first access — tables that haven't been written to yet don't get indexes.Minor issue:
CompositeIndex.directionfield (ASC/DESC) is declared in TypeScript but dropped byDataSchemaManager— all indexes are ascending. Not critical for alpha.3. Cursor pagination — TYPES EXIST, NOT IMPLEMENTED
Cursor,CursorDirection,ComparableValuedefined inquery.rs.StorageQuery.cursorfield is deserialized but neithersqlite.rsnorpostgres.rsreads it. All pagination is OFFSET-based. This is fine at alpha data volumes.Remaining work
directionfromCompositeIndexmetadata through to SQLDowngrading from Phase 0 to Phase 1 — this is not a ship-blocker.
Gap analysis: mark Phase 0 progress, move #360 to Phase 1
joelteply commentedon Mar 25, 2026
Investigated: dates work correctly (TIMESTAMPTZ/RFC3339), composite indexes working for high-traffic tables, cursor pagination not needed for alpha (OFFSET sufficient). Schema auto-evolution added (auto-adds missing columns on Postgres UPDATE). No remaining work for alpha.