Skip to content

fix(selfhost): consume the injected central PostHog key as a POSTHOG_API_KEY fallback - #8635

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
xfodev:fix/selfhost-posthog-central-key-fallback-8626
Jul 25, 2026
Merged

fix(selfhost): consume the injected central PostHog key as a POSTHOG_API_KEY fallback#8635
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
xfodev:fix/selfhost-posthog-central-key-fallback-8626

Conversation

@xfodev

@xfodev xfodev commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

The hosted control-plane injects a fleet-wide LOOPOVER_CENTRAL_POSTHOG_KEY into each tenant container so the self-host image reports errors to the loopover-owned PostHog project. But initPostHog() in src/selfhost/posthog.ts only ever read POSTHOG_API_KEY — so the injected central key was never consumed, and hosted tenant containers reported to nothing.

  • initPostHog() now resolves the key as processEnvString(env, "POSTHOG_API_KEY") ?? processEnvString(env, "LOOPOVER_CENTRAL_POSTHOG_KEY"): the operator's own POSTHOG_API_KEY keeps highest precedence (unchanged), and the hosted-injected central key is used only as a fallback when POSTHOG_API_KEY is unset — a hosted-image fallback, never a silent override of an operator's explicit config.
  • When neither var is set, initPostHog still returns false and stays a complete no-op — self-host's existing opt-in behavior is unchanged.
  • The module's self-host env-var header block is updated to name LOOPOVER_CENTRAL_POSTHOG_KEY as a fallback source alongside POSTHOG_API_KEY.
  • Consumer-side fix only — the control-plane injection side is already correct and out of scope (its tests are left passing unmodified).

Tests

test/unit/selfhost-posthog.test.ts (82 pass, +3): the central key activates the client when POSTHOG_API_KEY is unset (asserts the client is constructed with the central key); POSTHOG_API_KEY still 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-posthog test file green (82); tsc clean on the changed file.
  • No behavior change when neither var is set; operator POSTHOG_API_KEY precedence preserved.
  • No secret/wallet/hotkey/trust/reward terms; control-plane injection side untouched.

Closes #8626

…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
@xfodev
xfodev requested a review from JSONbored as a code owner July 25, 2026 16:02
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.61%. Comparing base (b471ee1) to head (1034189).
⚠️ Report is 2 commits behind head on main.

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     
Flag Coverage Δ
backend 99.34% <100.00%> (+5.68%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/selfhost/posthog.ts 99.34% <100.00%> (ø)

... and 701 files with indirect coverage changes

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 25, 2026
@loopover-orb

loopover-orb Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-25 16:10:59 UTC

2 files · 1 AI reviewer · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This is a small, correctly-scoped fix: initPostHog() now falls back to LOOPOVER_CENTRAL_POSTHOG_KEY when POSTHOG_API_KEY is unset, preserving operator-key precedence and the existing no-op-when-neither-set behavior. The change is minimal, well-commented, and the diff maps cleanly to the stated bug (injected central key was never consumed). Test coverage directly exercises both branches of the new fallback (`??`) plus the neither-set no-op path, so the new logic is well-guarded.

Nits — 3 non-blocking
  • The comment block above initPostHog references `control-plane/src/container-driver.ts` as the injection site (src/selfhost/posthog.ts:138) — worth double-checking that path is still accurate/exists, since a stale cross-repo/cross-file reference in a comment is easy to drift.
  • LOOPOVER_CENTRAL_POSTHOG_KEY is read via `processEnvString` which trims blank/whitespace-only values to undefined, but there's no explicit test for a blank central key falling through to no-op the way there is for POSTHOG_API_KEY — minor asymmetry in test coverage.
  • Consider adding one more test case mirroring the existing 'blank/whitespace POSTHOG_API_KEY' test but for LOOPOVER_CENTRAL_POSTHOG_KEY, for full symmetry.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8626
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 56 registered-repo PR(s), 23 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor xfodev; Gittensor profile; 56 PR(s), 0 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff implements the exact fallback (POSTHOG_API_KEY ?? LOOPOVER_CENTRAL_POSTHOG_KEY) requested, adds all three required regression tests (fallback activation, operator precedence, no-op when neither set), and updates the header comment block to document the new fallback var as required.

Review context
  • Author: xfodev
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: JavaScript, TypeScript
  • Official Gittensor activity: 56 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask 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.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

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.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 9f69c95 into JSONbored:main Jul 25, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hosted tenant containers never actually consume the central PostHog key #7876 injects

1 participant