Skip to content

feat: cross-tool user identity via MAGNET_USER_ID / X-Magnet-User-ID - #1

Merged
helinakdogan merged 1 commit into
mainfrom
feat/cross-tool-user-identity
Jun 8, 2026
Merged

feat: cross-tool user identity via MAGNET_USER_ID / X-Magnet-User-ID#1
helinakdogan merged 1 commit into
mainfrom
feat/cross-tool-user-identity

Conversation

@helinakdogan

Copy link
Copy Markdown
Owner

Summary

  • proxy/main.py: chat_completions now reads X-Magnet-User-ID header first; falls back to x-session-id when absent. The resolved value is used as raw_user_id before project-scoped hashing.
  • sdk/magnet/client.py: Added _default_user_id (read from MAGNET_USER_ID env var) in __init__. Added _resolve_user_id() helper. All public methods (add, async_add, search, get_all, delete_all, get_profile, get_injection, force_reflect, get_pending_signals, get_recommended_model) now accept user_id: str | None = None and resolve it via the helper.
  • Also fixed a pre-existing argument-order bug in get_recommended_model (get_profile(project_id, user_id)get_profile(user_id, project_id)).

Usage

SDK:

export MAGNET_USER_ID=alice@company.com
memory = BehavioralMemory(...)
memory.add(messages)  # user_id resolved from env

Proxy:

X-Magnet-User-ID: alice@company.com

Same user profile is recognized across Claude Code, Cursor, Codex — any tool that sets the same identifier.

Test plan

  • SDK: call add() without user_id with MAGNET_USER_ID set — profile stored under correct tenant
  • SDK: call add() without MAGNET_USER_ID and without user_id — raises ValueError
  • Proxy: send request with X-Magnet-User-ID header — same hash as a request with that value as x-session-id
  • Proxy: send request without X-Magnet-User-ID — falls back to x-session-id as before

🤖 Generated with Claude Code

@helinakdogan
helinakdogan merged commit 270b30b into main Jun 8, 2026
1 check failed
@helinakdogan
helinakdogan deleted the feat/cross-tool-user-identity branch June 8, 2026 13:43
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