From dfd94bac33fd0e60dc24be382c78e8605a5f1dc7 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 20 Aug 2025 22:41:19 -0700 Subject: [PATCH] fix: redux bug --- .../redux/thunks/handleApplyStateUpdate.ts | 10 +++-- gui/src/util/editOutcomeLogger.ts | 38 +++++++++++++------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/gui/src/redux/thunks/handleApplyStateUpdate.ts b/gui/src/redux/thunks/handleApplyStateUpdate.ts index 93cf117cb..6c5c360fe 100644 --- a/gui/src/redux/thunks/handleApplyStateUpdate.ts +++ b/gui/src/redux/thunks/handleApplyStateUpdate.ts @@ -67,15 +67,17 @@ export const handleApplyStateUpdate = createAsyncThunk< logToolUsage(toolCallState, accepted, true, extra.ideMessenger); // Log edit outcome for Agent Mode - const newState = + const newApplyState = getState().session.codeBlockApplyStates.states.find( (s) => s.streamId === applyState.streamId, ); - - if (newState) { + const newState = getState(); + if (newApplyState) { void logAgentModeEditOutcome( + newState.session.history, + newState.config.config, toolCallState, - newState, + newApplyState, accepted, extra.ideMessenger, ); diff --git a/gui/src/util/editOutcomeLogger.ts b/gui/src/util/editOutcomeLogger.ts index 124f11ed3..e7e51bb49 100644 --- a/gui/src/util/editOutcomeLogger.ts +++ b/gui/src/util/editOutcomeLogger.ts @@ -1,18 +1,23 @@ -import { ApplyState, ToolCallState } from "core"; +import { + ApplyState, + BrowserSerializedContinueConfig, + ToolCallState, +} from "core"; import { IIdeMessenger } from "../context/IdeMessenger"; -import { store } from "../redux/store"; +import { ChatHistoryItemWithMessageId } from "../redux/slices/sessionSlice"; /** * Extract model information from tool call state */ -function extractModelInfo(toolCallState: ToolCallState): { +function extractModelInfo( + history: ChatHistoryItemWithMessageId[], + config: BrowserSerializedContinueConfig, + toolCallState: ToolCallState, +): { modelProvider: string; modelName: string; modelTitle: string; } { - // Get the conversation history to find the model info - const history = store.getState().session.history; - // Find the assistant message that contains this tool call const assistantMessage = history.find( (item) => @@ -35,7 +40,6 @@ function extractModelInfo(toolCallState: ToolCallState): { } // Fallback to config if not found in message - const config = store.getState().config.config; const chatModel = config?.selectedModelByRole?.chat; return { @@ -48,12 +52,13 @@ function extractModelInfo(toolCallState: ToolCallState): { /** * Extract prompt and completion from tool call state */ -function extractPromptAndCompletion(toolCallState: ToolCallState): { +function extractPromptAndCompletion( + history: ChatHistoryItemWithMessageId[], + toolCallState: ToolCallState, +): { prompt: string; completion: string; } { - const history = store.getState().session.history; - // Find the assistant message with this tool call const assistantMessageIndex = history.findIndex( (item) => @@ -144,12 +149,17 @@ function extractCodeChanges(applyState: ApplyState): { * Assemble complete edit outcome data from tool call and apply state */ export function assembleEditOutcomeData( + history: ChatHistoryItemWithMessageId[], + config: BrowserSerializedContinueConfig, toolCallState: ToolCallState, applyState: ApplyState, accepted: boolean, ) { - const modelInfo = extractModelInfo(toolCallState); - const promptAndCompletion = extractPromptAndCompletion(toolCallState); + const modelInfo = extractModelInfo(history, config, toolCallState); + const promptAndCompletion = extractPromptAndCompletion( + history, + toolCallState, + ); const codeChanges = extractCodeChanges(applyState); return { @@ -174,6 +184,8 @@ export function assembleEditOutcomeData( * Log Agent Mode edit outcome to editOutcome.jsonl */ export async function logAgentModeEditOutcome( + history: ChatHistoryItemWithMessageId[], + config: BrowserSerializedContinueConfig, toolCallState: ToolCallState, applyState: ApplyState, accepted: boolean, @@ -182,6 +194,8 @@ export async function logAgentModeEditOutcome( // Use the original file content stored in applyState, captured before edits were applied const editOutcomeData = assembleEditOutcomeData( + history, + config, toolCallState, applyState, accepted,