mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #4727] [MERGED] fix(server): adaptive sandbox IPC polling instead of fixed 25ms intervals #6480
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#6480
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/4727
Author: @kolacheee
Created: 8/7/2026
Status: ✅ Merged
Merged: 8/7/2026
Merged by: @kolacheee
Base:
staging← Head:fix/4706-extension-ipc-idle-wakeups📝 Commits (10+)
45294c2fix(server): adaptive sandbox IPC polling instead of fixed 25ms intervalsb1d7a87Merge branch 'staging' into fix/4706-extension-ipc-idle-wakeups144ad82fix(server): cap the runner's residual input, await the output-handle close, and await runner exit in the IPC regression cleanup6b08e8dfix(server): mark expectedStop before every host-initiated sandbox kill so specific errors survive the close handlerc8874affix(server): guard the close handler's active-map delete, tolerate cleanup races in the drain, and warn on failed stop writesd056141fix(server): serialize sandbox cleanup behind the close handler's finalization promise16087bdfix(server): route startup-failure teardown through stopExtension and contain cleanup rejections in the close finalizer1f36e03fix(server): skip the dead close-event wait when stopping an already-exited sandboxc8e60b4fix(server): never dispatch storage during the final drain and contain storage-reply failures6fa406bfix(server): never race fallback cleanup against close finalization, and gate storage dispatch on expectedStop📊 Changes
5 files changed (+599 additions, -44 deletions)
View changed files
📝
package.json(+1 -1)📝
packages/server/src/assets/personal-extension-runner.mjs(+41 -4)📝
packages/server/src/services/extensions/personal-server-extension-runtime.ts(+223 -39)➕
packages/server/src/services/extensions/sandbox-protocol.ts(+95 -0)➕
scripts/regressions/extension-ipc.regression.ts(+239 -0)📄 Description
Linked issue
Closes #4706
Why this change
What changed
Adaptive cadence on both sides (new pure module
sandbox-protocol.ts+personal-server-extension-runtime.ts+personal-extension-runner.mjs): the fixed intervals are now self-scheduling timeout chains that poll at the old 25 ms only while traffic is flowing (startup handshake unsettled, or bytes/messages moved within the last 3 s) and drop to 1 s (host) / 250 ms (runner) at idle. Each side'ssend()flips the other direction back to hot, since a reply is expected — storage round-trips and the stop handshake keep today's latency. Steady-state wakeups drop from ~80/s to ~5/s per extension.Heartbeat 1 s → 5 s (5× fewer flash writes) with the host's unresponsive threshold rescaled 5 s → 25 s — the same five-missed-beats multiple as before — and the watchdog cadence 250 ms → 1 s.
CLEANUP_TIMEOUT_MSgains headroom (3 s → 3.5 s) for the runner's idle stop pickup.Per-message size cap (red-team amendment from the issue): the host's
MAX_PROTOCOL_BYTEScheck previously applied to the whole buffered chunk — a fair approximation at 25 ms, but at an idle cadence the buffer batches everything that arrived across the silence, so several individually-legal messages bursting after a quiet spell would have been killed as one "oversized message". Extraction now caps each message individually (newline index per line, residual buffer after extraction) via the pureextractProtocolLines.Final drain on close (red-team amendment):
handleClosenow waits out any in-flight poll and runs one last read before closing the file handle, before theexpectedStopcheck (so a drainedfatalmessage attributes the exit correctly instead of racing the generic fallback), and beforesandbox.cleanup()removes the directory.Timer-handle hygiene (red-team amendment): the stored poller handles are reassigned on every tick of the chains — clearing a stale handle from a previous tick can't leave a live timer running. The runner's heartbeat interval remains the process-liveness anchor.
The runner inlines its constants (it's a standalone sandbox asset that cannot import server modules) with a sync comment; the regression pins the pairing.
An adversarial review pass on this diff (verifier ran an A/B harness driving the real runner against a faithful host transcription) caught and fixed two things:
The new close-time drain could resolve the startup handshake from a child that had already crashed right after
ready(unhandled rejection →fatal→ exit):load()would then insert the dead sandbox into the active set, report it as running, and a later stop-all would fail on its deleted input file — aborting shutdown of the healthy extensions (reproduced 6/6 pre-fix).load()now refuses to activate a sandbox whose child has exited or is marked stopped (surfacing the drainedfatal's message instead), and a failed stop-write no longer aborts the kill/cleanup path.Two of the regression's "no fixed 25 ms interval" source pins were regexes that could not match the code they forbid (a negated character class can't cross the
)in() => void …) — assertions that could never fail. Replaced with exact-substring forbids plus positive pins asserting the chains exist and their delay expressions actually consult the idle constants.New regression (
extension-ipc.regression.ts, wired intoregression:issues): extraction semantics (a legal burst is not oversized; per-line and residual caps; split-message reassembly), cadence floors (no 25 ms idle timer or 250 ms watchdog can quietly return), the five-missed-beats multiple, host/runner constant sync via source scan — plus a live end-to-end of the real runner under plainnode: start handshake, extension log delivery, a stop sent after the hot window lapses is picked up within the idle-cadence bound, clean exit 0.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
pnpm checkand the fullregression:issueslane pass locally, including the new IPC regression's live runner pass (realpersonal-extension-runner.mjsunder plainnode: handshake, log delivery, stop-after-silence within the idle bound, exit 0).dist/assets/personal-extension-runner.mjsmatches source byte-for-byte afterpnpm build(the build copies assets).Still to verify manually (contributor to-do — Windows cannot run the OS-sandboxed spawn, so the full host+sandbox pair needs a Linux/Termux pass):
Sandboxed … with …log), storage get/patch round-trips work, logs stream, disable/enable restarts it cleanly, and the sandbox dir shows the new cadences (heartbeat mtime every ~5 s; input/output stats quiet at idle).Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)No user-facing docs impact — internal IPC cadence; no configuration surface changed.
Summary by CodeRabbit
Bug Fixes
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.