mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #4706] [Issue]: Personal server-extension IPC: 25ms file polls x2 + 250ms watchdog + 1s heartbeat writes (~80 wakeups/s per extension, from boot) #2580
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#2580
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/4706
Originally assigned to: @kolacheee on GitHub.
Summary
Each running personal server extension costs ~80 timer wakeups per second plus one flash write per second, continuously from boot: the host polls the sandbox output file every 25ms and runs a 250ms double-stat watchdog; the runner polls its input file every 25ms and heartbeat-writes every 1s. Flagged inside #4629 during the mobile-battery investigation ("related, happy to split") but never fixed — on a Termux self-host with a server extension installed this is the largest remaining passive drain.
Expected behavior
Idle extensions cost near-zero wakeups; polling tightens only while traffic is flowing (startup handshake, storage bursts, stop), preserving today's latency where it matters.
Actual behavior
personal-server-extension-runtime.ts:394—outputPollersetInterval(25ms)doing an fstat (+read) per tick;:289-312— watchdogsetInterval(250ms)doing twostat()s per tick.personal-extension-runner.mjs:226—inputPollersetInterval(25ms);:228-230— heartbeatwriteFileevery 1s (a flash write per second, forever).serverJs(runtime.ts:128,:239-242) — zero-extension installs pay nothing.Steps to reproduce
Environment
d6275fa0bLogs, screenshots, or video
Code trace, line references against staging
d6275fa0b.Additional context
Regression-safe fix (designed + red-teamed)
Keep the file transport untouched (it is the sandbox security design) — change only the polling discipline:
setTimeoutchains: host output poll 25ms while HOT / 1000ms while idle; runner input poll 25ms HOT / 250ms idle. HOT := startup not settled, or bytes moved / a message was sent within the last ~3s. Startup handshake and storage bursts keep today's 25ms feel; steady-state drops from 40 stats/s to ~1/s per side. Latency contract verified: no storage/tool deadline exists to trip (runner.mjs:39-45,runtime.ts:201-227— no timeouts either direction; host→runner messages are exactly start/stop/storage-result), so the worst-case ≤1s first-message-after-silence delay is safe; stop responsiveness is bounded by the runner's 250ms idle cadence (rescaleCLEANUP_TIMEOUT_MS3000→3500 for margin).fs.watchonly as an optional fast-path behind a runtime probe (inotify works on Termux home paths but is unreliable on FUSE/shared mounts) — never as the correctness mechanism; the poll chain remains the fallback.Amendments from the adversarial pass (must be in the implementation):
MAX_PROTOCOL_BYTESfalse-kill:pollOutputreads all available bytes and checksoutputBuffer.byteLength > 2MBbefore line-splitting (runtime.ts:336-344). At 25ms that approximates a per-message cap; at a 1s idle cadence it measures bytes accumulated across the idle gap — two individually-legal ~1.5MB messages bursting after >3s of silence would batch to ~3MB in one read and kill a healthy extension. Move the cap to the residual (incomplete-line) buffer after line extraction, which is the actual single-message semantic. Burst-after-silence is exactly the traffic shape adaptive polling creates — this is not optional.pollingOutputre-entrancy guard (runtime.ts:325-326) by awaiting any in-flight poll or looping to a clean pass, (b) complete beforeoutputHandle.close()(:400) and beforesandbox.cleanup()(:408) rm-rf's the dir, and (c) run before theexpectedStopcheck so a drainedfatalmessage (:375) doesn't suppress or get suppressed by the generic exit fallback (:403-406) in the wrong order.active.outputPoller/inputPoller) — clearing a stale handle from a previous tick would leave the live timer running and hold the process alive.Related: #4629 (the client-side polling half, fixed in #4643); #4704 / #4705 (remaining autonomous-polling costs).
Template check