Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/five-candles-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@voltagent/core": patch
---

fix(core): persist reasoning and tool parts across step checkpoint flushes (#1130)

When `conversationPersistence.mode = "step"` was used with tool calls, some checkpoint flows could
persist incomplete assistant messages and lose non-text parts in stored conversation history.

This update preserves complete assistant message parts during checkpoint merges and persistence
flushes, including reasoning, tool-call, tool-result, and text parts.

Regression coverage is expanded with end-to-end agent persistence tests against both LibSQL and
PostgreSQL backends to reduce the chance of similar regressions.
35 changes: 34 additions & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,42 @@ jobs:
- name: Test Package
run: lerna run test --scope "${{ steps.scope.outputs.scope }}"

e2e-tests:
runs-on: ubuntu-latest
name: E2E Tests
services:
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
postgres:
image: postgres:16
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: voltagent_test
ports:
- 5432:5432
options: >-

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.

⚠️ Potential issue | 🟠 Major

Align Postgres port between workflow service and e2e test defaults.

The e2e Postgres spec uses 5433 by default (Line 16 in packages/e2e/src/message-persistence.postgres.e2e.spec.ts), but this job exposes 5432 and does not set VOLTAGENT_E2E_POSTGRES_PORT. That can make this CI job fail with an unreachable DB.

Suggested fix
       - name: Run E2E Tests
         run: pnpm --filter `@voltagent/e2e` test
+        env:
+          VOLTAGENT_E2E_POSTGRES_PORT: "5432"

Also applies to: 85-86

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

In @.github/workflows/prerelease.yml around lines 65 - 67, The workflow exposes
Postgres on port 5432 but the e2e tests expect port 5433, causing connectivity
failures; update the workflow service to align ports or export
VOLTAGENT_E2E_POSTGRES_PORT so tests target the same port — specifically change
the service ports mapping to expose 5433:5432 or set the environment variable
VOLTAGENT_E2E_POSTGRES_PORT=5432/5433 (matching the test default) in the job
configuration so the e2e test runner and the workflow Postgres service use the
same port.

--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Install Dependencies
run: pnpm install
env:
NODE_OPTIONS: "--max-old-space-size=8192"
- name: Build E2E Dependencies
run: pnpm lerna run build --scope @voltagent/e2e --include-dependencies
- name: Run E2E Tests
run: pnpm --filter @voltagent/e2e test

prerelease:
name: Prerelease
needs: test-packages
needs: [test-packages, e2e-tests]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,63 @@ jobs:
npm run test:integration:ci
env:
DATABASE_URL: postgresql://test:test@localhost:5432/voltagent_test

e2e-tests:
runs-on: ubuntu-latest
name: E2E Tests
concurrency:
group: ${{ github.ref }}-e2e-tests
cancel-in-progress: true
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: voltagent_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for E2E-related changes
id: check_e2e
run: |
if git diff --name-only origin/main...HEAD | grep -E '^(\.github/workflows/pull-request\.yml|packages/e2e/|packages/core/|packages/libsql/|packages/postgres/|packages/internal/|packages/logger/|package\.json|pnpm-lock\.yaml)'; then
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
echo "e2e_changed=true" >> $GITHUB_OUTPUT
else
echo "e2e_changed=false" >> $GITHUB_OUTPUT
fi

- name: Skip if no E2E-related changes
if: steps.check_e2e.outputs.e2e_changed == 'false'
run: echo "No E2E-related changes detected, skipping E2E tests"

- uses: pnpm/action-setup@v4
if: steps.check_e2e.outputs.e2e_changed == 'true'
- uses: actions/setup-node@v4
if: steps.check_e2e.outputs.e2e_changed == 'true'
with:
node-version: 20
cache: "pnpm"

- name: Install Dependencies
if: steps.check_e2e.outputs.e2e_changed == 'true'
run: pnpm install
env:
NODE_OPTIONS: "--max-old-space-size=8192"

- name: Build E2E Dependencies
if: steps.check_e2e.outputs.e2e_changed == 'true'
run: pnpm lerna run build --scope @voltagent/e2e --include-dependencies

- name: Run E2E Tests
if: steps.check_e2e.outputs.e2e_changed == 'true'
run: pnpm --filter @voltagent/e2e test
35 changes: 34 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,41 @@ jobs:
- name: Test Package
run: lerna run test --scope "${{ steps.scope.outputs.scope }}"

e2e-tests:
runs-on: ubuntu-latest
name: E2E Tests
services:
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
postgres:
image: postgres:16
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: voltagent_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Install Dependencies
run: pnpm install
env:
NODE_OPTIONS: "--max-old-space-size=8192"
- name: Build E2E Dependencies
run: pnpm lerna run build --scope @voltagent/e2e --include-dependencies
- name: Run E2E Tests
run: pnpm --filter @voltagent/e2e test

publish:
needs: test-packages
needs: [test-packages, e2e-tests]
permissions:
contents: write
id-token: write
Expand Down
72 changes: 72 additions & 0 deletions packages/core/src/agent/conversation-buffer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,78 @@ describe("ConversationBuffer", () => {
expect(reasoningParts[1]?.providerMetadata).toEqual({ openai: { itemId: "rs_TWO" } });
});

it("merges subsequent response checkpoints with same assistant id after an intermediate flush", () => {
const buffer = new ConversationBuffer();

buffer.addModelMessages(
[
{
id: "response-1",
role: "assistant",
content: [
{
type: "tool-call",
toolCallId: "call-1",
toolName: "getWeather",
input: { location: "Berlin" },
},
],
},
{
role: "tool",
content: [
{
type: "tool-result",
toolCallId: "call-1",
toolName: "getWeather",
output: { condition: "sunny" },
},
],
},
],
"response",
);

const firstFlush = buffer.drainPendingMessages();
expect(firstFlush).toHaveLength(1);
expect(firstFlush[0]?.id).toBe("response-1");

buffer.addModelMessages(
[
{
id: "response-1",
role: "assistant",
content: [
{
type: "text",
text: "Berlin hava durumu güneşli.",
},
],
},
],
"response",
);

const secondFlush = buffer.drainPendingMessages();
expect(secondFlush).toHaveLength(1);
expect(secondFlush[0]?.id).toBe("response-1");
expect(secondFlush[0]?.parts).toEqual([
{
type: "tool-getWeather",
toolCallId: "call-1",
state: "output-available",
input: { location: "Berlin" },
output: { condition: "sunny" },
providerExecuted: false,
},
{ type: "step-start" },
{ type: "text", text: "Berlin hava durumu güneşli." },
]);

const all = buffer.getAllMessages();
expect(all).toHaveLength(1);
});

it("preserves preloaded memory messages without marking them pending", () => {
const existing: UIMessage[] = [
{
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/agent/conversation-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ export class ConversationBuffer {
}

if (source === "response") {
const hasSameAssistantId =
typeof message.id === "string" &&
message.id.length > 0 &&
typeof lastMessage.id === "string" &&
lastMessage.id.length > 0 &&
message.id === lastMessage.id;

if (hasSameAssistantId) {
this.mergeAssistantMessage(message);
this.activeAssistantMessageId = lastMessage.id;
return;
}

const isActiveTarget =
this.activeAssistantMessageId !== undefined &&
this.activeAssistantMessageId === lastMessage.id;
Expand Down
101 changes: 101 additions & 0 deletions packages/core/src/agent/memory-persistence.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,105 @@ describe("Conversation persistence integration", () => {
output: { results: ["Result A", "Result B"] },
});
});

it("keeps tool call/result parts when final text arrives after an intermediate checkpoint flush", async () => {
const logger = createLogger();
const memoryManager = {
saveMessage: vi.fn().mockResolvedValue(undefined),
};

const buffer = new ConversationBuffer(undefined, logger as any);
const queue = new MemoryPersistQueue(memoryManager as any, {
debounceMs: 0,
logger: logger as any,
});
const oc = createOperationContext(logger);

buffer.addModelMessages(
[
{
id: "assistant-checkpoint",
role: "assistant",
content: [
{
type: "reasoning",
text: "First I should read the calendar for that date.",
},
{
type: "tool-call",
toolCallId: "call-1",
toolName: "checkCalendar",
input: { date: "2023-11-15" },
},
],
},
{
role: "tool",
content: [
{
type: "tool-result",
toolCallId: "call-1",
toolName: "checkCalendar",
output: {
events: [{ title: "Team meeting" }],
},
},
],
},
],
"response",
);

await queue.flush(buffer, oc);

buffer.addModelMessages(
[
{
id: "assistant-checkpoint",
role: "assistant",
content: [
{
type: "text",
text: "You have one event: Team meeting.",
},
],
},
],
"response",
);

await queue.flush(buffer, oc);

expect(memoryManager.saveMessage).toHaveBeenCalledTimes(2);

const persistedAssistantMessages = memoryManager.saveMessage.mock.calls.map(
(call) => call[1] as UIMessage,
);
const firstMessage = persistedAssistantMessages[0];
const finalMessage = persistedAssistantMessages[1];

expect(firstMessage?.id).toBe("assistant-checkpoint");
expect(finalMessage?.id).toBe("assistant-checkpoint");
expect(finalMessage?.parts.map((part: any) => part.type)).toEqual([
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"reasoning",
"tool-checkCalendar",
"step-start",
"text",
]);
expect(finalMessage?.parts[0]).toMatchObject({
type: "reasoning",
text: "First I should read the calendar for that date.",
});
expect(finalMessage?.parts[1]).toMatchObject({
toolCallId: "call-1",
state: "output-available",
output: {
events: [{ title: "Team meeting" }],
},
});
expect(finalMessage?.parts[3]).toMatchObject({
type: "text",
text: "You have one event: Team meeting.",
});
});
});
Loading
Loading