Skip to content

fix(runtime/tui): gate stale resume checkpoint and complete verification lifecycle event contract#680

Merged
Cai-Tang-www merged 4 commits into
1024XEngineer:mainfrom
Cai-Tang-www:fix/review-resume-gate-verify-lifecycle-main
May 21, 2026
Merged

fix(runtime/tui): gate stale resume checkpoint and complete verification lifecycle event contract#680
Cai-Tang-www merged 4 commits into
1024XEngineer:mainfrom
Cai-Tang-www:fix/review-resume-gate-verify-lifecycle-main

Conversation

@Cai-Tang-www
Copy link
Copy Markdown
Collaborator

背景

本 PR 针对本轮 review 的两个中等问题做收敛修复:

  1. applyResumeCheckpoint 仅按 session_id 取最新记录,未校验 workspace_key/transcript_revision,存在“旧 checkpoint 误导新 run 进入 plan/verify”的风险。
  2. runtime 已发出 verification_started / verification_stage_finished / verification_finished,但 TUI 侧未形成完整强类型消费闭环,部分事件会以原始 map 形态被忽略。

变更概览

1) Runtime:恢复 checkpoint 增加一致性闸门

文件:internal/runtime/checkpoint_resume.go

  • updateResumeCheckpoint 现在会持久化当前 transcript 逻辑版本(按消息数计算)。
  • 新增工作区键解析逻辑:优先会话 workdir,缺失时回退运行时生效目录,统一生成 workspace_key
  • applyResumeCheckpoint 在应用策略前新增匹配校验:
    • workspace_key 必须匹配当前 run;
    • transcript_revision 必须匹配当前会话 transcript 版本。
  • 不匹配时直接跳过应用,避免 stale checkpoint 污染新一轮执行策略。

2) TUI 契约闭环:verification lifecycle 事件端到端消费

文件:

  • internal/tui/services/runtime_contract.go

  • internal/tui/services/gateway_stream_client.go

  • internal/tui/core/app/update.go

  • 增加 VerificationStartedPayload 契约类型。

  • gateway_stream_client 补充三类 lifecycle 事件的强类型解码:

    • verification_started
    • verification_stage_finished
    • verification_finished
  • update 侧注册并实现对应 handler,将事件转为可见 activity(不再静默透传)。

测试

新增/更新测试覆盖:

  • internal/runtime/checkpoint_flow_test.go
    • 校验 workspace mismatch 跳过 resume;
    • 校验 transcript revision mismatch 跳过 resume;
    • 调整 resume verify closure 启动用例,确保在匹配条件下可正常触发恢复策略。
  • internal/tui/services/gateway_stream_client_additional_test.go
    • 覆盖 verification lifecycle 三类 payload 的强类型恢复。
  • internal/tui/core/app/update_runtime_events_test.go
    • 覆盖 handler 注册完整性;
    • 覆盖三类 verification lifecycle handler 的有效/无效 payload 分支。

本地执行:

  • go test ./internal/runtime -run "Resume|Verification"
  • go test ./internal/tui/services ./internal/tui/core/app

改动价值

  • 将 resume 策略应用从“仅按 session 最新记录”升级为“按工作区+转录版本双重一致性判定”,显著降低误恢复概率。
  • 补齐 verification lifecycle 的 runtime→gateway→tui 事件契约闭环,增强可观测性与调试确定性。
  • 变更保持最小侵入:不改主循环语义,只加守卫与消费链补全。

风险与兼容性

  • 风险可控:仅在 checkpoint 不匹配时跳过恢复策略,默认回退既有 run 路径(plan 起步)。
  • 向后兼容:新增字段/事件消费均为增量,不破坏现有事件类型与调用方。

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 95.30201% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/tui/core/app/update.go 85.41% 3 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

fennoai[bot]

This comment was marked as outdated.

@Cai-Tang-www
Copy link
Copy Markdown
Collaborator Author

/review

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One noteworthy regression risk found in the resume-token change.

Comment thread internal/runtime/checkpoint_resume.go Outdated
@Cai-Tang-www Cai-Tang-www merged commit 5ca835c into 1024XEngineer:main May 21, 2026
3 checks passed
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.

1 participant