Skip to content

Commit e2c89db

Browse files
xgopilotphantom5099
andcommitted
fix(runtime): correct unverified-write state transitions in mixed verify/write turns
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
1 parent 1b78eeb commit e2c89db

2 files changed

Lines changed: 52 additions & 6 deletions

File tree

internal/runtime/turn_control.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,25 @@ func collectCompletionState(
3232

3333
// applyToolExecutionCompletion 更新一轮工具执行后的 completion 事实。
3434
func applyToolExecutionCompletion(current controlplane.CompletionState, summary toolExecutionSummary) controlplane.CompletionState {
35-
if summary.HasSuccessfulWorkspaceWrite {
36-
current.HasUnverifiedWrites = true
35+
if len(summary.Results) == 0 {
36+
if summary.HasSuccessfulWorkspaceWrite {
37+
current.HasUnverifiedWrites = true
38+
}
39+
if summary.HasSuccessfulVerification {
40+
current.HasUnverifiedWrites = false
41+
}
42+
return current
3743
}
38-
if summary.HasSuccessfulVerification {
39-
current.HasUnverifiedWrites = false
44+
for _, result := range summary.Results {
45+
if result.IsError {
46+
continue
47+
}
48+
if result.Facts.WorkspaceWrite {
49+
current.HasUnverifiedWrites = true
50+
}
51+
if result.Facts.VerificationPerformed && result.Facts.VerificationPassed {
52+
current.HasUnverifiedWrites = false
53+
}
4054
}
4155
return current
4256
}

internal/runtime/turn_control_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,52 @@ func TestApplyToolExecutionCompletionTracksWriteAndVerification(t *testing.T) {
2828
t.Parallel()
2929

3030
written := applyToolExecutionCompletion(controlplane.CompletionState{}, toolExecutionSummary{
31-
HasSuccessfulWorkspaceWrite: true,
31+
Results: []tools.ToolResult{
32+
{Facts: tools.ToolExecutionFacts{WorkspaceWrite: true}},
33+
},
3234
})
3335
if !written.HasUnverifiedWrites {
3436
t.Fatalf("expected successful write to require verification, got %+v", written)
3537
}
3638

3739
verified := applyToolExecutionCompletion(written, toolExecutionSummary{
38-
HasSuccessfulVerification: true,
40+
Results: []tools.ToolResult{
41+
{Facts: tools.ToolExecutionFacts{VerificationPerformed: true, VerificationPassed: true}},
42+
},
3943
})
4044
if verified.HasUnverifiedWrites {
4145
t.Fatalf("expected explicit verification to clear pending write, got %+v", verified)
4246
}
4347
}
4448

49+
func TestApplyToolExecutionCompletionKeepsUnverifiedWhenVerifyBeforeWrite(t *testing.T) {
50+
t.Parallel()
51+
52+
got := applyToolExecutionCompletion(controlplane.CompletionState{}, toolExecutionSummary{
53+
Results: []tools.ToolResult{
54+
{Facts: tools.ToolExecutionFacts{VerificationPerformed: true, VerificationPassed: true}},
55+
{Facts: tools.ToolExecutionFacts{WorkspaceWrite: true}},
56+
},
57+
})
58+
if !got.HasUnverifiedWrites {
59+
t.Fatalf("expected write after verify to remain unverified, got %+v", got)
60+
}
61+
}
62+
63+
func TestApplyToolExecutionCompletionClearsWhenVerifyAfterWrite(t *testing.T) {
64+
t.Parallel()
65+
66+
got := applyToolExecutionCompletion(controlplane.CompletionState{}, toolExecutionSummary{
67+
Results: []tools.ToolResult{
68+
{Facts: tools.ToolExecutionFacts{WorkspaceWrite: true}},
69+
{Facts: tools.ToolExecutionFacts{VerificationPerformed: true, VerificationPassed: true}},
70+
},
71+
})
72+
if got.HasUnverifiedWrites {
73+
t.Fatalf("expected verify after write to clear unverified flag, got %+v", got)
74+
}
75+
}
76+
4577
func TestHasPendingAgentTodosBlocksOnAnyNonTerminalTodo(t *testing.T) {
4678
t.Parallel()
4779

0 commit comments

Comments
 (0)