Skip to content

fix: preserve ROUTATIC_PROXY_* env vars in launchd autostart - #125

Merged
samueltuyizere merged 3 commits into
routatic:mainfrom
stefanoverna:fix/autostart-env-vars
Jul 23, 2026
Merged

fix: preserve ROUTATIC_PROXY_* env vars in launchd autostart#125
samueltuyizere merged 3 commits into
routatic:mainfrom
stefanoverna:fix/autostart-env-vars

Conversation

@stefanoverna

Copy link
Copy Markdown
Contributor

What

The launchd plist generated by autostart enable didn't include environment variables. When the proxy was started via launchd (e.g., at login), it would launch without ROUTATIC_PROXY_API_KEY and other configuration from the user's environment.

Fix

Added ExtraEnv to the plist template and populate it from the current process environment, filtering for ROUTATIC_PROXY_* variables.

Testing

  • All daemon tests pass
  • Manually verified plist contains env vars after autostart enable

The launchd plist template only preserved PATH, so ROUTATIC_PROXY_*
environment variables (like ROUTATIC_PROXY_API_KEY) were lost when the
proxy restarted on login. This caused the autostarted proxy to fail
because it couldn't find the API key.

Now all ROUTATIC_PROXY_* vars from the current environment are written
into the plist's EnvironmentVariables dict so the proxy starts
correctly after a reboot.
Comment thread internal/daemon/autostart_darwin.go Outdated
Comment thread internal/daemon/autostart_darwin_test.go
@kilo-code-bot

kilo-code-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Code Review Roast 🔥

Verdict: No Issues Found | Recommendation: Merge

Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything.

📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are.

Files Reviewed (2 files)
  • internal/daemon/autostart_darwin.go - previously reviewed, issues fixed
  • internal/daemon/autostart_darwin_test.go - previously reviewed, issues fixed
Previous Review Summary (commit d13ef67)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit d13ef67)

Verdict: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
🚨 critical 0
⚠️ warning 1
💡 suggestion 1
🤏 nitpick 0
Issue Details (click to expand)
File Line Roast
internal/daemon/autostart_darwin.go 59 text/template doesn't XML-escape env var values; a stray & in an API key bricks the plist
internal/daemon/autostart_darwin_test.go 43 Test doesn't actually set or verify ROUTATIC_PROXY_* env vars in the generated plist

🏆 Best part: The test fix is honest — they caught that the test was claiming serve while the template had start --background all along. Refreshing to see someone admit a test was wrong.

💀 Worst part: Inserting unescaped user-controlled strings into XML with text/template. One & in an env var value turns launchd into a very confused mess.

📊 Overall: Like ordering pizza and only getting the box. You got a box of XML. But where's my actual env var validation?

Files Reviewed (2 files)
  • internal/daemon/autostart_darwin.go - 1 warning
  • internal/daemon/autostart_darwin_test.go - 1 suggestion

Fix these issues in Kilo Cloud


Reviewed by step-3.7-flash · Input: 59.9K · Output: 8.6K · Cached: 160.6K

Review guidance: REVIEW.md from base branch main (truncated)

text/template does not escape XML special characters, so a stray &, <, or >
in an env var value would produce invalid plist XML. Added xmlEscape template
function using html.EscapeString.

Also added test coverage verifying ROUTATIC_PROXY_* vars with special
characters are properly escaped in the generated plist.
@stefanoverna

Copy link
Copy Markdown
Contributor Author

All issues addressed:

  1. XML escaping → fixed: added xmlEscape template function using html.EscapeString. Env var values with &, <, > are now properly escaped in the plist.
  2. Test coverage → fixed: test now sets ROUTATIC_PROXY_API_KEY=sk-test&key<value> and asserts the plist contains the XML-escaped equivalent sk-test&amp;key&lt;value&gt;.

All 8 daemon tests pass.

stefanoverna

This comment was marked as duplicate.

stefanoverna

This comment was marked as duplicate.

@samueltuyizere samueltuyizere left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@samueltuyizere
samueltuyizere merged commit 88b4fab into routatic:main Jul 23, 2026
2 checks passed
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.

2 participants