feat(hub): agent_run_events 保留策略与尾部快照 - #2070
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
captain 暗卷验收(独立复跑,2026-08-30):
验收通过,等 CI + 管理员合并队列。 |
Co-authored-by: Cursor <cursor@vectorcontrol.tech>
|
主线裁决收口:BLOCKED 的 background 接线已补(本提交)——在 wiring.go Background goroutines 段 StartDeliveryCleanupLoop 之后接 StartRunEventRetentionLoop(a.bg.Ctx(), a.DB, DefaultRetentionConfig()),与 outbox cleanup 同模式。指标为 promauto 自注册无需额外 Register。go build/vet + app/agentevent 包测试绿。 |
8ec1fc7 to
593f7d7
Compare
为终态任务的 agent_run_events 表新增保留策略,解决表无限增长问题。 - repository: PurgeTerminalRunEvents 单条 SQL 删除超窗事件,保留每任务尾部 K 条 - service/agentevent: RunEventsRetentionPass + StartRunEventRetentionLoop (24h cadence) - metrics: retention_runs/deleted_rows/failures 三个 promauto 指标(独立文件不碰 metrics.go) - L1 集成测试: 真 PG 验证终态清理 + 非终态负向用例 常量默认 30d 窗口 + 500 尾部,参照宏观设计基线 §5 目标 5。 background.go 接线由主线裁决(入口函数已就绪)。 Co-authored-by: Cursor <cursor@vectorcontrol.tech>
Co-authored-by: Cursor <cursor@vectorcontrol.tech>
…b-pure-packages 门禁) Co-authored-by: Cursor <cursor@vectorcontrol.tech>
Co-authored-by: Cursor <cursor@vectorcontrol.tech>
Co-authored-by: Cursor <cursor@vectorcontrol.tech>
a90f8e7 to
db337b1
Compare
背景
宏观设计基线 PR #2065 §5 目标 5 要求「事件日志必须有 snapshot + retention」。当前
agent_run_events表只有写入侧每任务上限(config.MaxRunEventsPerTask = 4096),没有任何保留策略清理——终态任务的事件行永久增长。变更
任务 1: repository 清理查询
hub-server/internal/repository/agent_run_event_retention.goPurgeTerminalRunEvents(db, cutoff, keepTail)— 单条 DELETE + 相关子查询,原子完成任务 2: service 编排 + 常量 + 指标
hub-server/internal/service/agentevent/retention.goDefaultRetentionWindow = 30d,DefaultKeepTail = 500,CleanupInterval = 24hRunEventsRetentionPass(ctx, db, cfg)— 可被任何循环调用的入口函数StartRunEventRetentionLoop(ctx, db, cfg)— 独立后台循环(参照 delivery outbox 模式)hub-server/internal/service/agentevent/metrics.go(promauto 自注册,不碰 Wave6 独占的 metrics.go)agenthub_agent_run_events_retention_runs_totalagenthub_agent_run_events_retention_deleted_rows_totalagenthub_agent_run_events_retention_failures_total任务 3: L1 集成测试(真 PG)
hub-server/tests/integration/agent_run_event_retention_test.goTestAgentRunEventRetention_PurgesTerminalTail: 终态任务 800→500,非终态/窗口内不受影响TestAgentRunEventRetention_NonTerminalNegative: 显式负向用例,running 任务 100 条事件不受影响任务 4: gates
go vet ./...✅make test-hub-integration✅python3 scripts/verify/verify-doc-ssot.py✅git diff --check✅BLOCKED: background.go 接线
hub-server/internal/app/background.go和wiring.go当前被孤儿恢复 lane 独占,本 lane 不碰。已提供可直接调用的入口函数agentevent.StartRunEventRetentionLoop(ctx, db, cfg),接线建议见 lane BLOCKED.md。文件清单
仅新增文件,全部在白名单路径内:
hub-server/internal/repository/agent_run_event_retention.gohub-server/internal/repository/agent_run_event_retention_test.gohub-server/internal/service/agentevent/retention.gohub-server/internal/service/agentevent/retention_test.gohub-server/internal/service/agentevent/metrics.gohub-server/tests/integration/agent_run_event_retention_test.go