Skip to content

[Bug] upsertLocalLoreBook not working in onStart and onOutput events #1041

@Nam-SW

Description

@Nam-SW

Bug Description

The upsertLocalLoreBook function works correctly in onButtonClick events but fails to persist changes when called from onStart and onOutput events in Lua scripts.

Environment

  • RisuAI version: 166.3.0
  • Event types affected: onStart, onOutput
  • Scripting language: Lua Trigger Script

Steps to Reproduce

  1. Create a Lua script that calls upsertLocalLoreBook in onStart or onOutput function
  2. Enter new inputs in Risu Chat
  3. Check if the local lorebook changes are saved
  4. Compare with the same function call in onButtonClick (which works correctly)

Expected Behavior

upsertLocalLoreBook should work consistently across all event types (onStart, onOutput, onButtonClick)

Actual Behavior

  • onButtonClick: Changes are saved correctly
  • onStart: Changes are not persisted
  • onOutput: Changes are not persisted
  • No errors are thrown in any case

Cause Analysis

The issue was caused by different chat object reference handling between event types:

  • onButtonClick (via runLuaButtonTrigger) → directly saves changes via setCurrentChat()
  • onStart/onOutput (via runTrigger) → was modifying char.chats[char.chatPage] instead of ScriptingEngineState.chat

(KR) 버그 설명

upsertLocalLoreBook 함수가 onButtonClick 이벤트에서는 정상적으로 작동하지만, Lua 스크립트의 onStartonOutput 이벤트에서 호출할 때는 변경사항이 저장되지 않는 문제가 있습니다.

환경

  • RisuAI 버전: 166.3.0
  • 영향받는 이벤트 타입: onStart, onOutput
  • 스크립팅 언어: Lua Trigger Script

재현 단계

  1. onStart 또는 onOutput 함수에서 upsertLocalLoreBook을 호출하는 Lua 스크립트를 작성
  2. 리스 앱 내 새 메세지 입력
  3. 로컬 로어북 변경사항이 저장되었는지 확인
  4. 동일한 함수를 onButtonClick에서 호출했을 때와 비교 (정상 작동함)

예상 동작

upsertLocalLoreBook이 모든 이벤트 타입(onStart, onOutput, onButtonClick)에서 일관되게 작동해야 함

실제 동작

  • onButtonClick: 변경사항이 정상적으로 저장됨
  • onStart: 변경사항이 지속되지 않음
  • onOutput: 변경사항이 지속되지 않음
  • 어떤 경우에도 오류는 발생하지 않음

원인 분석

이벤트 타입별로 채팅 객체 참조 처리 방식이 달라서 발생한 문제:

  • onButtonClick (runLuaButtonTrigger 경유) → setCurrentChat()을 통해 직접 변경사항 저장
  • onStart/onOutput (runTrigger 경유) → ScriptingEngineState.chat 대신 char.chats[char.chatPage]를 수정하고 있었음

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions