Skip to content

Auto-configure ChatSessionRepository bean with event publishing #3

Description

@jasperblues

Summary

Currently ChatSessionRepositoryImpl is not created by auto-configuration — consuming apps (e.g., guide) must construct it manually in their @Configuration classes. This means they need to explicitly pass ApplicationEventPublisher (and any future dependencies) to the constructor, which is easy to miss.

Current Behavior

The autoconfigure provides:

  • StoredConversationFactory
  • SessionEventAwaiter
  • InMemoryConversationFactory
  • ConversationFactoryProvider

But not ChatSessionRepository. Apps must create it themselves:

@Bean
fun chatSessionRepository(
    @Qualifier("neoGraphObjectManager") graphObjectManager: GraphObjectManager,
    eventPublisher: ApplicationEventPublisher
): ChatSessionRepository {
    return ChatSessionRepositoryImpl(graphObjectManager, eventPublisher)
}

Proposed Behavior

The autoconfigure should provide a default ChatSessionRepository bean (@ConditionalOnMissingBean) that:

  • Accepts a GraphObjectManager (or connection properties like spring.neo4j.uri, spring.neo4j.authentication.*)
  • Auto-injects ApplicationEventPublisher for SessionCreatedEvent publishing
  • Can be overridden by apps that need custom setup

Apps would only need to provide:

  1. Connection properties or a compatible GraphObjectManager bean
  2. Subtype registrations (e.g., PersistenceManager.registerSubtype) for their user types

Context

This came up while fixing a race condition where StoredConversation.addMessageInternal tried to persist a message before the session existed. The fix (SessionEventAwaiter + SessionCreatedEvent) requires ChatSessionRepositoryImpl to have the eventPublisher — which was missed in the guide's manual construction until caught during review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions