Skip to content

fix: persist feedback metadata on assistant messages so history reloa…#1014

Merged
omeraplak merged 3 commits intomainfrom
fix/persist-feedback
Feb 3, 2026
Merged

fix: persist feedback metadata on assistant messages so history reloa…#1014
omeraplak merged 3 commits intomainfrom
fix/persist-feedback

Conversation

@omeraplak
Copy link
Member

@omeraplak omeraplak commented Feb 3, 2026

…ds keep feedback actions

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

What is the new behavior?

fixes (issue)

Notes for reviewers


Summary by cubic

Persist feedback metadata on assistant messages so history reloads keep previous feedback actions. Fixes #1009.

  • Bug Fixes
    • Add ConversationBuffer.addMetadataToLastAssistantMessage(metadata, { requirePending }) returning a boolean to signal success.
    • If metadata can’t attach (no pending assistant message), the agent now injects the latest response messages and re-applies the metadata.
    • findLastAssistantIndex now supports pendingOnly to correctly target the in-flight assistant message.

Written for commit 6fec173. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Improved persistence of feedback metadata on assistant messages so history reloads retain feedback; metadata application now correctly handles pending messages and retries when needed, making message buffering and streaming more robust.
  • Tests

    • Added tests covering feedback metadata persistence and pending-message handling to prevent regressions.

@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

🦋 Changeset detected

Latest commit: 6fec173

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

@omeraplak omeraplak linked an issue Feb 3, 2026 that may be closed by this pull request
@joggrbot

This comment has been minimized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

Adds feedback metadata persistence to assistant messages, changes conversation buffer APIs to support pending-only metadata application with boolean success returns, updates agent flows to capture and retry attaching response messages when metadata application initially fails, and adds tests and a changeset entry.

Changes

Cohort / File(s) Summary
Release Notes
\.changeset/eight-paths-shake.md
New changeset documenting a patch for @voltagent/core and the feedback metadata persistence fix.
Agent Flow
packages/core/src/agent/agent.ts
Captures latestResponseMessages in generate/stream flows; applies feedback metadata with requirePending: true; re-attaches response messages and retries metadata application when initial apply fails; uses filterResponseMessages helpers when buffering.
Conversation Buffer
packages/core/src/agent/conversation-buffer.ts
addMetadataToLastAssistantMessage now accepts options?: { requirePending?: boolean } and returns boolean; findLastAssistantIndex accepts options?: { pendingOnly?: boolean }; logic updated to support pending-only semantics and surface success/failure.
Tests
packages/core/src/agent/conversation-buffer.spec.ts
Adds tests covering requirePending behavior: attaching metadata only to a pending assistant message, and no-op when no pending assistant message exists.

Sequence Diagram

sequenceDiagram
    participant Agent as Agent Flow
    participant Buffer as ConversationBuffer
    participant Feedback as Feedback System

    rect rgba(100, 150, 200, 0.5)
        Note over Agent,Feedback: Feedback persistence with pending-only apply and retry
        Agent->>Agent: Capture latestResponseMessages
        Agent->>Buffer: addMetadataToLastAssistantMessage(metadata, {requirePending: true})
        Buffer->>Buffer: findLastAssistantIndex({pendingOnly: true})
        alt Metadata Applied
            Buffer-->>Agent: return true
            Agent->>Feedback: persist feedback
        else Not Applied & latestResponseMessages exist
            Buffer-->>Agent: return false
            Agent->>Buffer: addModelMessages(latestResponseMessages, "response")
            Agent->>Buffer: addMetadataToLastAssistantMessage(metadata, {requirePending: true})
            Buffer-->>Agent: return boolean
            Agent->>Feedback: persist feedback (if true) or skip (if false)
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through messages, metadata in paw,
Pinned pending whispers that users saw,
When first attach failed I bounced them back,
Now feedback stays on history's track,
A little hop for persistent law.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and concisely summarizes the main fix: persisting feedback metadata on assistant messages for history reload retention.
Description check ✅ Passed The description includes required sections: commit guidelines acknowledgment, tests added, docs updated, changesets added, linked issue (#1009), and a summary explaining the changes and their purpose.
Linked Issues check ✅ Passed The pull request code changes directly address issue #1009 by implementing persistent feedback metadata on assistant messages and adding fallback re-attachment of response messages to ensure metadata application succeeds.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objective: enhancing ConversationBuffer, adding type helpers in agent.ts, and adding corresponding tests align with fixing feedback persistence.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/persist-feedback

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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 3, 2026

Deploying voltagent with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6fec173
Status: ✅  Deploy successful!
Preview URL: https://445ed29c.voltagent.pages.dev
Branch Preview URL: https://fix-persist-feedback.voltagent.pages.dev

View logs

Copy link
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 3 files

Copy link
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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/core/src/agent/agent.ts`:
- Around line 1022-1036: The code unsafely casts result.response?.messages and
finalResult.response?.messages to ModelMessage[] before calling
buffer.addModelMessages; add a runtime type guard that validates each item is a
valid ResponseMessage (e.g., has required discriminators/fields for
AssistantModelMessage or ToolModelMessage) and filter/map the array to only
include validated items before calling buffer.addModelMessages and before
calling buffer.addMetadataToLastAssistantMessage; update the three spots that
cast (the uses around result.response?.messages, finalResult.response?.messages,
and the third occurrence) to use this validation so only correctly typed
ModelMessage instances are passed to addModelMessages and related helpers.

@omeraplak omeraplak merged commit e121adc into main Feb 3, 2026
23 checks passed
@omeraplak omeraplak deleted the fix/persist-feedback branch February 3, 2026 23:55
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.

[FEAT]feedback cannot be persisted

1 participant