mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #511] [MERGED] fix(runtime-config): defer ensureEnvFileExists warn past import cycle #4649
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#4649
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/511
Author: @Romuromylus
Created: 5/7/2026
Status: ✅ Merged
Merged: 5/7/2026
Merged by: @Romuromylus
Base:
main← Head:fix/runtime-config-tdz📝 Commits (1)
65db33cfix(runtime-config): defer ensureEnvFileExists warn past import cycle📊 Changes
1 file changed (+13 additions, -4 deletions)
View changed files
📝
packages/server/src/config/runtime-config.ts(+13 -4)📄 Description
Linked issue
Closes #510
Why this change
PR #507 added
ensureEnvFileExists()to auto-create.envat startup. When the write fails (read-only filesystem, or a Docker user that lacks write permission to the monorepo root — exactly what happens to thenodeuser against root-owned/appin the upstream Dockerfile), the catch referencessharedLogger, which is in TDZ at that point in startup. Node throwsReferenceError: Cannot access 'sharedLogger' before initialization, which masks the originalEACCESand crash-loops the container with exit 1.runtime-config.tsandlib/logger.tsform an import cycle.packages/server/src/index.tsimportslib/logger.jsfirst (line 7), thenconfig/runtime-config.js(line 8), so the cycle enters throughlogger.ts. Whilelogger.tsis mid-evaluation,runtime-config.tsruns to its bottom-of-fileloadRuntimeEnv()call. Function-declaration exports (getLogLevel,getNodeEnv) survive the partial-module access because they're hoisted in the linking phase, but theconstexport binding forloggeris still uninitialized — synchronous access from the catch is aReferenceError.Reproduces deterministically on EasyPanel, Docker Swarm, and any container/host where the node user lacks write permission to the resolved
MONOREPO_ROOT.What changed
sharedLogger.warncall insetImmediate(...)insideensureEnvFileExists's catch, so the access fires one tick later — after both modules in the cycle finish evaluating.The diagnostic is preserved; startup no longer crashes on read-only or locked-down filesystems, matching the function comment's promise that the write is best-effort.
Considered alternatives:
process.env.LOG_LEVEL/NODE_ENVreads inlogger.ts— eliminates this whole TDZ class but changes semantics: today the cycle's evaluation order meansloadRuntimeEnv()populatesprocess.envfrom.envbeforepino()is constructed, soLOG_LEVELset in.envis honored. Inlining drops that.The deferred-warn fix is the smallest change that closes the regression without surrendering either the diagnostic or the
.env-drivenLOG_LEVELbehavior.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Verified on a downstream fork deployed via EasyPanel against the same upstream Dockerfile that crash-loops the unpatched server:
task: non-zero exit (1)).Up, server listens on0.0.0.0:7860, public endpoint returns the configured401(basicAuth gate) instead of the upstream "Not Found" / restart-loop. App is reachable and behaves normally.pnpm checkpasses locally on the patched tree (TypeScript + ESLint + client/server build).Reviewer should still tick the boxes after running their own check + container smoke per the template instructions.
Docs and release impact
UI evidence (if applicable)
N/A — server-side bootstrap fix, no UI surface.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.