Skip to content

Commit 0a04b0d

Browse files
xgopilotphantom5099
authored andcommitted
fix: resolve mainline conflicts for checkpoint diff
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
1 parent 5853ee3 commit 0a04b0d

7 files changed

Lines changed: 18 additions & 16 deletions

File tree

internal/cli/gateway_runtime_bridge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,8 +1722,8 @@ func (b *gatewayRuntimePortBridge) CheckpointDiff(ctx context.Context, input gat
17221722
result, err := cp.CheckpointDiff(ctx, agentruntime.CheckpointDiffInput{
17231723
SessionID: strings.TrimSpace(input.SessionID),
17241724
CheckpointID: strings.TrimSpace(input.CheckpointID),
1725-
RunID: strings.TrimSpace(input.RunID),
17261725
Scope: strings.TrimSpace(input.Scope),
1726+
RunID: strings.TrimSpace(input.RunID),
17271727
})
17281728
if err != nil {
17291729
return gateway.CheckpointDiffResult{}, err

internal/gateway/bootstrap.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,15 +2105,15 @@ func decodeCheckpointDiffPayload(payload any) CheckpointDiffInput {
21052105
SubjectID: strings.TrimSpace(typed.SubjectID),
21062106
SessionID: strings.TrimSpace(typed.SessionID),
21072107
CheckpointID: strings.TrimSpace(typed.CheckpointID),
2108-
RunID: strings.TrimSpace(typed.RunID),
21092108
Scope: strings.TrimSpace(typed.Scope),
2109+
RunID: strings.TrimSpace(typed.RunID),
21102110
}
21112111
case map[string]any:
21122112
return CheckpointDiffInput{
21132113
SessionID: readStringValue(typed, "session_id"),
21142114
CheckpointID: readStringValue(typed, "checkpoint_id"),
2115-
RunID: readStringValue(typed, "run_id"),
21162115
Scope: readStringValue(typed, "scope"),
2116+
RunID: readStringValue(typed, "run_id"),
21172117
}
21182118
default:
21192119
raw, marshalErr := json.Marshal(payload)
@@ -2130,8 +2130,8 @@ func decodeCheckpointDiffPayload(payload any) CheckpointDiffInput {
21302130
return CheckpointDiffInput{
21312131
SessionID: strings.TrimSpace(decoded.SessionID),
21322132
CheckpointID: strings.TrimSpace(decoded.CheckpointID),
2133-
RunID: strings.TrimSpace(decoded.RunID),
21342133
Scope: strings.TrimSpace(decoded.Scope),
2134+
RunID: strings.TrimSpace(decoded.RunID),
21352135
}
21362136
}
21372137
}

internal/gateway/contracts.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ type CheckpointDiffInput struct {
326326
SessionID string `json:"session_id"`
327327
// CheckpointID 是可选的 checkpoint 标识,为空则查最新代码检查点。
328328
CheckpointID string `json:"checkpoint_id,omitempty"`
329-
// RunID 是 run 范围 diff 的运行标识。
330-
RunID string `json:"run_id,omitempty"`
331-
// Scope 控制 diff 范围;为空保持相邻 checkpoint,run 表示本次请求净变更。
329+
// Scope 可选,为 "run" 时按 run_id 做聚合 diff;为空时沿用相邻 checkpoint 对比行为。
332330
Scope string `json:"scope,omitempty"`
331+
// RunID 在 scope=run 时指定目标 run。
332+
RunID string `json:"run_id,omitempty"`
333333
}
334334

335335
// CheckpointDiffResult 描述两个相邻代码检查点之间的差异。

internal/gateway/protocol/jsonrpc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ type UndoRestoreParams struct {
303303
type CheckpointDiffParams struct {
304304
SessionID string `json:"session_id"`
305305
CheckpointID string `json:"checkpoint_id,omitempty"`
306-
RunID string `json:"run_id,omitempty"`
307-
Scope string `json:"scope,omitempty"`
306+
Scope string `json:"scope,omitempty"` // 可选,"run" 表示 run 级聚合 diff
307+
RunID string `json:"run_id,omitempty"` // scope=run 时必需
308308
}
309309

310310
// ResolvePermissionParams 表示 gateway.resolvePermission 参数。
@@ -954,8 +954,8 @@ func decodeCheckpointDiffParams(raw json.RawMessage) (CheckpointDiffParams, *JSO
954954
return decodeParams(raw, "checkpoint.diff", func(p *CheckpointDiffParams) *JSONRPCError {
955955
p.SessionID = strings.TrimSpace(p.SessionID)
956956
p.CheckpointID = strings.TrimSpace(p.CheckpointID)
957-
p.RunID = strings.TrimSpace(p.RunID)
958957
p.Scope = strings.TrimSpace(p.Scope)
958+
p.RunID = strings.TrimSpace(p.RunID)
959959
if p.SessionID == "" {
960960
return NewJSONRPCError(JSONRPCCodeInvalidParams, "missing required field: params.session_id", GatewayCodeMissingRequiredField)
961961
}

internal/runtime/checkpoint_flow_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ func TestCheckpointDiff_ScopeRun_ReturnsAggregateDiff(t *testing.T) {
10261026
if len(modifiedPaths) != 1 || modifiedPaths[0] != "a.txt" {
10271027
t.Fatalf("expected a.txt modified, got added=%v modified=%v", addedPaths, modifiedPaths)
10281028
}
1029-
// CheckpointID should be set to the target (last) checkpoint in the run
1029+
// 当前 run-scope diff 默认返回目标 checkpoint(未显式指定时为最新 checkpoint)。
10301030
if result.CheckpointID != "cp-2" {
10311031
t.Fatalf("CheckpointID = %q, want cp-2", result.CheckpointID)
10321032
}

internal/runtime/checkpoint_restore.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ func (s *Service) restoreCheckpointCore(ctx context.Context, sessionID, checkpoi
7171
records, listErr := s.checkpointStore.ListCheckpoints(ctx, sessionID, checkpoint.ListCheckpointOpts{Limit: 5})
7272
if listErr == nil {
7373
for _, r := range records {
74-
if r.Reason == agentsession.CheckpointReasonEndOfTurn &&
75-
checkpoint.IsPerEditRef(r.CodeCheckpointRef) {
74+
if r.Reason == agentsession.CheckpointReasonEndOfTurn && checkpoint.IsPerEditRef(r.CodeCheckpointRef) {
7675
fallbackRef = r.CodeCheckpointRef
7776
break
7877
}
@@ -304,8 +303,8 @@ func (s *Service) updateRuntimeSessionAfterRestore(sessionID string, head agents
304303
type CheckpointDiffInput struct {
305304
SessionID string `json:"session_id"`
306305
CheckpointID string `json:"checkpoint_id,omitempty"` // 可选,为空则查最新代码检查点
307-
RunID string `json:"run_id,omitempty"`
308-
Scope string `json:"scope,omitempty"`
306+
Scope string `json:"scope,omitempty"` // 可选,"run" 表示 run 级聚合 diff
307+
RunID string `json:"run_id,omitempty"` // scope=run 时指定目标 run
309308
}
310309

311310
// CheckpointDiffResult 描述两个相邻代码检查点之间的差异。

internal/runtime/run.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@ func (s *Service) Run(ctx context.Context, input UserInput) (err error) {
104104
}
105105
if statePtr != nil && s.perEditStore != nil && statePtr.baselineCheckpointID != "" && statePtr.lastEndOfTurnCheckpointID != "" {
106106
runEndCtx := context.Background()
107-
records, listErr := s.checkpointStore.ListCheckpoints(runEndCtx, statePtr.session.ID, checkpoint.ListCheckpointOpts{RunID: statePtr.runID})
107+
records, listErr := s.checkpointStore.ListCheckpoints(runEndCtx, statePtr.session.ID, checkpoint.ListCheckpointOpts{})
108108
if listErr == nil {
109109
var perEditIDs []string
110110
for _, r := range records {
111+
if strings.TrimSpace(r.RunID) != statePtr.runID {
112+
continue
113+
}
111114
if checkpoint.IsPerEditRef(r.CodeCheckpointRef) {
112115
perEditIDs = append(perEditIDs, checkpoint.PerEditCheckpointIDFromRef(r.CodeCheckpointRef))
113116
}

0 commit comments

Comments
 (0)