Skip to content

ConfigService: process environment wins over .env - #48

Merged
manish-wekan merged 1 commit into
mainfrom
fix/process-env-wins-over-dotenv
Oct 16, 2026
Merged

manish-wekan merged 1 commit into
mainfrom
fix/process-env-wins-over-dotenv

Conversation

@manish-wekan

Copy link
Copy Markdown
Collaborator

Fixes the root cause of NitroStudio NITSTD-222 (a second MCP started on 3001 binds 3000 and dies with "address already in use").

Cause: ConfigService.__init__ wrote every .env key over os.environ, so the PORT=3000 that nitrostack init puts in .env overrode the PORT a host passes at start-up. resolve_http_port() then returned 3000.

Change: keys already in the process environment are kept, as with python-dotenv and Node's dotenv. .env still fills keys the process doesn't set; defaults stay lowest.

Note: projects vendor the SDK (vendor/nitrostack), so existing projects need their copy refreshed to get this.

Testing

  • New: test_config_process_env_wins_over_env_file (.env PORT=3000 + env PORT=3001 → config and resolve_http_port() are 3001; file-only keys and defaults still apply) and test_config_env_file_port_applies_when_process_has_none. The first fails without the change.
  • Full suite passes (pytest tests, dev extras).
  • End-to-end on a copy of a real project with .env PORT=3000, started with PORT=3007: binds 127.0.0.1:3007 with this change, 127.0.0.1:3000 without.

🤖 Generated with Claude Code

.env values were written over os.environ unconditionally, so the PORT=3000
that `nitrostack init` puts in .env overrode the PORT a host passes when
starting the server. NitroStudio starts a second project on 3001; it bound
3000 anyway and died with "address already in use" (NITSTD-222).

Keys already in the process environment are now kept, as with
python-dotenv and Node's dotenv. .env still fills keys the process
doesn't set, and defaults stay lowest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@manish-wekan
manish-wekan merged commit f14c94b into main Oct 16, 2026
3 checks passed
@manish-wekan manish-wekan mentioned this pull request Oct 16, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant