mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #4715] [MERGED] fix(autonomous): poll lightweight candidate ids instead of the full chat list every 30s #6474
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#6474
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4715
Author: @kolacheee
Created: 8/7/2026
Status: ✅ Merged
Merged: 8/7/2026
Merged by: @kolacheee
Base:
staging← Head:fix/4704-autonomous-candidates-poll📝 Commits (1)
661b61dfix(autonomous): poll lightweight candidate ids instead of the full chat list📊 Changes
5 files changed (+169 additions, -19 deletions)
View changed files
📝
packages/client/src/hooks/use-autonomous-messaging.ts(+9 -3)📝
packages/client/src/hooks/use-background-autonomous.ts(+53 -16)📝
packages/server/src/routes/chats.routes.ts(+26 -0)➕
packages/server/src/services/conversation/autonomous-candidates.ts(+35 -0)📝
scripts/regressions/open-issues.regression.ts(+46 -0)📄 Description
Linked issue
Closes #4704 (from the Termux battery follow-up audit; related: #4629/#4643 fixed the extension-poll half, #4705 covers the server-side scheduler sweep)
Why this change
The background-autonomous poller fetched the full
/chatslist every 30 seconds on every open client, even with zero autonomous chats — and each of those GETs also ran the empty-DM-cleanup pass (an O(total-messages)countMessagesscan per DM thread on the file-native store). On a Termux self-host the phone pays both the radio and the server CPU for that, forever. It was the heaviest remaining idle network cost after #4643.What changed
GET /chats/autonomous-candidates— returns only[{ id }]for conversation chats with autonomous messaging enabled (excluding the Professor Mari home assistant), via a pure predicate (services/conversation/autonomous-candidates.ts) shared with the regression suite. No full-list serialization, no cleanup scans. Static path, so Fastify prefers it overGET /:id.GET /chatsrancleanupEmptyRoleplayDmChatsas a side effect; without it, an emptied DM thread with stale in-memory activity state could receive an autonomous message and permanently exempt itself from cleanup. The route excludes zero-message chats carrying the DM markers (countMessagesruns only for DM-marker candidates, so the scan cost the endpoint exists to avoid stays avoided). Marker expression mirrors the cleanup's, with a sync-note comment on both sides.use-background-autonomous.ts) — same 30s cadence (cross-device discovery unchanged at ≤1 tick), same client-side exclusions (active chat, in-flight generations). Against pre-#4704 servers it falls back to the legacy full-list fetch with identical local filtering; a definitive 404 latches the fallback for the session (transient errors keep retrying; reload after a server upgrade resets it), with a one-timeconsole.debugnote.use-autonomous-messaging.ts) — it refetched the full character list every 30s during open autonomous conversations, but its stated purpose (sidebar status dots) reads["characters","summaries"], which the invalidated key never matched. Dot freshness actually comes from chat-metadata status snapshots plus the summaries query's staleTime/focus refetches.Review provenance: the fix design was red-teamed before implementation (including an explicit trace proving message-edit persistence is fully independent of this poll — the concern is answered in #4704), and the implementation then went through a second adversarial review that found 3 issues, all fixed here: the empty-DM cleanup dependency (the old poll was accidentally load-bearing), the fallback lacking a 404 latch, and a wrong comment. Zero findings refuted.
Known pre-existing (not fixed here):
ConversationPresenceCard's signature invalidation targets the same mismatchedcharacterKeys.list()key — flagged during review; happy to file/fix separately.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Automated/scripted checks already performed (green):
pnpm check(lint + production build) — run twice (post-implementation, post-review-fixes)regression:issuesopen-issues lane — passes with new cases for the candidate predicate (mode/metadata/Mari/unparseable) and the DM-marker helperGET /api/chats/autonomous-candidates(zero legacy/chatscalls observed); direct probe returns200with the[{id}]shape (empty array on a no-autonomous install, which the shape check accepts without falling back); hidden-tab gating still skips ticksStill to verify manually (please tick above once done):
Docs and release impact
No user-facing docs cover the polling internals; no version bump.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.