mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 23:06:17 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The claude_local adapter's ACP lane classifies cost events for the ledger via resolveClaudeAcpBillingIdentity > - When an agent runs with a managed AI subscription connection and the host process happens to have ANTHROPIC_API_KEY in its environment, resolveClaudeAcpBillingIdentity incorrectly inspected process.env because considerHostEnv only checked whether target.kind was remote > - The probe (testClaudeAcpEnvironment) and execution paths in the same package already check !targetIsRemote && !config.managedAiConnection, and the CLI lane only inspects the effective run environment > - This pull request updates considerHostEnv in resolveClaudeAcpBillingIdentity to also check !config.managedAiConnection, preventing host environment leaks from misclassifying subscription runs as metered API spend > - The benefit is that subscription runs on managed AI connections correctly file as subscription_included at $0 rather than metered API spend even if the host environment has an Anthropic key ## Linked Issues or Issue Description Fixes #22388 Related: #20955 ## What Changed - Updated `resolveClaudeAcpBillingIdentity` in `packages/adapters/claude-local/src/server/acp.ts` to gate `considerHostEnv` on `!config.managedAiConnection`, aligning it with `testClaudeAcpEnvironment` and `testEnvironment`. - Added unit tests in `packages/adapters/claude-local/src/server/acp.test.ts` verifying that `resolveClaudeAcpBillingIdentity` ignores host environment when `managedAiConnection` is configured, while preserving `api` billing when `managedAiConnection` is used with `api_key` and config credentials. ## Verification - Ran `vitest run packages/adapters/claude-local/src/server/acp.test.ts` (43 passed). - Built package via `pnpm --filter @paperclipai/adapter-claude-local build` (0 TypeScript errors). - Ran all ACP suites in `claude-local` (`acp.auth.test.ts`, `acp.quota.test.ts`, `acp.test.ts`) (97 passed). ## Risks - Low risk: Only affects ACP billing identity resolution when `managedAiConnection` is set. Unmanaged local runs and remote execution targets maintain their existing behavior. ## Model Used - Model: Gemini 2.5 Flash - Reasoning: Chain-of-thought analysis, autonomous codebase investigation, test-driven reproduction, and verification ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: commitperclip[bot] <284812584+commitperclip[bot]@users.noreply.github.com>