diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_protocol/planning_submit.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_protocol/planning_submit.rs index dd614e229..3736cec90 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_protocol/planning_submit.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_protocol/planning_submit.rs @@ -4484,21 +4484,49 @@ mod tests { context.action_id = pending.action_id.clone(); context.action_fingerprint = pending.action_fingerprint.clone(); - execute_plan_submit_gdd(&root, &context, &input).expect("commit GDD"); + let submit_result = execute_plan_submit_gdd(&root, &context, &input).expect("commit GDD"); assert_eq!( fold_plan_provider_usage_into_session_at_locked(&root) .expect("submit batch must defer final usage"), PlanProviderUsageFoldOutcome::Deferred ); + // Close the child through the production writer rather than a + // hand-rolled terminal state. It stamps the task projection with the + // submit `actionId`, which is what makes the receipt consumption below + // collide on the (runId, actionId, phase) idempotency key. A plain + // `append_game_creator_agent_runtime_task` leaves no keyed row, so the + // collision never happens and this test passes over a lane that fails + // 100% of the time in production. + let delivery = new_static_delegate_delivery( + GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID, + "root-session-001", + &context.root_run_id, + "parent-action-001", + &context.delegation_id, + GAME_CREATOR_PROJECT_PLANNING_AGENT_ID, + &context.session_id, + &context.created_by_run_id, + ); + create_or_read_static_delegate_delivery_at(&root, &delivery) + .expect("create planning delivery"); + mark_static_delegate_delivery_ready_at( + &root, + GAME_CREATOR_PROJECT_PLANNING_AGENT_ID, + &context.session_id, + &context.created_by_run_id, + &context.delegation_id, + "completed", + &format!("Fast GDD v{} 已提交。", submit_result.gdd_ref.version), + ) + .expect("close planning delivery"); let mut child_completed = child_runtime.clone(); - child_completed.status = "completed".to_string(); - child_completed.phase = "completed".to_string(); - child_completed.current_action = "Fast GDD 已提交".to_string(); - child_completed.pending_tool_action = Some(pending.summary()); - append_game_creator_agent_runtime_task(&root, &child_completed) - .expect("append completed planning child task"); - write_game_creator_agent_runtime_state(&root, &child_completed) - .expect("persist completed planning child state"); + ensure_project_planning_submit_child_completion_at( + &root, + &mut child_completed, + &pending, + &submit_result, + ) + .expect("close planning child at the submit point"); let gdd = read_plan_gdd_chain(&root) .expect("read submitted GDD")