Thread gateway auth explicitly on the anthropic triage path; drop the process.env fallback
Nobody has claimed this yet.
- 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 fromboot.accessToken). - anthropic path relies on an implicit
process.envfallback:createTriageLLMProvider()is called with no args and readsprocess.env.ANTHROPIC_BASE_URL/process.env.ANTHROPIC_AUTH_TOKEN, whichinitializeAgentsets 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.ts—createTriageLLMProvider(auth?)currently doesauth?.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).gatewayUrlandconfig.posthogApiKey.runAgent(~L762) builds the triage provider at ~L934 withcreateTriageLLMProvider()(no args) and only receivesagentConfig— the creds are not in scope, which is the whole problem.
Suggested approach
- Carry
gatewayUrl+posthogApiKeyfrominitializeAgentintorunAgent— either as fields onAgentRunConfigor a dedicated param. (Don't just re-readprocess.envinsiderunAgent; that defeats the purpose.) - At the
runAgentcall site, passcreateTriageLLMProvider({ baseURL: gatewayUrl, authToken: posthogApiKey }). - Make
authrequired increateTriageLLMProvider(or keep it optional but returnundefinedwhen absent — fail-closed, triage skipped). Remove theprocess.env.ANTHROPIC_*reads. - Leave
initializeAgent'sprocess.env.ANTHROPIC_BASE_URL = gatewayUrlset — 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
triageAuthexplicitly. - 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
TriageGatewayAuthand theauthparam).
Acceptance
- No
process.env.ANTHROPIC_*reads remain intriage-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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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