mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #4705] [Issue]: Server autonomous scheduler full-sweeps chats.list() + metadata JSON.parse every 60s with no opt-in gate #2582
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#2582
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?
Originally created by @kolacheee on GitHub (Aug 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4705
Originally assigned to: @SpicyMarinara, @kolacheee on GitHub.
Summary
The server-side autonomous scheduler runs a 60-second full sweep forever, with no opt-in gate: every tick calls
chats.list()andJSON.parses every conversation chat's metadata, even when zero chats have autonomous messaging enabled and zero clients are connected. On a Termux self-host this is a permanent idle cost. Same shape as the Noodler reconciler fixed in PR #4635 — this is the remaining unconditional sweep.Follow-up from the mobile-battery investigation (the Termux reporter's "passive discharge" round).
Expected behavior
The 60s sweep short-circuits cheaply when nothing is enabled, and a chat becoming autonomous-enabled (from any device) is still picked up within a bounded window (≤ one sweep interval after the enabling write).
Actual behavior
packages/server/src/services/conversation/server-autonomous-scheduler.service.ts:19(SERVER_AUTONOMOUS_POLL_MS = 60_000),:368-385—poll()callschats.list()every tick unconditionally;shouldConsiderChat(:81-86) JSON.parses each conversation chat's metadata.chats.list()sorts all chats per call (chats.storage.ts:462-465). Runs from ~20s after boot for the process lifetime.Steps to reproduce
poll()— full list + parse sweep every 60s indefinitely.Environment
d6275fa0bLogs, screenshots, or video
Code trace, line references against staging
d6275fa0b.Additional context
Regression-safe fix (designed + red-teamed)
The Noodler pattern (cheap probe before the heavy scan) doesn't transfer directly: the file-native store has no indexes, so "does ANY chat have
autonomousMessages: true" has no cheap query — and a substring probe over raw metadata couples to JSON serialization details (a false negative silently kills the feature: the exact regression class to avoid). Instead, gate on a store-level write-generation counter:file-backed-store.ts, add a per-table write-generation counter bumped insidemarkDirty(table)(:1242-1251) — the single choke point every insert/update/delete already funnels through, including transactional writes, cascades, and the capability-package direct writers. Deliberately do not roll the counter back on transaction rollback (a spurious sweep is safe; a missed one is not). ExposegetTableWriteGeneration(table).Amendment from the adversarial pass (must be in the implementation): a sweep that exits via the concurrency-cap break (
:375, which fires beforeshouldConsiderChat, so eligibility was never evaluated) or the stopped-return (:374) is inconclusive — never record "no eligible chats" from it. Otherwise: two eligible chats holdrunningChatsslots inside minutes-scale busy-delay timers (:251-284, slot released in the timer finally), the sweep exits at iteration 1 having considered zero chats, recordsfoundNone, both delayed generations then terminate through paths that only touch the in-memory progress map (presence/backoff/409/discard →clearGenerationInProgress,autonomous.service.ts:244-249, no chats-table write) — and the scheduler goes dormant with enabled chats until an unrelated write. Only a sweep that actually evaluated every chat may record the none-eligible conclusion.Related (same subsystem, client side): the 30s full-
/chatsbackground poll is #4704.Template check