feat(gateway): 多租户2b-A —— Task 加 owner/tenant 隔离 + 系统旁路修 admin 全局口径
- store.WithoutTenant(ctx):显式跨租户旁路,插件即使 ctx 带租户也不过滤。 修复增量2 引入的回归:admin SystemCounts 数 KB 时被 admin 自己租户误过滤。 AdminOverview 改用旁路 ctx → 任务/KB/Doc/Eval 恢复全平台口径。 - Task 加 TenantID(插件自动填) + Owner(提交者 user.id) + isTenantScoped()。 SaveTask 记录 owner;RecentTasks/RecentRuns 按 owner+租户过滤"我的运行"。 RecentRuns 是 raw Table 查询绕过插件,手动补 owner+tenant WHERE。 live 验证:A 提交任务 → 行 owner/tenant 自动填对 ✓;A 的 /runs 只见己方、 B 空、legacy 无 owner 行被排除 ✓;admin/overview tasks_total=39/kb_count=21 = DB 全局真值(旁路生效,回归已修)✓。 Eval/Doc/DocLink 的 tenant 传播见 2b-B。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -17,15 +17,19 @@ type User struct {
|
||||
// 业务 id(task_xxx,用于 NATS subject/stream)单列 TaskID,主键统一雪花。
|
||||
type Task struct {
|
||||
BaseModel
|
||||
TaskID string `gorm:"uniqueIndex;size:64"` // task_xxx
|
||||
Graph string `gorm:"type:jsonb"` // React Flow 导出的 DSL 原文
|
||||
Status string `gorm:"size:32"` // submitted / running / done / failed / timeout
|
||||
Detail string `gorm:"type:text"` // 失败/超时原因等(状态机回写)
|
||||
TenantID string `gorm:"size:64;index"` // 多租户作用域(tenant 插件按 ctx 自动填/过滤)
|
||||
Owner string `gorm:"size:64;index"` // 提交者 user.id(个人工作台按此过滤"我的运行")
|
||||
TaskID string `gorm:"uniqueIndex;size:64"` // task_xxx
|
||||
Graph string `gorm:"type:jsonb"` // React Flow 导出的 DSL 原文
|
||||
Status string `gorm:"size:32"` // submitted / running / done / failed / timeout
|
||||
Detail string `gorm:"type:text"` // 失败/超时原因等(状态机回写)
|
||||
// 收尾持久化:供「运行历史复盘」永久回放(Redis 流仅 10min TTL,过期后历史任务靠这两列)。
|
||||
Output string `gorm:"type:text"` // 最终模型输出(收尾时由网关从流快照落库)
|
||||
Trace string `gorm:"type:text"` // 执行轨迹事件 JSON 数组(存为文本,容忍空串;不在库内查它)
|
||||
}
|
||||
|
||||
func (Task) isTenantScoped() {}
|
||||
|
||||
// Eval 是一次任务的自动化评测结果(dispatcher 评完经 NATS 回写,每任务一条,按 task_id upsert)。
|
||||
type Eval struct {
|
||||
BaseModel
|
||||
|
||||
Reference in New Issue
Block a user