Skip to content

UIMessage.createdAt cannot survive model-message persistence #1064

Closed

Description

@kolaworld

TanStack AI version

0.43.0

Framework/Library version

@tanstack/ai-persistence: 0.1.0, @tanstack/ai-client`: 0.23.0, @tanstack/ai-svelte: 0.16.0

Describe the bug and the steps to reproduce it

UIMessage carries an optional createdAt timestamp in types.ts#L507-L512, but ModelMessage has no corresponding field in types.ts#L358-L379.

Server persistence stores ModelMessage[] (MessageStore.saveThread), so any live createdAt is dropped before the transcript is saved.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/edit/vitejs-vite-9xjaewse?file=package.json,index.html,src%2Fmain.ts

const originalCreatedAt = new Date('2024-01-01T00:00:00.000Z')

const [modelMessage] = uiMessageToModelMessages({
  id: 'message-1',
  role: 'user',
  createdAt: originalCreatedAt,
  parts: [{ type: 'text', content: 'Hello' }],
})

// ModelMessage has no createdAt field today
expect('createdAt' in modelMessage).toBe(false)

const [uiMessage] = modelMessagesToUIMessages([modelMessage])
expect(uiMessage.createdAt).toBeUndefined()

const normalized = normalizeToUIMessage(modelMessage, () => 'message-1')
// Fresh stamp — not the original wall-clock time
expect(normalized.createdAt).not.toEqual(originalCreatedAt)

Expected behavior

Add an optional createdAt on ModelMessage Then:

  • One-to-one UI → model conversion copies UIMessage.createdAt onto the ModelMessage.
  • Model → UI conversion restores it onto UIMessage.createdAt.
  • normalizeToUIMessage() prefers a persisted createdAt and only falls back to new Date() when absent.

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Activity

  1. mikemikimike commented on Aug 10, 2026

    @mikemikimike
    Contributor

    I’m preparing a focused PR for this issue. The change will preserve the optional createdAt timestamp through UIMessage/ModelMessage conversion and add regression coverage without requiring a model or API key.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions