[GH-ISSUE #5514] Extension sandbox watchdog kills healthy extensions after a process-wide freeze (no resume grace) #3065

Closed
opened 2026-10-21 05:59:18 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @kolacheee on GitHub.

Found while auditing #5506 (does not affect Termux — server extensions cannot run there since bubblewrap is unavailable; this is a desktop Linux/macOS issue).

The server-extension sandbox watchdog judges staleness by wall-clock delta: every 1s it compares Date.now() - lastHeartbeat (heartbeat-file mtime) against SANDBOX_HEARTBEAT_STALE_MS = 25s (packages/server/src/services/extensions/personal-server-extension-runtime.ts:372-401, sandbox-protocol.ts:40 on staging). When the OS suspends/freezes the whole process group for more than ~25s (laptop lid close, cgroup freezer, container pause, sleep), the host and the sandboxed child resume together — but the host's first watchdog tick races the child's first post-resume heartbeat write. If the host wins the race, it SIGKILLs a perfectly healthy extension, sets the status to "Server extension was stopped because its sandbox became unresponsive", and never auto-restarts it, so the extension stays dead until a manual reload.

The teardown itself is crash-safe (#4727 hardening verified) — the defect is only the false-positive kill.

Fix shape: give the watchdog a resume grace — track the watchdog's own last tick time, and when now - lastTick vastly exceeds the 1s cadence (i.e., the whole process was frozen), reset lastHeartbeat = now before judging staleness, so the child gets one full stale-window after any freeze.

Originally created by @kolacheee on GitHub (Aug 25, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5514 Originally assigned to: @kolacheee on GitHub. Found while auditing #5506 (does not affect Termux — server extensions cannot run there since bubblewrap is unavailable; this is a desktop Linux/macOS issue). The server-extension sandbox watchdog judges staleness by wall-clock delta: every 1s it compares `Date.now() - lastHeartbeat` (heartbeat-file mtime) against `SANDBOX_HEARTBEAT_STALE_MS` = 25s (`packages/server/src/services/extensions/personal-server-extension-runtime.ts:372-401`, `sandbox-protocol.ts:40` on staging). When the OS suspends/freezes the whole process group for more than ~25s (laptop lid close, cgroup freezer, container pause, sleep), the host and the sandboxed child resume together — but the host's first watchdog tick races the child's first post-resume heartbeat write. If the host wins the race, it SIGKILLs a perfectly healthy extension, sets the status to "Server extension was stopped because its sandbox became unresponsive", and never auto-restarts it, so the extension stays dead until a manual reload. The teardown itself is crash-safe (#4727 hardening verified) — the defect is only the false-positive kill. Fix shape: give the watchdog a resume grace — track the watchdog's own last tick time, and when `now - lastTick` vastly exceeds the 1s cadence (i.e., the whole process was frozen), reset `lastHeartbeat = now` before judging staleness, so the child gets one full stale-window after any freeze.
bsakaguchi 2026-10-21 05:59:18 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Aug 25, 2026):

@kolacheee I am taking the minimal implementation into one release-hardening PR against staging now, using the fix boundaries from your audit. I will keep your diagnosis credited in the PR and avoid expanding scope beyond the four verified paths.

<!-- gh-comment-id:5409720578 --> @SpicyMarinara commented on GitHub (Aug 25, 2026): @kolacheee I am taking the minimal implementation into one release-hardening PR against staging now, using the fix boundaries from your audit. I will keep your diagnosis credited in the PR and avoid expanding scope beyond the four verified paths.
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#3065
No description provided.