fix(api): resolve LANGFUSE_HOST lazily so .env.langfuse host is honored - #20
Conversation
baseUrl was a module-level const evaluated at import time. Because ESM imports are hoisted, api.ts was evaluated before index.ts's body loaded .env.langfuse into process.env, so a LANGFUSE_HOST set there was silently ignored by the public API client (client.ts already honored it via its lazy singleton read). Replace the const with a lazy getBaseUrl() called at request time, and reuse it from client.ts to drop the duplicated default host string. Add host-resolution regression tests (RED->GREEN verified).
|
Warning Review limit reached
More reviews will be available in 57 minutes and 16 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Replace the module-level
export const baseUrlinsrc/lib/api.tswith a lazygetBaseUrl()function that readsprocess.env.LANGFUSE_HOSTat call time.langfuseApi()now resolves the host per request;client.tsreusesgetBaseUrl()(dropping its duplicated default-host literal).Why
baseUrlwas evaluated at module-load time. In ESM, staticimportdeclarations are hoisted, soapi.ts(imported transitively by the tool modules) was fully evaluated beforeindex.ts's module body ran the.env.langfuseloader. The result: aLANGFUSE_HOSTset in.env.langfusewas silently ignored by the public API client — even thoughclient.tshonored it (it readprocess.envlazily inside its singleton). This made the two clients inconsistent and broke the documented per-project override (feat(env): per-project .env.langfuse credential override, #17) forLANGFUSE_HOST.The fix makes
api.tsread the host lazily, restoring the documented priority (.env.langfuse > Plugin ${VAR} > ~/.zshenv) and aligning both clients.Origin
Surfaced by a security review of the repo. Two candidates were raised:
.env.langfuseunconditional credential override — intentionally not changed: it is the documented, deliberate behavior of feat(env): per-project .env.langfuse credential override #17; the security filter rated it a false positive (3/10, requires write access to the server's CWD, outside the threat model). Reversing it (=→??=) would regress feat(env): per-project .env.langfuse credential override #17.LANGFUSE_HOSTignored byapi.ts(this PR) — a real correctness bug, fixed here.Reviewer notes
api.tshas zero imports;client.ts→api.tsis one-way.export const baseUrlhad no external consumers (no file imported{ baseUrl }).client.ts's singleton timing is unchanged — firstgetLangfuseClient()call happens at request time (used as a default-param expression intraces.ts/observations.ts/sessions.ts), well after.env.langfuseloads.Test plan
bun test— 56 pass / 0 fail (3 new host-resolution regression tests, RED→GREEN verified)bun run typecheck— cleanbun run lint— clean (--max-warnings=0)