Skip to content

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

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

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.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants