Skip to content

fix(langfuse): key end-user attribution by profile so senders can't cross profiles - #448

Open
fredheathcote007 wants to merge 1 commit into
NousResearch:mainfrom
fredheathcote007:fix/langfuse-profile-scoped-attribution
Open

fredheathcote007 wants to merge 1 commit into
NousResearch:mainfrom
fredheathcote007:fix/langfuse-profile-scoped-attribution

Conversation

@fredheathcote007

Copy link
Copy Markdown

What

#293 scoped trace state and shutdown to the active profile. The two end-user attribution maps were not included: _SENDER_BY_TURN and _USER_BY_CHILD_SESSION are still keyed by bare turn and child-session ids. Under a multiplexed gateway, two profiles can reuse those ids. Their senders then cross over:

  • Opted-out profile exports another profile's user. Profile A (opted in) stashes user-a for turn same-turn. Profile B has end_user_attribution off, but its turn with the same id opens with userId = user-a.
  • Two opted-in profiles swap senders. When both stash a sender for the same turn id before their roots open, A's trace gets B's user.
  • Subagent inheritance leaks the same way. A child-session id reused in B inherits A's user, and B's subagent_stop clears the user that A's child inherited.

The end_user_attribution opt-in is per profile, so this is a privacy issue: one profile's end-user id reaches a Langfuse project that never opted in.

Fix

Both maps are now keyed with the same per-profile namespace that #293 uses for trace state (_profile_attribution_key → profile:<home>:<id>). The namespace stays in process; nothing new is exported.

Tests

Added to test_langfuse_multiprofile_lifecycle.py, using its existing two-profile fixture:

Test On main With fix
test_opted_out_profile_never_exports_another_profiles_sender fail ('user-a' == '') pass
test_same_turn_id_keeps_each_profiles_own_sender fail ('user-b' == 'user-a') pass
test_subagent_user_is_inherited_only_within_its_profile fail ('user-a' == '') pass
test_concurrent_profiles_with_the_same_turn_ids_keep_their_senders (64 racing iterations) fail (iteration 0) pass

test_sender_stash_is_bounded now expects the namespaced keys.

The full langfuse suite passes (182 tests) and hermes plugins validate passes. Both were run on Linux with Python 3.14 against current hermes-agent main, using the install steps from this repo's tests.yml. I haven't run them on macOS or Windows locally; CI covers those.

🤖 Generated with Claude Code

…ross profiles

NousResearch#293 scoped trace state and shutdown to the active profile, but the sender
maps (_SENDER_BY_TURN, _USER_BY_CHILD_SESSION) stayed keyed by bare turn and
child-session ids. Under a multiplexed gateway two profiles can reuse those
ids, so:

- profile B's trace exported profile A's sender as its userId, even when B
  never opted in to end_user_attribution;
- two opted-in profiles with the same turn id swapped senders;
- a subagent session id reused in B inherited A's user, and B's
  subagent_stop cleared A's inherited user.

Key both maps with the same per-profile namespace as the trace state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant