Skip to content

feat: Alert user with fix options when chat fmIndex is out of range#1497

Open
sub-hub wants to merge 3 commits into
kwaroran:mainfrom
sub-hub:firstmessageError
Open

feat: Alert user with fix options when chat fmIndex is out of range#1497
sub-hub wants to merge 3 commits into
kwaroran:mainfrom
sub-hub:firstmessageError

Conversation

@sub-hub

@sub-hub sub-hub commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

PR Checklist

  • Required Checks
    • Have you added type definitions?
    • Have you tested your changes?
    • Have you checked that it won't break any existing features?
  • If your PR uses models1, check the following:
    • Have you checked if it works normally in all models?
    • Have you checked if it works normally in all web, local, and node-hosted versions? If it doesn't, have you blocked it in those versions?
  • If your PR is highly AI generated2, check the following:
    • Have you understood what the code does?
    • Have you cleaned up any unnecessary or redundant code?
    • Is it not a huge change?
      • We currently do not accept highly AI generated PRs that are large changes.

Images

image fmindex is completely out of range, but it shows the bot's first fm. image

Send a chat also works very well.

image

Summary

The first message index in the chat data is stored separately from the bot, so the first message index in the chat can be larger than the size of the first message the bot has when the chat put in to the another bot.

So places that use fmindex should have exceptions, but they don't have them now.
I Added ?? firstMessage fallback to all alternateGreetings[fmIndex] lookups across DefaultChatScreen, cbs.ts, index.svelte.ts, scripts.ts, and triggers.ts

The Popup

When fmIndex goes out of bounds, the user is shown a popup with two options:

  • A. Use the default first message
  • B. Use an empty first message

The popup check triggers in two scenarios:

  1. Before sending a chat — validates fmIndex right before building the prompt. If out of bounds, the popup blocks sending until the user fixes it.
  2. After importing chat data — validates chat index 0 right after import. For risuAllChats, only the first item is checked, but since the validation repeats on send, this isn't a major issue.

Concern

There are similar fmIndex issues that were not fixed in this PR, as they are far removed from the original problem:

  • HypaV3Modal/utils.ts — returns null instead of firstMessage
  • branches.ts — uses ?? 0 instead of ?? firstMessage
  • characters.ts (exportChat HTML mode) — uses ?? 0 instead of ?? firstMessage

Reproduction

{
    "type": "risuChat",
    "ver": 2,
    "data": {
        "message": [],
        "note": "",
        "name": "New Chat 1",
        "localLore": [],
        "fmIndex": 999,
        "id": "eded059d-5f9e-49db-b51a-bd1228b2369d"
    },
    "folders": []
}

Try to import the above json into any bot. You will get an error if you try to send a chat.

Details

To be more specific, I have configured the bot to use the first fm if there is no data corresponding to fmindex.
This applies to the backend, frontend, cbs, triggers, and even @@repeat_back.

We must decide whether to use the first fm or the last fm when a value does not exist in the data using fmindex going forward.

If my approach (Use first fm) differs from yours, please let me know.

Footnotes

  1. Modifies the behavior of prompting, requesting, or handling responses from AI models.

  2. Over 80% of the code is AI generated.

@sub-hub

sub-hub commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

Oh, and if fmindex is out of range and you want to switch to a different fm, simply pressing the right arrow key returns fmindex to the beginning.

So I didn't change this behavior.

@sub-hub sub-hub marked this pull request as draft June 22, 2026 01:46
@sub-hub sub-hub marked this pull request as ready for review June 23, 2026 02:42
@sub-hub sub-hub changed the title fix: Prevent crash when first message index is out of bounds. feat: Alert user with fix options when chat fmIndex is out of range Jun 23, 2026
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.

1 participant