Skip to content

refactor(core): centralize session message rows - #41830

Open
kitlangton wants to merge 1 commit into
v2from
message-row-codec
Open

refactor(core): centralize session message rows#41830
kitlangton wants to merge 1 commit into
v2from
message-row-codec

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Centralizes the persisted SessionMessage representation boundary in SessionMessageRow instead of repeating { id, type, data } assembly and splitting throughout session persistence.

How

  • Adds packages/core/src/session/message-row.ts with effectful decode, synchronous decode, and synchronous encode operations.
  • Migrates message persistence in the store, history, pending promotion, revert planning, projector, and transfer import paths.
  • Keeps transaction handling, sequence numbers, timestamps, session ownership, and decode error policy at each call site.
  • Keeps session_pending row codecs and fork row copying separate because those operations do not encode or decode the canonical message-row representation.
  • Adds focused tests for representation round trips and canonical column precedence over stale JSON keys.

Scope

This is representation-only refactoring. It does not change the session_message schema, durable event behavior, pending input encoding, fork batching, or caller-specific error handling.

Testing

  • bun run test test/session-message-row.test.ts test/session-projector.test.ts test/session-create.test.ts test/session-prompt.test.ts from packages/core: 86 passed
  • bun typecheck from packages/core
  • Push hook: typechecked all 39 workspace packages
  • Prettier check on all changed files
  • git diff --check

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

  • packages/core/src/session/message-row.ts — clean extraction; the module follows the repo's self-export namespace pattern, and decode/decodeSync/encode cover all three call-site shapes (effectful, sync, encode). Canonical-column precedence ({ ...row.data, id: row.type && row.id } spread order) is preserved exactly.
  • message-row.ts:17 — encode re-wraps with SessionMessage.ID.make(id) after encodeMessage already produced a branded id; harmless but slightly redundant — worth a one-line comment if intentional.
  • Migration across history/pending/projector/revert/store/transfer is mechanical and behavior-preserving; transaction handling, seq, and timestamps stay at call sites as described. Fork/pending-table codecs correctly left alone since they don't use the canonical representation.
  • Tests pin both round-trip and stale-JSON-key precedence — exactly the invariants this boundary owns. Representation-only claim holds up against the diff.
  • Heads-up: PR currently conflicts with dev (mergeable_state: dirty) — rebase needed. No blocking issues found.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@kitlangton@Enough1122