Auth: correctly attribute child agent run to the parent key - #32268
Auth: correctly attribute child agent run to the parent key#32268fabiencelier wants to merge 2 commits into
Conversation
|
There was a problem hiding this comment.
cc-verify: violations found!
- one-usage-key-identity: Spend precheck and traces bypass helper
Findings and notifications outside the PR diff:
Source: front-api/routes/v1/w/[wId]/assistant/conversations/index.ts:187
This pre-existing gate violates the new one-usage-key-identity contract on Authenticator.keyForUsageAttribution (front/lib/auth.ts) by still checking auth.key(). When a forwarded originating key is capped but the system key is uncapped, this precheck allows an empty conversation to be persisted before the updated postUserMessage gate rejects its message; use keyForUsageAttribution() here too.
Source: front/lib/api/llm/llm.ts:292
This pre-existing trace writer violates the new one-usage-key-identity contract on Authenticator.keyForUsageAttribution (front/lib/auth.ts) by persisting authenticator.key().id alongside the generation’s token usage. For an attributed run_agent sub-agent, Langfuse therefore records the system key while message analytics and spend counters record the originating key; resolve apiKeyId through the new helper.
Description
closes https://github.com/dust-tt/tasks/issues/9537
run agent calls originating from API calls were not correctly assigned to the api key.
This fixes the issue by correctly attributing the key in the auth + using the attribution key everywhere
Tested locally: before the fix child run where wrongly billed on no key and the rate limiter was not hit.
After the fix, the billing is done on correct key + rate limiter is used.
Note that attribution key was already added in #26888 but removed in #26933
Tests
Risk
medium, this impact authentication
Deploy Plan
deploy front