mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #4723] [MERGED] fix(server): replace the env-watcher's 2s stat-poll with an event-driven directory watch #6477
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#6477
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/4723
Author: @kolacheee
Created: 8/7/2026
Status: ✅ Merged
Merged: 8/7/2026
Merged by: @kolacheee
Base:
staging← Head:fix/4707-env-watcher-idle-wakeups📝 Commits (3)
597270efix(server): replace the env-watcher's 2s stat-poll with an event-driven directory watch58a1f24fix(server): bound the env-watcher debounce deferral, handle bare watcher close, and harden the regression8b5a488docs: describe the env-watch default's debounce and automatic fallback in the reference table📊 Changes
5 files changed (+330 additions, -27 deletions)
View changed files
📝
.env.example(+5 -0)📝
docs/CONFIGURATION.md(+5 -2)📝
package.json(+1 -1)📝
packages/server/src/config/env-watcher.ts(+175 -24)➕
scripts/regressions/env-watcher.regression.ts(+144 -0)📄 Description
Linked issue
Closes #4707
Why this change
.envhot-reload watcher stat-polled the env file every 2 seconds for the server's lifetime (fs.watchFileis stat-polling, not inotify). That made it the highest-frequency permanent timer on an idle Marinara server — individually cheap, but 30 wakeups/minute forever prevents deep idle on phone-hosted (Termux) installs, where this class of timer is what keeps the battery drain floor up (follow-up from the mobile-battery investigation, alongside #4704/#4705).What changed
All changes in
packages/server/src/config/env-watcher.tsplus docs and a new regression:fs.watchon the parent directory of the env path, filtered to the file's basename, with{ persistent: false }and a 250 ms debounce funneling into the pre-existing mtime/size dedupe. Directory-watching (rather than watching the file) is deliberate: it survives atomic-replace saves (editors rename a new inode over the file, which detaches file-level watchers) and works when the.envdoesn't exist yet. Zero idle wakeups.fs.watchthrows at setup or the watcher errors later), the watcher falls back to the oldfs.watchFileapproach at a 30 s interval instead of 2 s, with a log line saying so. Env edits are human-timescale; worst-case latency stays acceptable at 1/15th the wakeups.MARINARA_ENV_WATCH=pollforces the 30 s stat-poll, which sees every write. The docs describe exactly this boundary rather than overpromising automatic detection. (No documented deployment path — native installs, Docker named volumes, Termux$HOME— is affected; all have working change notification.)MARINARA_ENV_WATCH=0(alsofalse/off/no) disables watching entirely; manual reloads and everything else keep working. Both values are checked once at startup (work from the shell env or from.envitself, since the initial env load precedes the watcher start), added to the restart-required key list,docs/CONFIGURATION.md, and.env.example. Deliberately not defaulted off anywhere, including the Termux launcher — that would silently kill the documented no-restart security-config reload for exactly the users who rely on it.startEnvWatcher() → { stop, reloadNow }interface are unchanged;index.tsis untouched.scripts/regressions/env-watcher.regression.ts, wired intoregression:issues): drives the real watcher against a temp env file — creation-from-nothing pickup (the auto-created header file fromruntime-config's import-time load is explicitly removed first, so the missing-file branch genuinely runs) with a 2 s latency ceiling that fails if events aren't driving the pickup, in-place edits, atomic replace via rename (the motivating hazard), deletion clearing loaded keys,stop()effectiveness, the mode resolver, and the opt-out (no watching,reloadNow()still functional). Also pins the 30 s fallback floor so the high-frequency timer can't quietly come back.An adversarial review pass against the diff caught three things, all addressed: the module comment and docs originally overpromised the fallback (silent non-delivery neither throws nor errors, so it cannot auto-engage — the docs now state the boundary honestly and
MARINARA_ENV_WATCH=pollgives those setups a real remedy); the regression's "file does not exist yet" scenario never actually ran (runtime-configauto-creates the env file at import — now unlinked first, with a precondition assert); and the original latency assertion's ceiling equaled its wait budget, making it unfireable (now a literal 2 s bound well under the 10 s budget).Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
pnpm checkand the fullregression:issueslane pass locally, including the new env-watcher regression (event-driven pickup latency, atomic replace, deletion, stop, opt-out).[env-watcher] Watching …, and a live edit of the env file is applied and logged without restart.Still to verify manually (contributor to-do):
.envedit still hot-reloads (the regression runs on Windows; inotify semantics differ from ReadDirectoryChangesW).BASIC_AUTH_PASS) still takes effect without restart on a running install.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)docs/CONFIGURATION.md§ "Restart or hot reload" updated (reload timing, fallback behavior,MARINARA_ENV_WATCH);[docs-i18n]follow-up filed as #4722.Summary by CodeRabbit
New Features
.envchange detection with debounced reloads.Documentation
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.