Skip to content

refactor(core): avoid redundant decode and re-branding in session inbox and projector - #57890

Merged
rekram1-node merged 1 commit into
devfrom
core-session-sql-inbox
Oct 21, 2026
Merged

rekram1-node merged 1 commit into
devfrom
core-session-sql-inbox

Conversation

@rekram1-node

Copy link
Copy Markdown
Contributor

Problem

  • SessionInbox.promotedFromMessage decoded the message row with SessionHistory.decodeMessageRowSync(row) and then ran Schema.decodeUnknownSync(UserPayload) / Schema.decodeUnknownSync(SyntheticPayload) a second time over the already-decoded SessionMessage.User or SessionMessage.Synthetic (re-validating all file attachments), followed by an unreachable LifecycleConflict fallback.
  • SessionTable.agent in packages/core/src/session/sql.ts was untyped (text()), requiring Agent.ID.make(row.agent) when reading rows in SessionProjector and SessionInfo.fromRow.
  • SessionProjector destructured id from encodeMessage(message) and re-branded it with SessionMessage.ID.make(id) instead of using message.id directly.

Change

 SessionInbox.promotedFromMessage(row)
   message = SessionHistory.decodeMessageRowSync(row)
   if message.type === "user"
-    User.make({ ..., payload: decodeUser(message) })
+    User.make({ ..., payload: UserPayload.make({ text, files, agents, skills, metadata }) })
   if message.type === "synthetic"
-    Synthetic.make({ ..., payload: decodeSynthetic(message) })
-  return yield* new LifecycleConflict({ id })
+    Synthetic.make({ ..., payload: SyntheticPayload.make({ text, description, metadata }) })
 SessionTable (packages/core/src/session/sql.ts)
-  agent: text()
+  agent: text().$type<Agent.ID>()

 SessionProjector
   updateMessage(message) / insertMessage(message)
-    eq(SessionMessageTable.id, SessionMessage.ID.make(encoded.id))
+    eq(SessionMessageTable.id, message.id)
   getAgent()
-    row?.agent ? Agent.ID.make(row.agent) : undefined
+    row?.agent ?? undefined

 SessionInfo.fromRow(row)
-  agent: row.agent ? Agent.ID.make(row.agent) : undefined
+  agent: row.agent ?? undefined

Out of scope

  • Pending inbox payload decoding in SessionInbox.fromRow (which decodes raw JSON column values from SessionInboxTable).

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sound. I type-checked packages/core and ran the changed tests plus the inbox and session suites; all pass. The removed LifecycleConflict fallback really is unreachable, since row.type is checked before decoding. Building the payloads directly gives the same fields as the old double decode. $type<Agent.ID>() changes only the TypeScript type, not the stored column.

Public API is unchanged (internal packages/core types and table typing only).

@rekram1-node
rekram1-node merged commit 6dfc681 into dev Oct 21, 2026
13 checks passed
@rekram1-node
rekram1-node deleted the core-session-sql-inbox branch October 21, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant