fix(selfhost): consume the injected central PostHog key as a POSTHOG_API_KEY fallback - #8635
Conversation
…API_KEY fallback The hosted control-plane injects a fleet-wide LOOPOVER_CENTRAL_POSTHOG_KEY into each tenant container, but initPostHog() only ever read POSTHOG_API_KEY -- so the injected key was never consumed and hosted tenant containers reported to nothing. Resolve the key as POSTHOG_API_KEY (operator override, highest precedence, unchanged) falling back to LOOPOVER_CENTRAL_POSTHOG_KEY when POSTHOG_API_KEY is unset; when neither is set initPostHog stays a complete no-op (returns false), unchanged. Document the fallback in the module's self-host env-var header block. Consumer-side fix only; the control-plane injection side is already correct and untouched. Adds regression tests: the central key activates the client when POSTHOG_API_KEY is unset, POSTHOG_API_KEY still wins when both are set, and neither-set stays a no-op. Closes JSONbored#8626
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8635 +/- ##
==========================================
- Coverage 92.77% 90.61% -2.16%
==========================================
Files 798 97 -701
Lines 79464 22642 -56822
Branches 24078 3947 -20131
==========================================
- Hits 73725 20518 -53207
+ Misses 4592 1945 -2647
+ Partials 1147 179 -968
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-25 16:10:59 UTC
Review summary Nits — 3 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
Summary
The hosted control-plane injects a fleet-wide
LOOPOVER_CENTRAL_POSTHOG_KEYinto each tenant container so the self-host image reports errors to the loopover-owned PostHog project. ButinitPostHog()insrc/selfhost/posthog.tsonly ever readPOSTHOG_API_KEY— so the injected central key was never consumed, and hosted tenant containers reported to nothing.initPostHog()now resolves the key asprocessEnvString(env, "POSTHOG_API_KEY") ?? processEnvString(env, "LOOPOVER_CENTRAL_POSTHOG_KEY"): the operator's ownPOSTHOG_API_KEYkeeps highest precedence (unchanged), and the hosted-injected central key is used only as a fallback whenPOSTHOG_API_KEYis unset — a hosted-image fallback, never a silent override of an operator's explicit config.initPostHogstill returnsfalseand stays a complete no-op — self-host's existing opt-in behavior is unchanged.LOOPOVER_CENTRAL_POSTHOG_KEYas a fallback source alongsidePOSTHOG_API_KEY.Tests
test/unit/selfhost-posthog.test.ts(82 pass, +3): the central key activates the client whenPOSTHOG_API_KEYis unset (asserts the client is constructed with the central key);POSTHOG_API_KEYstill wins when both are set (client uses the operator key, never the central one); neither-set stays a no-op (false, client never constructed). These are the exact regression guards against an injected-but-never-consumed env var recurring — both branches of the new fallback covered.Validation
selfhost-posthogtest file green (82);tscclean on the changed file.POSTHOG_API_KEYprecedence preserved.Closes #8626