PostHog / PostHog/wizard

Thread gateway auth explicitly on the anthropic triage path; drop the process.env fallback

Open
#825 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

agent-ready P3 wizard-pain
Dominant language
TypeScript
Stars
197
Forks
51
Avg merge
1d 23h
Merged PRs (30d)
94

Description

Problem

The warlock triage LLM provider gets its gateway auth two different ways depending on the harness:

  • pi path passes it explicitly via ToolGateContext.triageAuth (gateway URL + oauth token from boot.accessToken).
  • anthropic path relies on an implicit process.env fallback: createTriageLLMProvider() is called with no args and reads process.env.ANTHROPIC_BASE_URL / process.env.ANTHROPIC_AUTH_TOKEN, which initializeAgent sets earlier in the run.

The env fallback works (the value is the gateway URL, not the raw Anthropic API — the name just follows the SDK convention), but it's an implicit side-channel: runAgent doesn't actually have the gateway creds in scope, so it depends on initializeAgent having mutated process.env first. That's fragile and reads as "triage talks to Anthropic directly" to anyone skimming the code (see review thread on #804).

Goal: thread the gateway auth explicitly on the anthropic path too, then drop the process.env fallback from createTriageLLMProvider, so neither harness depends on the env side-channel.

Why this is a follow-up, not part of #804

#804 (pi → warlock migration) scoped its auth change to the pi path. Doing the anthropic side means plumbing creds across the initializeAgent → runAgent boundary, which is anthropic-control-path surgery out of that PR's scope. Also aligns with eventually retiring the anthropic control path — a triage provider that already takes explicit auth has no env archaeology to remove later.

Where

  • src/lib/agent/triage-provider.tscreateTriageLLMProvider(auth?) currently does auth?.baseURL ?? process.env.ANTHROPIC_BASE_URL (and same for the token). Drop the ?? process.env.* fallback so auth comes only from the param.
  • src/lib/agent/agent-interface.ts — two spots:
    • initializeAgent (~L627–638) has the creds: gatewayUrl = HostResolution.fromApiHost(config.posthogApiHost).gatewayUrl and config.posthogApiKey.
    • runAgent (~L762) builds the triage provider at ~L934 with createTriageLLMProvider() (no args) and only receives agentConfig — the creds are not in scope, which is the whole problem.

Suggested approach

  1. Carry gatewayUrl + posthogApiKey from initializeAgent into runAgent — either as fields on AgentRunConfig or a dedicated param. (Don't just re-read process.env inside runAgent; that defeats the purpose.)
  2. At the runAgent call site, pass createTriageLLMProvider({ baseURL: gatewayUrl, authToken: posthogApiKey }).
  3. Make auth required in createTriageLLMProvider (or keep it optional but return undefined when absent — fail-closed, triage skipped). Remove the process.env.ANTHROPIC_* reads.
  4. Leave initializeAgent's process.env.ANTHROPIC_BASE_URL = gatewayUrl set — that's still needed by the Claude Agent SDK subprocess for the agent's model calls. This issue only stops triage from reading env.

Notes

  • Do NOT change the pi path — it already passes triageAuth explicitly.
  • The triage model stays Haiku regardless of the agent model; this is purely about where the gateway auth comes from.
  • Depends on #804 landing first (it introduced TriageGatewayAuth and the auth param).

Acceptance

  • No process.env.ANTHROPIC_* reads remain in triage-provider.ts.
  • Both harnesses build their triage provider from explicitly-passed gateway auth.
  • Existing triage tests still pass; add a test that the anthropic-path provider is built from passed auth (not env).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read src/lib/agent/triage-provider.ts and the initializeAgent/runAgent flow in src/lib/agent/agent-interface.ts, then run the existing triage tests. Trace gatewayUrl and posthogApiKey across the agent boundary and build the anthropic-path provider from explicit auth. Done means triage-provider.ts has no process.env.ANTHROPIC_* reads, both harnesses pass explicit auth, and coverage verifies the anthropic path uses the passed values.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
authentication, backend, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.