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:
Blizzard
2026-07-07 09:18:15 +08:00
parent 30d667954b
commit ee1e9cfdca
5 changed files with 46 additions and 19 deletions
@@ -65,7 +65,7 @@ func (h *Handler) SubmitTask(c *gin.Context) {
task.Meta[contract.MetaSafetyCheck] = true
}
// 持久化任务提交(best-effort:降级模式下静默跳过,不阻断发布)。
if err := h.db.SaveTask(c.Request.Context(), task.ID, string(task.Graph)); err != nil {
if err := h.db.SaveTask(c.Request.Context(), userID(c), task.ID, string(task.Graph)); err != nil {
log.Printf("[gateway] save task %s failed: %v", task.ID, err)
}
if err := h.bus.PublishTask(c.Request.Context(), task); err != nil {
@@ -419,7 +419,7 @@ func (h *Handler) StatsOverview(c *gin.Context) {
// 近期运行 feed。
recent := make([]gin.H, 0, 8)
for _, t := range h.db.RecentTasks(ctx, 8) {
for _, t := range h.db.RecentTasks(ctx, uid, 8) {
recent = append(recent, gin.H{
"task_id": t.TaskID, "status": t.Status, "detail": t.Detail, "at": t.CreatedAt,
})
@@ -464,7 +464,7 @@ func (h *Handler) Runs(c *gin.Context) {
limit = n
}
}
c.JSON(http.StatusOK, gin.H{"runs": h.db.RecentRuns(c.Request.Context(), limit)})
c.JSON(http.StatusOK, gin.H{"runs": h.db.RecentRuns(c.Request.Context(), userID(c), limit)})
}
// ListMemory: GET /api/v1/memory —— 列出当前用户的全部偏好(结构化,供记忆面板)。