Skip to content

fix(core): initialize title generation for default memory#1248

Merged
omeraplak merged 1 commit intomainfrom
fix/global-memory-title-generation
Apr 25, 2026
Merged

fix(core): initialize title generation for default memory#1248
omeraplak merged 1 commit intomainfrom
fix/global-memory-title-generation

Conversation

@omeraplak
Copy link
Copy Markdown
Member

@omeraplak omeraplak commented Apr 25, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

When Memory is passed globally to VoltAgent, preconstructed agents receive it later through __setDefaultMemory. That updated the MemoryManager conversation memory, but did not initialize the conversation title generator, so generateTitle fell back to the default title.

What is the new behavior?

__setDefaultMemory now initializes the title generator from the default memory when assigning it to the agent memory manager. The memory manager also clears the generator when memory is disabled and handles concurrent conversation creation races while saving messages.

fixes #1232

Notes for reviewers

Docs were not updated because this restores the documented generateTitle behavior for global memory.

Validated with:

  • pnpm vitest run src/voltagent.spec.ts src/memory/manager/memory-manager.spec.ts --reporter=verbose
  • pnpm biome check .changeset/global-memory-title-generation.md packages/core/src/agent/agent.ts packages/core/src/memory/manager/memory-manager.ts packages/core/src/voltagent.spec.ts
  • Reproduced from examples/base before and after the fix; after the fix the title resolves to the generated title instead of the fallback.

Summary by cubic

Fixes conversation title generation when global Memory is provided to VoltAgent, so preconstructed agents now use generated titles instead of the fallback. Also hardens memory handling when disabled and during concurrent conversation creation. Fixes #1232.

  • Bug Fixes
    • Initialize and manage the title generator via __setDefaultMemory and MemoryManager.setMemory (set on assign, clear on disable).
    • Handle “conversation already exists” races in createConversation to avoid failures.
    • Add a test validating generated titles with global memory.

Written for commit 9ed9915. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed conversation title generation when memory is provided globally to VoltAgent, ensuring proper title initialization and persistence.
    • Improved reliability with better handling of concurrent conversation creation scenarios.
  • Tests

    • Added test coverage for global memory title generation functionality.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 25, 2026

🦋 Changeset detected

Latest commit: 9ed9915

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

📝 Walkthrough

Walkthrough

Fixes conversation title generation when memory is provided globally to VoltAgent. Updates Agent.__setDefaultMemory to pass a ConversationTitleGenerator to MemoryManager, extends MemoryManager.setMemory to accept an optional titleGenerator parameter, and adds race condition handling for conversation creation.

Changes

Cohort / File(s) Summary
Changeset Documentation
.changeset/global-memory-title-generation.md
Patch release documentation for conversation title generation fix when memory is configured globally.
Title Generator Initialization
packages/core/src/agent/agent.ts, packages/core/src/memory/manager/memory-manager.ts
Agent.__setDefaultMemory now passes a generated ConversationTitleGenerator to MemoryManager. MemoryManager.setMemory signature updated to accept optional titleGenerator parameter and update internal titleGenerator alongside memory state.
Race Condition Handling
packages/core/src/memory/manager/memory-manager.ts
saveMessage now catches and suppresses conversation creation errors when isConversationAlreadyExistsError returns true, logging debug messages for race condition scenarios.
Test Coverage
packages/core/src/voltagent.spec.ts
New test verifying that when VoltAgent receives preconstructed Agent and global Memory with generateTitle: true, saving messages triggers title generation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • PR #986: Introduced ConversationTitleGenerator feature and initial title generation wiring; this PR completes the integration for globally-configured memory scenarios.
  • PR #1131: Both PRs enhance MemoryManager conversation creation error handling and race condition detection.
  • PR #967: Both PRs build on Agent.__setDefaultMemory and MemoryManager.setMemory for global memory initialization patterns.

Suggested reviewers

  • lzj960515

Poem

🐰 A tale of titles lost and found...
When memory flows from global ground,
titleGenerator rises to the call,
No more shall conversations stand so tall—
With MemoryManager's grace, they find their name,
And conversations bloom once more the same! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(core): initialize title generation for default memory' clearly and specifically describes the main fix: initializing title generation when default memory is set.
Description check ✅ Passed The PR description comprehensively covers all required sections: checklist items, current/new behavior, issue link, validation steps, and notes for reviewers explaining why docs were not updated.
Linked Issues check ✅ Passed All coding requirements from #1232 are met: title generator is re-initialized in __setDefaultMemory, conversation creation races are handled, and generateTitle now works with global memory as documented.
Out of Scope Changes check ✅ Passed All changes directly address issue #1232: MemoryManager.setMemory signature addition, race condition handling in saveMessage, test coverage for title generation with global memory, and changeset documentation are all in-scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/global-memory-title-generation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@joggrbot

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/core/src/memory/manager/memory-manager.ts (2)

791-802: Minor: setMemory(memory) silently clears an existing titleGenerator.

When memory instanceof Memory and titleGenerator is omitted, Line 800 still writes undefined over any previously configured generator. The single in-tree caller (Agent.__setDefaultMemory) always passes the generator so this is safe today, but it's a quiet footgun if another caller later wants to swap the backing store without touching title generation. Consider either (a) only updating titleGenerator when explicitly provided, or (b) documenting the "pass memory ⇒ also pass generator" contract on the method.

♻️ Option (a) — only overwrite when caller opts in
-  setMemory(memory: Memory | false, titleGenerator?: ConversationTitleGenerator): void {
+  setMemory(memory: Memory | false, titleGenerator?: ConversationTitleGenerator): void {
     if (memory === false) {
       this.conversationMemory = undefined;
       this.titleGenerator = undefined;
       return;
     }

     if (memory instanceof Memory) {
       this.conversationMemory = memory;
-      this.titleGenerator = titleGenerator;
+      if (arguments.length >= 2) {
+        this.titleGenerator = titleGenerator;
+      }
     }
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/memory/manager/memory-manager.ts` around lines 791 - 802,
The setMemory method currently overwrites this.titleGenerator with undefined
when called without a generator; change it so that when memory instanceof Memory
you always set this.conversationMemory = memory but only assign
this.titleGenerator = titleGenerator if a non-undefined titleGenerator argument
was passed (i.e., treat titleGenerator as optional). Update references in
setMemory (and note callers like Agent.__setDefaultMemory remain compatible) so
swapping the Memory store doesn't silently clear an existing
ConversationTitleGenerator.

144-163: Optional: align race handling with ensureConversationExists.

In the duplicate/race branch of ensureConversationExists (Lines 672–684) we call updateConversation(conversationId, {}) to refresh updatedAt. The new race branch here just swallows and falls through to saveMessageWithContext. That's fine in practice (the subsequent message save normally touches the conversation), but mirroring the updateConversation call would keep the two ensure-conversation paths behaviorally identical and avoid surprising divergence if a storage adapter ever decouples message writes from conversation timestamp updates.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/memory/manager/memory-manager.ts` around lines 144 - 163,
The duplicate-race branch in createConversation currently swallows the error and
falls through, diverging from ensureConversationExists which calls
updateConversation(conversationId, {}) to refresh timestamps; modify the catch
for createConversation in memory-manager.ts so that when
isConversationAlreadyExistsError(createError) is true you call
this.updateConversation(conversationId, {}) (or the existing updateConversation
method) before continuing to saveMessageWithContext, keeping behavior consistent
with ensureConversationExists and ensuring conversation.updatedAt is refreshed
even on race.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/core/src/memory/manager/memory-manager.ts`:
- Around line 791-802: The setMemory method currently overwrites
this.titleGenerator with undefined when called without a generator; change it so
that when memory instanceof Memory you always set this.conversationMemory =
memory but only assign this.titleGenerator = titleGenerator if a non-undefined
titleGenerator argument was passed (i.e., treat titleGenerator as optional).
Update references in setMemory (and note callers like Agent.__setDefaultMemory
remain compatible) so swapping the Memory store doesn't silently clear an
existing ConversationTitleGenerator.
- Around line 144-163: The duplicate-race branch in createConversation currently
swallows the error and falls through, diverging from ensureConversationExists
which calls updateConversation(conversationId, {}) to refresh timestamps; modify
the catch for createConversation in memory-manager.ts so that when
isConversationAlreadyExistsError(createError) is true you call
this.updateConversation(conversationId, {}) (or the existing updateConversation
method) before continuing to saveMessageWithContext, keeping behavior consistent
with ensureConversationExists and ensuring conversation.updatedAt is refreshed
even on race.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1eb191f2-0c0d-44d6-8302-dcf3af93fa9c

📥 Commits

Reviewing files that changed from the base of the PR and between 832f094 and 9ed9915.

📒 Files selected for processing (4)
  • .changeset/global-memory-title-generation.md
  • packages/core/src/agent/agent.ts
  • packages/core/src/memory/manager/memory-manager.ts
  • packages/core/src/voltagent.spec.ts

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

@omeraplak omeraplak merged commit 69b78fd into main Apr 25, 2026
23 of 24 checks passed
@omeraplak omeraplak deleted the fix/global-memory-title-generation branch April 25, 2026 13:10
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.

Memory: __setDefaultMemory does not initialize titleGenerator, breaking generateTitle for global memory

1 participant