[GH-ISSUE #3392] [Issue]: #3322 still present on main — RP wizard "Use Settings Presets" skips the first message (greeting guard counts system "joined" notices) #1837

Closed
opened 2026-10-21 05:43:08 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jul 8, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3392

Originally assigned to: @SpicyMarinara on GitHub.

Follow-up to #3322 (closed / marked fixed for v2.1.1). A user reports it's still happening on current main, and it is — the fix was applied but doesn't work because of the guard it uses.

What's wrong

Creating a Roleplay chat via the wizard's "Use Settings Presets" shortcut still opens the chat with no first message — only the "X has joined the chat" system notice — exactly like the original #3322 report.

Why the fix doesn't work

The #3322 fix added seedInitialGreetingsIfEmpty() to handleShortcutApply, guarded to seed the greeting only when the chat is "empty." But the guard uses the total message count, and by the time it runs the chat already contains the system "joined the chat" notices — so count > 0 is always true, the guard returns early, and the greeting is never posted.

The original issue's proposed fix specifically said to guard on "no non-system messages yet." The implementation guards on total messages instead, which includes those system join notices.

How to reproduce (try it yourself)

  1. Sidebar → RP tab → New Roleplay.
  2. In the wizard, click Use Settings Presets.
  3. Pick a chat preset and select a character that has a first_mes.
  4. Click Apply & Start.

You'll see: the chat opens with no first message — only the "X has joined the chat" notice (same as #3322).
Expected: the character's first_mes is posted as the opening assistant message (with alternate greetings as swipes), like the full step-by-step wizard path.

Where it is

packages/client/src/components/chat/ChatSetupWizard.tsx — seedInitialGreetingsIfEmpty (lines 1998-2009):

const { count } = await api.get<{ count: number }>(`/chats/${chat.id}/message-count`);
if (count > 0) return;   // counts the system "joined" notices, so it always skips
...
for (const charId of chatCharIds) await createInitialGreetingForCharacter(charId);

called from handleShortcutApply (lines 2013 and 2023).

  • The count comes from countMessages (packages/server/src/services/storage/chats.storage.ts:791-794), which counts all rows with no role filter:
    async countMessages(chatId) { const rows = await db.select({ id: messages.id }).from(messages).where(eq(messages.chatId, chatId)); return rows.length; }
    
  • The "joined the chat" notices are role: "system" messages, created when characters are added to the chat (packages/server/src/routes/chats.routes.ts:715-721), which happens during the wizard — before Apply & Start.

So by the time seedInitialGreetingsIfEmpty runs, count already includes those system messages → count > 0 → early return → no greeting. (For contrast, the full step-by-step path finishWizard, lines 1987-1996, calls createInitialGreetingForCharacter unconditionally, which is why it still works.)

What's happening

The guard was meant to avoid duplicating the greeting in the character-card quick-start flow (where an assistant greeting is pre-injected). But it keys on total message count including system join notices, so in the "New Roleplay wizard" flow — where only system notices exist, no greeting — it wrongly concludes the chat is non-empty and skips seeding.

Suggested fix

Guard on the presence of a non-system message (an actual greeting / assistant / user message), not the total count — matching the original issue's stated intent ("no non-system messages yet"). Options:

  • Skip only when a non-system message already exists — e.g. add a count/lookup that excludes role === "system" (and likely "narrator"), or fetch the messages and check.
  • Or specifically check whether an assistant greeting (first_mes) already exists before seeding, so the character-card quick-start dedup still holds while the wizard flow seeds correctly.

AI-investigated against current main (v2.1.1 tree; fix from commit 2f3bef600 "[codex] v2.1.1 issue sweep #3331" is present but ineffective). The guard, countMessages, and the system-join-notice creation were all read and confirmed. Please verify in-app before fixing.

Originally created by @kolacheee on GitHub (Jul 8, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3392 Originally assigned to: @SpicyMarinara on GitHub. Follow-up to #3322 (closed / marked fixed for v2.1.1). A user reports it's **still happening on current `main`**, and it is — the fix was applied but doesn't work because of the guard it uses. **What's wrong** Creating a Roleplay chat via the wizard's **"Use Settings Presets"** shortcut still opens the chat with no first message — only the "X has joined the chat" system notice — exactly like the original #3322 report. **Why the fix doesn't work** The #3322 fix added `seedInitialGreetingsIfEmpty()` to `handleShortcutApply`, guarded to seed the greeting only when the chat is "empty." But the guard uses the **total** message count, and by the time it runs the chat already contains the system **"joined the chat"** notices — so `count > 0` is always true, the guard returns early, and the greeting is never posted. The original issue's proposed fix specifically said to guard on "no **non-system** messages yet." The implementation guards on total messages instead, which includes those system join notices. **How to reproduce (try it yourself)** 1. Sidebar → RP tab → **New Roleplay**. 2. In the wizard, click **Use Settings Presets**. 3. Pick a chat preset and select a character that has a `first_mes`. 4. Click **Apply & Start**. **You'll see:** the chat opens with no first message — only the "X has joined the chat" notice (same as #3322). **Expected:** the character's `first_mes` is posted as the opening assistant message (with alternate greetings as swipes), like the full step-by-step wizard path. **Where it is** `packages/client/src/components/chat/ChatSetupWizard.tsx` — `seedInitialGreetingsIfEmpty` (lines 1998-2009): ``` const { count } = await api.get<{ count: number }>(`/chats/${chat.id}/message-count`); if (count > 0) return; // counts the system "joined" notices, so it always skips ... for (const charId of chatCharIds) await createInitialGreetingForCharacter(charId); ``` called from `handleShortcutApply` (lines 2013 and 2023). - The count comes from `countMessages` (`packages/server/src/services/storage/chats.storage.ts:791-794`), which counts **all** rows with **no role filter**: ``` async countMessages(chatId) { const rows = await db.select({ id: messages.id }).from(messages).where(eq(messages.chatId, chatId)); return rows.length; } ``` - The "joined the chat" notices are `role: "system"` messages, created when characters are added to the chat (`packages/server/src/routes/chats.routes.ts:715-721`), which happens during the wizard — before **Apply & Start**. So by the time `seedInitialGreetingsIfEmpty` runs, `count` already includes those system messages → `count > 0` → early return → no greeting. (For contrast, the full step-by-step path `finishWizard`, lines 1987-1996, calls `createInitialGreetingForCharacter` **unconditionally**, which is why it still works.) **What's happening** The guard was meant to avoid duplicating the greeting in the character-card quick-start flow (where an assistant greeting is pre-injected). But it keys on total message count including system join notices, so in the "New Roleplay wizard" flow — where only system notices exist, no greeting — it wrongly concludes the chat is non-empty and skips seeding. **Suggested fix** Guard on the presence of a **non-system** message (an actual greeting / assistant / user message), not the total count — matching the original issue's stated intent ("no non-system messages yet"). Options: - Skip only when a non-system message already exists — e.g. add a count/lookup that excludes `role === "system"` (and likely `"narrator"`), or fetch the messages and check. - Or specifically check whether an assistant greeting (`first_mes`) already exists before seeding, so the character-card quick-start dedup still holds while the wizard flow seeds correctly. --- *AI-investigated against current `main` (v2.1.1 tree; fix from commit `2f3bef600` "[codex] v2.1.1 issue sweep #3331" is present but ineffective). The guard, `countMessages`, and the system-join-notice creation were all read and confirmed. Please verify in-app before fixing.*
bsakaguchi 2026-10-21 05:43:08 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jul 8, 2026):

Fixed in PR #3396, merged into staging at d22ba7af.

<!-- gh-comment-id:4920044428 --> @SpicyMarinara commented on GitHub (Jul 8, 2026): Fixed in PR #3396, merged into staging at d22ba7af.
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#1837
No description provided.