Skip to content

Retain unconfirmed-stop evidence after agent ending timeout - #117

Merged
EricWvi merged 6 commits into
ora-space:mainfrom
wanglongan587:feat/390-restore-stop-evidence
Oct 21, 2026
Merged

EricWvi merged 6 commits into
ora-space:mainfrom
wanglongan587:feat/390-restore-stop-evidence

Conversation

@wanglongan587

@wanglongan587 wanglongan587 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Cloud retains a named stop_unconfirmed observation on the existing residual row when its end-confirmation window expires without a real Node terminal. Reconciliation preserves the original observation time, residual reason and responsibility, and admission/deletion fences. It grants no termination or reclamation authority.

Refs ora-space/circus#390

Node companion: ora-space/desktop#712.

ADR: decisions/node/revision/20261018-complete-restore-deadline-and-cancel-confirmation.md remains approved. This PR implements the Cloud evidence portion of D6. Joint fault validation and Git Server adoption remain in the linked implementation run. The owner's later decision to also accept an authoritative NotStarted reply (ora-space/circus#421) is follow-up work tracked by ora-space/circus#423 and #424; it does not change this PR.

Migration: 0059_agent_restore_stop_evidence.sql, merged with main 6fb86d1, which already carries 0053_retire_tenant_level_clones.sql through 0057_agent_run_residual_reclamation.sql and cloud#116's 0058_agent_run_controlled_reclamation.sql. No applied migration is changed; the Chinese and English migration indexes, their file count (61), the migration test name and its migrationsBefore reference follow the new number.

Upgrade snapshot: cloud#112 merged 0057_agent_run_residual_reclamation.sql after the previous head was reviewed, and its residualMigrationHistory helper compared the complete residual row, so any later additive column makes that comparison differ. The helper already subtracts the columns 0057 itself adds; stop_evidence joins that exclusion list, which keeps the assertion "the upgrade rewrote no legacy residual or business fact" intact. Without this, TestMigration0057ResidualReclamationUpgradePreservesHistory fails on every branch that adds a residual column after 0057. cloud#116's TestControlledResidualMigrationUpgradePreserves0057HistoryAndDoesNotInventD8Ledger snapshots full residual rows before Migrate applies 0058 and every later file, so it subtracts stop_evidence the same way.

Validation at 37dc097:

  • gofmt clean; go build ./..., go vet ./internal/core ./integration, go run ./cmd/checkformat and git diff --check upstream/main...HEAD passed.
  • Real PostgreSQL 18.6 (author, on head 37dc097, under the previous 0058 name): TestMigration0058RestoreStopEvidenceFreshUpgradeAndRepeat (fresh, upgrade from the previous schema, repeated application), TestRestoreStopUnknownAddsOneResidualObservationWithoutReclaimAuthority and the four TestMigration0057ResidualReclamation* tests passed.
  • Compared with the reviewed 9d528f5, the functional code is unchanged: the migration keeps the same SQL blob (29d4a26), renamed to 0059 after cloud#112 and cloud#116 took 0057 and 0058; the merge with main only resolves both migration indexes, and two test-only edits follow (renumbered test, stop_evidence excluded from the 0058 upgrade snapshot).
  • Backend CI on head 35815c2: pending (previous head 37dc097 passed run 39562556878 before the renumbering).

@creegon2 creegon2 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.

复审对象:desktop#712 @ 616ef100(PR 基于 main 391e62a4),cloud#117 @ c707072b(PR 基于 main 9814cacd)。依据:specs main 911c976 中的 decisions/node/revision/20261018-complete-restore-deadline-and-cancel-confirmation.md(D1/D4/D6)。本轮改动(01f56f77..616ef100 去掉 rebase 带入的 main 提交后只有 616ef100 一个提交,range-diff 确认前两个提交与上轮内容相同)和两份 PR 的全部内容都看过。

结论:Request changes

代码本身没有发现问题。阻断原因只是 main 已经合入了 0053_retire_tenant_level_clones.sql 和 0054_git_delivery_refs.sql,本 PR 的 0053 与它撞号,PR 现在显示 CONFLICTING。rebase、重新编号、CI 重新通过之后,cloud 这边可以给 LGTM。

P1 阻断(合并前置条件,不是代码缺陷)— 迁移号与 main 冲突

  • cloud main 现在是 a9c5f20,已有 0053_retire_tenant_level_clones.sql 和 0054_git_delivery_refs.sql。PR 的 internal/core/migrations/0053_agent_restore_stop_evidence.sql 与之撞号。git merge-tree --write-tree a9c5f20 c707072b 显示 internal/core/migrations/README.md 和 README.en.md 冲突,gh pr view 117 --json mergeable 返回 CONFLICTING / DIRTY。
  • 要求:rebase 到最新 main,按 main 实际情况顺延编号(目前是 0055;合并前再按"先合者占号"核对一次),同步 migrationsBefore、测试名 TestMigration0053...、中英文 README 的条目和文件计数,然后让 Backend CI 在新 head 上重新通过。

代码复审结果:没有发现问题

  • internal/core/agent_run_startup_budget.go:85-90:证据和残留行插入、业务收尾在同一个事务里。用 NOT stop_evidence ? 'stop_unconfirmed' 防止重复写入,observedAt 不会被续期。不改 reason、responsibility,不授予强停或删除权限。executionId 取自 result IS NULL 的原执行(:68)。这些与 ADR D6 的到期行为和落地顺序第 6 步一致。
  • 迁移只加一个 NOT NULL DEFAULT '{}' 的 object 列,旧行不回填任何历史观察。
  • 测试 TestRestoreStopUnknownAddsOneResidualObservationWithoutReclaimAuthority 走的是真实入口 StartQueuedAgentSessionsOnce。我把 UPDATE 临时改成 WHERE false 后,这个测试失败:invalid named stop evidence: {} / agent_start_failed。这说明测试在没有这项改动时确实会失败。

验证方法和命令见 desktop#712 上同一轮 review 的"验证"一节(cloud 部分)。

🤖 Generated with Claude Code

@creegon2 creegon2 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.

复审对象:cloud#117 @ a5bd2a0e6d97ff2f0d6840b80a6efd6968c1c20a(基于 main a9c5f20f)。依据:specs main 6aad4f9 的 decisions/node/revision/20261018-complete-restore-deadline-and-cancel-confirmation.md D6 和落地顺序第 6 步。

结论:Approve

上轮唯一的阻断是迁移号冲突,现在已经解决,代码没有变化。

与上一轮 head c707072b 的差异只有重新编号

  • 我把 git diff 9814cacd c707072b 和 git diff a9c5f20f a5bd2a0e 两份补丁去掉 index 行后逐行对比。差异只有以下几处:

    • 文件名从 0053_agent_restore_stop_evidence.sql 改为 0055_agent_restore_stop_evidence.sql;
    • 测试名改为 TestMigration0055RestoreStopEvidenceFreshUpgradeAndRepeat,schema 前缀改为 test_stop55f_ / test_stop55u_;
    • migrationsBefore(t, "0055_agent_restore_stop_evidence.sql");
    • 中英文 README 的条目、说明和文件计数。

    agent_run_startup_budget.go、agent_run_restore_stop_db_test.go、迁移 SQL 正文和两份 startup-settlement 文档都没有变化。

  • 一致性:

    • internal/core/migrations/ 下实际有 57 个 .sql 文件,中英文 README 都写 57;
    • 仓库里已经没有 0053_agent_restore 或 TestMigration0053Restore 的残留引用;
    • main 上的 0053_retire_tenant_level_clones.sql 和 0054_git_delivery_refs.sql 保持不变。
  • 合并状态:

    • gh pr view 117 显示 MERGEABLE / CLEAN;
    • cloud main 现在已到 4128d86(合入了 cloud#118,没有新增迁移),git merge-tree --write-tree 4128d86 a5bd2a0e 没有冲突,0055 仍然空着。
  • CI:Backend check(run 39536019084,head a5bd2a0e,02:58:54Z–03:08:50Z)结论为 success。

代码结论沿用上轮

上轮的代码审查结论不变,本轮代码没有改动:

  • 证据和残留行在同一事务中写入;
  • 用 NOT stop_evidence ? 'stop_unconfirmed' 去重;
  • 不改 reason 和 responsibility,不授予回收权限。

上轮还做过一次变异检查:去掉证据写入后,测试会失败。

迁移号提醒:cloud#112 和 cloud#114 也在用 0055,先合入的 PR 占用这个号,其余的顺延。这一点不阻断本 PR。

@wanglongan587
wanglongan587 force-pushed the feat/390-restore-stop-evidence branch from a5bd2a0 to e8c570e Compare October 21, 2026 05:33

@creegon2 creegon2 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.

复审对象:cloud#117 @ e8c570e70007ecaab6185af38d7be9ba7b23b9a8(基于 main df9799c)。

结论:Approve

上一个 head a5bd2a0e 的 0055 在 cloud#119 合入后与 main 冲突。作者已经 rebase 到 df9799c,迁移改为 0056_agent_restore_stop_evidence.sql。

  • 改动只有重新编号:我把 git diff a9c5f20f a5bd2a0e 和 git diff df9799c e8c570e7 两份补丁去掉 index/@@ 行后逐行对比。差异只有以下几处:

    • 迁移文件名、测试名 TestMigration0056RestoreStopEvidenceFreshUpgradeAndRepeat、migrationsBefore(t, "0056_agent_restore_stop_evidence.sql");
    • 中英文 README 的条目、说明和文件计数(58);
    • README 中的上下文行(main 上新增了 0055 的条目)。

    Go 代码、SQL 正文和文档正文都没有变化。

  • 一致性:internal/core/migrations/ 下实际有 58 个 .sql 文件,旧编号已无残留引用。gh pr view 117 显示 MERGEABLE。

  • CI:Backend check run 39550219965(head e8c570e7,05:33Z 开始,05:42Z 结束)结论为 success。

  • 迁移号提醒:cloud#114 也用 0056(0056_workflow_invocation_reference.sql,尚未合入)。先合入的 PR 占用这个号,后合入的那个需要再次顺延,并在新 head 上重新跑 CI。

代码审查结论沿用之前几轮:

  • 证据和残留行在同一事务中写入;
  • 用 NOT stop_evidence ? 'stop_unconfirmed' 去重;
  • 不改 reason 和 responsibility,不授予回收权限。

@wanglongan587
wanglongan587 force-pushed the feat/390-restore-stop-evidence branch from e8c570e to 9d528f5 Compare October 21, 2026 06:25

@creegon2 creegon2 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.

复审对象:cloud#117 @ 9d528f5(基于 main 7588357)。上一轮 Approve 的是 e8c570e。

结论:Approve

这一轮只改了迁移编号:

  • 0056_agent_restore_stop_evidence.sql 改名为 0057_agent_restore_stop_evidence.sql。两边是同一个 blob 29d4a26,SQL 内容没变。
  • 我把 git diff df9799c e8c570e 和 git diff 7588357 9d528f5 逐文件对比:
    • agent_run_startup_budget.go、agent_run_restore_stop_db_test.go 和两份 startup-settlement 文档的改动逐行相同;
    • 迁移测试只改了测试名 TestMigration0057RestoreStopEvidenceFreshUpgradeAndRepeat、schema 前缀 test_stop57f_ / test_stop57u_ 和 migrationsBefore 的文件名。
  • internal/core/migrations/ 下实际有 59 个 .sql 文件,与中英 README 的计数一致。最新 main 48b77fc 上最高的迁移是 0056,0057 目前空着。
  • CI:Backend check 在 9d528f5 上通过。

迁移号提醒:cloud#112(0057_agent_run_residual_reclamation.sql)也排在 0057,先合入的占用这个号,后合入的顺延。

@wanglongan587
wanglongan587 force-pushed the feat/390-restore-stop-evidence branch from 9d528f5 to b3cceb5 Compare October 21, 2026 07:13

@creegon2 creegon2 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.

复审对象:cloud#117 @ 37dc097(基于 main 35b536f)。上一轮 Approve 的是 9d528f5。

结论:Approve

我把 git diff 48b77fc 9d528f5 和 git diff 35b536f 37dc097 逐文件对比,把编号统一替换后,只剩下面这些差别:

  • 迁移改名为 0058_agent_restore_stop_evidence.sql,和上一轮是同一个 blob 29d4a26,SQL 没变。
  • 测试名、schema 前缀 test_stop58f_ / test_stop58u_、migrationsBefore 跟着改了;中英 README 计数 59 → 60,0058 那一行排在 main 的 0057 后面。agent_run_startup_budget.go、agent_run_restore_stop_db_test.go 和两份 startup-settlement 文档没有变化。
  • residualMigrationHistory 的排除列表里加了 stop_evidence。0057 的升级测试比较的是残留行的完整 JSON,0058 加列以后不排除就一定会出现差异。这和排除 0057 自己那 11 个新列是同一种做法,断言"升级不改写旧残留行和业务事实"没有放宽。

其他核对:

  • main 921e73e 上最高的迁移是 0057,有 59 个 .sql 文件,0058 目前空着。
  • CI run 39562556878 的 head 就是 37dc097,check 通过。PR 是 MERGEABLE / CLEAN。

不影响合并的一处说明:PR 描述说 cloud#116 也会撞到这个快照断言。实际上 cloud#116 的 0058 只新建三张表,不给 agent_run_residuals 加列,它在合入 35b536f 之后的 CI 也通过了。所以不管哪个先合,后合的那个只需要改编号。

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.

3 participants