Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
better logging timestamps, added logging around builds, and fix for duplicate results issue
Dane Schneiderb76b3cf0bb4c
diff --git a/app/server/main.go b/app/server/main.goindex cbe4085f..d65de4c2 100644--- a/app/server/main.go+++ b/app/server/main.go@@ -1,12 +1,16 @@package mainimport (+ "log""plandex-server/setup""github.com/gorilla/mux")func main() {+ // Configure the default logger to include milliseconds in timestamps+ log.SetFlags(log.LstdFlags | log.Lmicroseconds)+r := mux.NewRouter()setup.MustLoadIp()setup.MustInitDb()diff --git a/app/server/model/plan/build_exec.go b/app/server/model/plan/build_exec.goindex a7c0345c..c790e56e 100644--- a/app/server/model/plan/build_exec.go+++ b/app/server/model/plan/build_exec.go@@ -158,6 +158,8 @@ func (buildState *activeBuildStreamState) execPlanBuild(activeBuild *types.ActivfilePath: filePath,activeBuild: activeBuild,}++ log.Println("execPlanBuild - fileState.loadBuildFile()")err := fileState.loadBuildFile(activeBuild)if err != nil {log.Printf("Error loading build file: %v\n", err)@@ -165,8 +167,10 @@ func (buildState *activeBuildStreamState) execPlanBuild(activeBuild *types.Activ}if activeBuild.IsVerification {+ log.Println("execPlanBuild - fileState.verifyFileBuild()")fileState.verifyFileBuild()} else {+ log.Println("execPlanBuild - fileState.buildFile()")fileState.buildFile()}}@@ -189,10 +193,12 @@ func (fileState *activeBuildStreamFileState) buildFile() {log.Printf("Building file %s\n", filePath)- log.Println("activePlan.ContextsByPath files:")- for k := range activePlan.ContextsByPath {- log.Println(k)- }+ log.Printf("%d files in context\n", len(activePlan.ContextsByPath))++ // log.Println("activePlan.ContextsByPath files:")+ // for k := range activePlan.ContextsByPath {+ // log.Println(k)+ // }// get relevant file context (if any)contextPart := activePlan.ContextsByPath[filePath]@@ -369,6 +375,9 @@ func (fileState *activeBuildStreamFileState) buildFileLineNums() {Temperature: config.Temperature,TopP: config.TopP,ResponseFormat: responseFormat,+ StreamOptions: &openai.StreamOptions{+ IncludeUsage: true,+ },}envVar := config.BaseModelConfig.ApiKeyEnvVar@@ -382,6 +391,7 @@ func (fileState *activeBuildStreamFileState) buildFileLineNums() {return}+ log.Printf("File %s: calling listenStreamChangesWithLineNums\n", filePath)go fileState.listenStreamChangesWithLineNums(stream)} else {@@ -423,6 +433,9 @@ func (fileState *activeBuildStreamFileState) buildFileLineNums() {return}+ // log the file path+ log.Printf("File %s: calling onBuildResult after non-streaming build\n", filePath)+fileState.onBuildResult(res)}diff --git a/app/server/model/plan/build_finish.go b/app/server/model/plan/build_finish.goindex a8bec870..6f513c2e 100644--- a/app/server/model/plan/build_finish.go+++ b/app/server/model/plan/build_finish.go@@ -280,6 +280,7 @@ func (fileState *activeBuildStreamFileState) onFinishBuildFile(planRes *db.PlanFif planRes.IsFix {if planRes.FixEpoch >= FixSyntaxEpochs-1 {// we're out of retries, just continue on to queue processing+ log.Printf("Out of retries for syntax fix for file %s\n", filePath)} else {fileState.syntaxNumEpoch++fileState.syntaxNumRetry = 0@@ -287,6 +288,7 @@ func (fileState *activeBuildStreamFileState) onFinishBuildFile(planRes *db.PlanFfileState.syntaxErrors = planRes.SyntaxErrorsfileState.preBuildState = fileState.updatedfileState.updated = updated+ log.Printf("Retrying syntax fix for file %s\n", filePath)go fileState.fixFileLineNums()return}@@ -295,6 +297,7 @@ func (fileState *activeBuildStreamFileState) onFinishBuildFile(planRes *db.PlanFfileState.syntaxErrors = planRes.SyntaxErrorsfileState.preBuildState = fileState.updatedfileState.updated = updated+ log.Printf("Fixing syntax for file %s\n", filePath)go fileState.fixFileLineNums()return}@@ -347,6 +350,8 @@ func (fileState *activeBuildStreamFileState) onFinishBuildFile(planRes *db.PlanFfileState.onFinishBuild()}} else {+ log.Println("Triggering verification build")+go fileState.execPlanBuild(&types.ActiveBuild{ReplyId: activeBuild.ReplyId,FileDescription: activeBuild.FileDescription,diff --git a/app/server/model/plan/build_fix.go b/app/server/model/plan/build_fix.goindex f73005d4..2984ee74 100644--- a/app/server/model/plan/build_fix.go+++ b/app/server/model/plan/build_fix.go@@ -122,6 +122,9 @@ func (fileState *activeBuildStreamFileState) fixFileLineNums() {Temperature: config.Temperature,TopP: config.TopP,ResponseFormat: responseFormat,+ StreamOptions: &openai.StreamOptions{+ IncludeUsage: true,+ },}envVar := config.BaseModelConfig.ApiKeyEnvVardiff --git a/app/server/model/plan/build_fix_stream.go b/app/server/model/plan/build_fix_stream.goindex 7ada737d..00e3adcf 100644--- a/app/server/model/plan/build_fix_stream.go+++ b/app/server/model/plan/build_fix_stream.go@@ -74,14 +74,13 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openselect {case <-activePlan.Ctx.Done():// The main context was canceled (not the timer)- if !streamFinished {- execHookOnStop(false)- }+ execHookOnStop(false)returncase <-timer.C:log.Println("\nFix: stream timed out due to inactivity")execHookOnStop(true)+if streamFinished {log.Println("\nFix stream finished-timed out waiting for usage chunk")return@@ -100,14 +99,18 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *opentimer.Reset(model.OPENAI_STREAM_CHUNK_TIMEOUT)} else {log.Printf("listenStreamFixChanges - File %s: Error receiving stream chunk: %v\n", filePath, err)- execHookOnStop(true)if err == context.Canceled {log.Printf("listenStreamFixChanges - File %s: Stream canceled\n", filePath)+ execHookOnStop(false)return}- fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream error: %v", err))+ execHookOnStop(true)++ if !streamFinished {+ fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream error: %v", err))+ }return}@@ -152,6 +155,12 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openreturn}+ // if stream finished and it's not a usage chunk, keep listening for usage chunk+ if streamFinished {+ log.Printf("listenStreamFixChanges - File %s: Stream finished, no usage chunk-will keep listening\n", filePath)+ continue+ }+var content stringchoice := response.Choices[0]delta := choice.Delta@@ -206,6 +215,8 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *openlog.Printf("listenStreamFixChanges - File %s: Parsed streamed replacements\n", filePath)// spew.Dump(streamed)streamFinished = true // Stream finished successfully++ log.Printf("listenStreamFixChanges - File %s: Stream finished\n", filePath)fileState.onFixResult(streamed)// Reset the timer for the usage chunkdiff --git a/app/server/model/plan/build_load.go b/app/server/model/plan/build_load.goindex 1e317c30..1dd4e1c8 100644--- a/app/server/model/plan/build_load.go+++ b/app/server/model/plan/build_load.go@@ -200,6 +200,7 @@ func (state *activeBuildStreamFileState) loadBuildFile(activeBuild *types.ActiveerrCh := make(chan error)go func() {+ log.Println("loadBuildFile - Getting current plan state")res, err := db.GetCurrentPlanState(db.CurrentPlanStateParams{OrgId: currentOrgId,PlanId: planId,diff --git a/app/server/model/plan/build_result.go b/app/server/model/plan/build_result.goindex 06a55d47..cdabce0d 100644--- a/app/server/model/plan/build_result.go+++ b/app/server/model/plan/build_result.go@@ -54,15 +54,6 @@ func GetPlanResult(ctx context.Context, params PlanResultParams) (*db.PlanFileRepreBuildStateLines := strings.Split(preBuildState, "\n")- // log.Printf("\n\ngetPlanResult - path: %s\n", filePath)- // log.Println("getPlanResult - preBuildState:")- // log.Println(preBuildState)- // log.Println("getPlanResult - preBuildStateLines:")- // log.Println(preBuildStateLines)- // log.Println("getPlanResult - fileContent:")- // log.Println(fileContent)- // log.Print("\n\n")-var replacements []*shared.Replacementvar highestEndLine int = 0@@ -73,7 +64,6 @@ func GetPlanResult(ctx context.Context, params PlanResultParams) (*db.PlanFileRe}var old string-new := streamedChange.Newif streamedChange.Old.EntireFile {@@ -86,34 +76,30 @@ func GetPlanResult(ctx context.Context, params PlanResultParams) (*db.PlanFileRecontinue}- // log.Printf("getPlanResult - streamedChange.Old.StartLine: %d\n", streamedChange.Old.StartLine)- // log.Printf("getPlanResult - streamedChange.Old.EndLine: %d\n", streamedChange.Old.EndLine)-startLine, endLine, err := streamedChange.GetLines()-if err != nil {- log.Println("getPlanResult - Error getting lines from streamedChange:", err)+ log.Printf("getPlanResult - File %s: Error getting lines from streamedChange: %v\n", filePath, err)return nil, "", false, fmt.Errorf("error getting lines from streamedChange: %v", err)}if startLine > len(preBuildStateLines) {- log.Printf("Start line is greater than preBuildStateLines length: %d > %d\n", startLine, len(preBuildStateLines))+ log.Printf("getPlanResult - File %s: Start line is greater than preBuildStateLines length: %d > %d\n", filePath, startLine, len(preBuildStateLines))return nil, "", false, fmt.Errorf("start line is greater than preBuildStateLines length: %d > %d", startLine, len(preBuildStateLines))}if endLine < 1 {- log.Printf("End line is less than 1: %d\n", endLine)+ log.Printf("getPlanResult - File %s: End line is less than 1: %d\n", filePath, endLine)return nil, "", false, fmt.Errorf("end line is less than 1: %d", endLine)}if endLine > len(preBuildStateLines) {- log.Printf("End line is greater than preBuildStateLines length: %d > %d\n", endLine, len(preBuildStateLines))+ log.Printf("getPlanResult - File %s: End line is greater than preBuildStateLines length: %d > %d\n", filePath, endLine, len(preBuildStateLines))return nil, "", false, fmt.Errorf("end line is greater than preBuildStateLines length: %d > %d", endLine, len(preBuildStateLines))}if startLine < highestEndLine {- log.Printf("Start line is less than highestEndLine: %d < %d\n", startLine, highestEndLine)+ log.Printf("getPlanResult - File %s: Start line is less than highestEndLine: %d < %d\n", filePath, startLine, highestEndLine)- log.Printf("streamedChange:\n")+ log.Printf("getPlanResult - File %s: streamedChange:\n", filePath)log.Println(spew.Sdump(streamedChangesWithLineNums))if params.OverlapStrategy == OverlapStrategyError {@@ -126,7 +112,7 @@ func GetPlanResult(ctx context.Context, params PlanResultParams) (*db.PlanFileReif endLine < highestEndLine {if params.OverlapStrategy == OverlapStrategyError {- log.Printf("End line is less than highestEndLine: %d < %d\n", endLine, highestEndLine)+ log.Printf("getPlanResult - File %s: End line is less than highestEndLine: %d < %d\n", filePath, endLine, highestEndLine)return nil, "", false, fmt.Errorf("end line is less than highestEndLine: %d < %d", endLine, highestEndLine)} else {continue@@ -143,8 +129,6 @@ func GetPlanResult(ctx context.Context, params PlanResultParams) (*db.PlanFileReold = strings.Join(preBuildStateLines[startLine-1:endLine], "\n")}- // log.Printf("getPlanResult - old: %s\n", old)-replacement := &shared.Replacement{Old: old,New: new,@@ -154,22 +138,12 @@ func GetPlanResult(ctx context.Context, params PlanResultParams) (*db.PlanFileRereplacements = append(replacements, replacement)}- log.Println("Will apply replacements")- // log.Println("preBuildState:", preBuildState)-- // log.Println("Replacements:")- // spew.Dump(replacements)+ log.Printf("getPlanResult - File %s: Will apply replacements\n", filePath)updated, allSucceeded := shared.ApplyReplacements(preBuildState, replacements, true)updated = shared.RemoveLineNums(updated)- // log sha256 hash of updated content- // hash := sha256.Sum256([]byte(updated))- // sha := hex.EncodeToString(hash[:])-- // log.Printf("apply result - %s - updated content hash: %s\n", filePath, sha)-for _, replacement := range replacements {id := uuid.New().String()replacement.Id = id@@ -194,26 +168,23 @@ func GetPlanResult(ctx context.Context, params PlanResultParams) (*db.PlanFileRe}if params.CheckSyntax {- // validate syntax (if we have a parser)validationRes, err := syntax.Validate(ctx, filePath, updated)-if err != nil {- log.Println("Error validating syntax:", err)+ log.Printf("getPlanResult - File %s: Error validating syntax: %v\n", filePath, err)return nil, "", false, fmt.Errorf("error validating syntax: %v", err)}res.WillCheckSyntax = validationRes.HasParser && !validationRes.TimedOutres.SyntaxValid = validationRes.Validres.SyntaxErrors = validationRes.Errors-}- // spew.Dump(res)-return &res, updated, allSucceeded, nil}func (fileState *activeBuildStreamFileState) onBuildResult(res types.ChangesWithLineNums) {+ log.Printf("onBuildResult - File: %s\n", fileState.filePath)+filePath := fileState.filePathbuild := fileState.buildcurrentOrgId := fileState.currentOrgId@@ -224,7 +195,7 @@ func (fileState *activeBuildStreamFileState) onBuildResult(res types.ChangesWithactivePlan := GetActivePlan(planId, branch)if activePlan == nil {- log.Printf("listenStream - Active plan not found for plan ID %s on branch %s\n", planId, branch)+ log.Printf("onBuildResult - File %s: Active plan not found for plan ID %s on branch %s\n", filePath, planId, branch)return}@@ -241,26 +212,28 @@ func (fileState *activeBuildStreamFileState) onBuildResult(res types.ChangesWithvar iStartLine intvar jStartLine int- // Convert the line number part to an integeriStartLine, _, err := sorted[i].GetLines()if err != nil {- log.Printf("listenStream - Error getting start line for change %v: %v\n", sorted[i], err)- fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - error getting start line for change %v: %v", sorted[i], err))+ log.Printf("onBuildResult - File %s: Error getting start line for change %v: %v\n", filePath, sorted[i], err)+ fileState.lineNumsRetryOrError(fmt.Errorf("onBuildResult - error getting start line for change %v: %v", sorted[i], err))return false}jStartLine, _, err = sorted[j].GetLines()if err != nil {- log.Printf("listenStream - Error getting start line for change %v: %v\n", sorted[j], err)- fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - error getting start line for change %v: %v", sorted[j], err))+ log.Printf("onBuildResult - File %s: Error getting start line for change %v: %v\n", filePath, sorted[j], err)+ fileState.lineNumsRetryOrError(fmt.Errorf("onBuildResult - error getting start line for change %v: %v", sorted[j], err))return false}return iStartLine < jStartLine})+ log.Printf("onBuildResult - File %s: fileState.streamedChangesWithLineNums = sorted\n", filePath)+ log.Printf("onBuildResult - File %s: num changes: %d\n", filePath, len(sorted))+fileState.streamedChangesWithLineNums = sortedvar overlapStrategy OverlapStrategy = OverlapStrategyError@@ -284,21 +257,20 @@ func (fileState *activeBuildStreamFileState) onBuildResult(res types.ChangesWith)if err != nil {- log.Println("listenStream - Error getting plan result:", err)- fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - error getting plan result for file '%s': %v", filePath, err))+ log.Printf("onBuildResult - File %s: Error getting plan result: %v\n", filePath, err)+ fileState.lineNumsRetryOrError(fmt.Errorf("onBuildResult - error getting plan result for file '%s': %v", filePath, err))return}if !allSucceeded {- log.Println("listenStream - Failed replacements:")+ log.Printf("onBuildResult - File %s: Failed replacements:\n", filePath)for _, replacement := range planFileResult.Replacements {if replacement.Failed {spew.Dump(replacement)}}- // no retry here as this should never happen- fileState.onBuildFileError(fmt.Errorf("listenStream - replacements failed for file '%s'", filePath))+ fileState.onBuildFileError(fmt.Errorf("onBuildResult - replacements failed for file '%s'", filePath))return}@@ -315,8 +287,8 @@ func (fileState *activeBuildStreamFileState) onBuildResult(res types.ChangesWithfileState.updated = updatedFile- log.Println("build stream - Plan file result:", planFileResult != nil)- log.Printf("updatedFile exists: %v\n", updatedFile != "")+ log.Printf("onBuildResult - File %s: Plan file result: %v\n", filePath, planFileResult != nil)+ log.Printf("onBuildResult - File %s: updatedFile exists: %v\n", filePath, updatedFile != "")fileState.onFinishBuildFile(planFileResult, updatedFile)}@@ -326,18 +298,18 @@ func (fileState *activeBuildStreamFileState) lineNumsRetryOrError(err error) {fileState.lineNumsNumRetry++fileState.activeBuild.WithLineNumsBuffer = ""fileState.activeBuild.WithLineNumsBufferTokens = 0- log.Printf("Retrying line nums build file '%s' due to error: %v\n", fileState.filePath, err)+ log.Printf("lineNumsRetryOrError - Retrying line nums build file '%s' due to error: %v\n", fileState.filePath, err)activePlan := GetActivePlan(fileState.plan.Id, fileState.branch)if activePlan == nil {- log.Println("lineNumsRetryOrError - Active plan not found")+ log.Printf("lineNumsRetryOrError - File %s: Active plan not found\n", fileState.filePath)return}select {case <-activePlan.Ctx.Done():- log.Println("lineNumsRetryOrError - Context canceled. Exiting.")+ log.Printf("lineNumsRetryOrError - File %s: Context canceled. Exiting.\n", fileState.filePath)returncase <-time.After(time.Duration((fileState.verifyFileNumRetry*fileState.verifyFileNumRetry)/2)*200*time.Millisecond + time.Duration(rand.Intn(500))*time.Millisecond):breakdiff --git a/app/server/model/plan/build_stream_line_nums.go b/app/server/model/plan/build_stream_line_nums.goindex 69c9bad6..8cc3799a 100644--- a/app/server/model/plan/build_stream_line_nums.go+++ b/app/server/model/plan/build_stream_line_nums.go@@ -23,6 +23,8 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(strplanId := fileState.plan.Idbranch := fileState.branch+ log.Printf("listenStream - Listening for streamed changes with line numbers for file %s\n", filePath)+activePlan := GetActivePlan(planId, branch)if activePlan == nil {@@ -70,13 +72,13 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str}}+ log.Printf("listenStream - File %s: Listening for stream chunks\n", filePath)+for {select {case <-activePlan.Ctx.Done():// The main context was canceled (not the timer)- if !streamFinished {- execHookOnStop(false)- }+ execHookOnStop(false)returncase <-timer.C:log.Println("\nBuild: stream timed out due to inactivity")@@ -99,22 +101,26 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(strtimer.Reset(model.OPENAI_STREAM_CHUNK_TIMEOUT)} else {log.Printf("listenStream - File %s: Error receiving stream chunk: %v\n", filePath, err)- execHookOnStop(true)if err == context.Canceled {log.Printf("listenStream - File %s: Stream canceled\n", filePath)// log.Println("current buffer:")// log.Println(fileState.activeBuild.WithLineNumsBuffer)+ execHookOnStop(false)return}- fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream error for file '%s': %v", filePath, err))+ execHookOnStop(true)++ if !streamFinished {+ fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream error for file '%s': %v", filePath, err))+ }return}if len(response.Choices) == 0 {if response.Usage != nil {- log.Println("Build stream usage:")+ log.Printf("listenStream - File %s: Stream usage chunk\n", filePath)spew.Dump(response.Usage)_, apiErr := hooks.ExecHook(hooks.DidSendModelRequest, hooks.HookParams{@@ -153,6 +159,12 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(strreturn}+ // if stream finished and it's not a usage chunk, keep listening for usage chunk+ if streamFinished {+ log.Printf("listenStream - File %s: Stream finished, no usage chunk-will keep listening\n", filePath)+ continue+ }+choice := response.Choices[0]var content stringdelta := response.Choices[0].Delta@@ -208,6 +220,8 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str// spew.Dump(streamed)streamFinished = true // Stream finished successfully++ log.Printf("listenStream - File %s: calling onBuildResult\n", filePath)fileState.onBuildResult(streamed)// Reset the timer for the usage chunk@@ -216,6 +230,8 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str}timer.Reset(model.OPENAI_USAGE_CHUNK_TIMEOUT)+ log.Printf("listenStream - File %s: continue for usage chunk\n", filePath)+continue // continue for usage chunk} else if len(delta.ToolCalls) == 0 {log.Println("listenStream - Stream chunk missing function call.")diff --git a/app/server/model/plan/build_verify.go b/app/server/model/plan/build_verify.goindex bdf9ce69..e0ce5dbf 100644--- a/app/server/model/plan/build_verify.go+++ b/app/server/model/plan/build_verify.go@@ -106,6 +106,7 @@ func (fileState *activeBuildStreamFileState) verifyFileBuild() {},})if apiErr != nil {+ log.Printf("verifyFileBuild - Error executing will send model request hook: %v\n", apiErr)activePlan.StreamDoneCh <- apiErrreturn}@@ -139,6 +140,9 @@ func (fileState *activeBuildStreamFileState) verifyFileBuild() {Temperature: config.Temperature,TopP: config.TopP,ResponseFormat: responseFormat,+ StreamOptions: &openai.StreamOptions{+ IncludeUsage: true,+ },}envVar := config.BaseModelConfig.ApiKeyEnvVardiff --git a/app/server/model/plan/build_verify_stream.go b/app/server/model/plan/build_verify_stream.goindex 90c5c730..3937c211 100644--- a/app/server/model/plan/build_verify_stream.go+++ b/app/server/model/plan/build_verify_stream.go@@ -74,19 +74,18 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *opselect {case <-activePlan.Ctx.Done():// The main context was canceled (not the timer)- if !streamFinished {- execHookOnStop(false)- }+ execHookOnStop(false)returncase <-timer.C:log.Println("\nVerify: stream timeout due to inactivity")++ execHookOnStop(true)+if streamFinished {log.Println("\nVerify stream finished-timed out waiting for usage chunk")return}- // Timer triggered because no new chunk was received in time- execHookOnStop(false)fileState.verifyRetryOrAbort(fmt.Errorf("listenStreamVerifyOutput - stream timeout due to inactivity for file '%s'", filePath))returndefault:@@ -100,14 +99,18 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *optimer.Reset(model.OPENAI_STREAM_CHUNK_TIMEOUT)} else {log.Printf("listenStreamVerifyOutput - File %s: Error receiving stream chunk: %v\n", filePath, err)- execHookOnStop(false)if err == context.Canceled {log.Printf("listenStreamVerifyOutput - File %s: Stream canceled\n", filePath)+ execHookOnStop(false)return}- fileState.verifyRetryOrAbort(fmt.Errorf("listenStreamVerifyOutput - stream error: %v", err))+ execHookOnStop(true)++ if !streamFinished {+ fileState.verifyRetryOrAbort(fmt.Errorf("listenStreamVerifyOutput - stream error: %v", err))+ }return}@@ -148,11 +151,17 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *opreturn}- execHookOnStop(false)+ execHookOnStop(true)fileState.verifyRetryOrAbort(fmt.Errorf("listenStreamVerifyOutput - stream error: no choices"))return}+ // if stream finished and it's not a usage chunk, keep listening for usage chunk+ if streamFinished {+ log.Printf("listenStreamVerifyOutput - File %s: Stream finished, no usage chunk-will keep listening\n", filePath)+ continue+ }+choice := response.Choices[0]var content stringdelta := choice.Delta@@ -163,7 +172,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *optrimmed := strings.TrimSpace(content)if trimmed == "{%invalidjson%}" || trimmed == "``(no output)``````" {log.Println("File", filePath+":", "%invalidjson%} token in streamed chunk")- execHookOnStop(false)+ execHookOnStop(true)fileState.verifyRetryOrAbort(fmt.Errorf("invalid JSON in streamed chunk for file '%s'", filePath))return}@@ -191,6 +200,8 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *oplog.Printf("listenStreamVerifyOutput - File %s: Parsed streamed verify result\n", filePath)// spew.Dump(streamed)streamFinished = true // Stream finished successfully++ log.Printf("listenStreamVerifyOutput - File %s: Streamed verify result\n", filePath)fileState.onVerifyResult(streamed)// Reset the timer for the usage chunk@@ -204,7 +215,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *oplog.Printf("listenStreamVerifyOuput - File %s: Stream chunk missing function call. Reason: %s\n", filePath, choice.FinishReason)- execHookOnStop(false)+ execHookOnStop(true)fileState.verifyRetryOrAbort(fmt.Errorf("listenStreamVerifyOutput - stream chunk missing function call. Reason: %s, File: %s", choice.FinishReason, filePath))}}diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.goindex d8beb6be..ee733275 100644--- a/app/server/model/plan/tell_exec.go+++ b/app/server/model/plan/tell_exec.go@@ -274,7 +274,8 @@ func execTellPlan(// if the user is continuing the plan, we need to check whether the previous message was a user message or assistant messagelastMessage := state.messages[len(state.messages)-1]- log.Println("User is continuing plan. Last message:\n\n", lastMessage.Content)+ log.Println("User is continuing plan. Last message role:", lastMessage.Role)+ // log.Println("User is continuing plan. Last message:\n\n", lastMessage.Content)if lastMessage.Role == openai.ChatMessageRoleUser {// if last message was a user message, we want to remove it from the messages array and then use that last message as the prompt so we can continue from where the user left offdiff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.goindex 98addee6..5e612b81 100644--- a/app/server/model/plan/tell_stream.go+++ b/app/server/model/plan/tell_stream.go@@ -96,17 +96,14 @@ mainLoop:case <-active.Ctx.Done():// The main modelContext was canceled (not the timer)log.Println("\nTell: stream canceled")-- if !streamFinished {- execHookOnStop(false)- }-+ execHookOnStop(false)returncase <-timer.C:// Timer triggered because no new chunk was received in timelog.Println("\nTell: stream timeout due to inactivity")if streamFinished {log.Println("Tell stream finished—timed out waiting for usage chunk")+ execHookOnStop(true)return} else {state.onError(fmt.Errorf("stream timeout due to inactivity"), true, "", "")@@ -122,14 +119,16 @@ mainLoop:<-timer.C}timer.Reset(model.OPENAI_STREAM_CHUNK_TIMEOUT)- }-- if err != nil {+ } else {if err.Error() == "context canceled" {log.Println("Tell: stream context canceled")- execHookOnStop(true)+ execHookOnStop(false)return}++ log.Printf("Tell: error receiving stream chunk: %v\n", err)+ execHookOnStop(true)+ return}if len(response.Choices) == 0 {@@ -173,6 +172,12 @@ mainLoop:continue mainLoop}+ // if stream finished and it's not a usage chunk, keeep listening for usage chunk+ if streamFinished {+ log.Println("Tell stream finished—no usage chunk-will keep listening")+ continue+ }+if len(response.Choices) > 1 {state.onError(fmt.Errorf("stream finished with more than one choice"), true, "", "")continue mainLoopdiff --git a/app/shared/plan_result_replacements.go b/app/shared/plan_result_replacements.goindex 5bf3a3d1..5788dc13 100644--- a/app/shared/plan_result_replacements.go+++ b/app/shared/plan_result_replacements.go@@ -15,9 +15,9 @@ func ApplyReplacements(content string, replacements []*Replacement, setFailed bolastInsertedIdx := 0for i, replacement := range replacements {- log.Println("replacement.Old:\n", replacement.Old)- log.Println("updated:\n", updated)- log.Println("lastInsertedIdx:", lastInsertedIdx)+ // log.Println("replacement.Old:\n", replacement.Old)+ // log.Println("updated:\n", updated)+ // log.Println("lastInsertedIdx:", lastInsertedIdx)pre := updated[:lastInsertedIdx]sub := updated[lastInsertedIdx:]@@ -43,14 +43,14 @@ func ApplyReplacements(content string, replacements []*Replacement, setFailed bo}log.Println("Replacement failed at index:", i)- log.Println("Replacement:")- log.Println(spew.Sdump(replacement))+ // log.Println("Replacement:")+ // log.Println(spew.Sdump(replacement))- log.Println("Updated:")- log.Println(updated)+ // log.Println("Updated:")+ // log.Println(updated)- log.Println("All replacements:")- log.Println(spew.Sdump(replacements))+ // log.Println("All replacements:")+ // log.Println(spew.Sdump(replacements))return updated, i@@ -126,7 +126,11 @@ func (planState *CurrentPlanState) GetFilesBeforeReplacement(for path, planResults := range planRes.FileResultsByPath {updated := files[path]- // log.Println("path: ", path)+ log.Println("path: ", path)+ log.Println("planResults: ", len(planResults))+ // spew.Dump(planResults)+ // log.Println("before PlanResLoop updated:")+ // log.Println(updated)PlanResLoop:for _, planRes := range planResults {@@ -166,8 +170,8 @@ func (planState *CurrentPlanState) GetFilesBeforeReplacement(updated = context.Bodyshas[path] = context.Sha- log.Println("setting updated content to context body. updated:")- log.Println(updated)+ log.Println("setting updated content to context body")+ // log.Println(updated)}replacements := []*Replacement{}@@ -194,19 +198,21 @@ func (planState *CurrentPlanState) GetFilesBeforeReplacement(maybeWithLineNums = AddLineNums(updated)}- log.Println("Before replacements. updated:")- log.Println(updated)+ // log.Println("Before replacements. updated:")+ // log.Println(updated)updated, allSucceeded = ApplyReplacements(maybeWithLineNums, replacements, false)updated = RemoveLineNums(updated)if !allSucceeded {- log.Println("updated:")- log.Println(updated)+ log.Println("Failed to apply replacements")++ // log.Println("replacements:")+ // log.Println(spew.Sdump(replacements))- log.Println("replacements:")- log.Println(spew.Sdump(replacements))+ // log.Println("updated:")+ // log.Println(updated)return nil, fmt.Errorf("plan replacement failed - %s", path)}