[PR #3] [CLOSED] Fix: pick most recent assistant message with findLast instead of find #4381

Closed
opened 2026-10-22 04:07:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3
Author: @Copilot
Created: 3/9/2026
Status: ❌ Closed

Base: release/1.2.0 ← Head: copilot/sub-pr-1-again


📝 Commits (2)

  • 141e825 Initial plan
  • 9b65eab Fix: use findLast instead of find for most recent assistant message

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+1 -1)

📄 Description

chats.listMessages() returns messages ordered by createdAt ascending, so .find() was resolving to the oldest assistant message — making mainResponse/messageId incorrect in conversations with multiple assistant turns.

Change

// Before — returns first (oldest) assistant message
const lastAssistant = recentMessages.find((m: any) => m.role === "assistant");

// After — returns last (most recent) assistant message
const lastAssistant = recentMessages.findLast((m: any) => m.role === "assistant");

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/3 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 3/9/2026 **Status:** ❌ Closed **Base:** `release/1.2.0` ← **Head:** `copilot/sub-pr-1-again` --- ### 📝 Commits (2) - [`141e825`](https://github.com/Pasta-Devs/Marinara-Engine/commit/141e8258abb706fdfbf44fdfc3caaefe308aa811) Initial plan - [`9b65eab`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9b65eab7f590d2f25f931c0b6f65c2486095ffa9) Fix: use findLast instead of find for most recent assistant message ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+1 -1) </details> ### 📄 Description `chats.listMessages()` returns messages ordered by `createdAt` ascending, so `.find()` was resolving to the *oldest* assistant message — making `mainResponse`/`messageId` incorrect in conversations with multiple assistant turns. ## Change ```ts // Before — returns first (oldest) assistant message const lastAssistant = recentMessages.find((m: any) => m.role === "assistant"); // After — returns last (most recent) assistant message const lastAssistant = recentMessages.findLast((m: any) => m.role === "assistant"); ``` <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:07:06 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4381
No description provided.