Skip to content

fix(tui): make edit-last-turn boundaries authoritative - #17

Merged
h3c-hexin merged 3 commits into
Pinvou:pinvou3-cleanfrom
qiuYliangM:fix/edit-last-turn-cut
Aug 25, 2026
Merged

fix(tui): make edit-last-turn boundaries authoritative#17
h3c-hexin merged 3 commits into
Pinvou:pinvou3-cleanfrom
qiuYliangM:fix/edit-last-turn-cut

Conversation

@qiuYliangM

@qiuYliangM qiuYliangM commented Aug 19, 2026

Copy link
Copy Markdown

Background

Op::EditLastTurn previously located the cut with a raw role == "user" scan even though tool results and runtime-owned control messages use that role for provider compatibility. A tool-using turn could therefore retain the old prompt and tool round-trip. The original fix separated editable prompts but still skipped unsupported real-user content and emitted only an advisory error on preflight rejection, which could leave embedded hosts busy or persisting an optimistic edit.

Changes

  • Centralizes edit target selection as editable, unsupported real-user content, or missing.
  • Excludes tool results and structurally trusted non-authoritative runtime messages, including current and legacy turn-metadata layouts, without trusting user-authored runtime lookalikes.
  • Stops at unsupported real-user content instead of falling through to an older text prompt.
  • Emits typed nonrecoverable edit_last_turn_* errors followed by authoritative TurnComplete(Failed) terminals for every edit preflight rejection.
  • Keeps the compatibility is_user_turn_prompt export and corrects the prompt_zones::truncate_to comment.
  • Adds behavior coverage for tool round-trips, current and future provenance values, legacy metadata, user-authored lookalikes, unsupported content, missing prompts, unchanged history, and zero provider dispatch.

Verification

  • cargo test -p codewhale-tui --lib --locked runtime_handoff: 12 passed.
  • cargo test -p codewhale-tui --lib --locked edit_last_turn: 3 passed.
  • cargo test -p codewhale-tui --tests --locked -- --skip runtime_api::tests::skill_lifecycle_uninstall_removes_installed_skill: library 10,098 passed; Cucumber 14 passed; integration 263 passed; PTY 65 passed, 3 ignored.
  • The unfiltered suite has one pre-existing environment-dependent failure in skill_lifecycle_uninstall_removes_installed_skill; its exact rerun fails on the unchanged target as well.
  • cargo fmt --all -- --check and git diff --check: passed.
  • cargo clippy --workspace --all-targets --locked -- -D warnings was run and is blocked by 27 pre-existing target-branch diagnostics, including private-interface and unused-mut warnings; none points to this pull request diff.

Known risks

  • Embedded hosts should consume the failed terminal as the lifecycle authority and use the typed error prefix to roll back optimistic edits. Companion integration: fix(chat): preserve authoritative edit-last-turn boundaries pinvou-agent#320.
  • Unsupported real-user content is rejected in place and remains unchanged; this is a deliberate safety boundary rather than an attempt to edit non-text payloads.

No-Issue: this fixes an existing edit replay boundary and lifecycle bug; the background, behavior, and verification are documented above.

Op::EditLastTurn 用 role=="user" 从尾部定位截断点,但工具结果与内部
运行时信封同样以 user 角色持久化;上一轮只要调用过工具,截断就会落在
最后一条 tool_result 上,旧 prompt 与工具往返残留在历史中,表现为模型
保留编辑前记忆、前端新旧气泡并存。

- 新增 is_user_turn_prompt 谓词(首块为 Text、不含 ToolResult 变体、
  非内部运行时信封与 runtime/subagent_handoff/shell_completion
  provenance),EditLastTurn 改用它定位截断点
- cut==None 时发送错误事件并终止,不再静默降级为追加发送
- 修正 prompt_zones truncate_to 与实现相反的注释
- 新增行为测试覆盖尾部带 tool_result 的截断与无用户消息时报错路径

Signed-off-by: luzeyang (INT) <lu.zeyang@h3c.com>
@github-actions

Copy link
Copy Markdown

Thanks @qiuYliangM for taking the time to contribute.

This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant recurring PR access by commenting /lgtm on a pull request.

…t-turn-cut

Signed-off-by: hexin <he.xin@h3c.com>
Classify editable, unsupported, and runtime-owned user-role messages in one place. Reject edit preflight failures with typed errors and an authoritative failed terminal so embedded hosts can roll back optimistic state safely.

Signed-off-by: hexin <he.xin@h3c.com>
@h3c-hexin h3c-hexin changed the title fix(tui): 编辑重发按真实用户消息定位截断点 fix(tui): make edit-last-turn boundaries authoritative Aug 25, 2026
@h3c-hexin h3c-hexin closed this Aug 25, 2026
@h3c-hexin h3c-hexin reopened this Aug 25, 2026
@h3c-hexin
h3c-hexin merged commit 07d183e into Pinvou:pinvou3-clean Aug 25, 2026
10 checks passed
h3c-hexin added a commit that referenced this pull request Aug 26, 2026
Locate the edit cut at the latest genuine user prompt instead of any provider-compatible user-role message. Reject missing and unsupported targets with a terminal failed outcome so embedded hosts cannot remain busy after an invalid edit.

Ported and adapted from #17.

Co-authored-by: 秋月凉梦 <1461574375@qq.com>
Signed-off-by: hexin <13790929+h3c-hexin@users.noreply.github.com>
Co-authored-by: 秋月凉梦 <185303122+qiuYliangM@users.noreply.github.com>
h3c-hexin added a commit that referenced this pull request Aug 26, 2026
Locate the edit cut at the latest genuine user prompt instead of any provider-compatible user-role message. Reject missing and unsupported targets with a terminal failed outcome so embedded hosts cannot remain busy after an invalid edit.

Ported and adapted from #17.

Co-authored-by: 秋月凉梦 <185303122+qiuYliangM@users.noreply.github.com>
Signed-off-by: hexin <13790929+h3c-hexin@users.noreply.github.com>
Hmbown pushed a commit to Hmbown/Codewhale that referenced this pull request Aug 26, 2026
Locate the edit cut at the latest genuine user prompt instead of any provider-compatible user-role message. Reject missing and unsupported targets with a terminal failed outcome so embedded hosts cannot remain busy after an invalid edit.

Ported and adapted from Pinvou#17.

Signed-off-by: hexin <13790929+h3c-hexin@users.noreply.github.com>
Co-authored-by: hexin <13790929+h3c-hexin@users.noreply.github.com>
Co-authored-by: 秋月凉梦 <185303122+qiuYliangM@users.noreply.github.com>
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.

2 participants