[GH-ISSUE #3045] [Issue]: Manual character replies pollute the autonomous follow-up counter, so a character's first reach-out is treated as a 2nd-round follow-up (double cooldown, wrong anchor, one fewer follow-up) #1615

Closed
opened 2026-10-21 05:40:48 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
In Conversation mode, the autonomous-messaging feature decides whether a character may send an unprompted message using a per-character send count. At count 0 it uses the FIRST-message gate (fires once the user has been idle past the base inactivity threshold). At count >= 1 it switches to the FOLLOW-UP branch: an escalating cooldown of 2^count * baseThreshold, measured from the last recorded send, capped at maxFollowups (default 3). The bug is that this counter is incremented by recordAssistantActivity, which the generate route calls for EVERY conversation assistant message — including normal manual (user-triggered) replies, not just autonomous ones. So after a normal user message + manual reply, the character's count is already 1. The next autonomous evaluation then: (a) skips the correct first-message inactivity gate; (b) requires 2x the base threshold instead of 1x; (c) measures that wait from the manual-reply timestamp instead of the user's last message; and (d) leaves only 2 real autonomous slots instead of 3. In a group individual-mode turn where several characters each reply to one user message, every replier starts at count 1, amplifying the effect across the whole group.

How to reproduce (try it yourself)

  1. Open a Conversation-mode chat with autonomousMessages enabled and a character schedule with inactivityThresholdMinutes = 120, status online.
  2. Send a user message (this clears the counter to 0 via recordUserActivity).
  3. Let the character reply normally (manual generation). On save, the counter becomes 1.
  4. Go idle and let /conversation/autonomous/check poll.

You'll see: the first autonomous message does not fire after ~120 min of silence; the follow-up branch is entered (count 1 -> threshold = 120 * 2^1 = 240 min, measured from the manual reply), and the character has only 2 autonomous slots left.
Expected: after ~120 min of user silence the FIRST autonomous message fires (count 0 path), measured from the user's last message, with 3 follow-up slots available.

Where it is

  • packages/server/src/services/conversation/autonomous.service.ts:187-201 — recordAssistantActivity increments autonomousMessages[characterId].count unconditionally whenever a characterId is passed; no autonomous gate.
  • packages/server/src/routes/generate.routes.ts:6977-6981 — calls recordAssistantActivity(input.chatId, targetCharId ?? undefined) for every conversation save (guard is only chatMode === "conversation" && !impersonate && !regenerate), with no input.autonomous check.
  • Consumer: autonomous.service.ts:353-392 — checkAutonomousMessaging reads sentCount (line 354) and branches into the Math.pow(2, sentCount) cooldown.
  • Reset: autonomous.service.ts:143-160 (recordUserActivity clears the counter).
  • Intent contrast (the smoking gun): generate.routes.ts:1309-1314 (shouldAccountAutonomousGeneration requires input.autonomous === true) gating the parallel persistent counter recordSavedAutonomousGeneration at 1545-1546.

What's happening
recordAssistantActivity conflates two distinct events into one counter that checkAutonomousMessaging assumes reflects autonomous messages only. The parallel daily-budget counter is correctly gated by input.autonomous === true, proving autonomous-only accounting was the intent; the in-memory follow-up counter just missed the same gate.

Suggested fix
Gate the in-memory counter increment so it only fires for genuinely autonomous sends, mirroring the existing shouldAccountAutonomousGeneration / input.autonomous gate. Pass the characterId only when autonomous; otherwise pass undefined so manual replies still update lastAssistantMessageAt and clear generationInProgressSince but do NOT bump the count. Apply at BOTH conversation-save call sites (a command-only/empty-prose reply pollutes via the second path too):

  • generate.routes.ts:6978 (main assistant save): recordAssistantActivity(input.chatId, input.autonomous ? (targetCharId ?? undefined) : undefined);
  • generate.routes.ts:6935 (command-only/empty-prose save): same change.

Regression notes: leave the roleplay-DM cross-post call sites (generate.routes.ts:9888, 9954) and /activity/assistant (conversation.routes.ts:673) unchanged — the DM sites legitimately seed follow-up state in the target chat, and /activity/assistant is only ever called with characterId undefined. lastAssistantMessageAt updates unconditionally before the if (characterId) guard inside recordAssistantActivity, so passing undefined still records the timestamp; only the per-character count is skipped. Genuine autonomous sends arrive with autonomous: true and flow through the same block, so escalation and the maxFollowups cap stay fully functional. input.autonomous defaults to false (chat.schema.ts:40), so the guard is always safe.

v2.0.7 note: generate.routes.ts was reworked in origin/staging; this bug PERSISTS there — recordAssistantActivity is still ungated by input.autonomous at staging lines ~7040 and ~7090 (vs main 6977-6981). Apply the gate at those call sites.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3045 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** In Conversation mode, the autonomous-messaging feature decides whether a character may send an unprompted message using a per-character send count. At count 0 it uses the FIRST-message gate (fires once the user has been idle past the base inactivity threshold). At count >= 1 it switches to the FOLLOW-UP branch: an escalating cooldown of `2^count * baseThreshold`, measured from the last recorded send, capped at `maxFollowups` (default 3). The bug is that this counter is incremented by `recordAssistantActivity`, which the generate route calls for EVERY conversation assistant message — including normal manual (user-triggered) replies, not just autonomous ones. So after a normal user message + manual reply, the character's count is already 1. The next autonomous evaluation then: (a) skips the correct first-message inactivity gate; (b) requires 2x the base threshold instead of 1x; (c) measures that wait from the manual-reply timestamp instead of the user's last message; and (d) leaves only 2 real autonomous slots instead of 3. In a group individual-mode turn where several characters each reply to one user message, every replier starts at count 1, amplifying the effect across the whole group. **How to reproduce (try it yourself)** 1. Open a Conversation-mode chat with autonomousMessages enabled and a character schedule with `inactivityThresholdMinutes` = 120, status online. 2. Send a user message (this clears the counter to 0 via recordUserActivity). 3. Let the character reply normally (manual generation). On save, the counter becomes 1. 4. Go idle and let /conversation/autonomous/check poll. You'll see: the first autonomous message does not fire after ~120 min of silence; the follow-up branch is entered (count 1 -> threshold = 120 * 2^1 = 240 min, measured from the manual reply), and the character has only 2 autonomous slots left. Expected: after ~120 min of user silence the FIRST autonomous message fires (count 0 path), measured from the user's last message, with 3 follow-up slots available. **Where it is** - `packages/server/src/services/conversation/autonomous.service.ts:187-201` — `recordAssistantActivity` increments `autonomousMessages[characterId].count` unconditionally whenever a characterId is passed; no autonomous gate. - `packages/server/src/routes/generate.routes.ts:6977-6981` — calls `recordAssistantActivity(input.chatId, targetCharId ?? undefined)` for every conversation save (guard is only `chatMode === "conversation" && !impersonate && !regenerate`), with no `input.autonomous` check. - Consumer: `autonomous.service.ts:353-392` — `checkAutonomousMessaging` reads `sentCount` (line 354) and branches into the `Math.pow(2, sentCount)` cooldown. - Reset: `autonomous.service.ts:143-160` (`recordUserActivity` clears the counter). - Intent contrast (the smoking gun): `generate.routes.ts:1309-1314` (`shouldAccountAutonomousGeneration` requires `input.autonomous === true`) gating the parallel persistent counter `recordSavedAutonomousGeneration` at `1545-1546`. **What's happening** `recordAssistantActivity` conflates two distinct events into one counter that `checkAutonomousMessaging` assumes reflects autonomous messages only. The parallel daily-budget counter is correctly gated by `input.autonomous === true`, proving autonomous-only accounting was the intent; the in-memory follow-up counter just missed the same gate. **Suggested fix** Gate the in-memory counter increment so it only fires for genuinely autonomous sends, mirroring the existing `shouldAccountAutonomousGeneration` / `input.autonomous` gate. Pass the characterId only when autonomous; otherwise pass undefined so manual replies still update `lastAssistantMessageAt` and clear `generationInProgressSince` but do NOT bump the count. Apply at BOTH conversation-save call sites (a command-only/empty-prose reply pollutes via the second path too): - `generate.routes.ts:6978` (main assistant save): `recordAssistantActivity(input.chatId, input.autonomous ? (targetCharId ?? undefined) : undefined);` - `generate.routes.ts:6935` (command-only/empty-prose save): same change. Regression notes: leave the roleplay-DM cross-post call sites (generate.routes.ts:9888, 9954) and `/activity/assistant` (conversation.routes.ts:673) unchanged — the DM sites legitimately seed follow-up state in the target chat, and /activity/assistant is only ever called with characterId undefined. `lastAssistantMessageAt` updates unconditionally before the `if (characterId)` guard inside `recordAssistantActivity`, so passing undefined still records the timestamp; only the per-character count is skipped. Genuine autonomous sends arrive with `autonomous: true` and flow through the same block, so escalation and the maxFollowups cap stay fully functional. `input.autonomous` defaults to false (chat.schema.ts:40), so the guard is always safe. *v2.0.7 note: `generate.routes.ts` was reworked in `origin/staging`; this bug PERSISTS there — `recordAssistantActivity` is still ungated by `input.autonomous` at staging lines ~7040 and ~7090 (vs main 6977-6981). Apply the gate at those call sites.* --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

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

Claiming this for the current staging sweep in draft PR #3053 (branch codex/issue-sweep-3033-3052).

<!-- gh-comment-id:4834989578 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Claiming this for the current staging sweep in draft PR #3053 (branch `codex/issue-sweep-3033-3052`).
Author
Owner

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

Fixed in PR #3053 on branch codex/issue-sweep-3033-3052 (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.

<!-- gh-comment-id:4835089496 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3053 on branch `codex/issue-sweep-3033-3052` (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.
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#1615
No description provided.