Skip to content

fix(identity): 统一 metadata.user_id 的 device_id 来源,消除身份不一致#1305

Closed
DaydreamCoding wants to merge 1 commit intoWei-Shaw:mainfrom
DaydreamCoding:fix/metadata-userid-consistency
Closed

fix(identity): 统一 metadata.user_id 的 device_id 来源,消除身份不一致#1305
DaydreamCoding wants to merge 1 commit intoWei-Shaw:mainfrom
DaydreamCoding:fix/metadata-userid-consistency

Conversation

@DaydreamCoding
Copy link

问题:同一账号在不同代码路径(buildOAuthMetadataUserID、测试请求、
token 刷新)使用不同的 device_id 来源(GetClaudeUserID / 随机生成 / fingerprint 缓存),导致上游看到同一账号发出的请求带有不同身份标识。

修复:

  • buildOAuthMetadataUserID: 统一使用 fp.ClientID 作为 device_id, 移除 GetClaudeUserID() 和 generateClientID() 随机 fallback
  • generateSessionString: 改为接收确定性参数 (clientID, accountUUID), 不再随机生成 device_id
  • AccountTestService: 注入 IdentityService,测试请求复用 fingerprint 缓存中的 ClientID,与正常请求保持一致
  • GetOrCreateFingerprint: 修复缓存中 ClientID 为空的异常(旧数据兼容)
  • RefreshToken: 从上游响应中提取 account_uuid / org_uuid
  • ClaudeTokenRefresher: 自动刷新时将 UUID 持久化到 account.Extra
  • refreshSingleAccount: 手动刷新时将 UUID 写入 Extra 并持久化

问题:同一账号在不同代码路径(buildOAuthMetadataUserID、测试请求、
token 刷新)使用不同的 device_id 来源(GetClaudeUserID / 随机生成 /
fingerprint 缓存),导致上游看到同一账号发出的请求带有不同身份标识。

修复:
- buildOAuthMetadataUserID: 统一使用 fp.ClientID 作为 device_id,
  移除 GetClaudeUserID() 和 generateClientID() 随机 fallback
- generateSessionString: 改为接收确定性参数 (clientID, accountUUID),
  不再随机生成 device_id
- AccountTestService: 注入 IdentityService,测试请求复用 fingerprint
  缓存中的 ClientID,与正常请求保持一致
- GetOrCreateFingerprint: 修复缓存中 ClientID 为空的异常(旧数据兼容)
- RefreshToken: 从上游响应中提取 account_uuid / org_uuid
- ClaudeTokenRefresher: 自动刷新时将 UUID 持久化到 account.Extra
- refreshSingleAccount: 手动刷新时将 UUID 写入 Extra 并持久化

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DaydreamCoding DaydreamCoding force-pushed the fix/metadata-userid-consistency branch from 27e7a78 to 288106f Compare March 25, 2026 17:48
@DaydreamCoding DaydreamCoding deleted the fix/metadata-userid-consistency branch March 26, 2026 14:40
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