Skip to content

feat(relay): expose user and group context to parameter override - #6534

Draft
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:feature/internal-param-user-id
Draft

feat(relay): expose user and group context to parameter override#6534
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:feature/internal-param-user-id

Conversation

@seefs001

@seefs001 seefs001 commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • New Features

    • Parameter overrides can now be conditionally applied based on user, user group, token group, and group usage context.
    • Conditions can also target the upstream model, enabling more precise configuration such as applying settings only to selected GPT models.
  • Tests

    • Added coverage for user, model, and group-based parameter override conditions.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

BuildParamOverrideContext now includes user and grouping fields from RelayInfo. Tests cover conditional service_tier overrides based on user/model matches and combined group context conditions.

Changes

Param override context

Layer / File(s) Summary
Context fields and conditional override validation
relay/common/override.go, relay/common/override_test.go
BuildParamOverrideContext now exposes user_id, user_group, token_group, and using_group; tests validate user/model and group-based conditional overrides.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: calcium-ion

Poem

A rabbit hops through fields so neat,
User and groups now guide the treat.
GPT matches, tiers softly bloom,
Tests check each condition’s room.
Carrots cheer the override tune!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: exposing user and group context to relay parameter overrides.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@relay/common/override.go`:
- Around line 2047-2049: Implement the documented token_group fallback in the
override publication logic around the TokenGroup and UserGroup fields: when
TokenGroup is empty, publish UserGroup instead; preserve an explicitly provided
TokenGroup unchanged. Add a regression test covering UserGroup set with an empty
TokenGroup and verify token_group-based overrides match.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fc631ee9-b2df-4044-bae4-2af201977a3c

📥 Commits

Reviewing files that changed from the base of the PR and between 66ee6b8 and 17d79d4.

📒 Files selected for processing (2)
  • relay/common/override.go
  • relay/common/override_test.go

Comment thread relay/common/override.go
Comment on lines +2047 to +2049
// - user_group:用户所属分组。
// - token_group:令牌指定的分组;未指定时回退为用户分组。
// - using_group:当前实际使用的分组,自动跨分组重试时可能变化。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Implement the documented token_group fallback.

Line 2060 publishes an empty TokenGroup unchanged, contradicting Line 2048’s fallback-to-UserGroup contract. Overrides conditioned on token_group will not match for tokens without an explicit group.

Proposed fix
 ctx["user_id"] = info.UserId
 ctx["user_group"] = info.UserGroup
-ctx["token_group"] = info.TokenGroup
+tokenGroup := info.TokenGroup
+if tokenGroup == "" {
+	tokenGroup = info.UserGroup
+}
+ctx["token_group"] = tokenGroup
 ctx["using_group"] = info.UsingGroup

Add a regression case with UserGroup set and TokenGroup empty.

Also applies to: 2058-2060

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relay/common/override.go` around lines 2047 - 2049, Implement the documented
token_group fallback in the override publication logic around the TokenGroup and
UserGroup fields: when TokenGroup is empty, publish UserGroup instead; preserve
an explicitly provided TokenGroup unchanged. Add a regression test covering
UserGroup set with an empty TokenGroup and verify token_group-based overrides
match.

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