fix(harness): guard fresh input lifecycle - #405
Open
openjiuwen-sync-bot[bot] wants to merge 3 commits into
Open
Conversation
|
|
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.
Paired: GitHub #405 ↔ GitCode !2243
/kind bug
修复的问题
本 PR 修复
DeepAgent交互生命周期中的并发竞态:TERMINATED重新写回IDLE;send_input()前完成的运行状态检查,可能在DeepAgent实际判定并入队 fresh turn 前失效。根因
现有实现分散地直接修改
_interaction_phase,部分 producer 只在进入异步边界前检查一次生命周期。此外,fresh/continuation 的最终判定和 work 入队都在DeepAgent的内部锁中完成。宿主只能在调用send_input()前检查运行状态,无法保证该检查在实际入队时仍然有效。这是一个跨异步边界的 TOCTOU 竞态:运行状态在入口处完成检查,但真正入队或修改阶段发生在等待内部锁或异步调用之后;在此期间,并发
stop()或配置更新可能使先前检查失效。修复方案
修复交互生命周期竞态。 统一通过状态转换函数修改交互阶段,并让
InteractionPhase.TERMINATED成为吸收态;在 send、attach、active round 和 supervisor 的关键异步边界后重新检查 runtime;复用现有生命周期锁串行化完整的 start/stop。该修复对所有DeepAgent默认生效,不依赖任何宿主注册。提供
FreshInputContextFactory。 通过DeepAgent.set_fresh_input_context_factory()提供可选的宿主扩展点,仅包围 fresh enqueue,使宿主能够在DeepAgent已判定为 fresh turn、但尚未入队时完成需要原子保护的准备工作。上下文进入失败时不入队,退出异常或取消不覆盖主要入队异常;STEER、FOLLOW_UP 和中断恢复等 continuation 路径保持原行为。该 factory 不承载 Agent Core 自身的生命周期修复;只有需要 fresh-turn 宿主上下文的调用方才需显式注册。验证结果
uv run --frozen pytest tests/unit_tests/harness/test_deep_agent_interaction.py:33 项通过;uv run --frozen ruff check --ignore F841 openjiuwen/harness/deep_agent.py tests/unit_tests/harness/test_deep_agent_interaction.py:通过;git diff --check:通过。自检清单
Linked Closing Issues:
Linked Closing Issues: