[GH-ISSUE #2475] [Issue]: Background autonomous trigger never sets the generation lock, allowing a duplicate autonomous reply #1218

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

Originally created by @Romuromylus on GitHub (Jun 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2475

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Low — concurrency regression. The background autonomous-message trigger never sets the shared in-memory generation lock (markGenerationInProgress), unlike main. During a busy/dnd-character delay window this allows a duplicate autonomous reply when the user navigates into the chat and the active-chat poller independently triggers.

Expected behavior

checkConversationAutonomous should set the shared generation lock when it decides to trigger (main does this on both the normal and offline-catch-up paths), so the active-chat poller's own checkAutonomousMessaging short-circuits and only one autonomous reply is produced.

Actual behavior

checkConversationAutonomous returns shouldTrigger: true without ever locking:

// src/engine/modes/chat/autonomous/autonomous.service.ts:226, 237-243
const scheduled = checkAutonomousMessaging(input.chatId, ...);
if (scheduled.shouldTrigger) return scheduled;       // 226 — no markGenerationInProgress
// ...
return { shouldTrigger: true, characterIds: [...], reason: "user_inactivity", ... };  // 237-243 — no lock

The shared lock generationInProgressSince is only read to gate (:445-451, :551-557), never set on a positive trigger. The background poller (use-background-autonomous.ts) relies solely on a per-hook generatingForRef Set plus an abortControllers check; it never sets the global lock. The only caller that sets it is the active-chat poller (use-autonomous-messaging.ts:79). So when the background poller has launched doGenerate for a busy/dnd character (delay window) and the user switches into that chat, the active-chat hook reads generationInProgressSince, sees nothing in progress, and can trigger its own generation — the abortControllers check only covers the in-flight HTTP request, not the pre-flight/assembly window — yielding a duplicate autonomous reply.

Steps to reproduce

  1. Background conversation chat with autonomous messages enabled and a dnd/idle character (nonzero busy delay).
  2. Background poll fires and schedules doGenerate after the delay.
  3. Within that window, open the chat; the active-chat poller triggers and generates; the background timer's doGenerate also runs → duplicate reply.

Impact area

  • Chat mode
  • Runtime systems: generation, world-state, visuals, tracker, or haptics

Environment

  • Branch or commit: refactor @ 1fae2c42
  • Run mode: Tauri desktop / web shell
  • OS + version: found via static source audit (not runtime-reproduced)
  • Node + pnpm versions: n/a (static audit)
  • Rust version, if relevant: n/a (static audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: n/a

Logs, screenshots, or video

Static trace: autonomous.service.ts:226, 237-243 (returns trigger without lock), use-background-autonomous.ts:113-129 (no markGenerationInProgress), contrast use-autonomous-messaging.ts:79 (the one caller that does lock).

Regression notes

Regression vs main, which calls markGenerationInProgress(chatId) on both the normal trigger and the offline-catch-up fallback (conversation.routes.ts ~653/~673). The refactor dropped that, so the cross-poller in-memory lock is never honored on the background path.

Additional context

Narrow window (requires a busy/dnd character, navigating in during the delay, and the active generation finishing before the background timer fires); outcome is a duplicate friendly message, no data loss — hence Low. Fix: call markGenerationInProgress(input.chatId) before each shouldTrigger: true return in checkConversationAutonomous, or have the background poller set the lock before scheduling the busy-delay timer.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2475 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Low — concurrency regression.** The background autonomous-message trigger never sets the shared in-memory generation lock (`markGenerationInProgress`), unlike main. During a busy/dnd-character delay window this allows a duplicate autonomous reply when the user navigates into the chat and the active-chat poller independently triggers. ## Expected behavior `checkConversationAutonomous` should set the shared generation lock when it decides to trigger (main does this on both the normal and offline-catch-up paths), so the active-chat poller's own `checkAutonomousMessaging` short-circuits and only one autonomous reply is produced. ## Actual behavior `checkConversationAutonomous` returns `shouldTrigger: true` without ever locking: ```ts // src/engine/modes/chat/autonomous/autonomous.service.ts:226, 237-243 const scheduled = checkAutonomousMessaging(input.chatId, ...); if (scheduled.shouldTrigger) return scheduled; // 226 — no markGenerationInProgress // ... return { shouldTrigger: true, characterIds: [...], reason: "user_inactivity", ... }; // 237-243 — no lock ``` The shared lock `generationInProgressSince` is only *read* to gate (`:445-451`, `:551-557`), never *set* on a positive trigger. The background poller (`use-background-autonomous.ts`) relies solely on a per-hook `generatingForRef` Set plus an `abortControllers` check; it never sets the global lock. The only caller that sets it is the active-chat poller (`use-autonomous-messaging.ts:79`). So when the background poller has launched `doGenerate` for a busy/dnd character (delay window) and the user switches into that chat, the active-chat hook reads `generationInProgressSince`, sees nothing in progress, and can trigger its own generation — the `abortControllers` check only covers the in-flight HTTP request, not the pre-flight/assembly window — yielding a duplicate autonomous reply. ## Steps to reproduce 1. Background conversation chat with autonomous messages enabled and a dnd/idle character (nonzero busy delay). 2. Background poll fires and schedules `doGenerate` after the delay. 3. Within that window, open the chat; the active-chat poller triggers and generates; the background timer's `doGenerate` also runs → duplicate reply. ## Impact area - [x] Chat mode - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics ## Environment - Branch or commit: refactor @ 1fae2c42 - Run mode: Tauri desktop / web shell - OS + version: found via static source audit (not runtime-reproduced) - Node + pnpm versions: n/a (static audit) - Rust version, if relevant: n/a (static audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: n/a ## Logs, screenshots, or video Static trace: `autonomous.service.ts:226, 237-243` (returns trigger without lock), `use-background-autonomous.ts:113-129` (no `markGenerationInProgress`), contrast `use-autonomous-messaging.ts:79` (the one caller that does lock). ## Regression notes Regression vs main, which calls `markGenerationInProgress(chatId)` on both the normal trigger and the offline-catch-up fallback (`conversation.routes.ts` ~653/~673). The refactor dropped that, so the cross-poller in-memory lock is never honored on the background path. ## Additional context Narrow window (requires a busy/dnd character, navigating in during the delay, and the active generation finishing before the background timer fires); outcome is a duplicate friendly message, no data loss — hence Low. Fix: call `markGenerationInProgress(input.chatId)` before each `shouldTrigger: true` return in `checkConversationAutonomous`, or have the background poller set the lock before scheduling the busy-delay timer. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:29:13 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jun 6, 2026):

Fixed on refactor in 038b7220.

Foreground and background autonomous triggers now set generation-in-progress locks before delayed generation begins and clear them on abort/finally, preventing duplicate autonomous replies.

Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.

<!-- gh-comment-id:4638719761 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. Foreground and background autonomous triggers now set generation-in-progress locks before delayed generation begins and clear them on abort/finally, preventing duplicate autonomous replies. Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.
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#1218
No description provided.