feat(automation): run-history retention + durable single-run detail (#2585)#2603
Merged
Merged
Conversation
…2585) Item 1 — retention for sys_automation_run terminal history (closes the unbounded-growth risk #2581 introduced, ADR-0057 posture): - write-time per-flow cap in recordTerminal (default 100 newest terminal runs per flow; runHistoryMaxPerFlow, 0 disables) - default-on periodic age sweep pruning terminal rows older than 30 days (runHistoryRetentionDays / runHistorySweepMs), mirroring the service-messaging notification retention pattern - suspended (paused) rows are live resumable state and are never pruned - new {status, created_at} index for the sweep Item 3 — durable single-run detail: - SuspendedRunStore.loadTerminal(runId); AutomationEngine.getRun falls back to the durable history row after a restart / ring-buffer eviction - terminal rows persist a bounded step log (steps_json: newest 200 steps, stacks stripped, 64 KB byte cap) plus finished_at and the last node reached, so "which node blew up" survives a restart Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VfAct34NhDJCJWrF6zhN1N
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 5 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
落地 #2585 中属于 framework 仓库的两项后续(第 2 项 Runs 界面在 objectui,另行处理):
第 1 项 —
sys_automation_run终态历史的保留策略(P1,收敛 #2581 引入的无界增长风险)ADR-0057 的声明式 lifecycle/LifecycleService 尚未实现(仍为 Proposed),因此按 issue 中的过渡方案落地,与 service-messaging 的
NotificationRetention模式保持一致:recordTerminal插入新历史行后,仅保留该 flow 最新的 100 条终态行(runHistoryMaxPerFlow,0关闭;单次写入最多删 50 行,避免遗留大表放大写开销)。runHistorySweepMs)删除超过 30 天(runHistoryRetentionDays,0关闭)的终态行。按status等值 +created_at $lt各删一遍(completed / failed),paused行是可恢复的活动状态,永不清理。ISO-8601 比较值,沿用 messaging 清理器踩过的 Postgres 坑的结论。{status, created_at}索引支撑清理;timerunref且在destroy()清除。第 3 项 — 持久化的单次运行详情(补完 #2581)
SuspendedRunStore新增可选loadTerminal(runId);AutomationEngine.getRun在内存 ring buffer 未命中时回退到持久化历史行 —— 重启后点开一条失败运行不再返回 404。steps_json列):引擎侧保留最新 200 步并剥离error.stack(MAX_PERSISTED_HISTORY_STEPS),存储侧再加 64 KB 字节上限(超出时对半截尾,保留最新步骤 —— 失败原因在尾部);同时写入finished_at与最后到达的node_id。与第 1 项的保留策略配合,行体积可控后持久化 steps 才安全。RunRecord新增finishedAt/steps;runRecordToLogEntry相应携带completedAt/steps。GET /:name/runs/:runId无需改动,直接受益。测试
run-history.test.ts:重启后getRun回退返回步骤级详情(失败节点 + 剥离 stack)、未知 id 返回 null、按流上限生效。suspended-run-store.test.ts:终态 steps 往返、loadTerminal不会把 paused 行当历史返回、写入时裁剪不动其他 flow 和 paused 行、年龄清理只删过期终态行、steps_json字节上限截尾。pnpm turbo test --filter=...@objectstack/service-automation:73 个任务全绿(含 runtime、dogfood 等全部下游)。已附 changeset。错误形态归一化(run 级 string vs step 级对象)按 issue 标注为低优先级,未在本 PR 处理。
Closes 部分 #2585(第 1、3 项;第 2 项在 objectui 跟进)。
🤖 Generated with Claude Code
https://claude.ai/code/session_01VfAct34NhDJCJWrF6zhN1N
Generated by Claude Code