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
Add session tracking to stream handling and improve error reporting
Dane Schneiderbae7e5d20b02
diff --git a/app/server/model/plan/tell_state.go b/app/server/model/plan/tell_state.goindex d0fab7f7..a8a853a7 100644--- a/app/server/model/plan/tell_state.go+++ b/app/server/model/plan/tell_state.go@@ -51,10 +51,13 @@ type activeTellStreamState struct {chunkProcessor *chunkProcessorgenerationId string- requestStartedAt time.Time- firstTokenAt time.Time- originalReq *types.ExtendedChatCompletionRequest- modelConfig *shared.ModelRoleConfig+ requestStartedAt time.Time+ firstTokenAt time.Time+ originalReq *types.ExtendedChatCompletionRequest+ tenativeModelConfig *shared.ModelRoleConfig+ modelConfig *shared.ModelRoleConfig++ skipConvoMessages map[string]bool}type chunkProcessor struct {diff --git a/app/server/model/plan/tell_stream_error.go b/app/server/model/plan/tell_stream_error.goindex c1f85593..d8416d66 100644--- a/app/server/model/plan/tell_stream_error.go+++ b/app/server/model/plan/tell_stream_error.go@@ -107,6 +107,7 @@ func (state *activeTellStreamState) onError(params onErrorParams) onErrorResultflags: shared.ConvoMessageFlags{CurrentStage: state.currentStage,HasUnfinishedSubtasks: hasUnfinishedSubtasks,+ HasError: true,},subtask: nil,addedSubtasks: nil,diff --git a/app/server/model/plan/tell_stream_finish.go b/app/server/model/plan/tell_stream_finish.goindex 7e4a52da..e53ba13b 100644--- a/app/server/model/plan/tell_stream_finish.go+++ b/app/server/model/plan/tell_stream_finish.go@@ -177,6 +177,7 @@ func (state *activeTellStreamState) handleStreamFinished() handleStreamFinishedRallSubtasksFinished: allSubtasksFinished,activatePaths: autoLoadContextResult.activatePaths,removedSubtasks: len(removedSubtasks) > 0,+ hasExplicitPaths: autoLoadContextResult.hasExplicitPaths,})if willContinue {diff --git a/app/server/model/plan/tell_stream_status.go b/app/server/model/plan/tell_stream_status.goindex 01d0f7f4..509e0dfd 100644--- a/app/server/model/plan/tell_stream_status.go+++ b/app/server/model/plan/tell_stream_status.go@@ -60,7 +60,7 @@ func (state *activeTellStreamState) handleDescAndExecStatus() handleDescAndExecSgo func() {log.Println("Getting exec status")var err *shared.ApiError- res, err := state.execStatusShouldContinue(active.CurrentReplyContent, active.Ctx)+ res, err := state.execStatusShouldContinue(active.CurrentReplyContent, active.SessionId, active.Ctx)if err != nil {errCh <- errreturn@@ -107,6 +107,7 @@ type willContinuePlanParams struct {removedSubtasks boolallSubtasksFinished boolactivatePaths map[string]bool+ hasExplicitPaths bool}func (state *activeTellStreamState) willContinuePlan(params willContinuePlanParams) bool {@@ -132,6 +133,12 @@ func (state *activeTellStreamState) willContinuePlan(params willContinuePlanParareturn false}+ // if no files were listed explicitly in a ### Files section, don't continue if it's chat mode+ if state.req.IsChatOnly && !params.hasExplicitPaths {+ log.Println("[willContinuePlan] Chat only - no files loaded - stopping")+ return false+ }+log.Println("[willContinuePlan] In context phase - continuing to planning phase")return true}diff --git a/app/server/model/plan/tell_stream_store.go b/app/server/model/plan/tell_stream_store.goindex e1c8273f..7ed087a0 100644--- a/app/server/model/plan/tell_stream_store.go+++ b/app/server/model/plan/tell_stream_store.go@@ -134,11 +134,12 @@ func (state *activeTellStreamState) storeOnFinished(params storeOnFinishedParamslog.Println("storeOnFinished: flags", flags)assistantMsg, convoCommitMsg, err := state.storeAssistantReply(repo, storeAssistantReplyParams{- flags: flags,- subtask: messageSubtask,- addedSubtasks: addedSubtasks,- activatedPaths: autoLoadContextResult.activatePaths,- removedSubtasks: removedSubtasks,+ flags: flags,+ subtask: messageSubtask,+ addedSubtasks: addedSubtasks,+ activatePaths: autoLoadContextResult.activatePaths,+ activatePathsOrdered: autoLoadContextResult.activatePathsOrdered,+ removedSubtasks: removedSubtasks,}) // updates state.convoif err != nil {@@ -245,18 +246,20 @@ func (state *activeTellStreamState) storeOnFinished(params storeOnFinishedParams}type storeAssistantReplyParams struct {- flags shared.ConvoMessageFlags- subtask *db.Subtask- addedSubtasks []*db.Subtask- activatedPaths map[string]bool- removedSubtasks []string+ flags shared.ConvoMessageFlags+ subtask *db.Subtask+ addedSubtasks []*db.Subtask+ activatePaths map[string]bool+ activatePathsOrdered []string+ removedSubtasks []string}func (state *activeTellStreamState) storeAssistantReply(repo *db.GitRepo, params storeAssistantReplyParams) (*db.ConvoMessage, string, error) {flags := params.flagssubtask := params.subtaskaddedSubtasks := params.addedSubtasks- activatedPaths := params.activatedPaths+ activatePaths := params.activatePaths+ activatePathsOrdered := params.activatePathsOrderedremovedSubtasks := params.removedSubtaskscurrentOrgId := state.currentOrgId@@ -276,19 +279,20 @@ func (state *activeTellStreamState) storeAssistantReply(repo *db.GitRepo, params// fmt.Println("raw message: ", activePlan.CurrentReplyContent)assistantMsg := db.ConvoMessage{- Id: replyId,- OrgId: currentOrgId,- PlanId: planId,- UserId: currentUserId,- Role: openai.ChatMessageRoleAssistant,- Tokens: replyNumTokens,- Num: num,- Message: activePlan.CurrentReplyContent,- Flags: flags,- Subtask: subtask,- AddedSubtasks: addedSubtasks,- ActivatedPaths: activatedPaths,- RemovedSubtasks: removedSubtasks,+ Id: replyId,+ OrgId: currentOrgId,+ PlanId: planId,+ UserId: currentUserId,+ Role: openai.ChatMessageRoleAssistant,+ Tokens: replyNumTokens,+ Num: num,+ Message: activePlan.CurrentReplyContent,+ Flags: flags,+ Subtask: subtask,+ AddedSubtasks: addedSubtasks,+ ActivatedPaths: activatePaths,+ ActivatedPathsOrdered: activatePathsOrdered,+ RemovedSubtasks: removedSubtasks,}commitMsg, err := db.StoreConvoMessage(repo, &assistantMsg, auth.User.Id, branch, false)