on main help sign in
fix(agent): remove timout for now (#1158)
e762ddfKujtim Hoxha
internal/llm/agent/agent.go−12
@@ -26,8 +26,6 @@ import (
26 "github.com/charmbracelet/crush/internal/shell"
26 "github.com/charmbracelet/crush/internal/shell"
27)
27)
28
28
29−const streamChunkTimeout = 2 * time.Minute
30−
31type AgentEventType string
29type AgentEventType string
32
30
33const (
31const (
@@ -554,10 +552,6 @@ func (a *agent) streamAndHandleEvents(ctx context.Context, sessionID string, msg
554 // Add the session and message ID into the context if needed by tools.
552 // Add the session and message ID into the context if needed by tools.
555 ctx = context.WithValue(ctx, tools.MessageIDContextKey, assistantMsg.ID)
553 ctx = context.WithValue(ctx, tools.MessageIDContextKey, assistantMsg.ID)
556
554
557− // Process each event in the stream.
558− timer := time.NewTimer(streamChunkTimeout)
559− defer timer.Stop()
560−
561loop:
555loop:
562 for {
556 for {
563 select {
557 select {
@@ -565,9 +559,6 @@ loop:
565 if !ok {
559 if !ok {
566 break loop
560 break loop
567 }
561 }
568− // Reset the timeout timer since we received a chunk
569− timer.Reset(streamChunkTimeout)
570−
571 if processErr := a.processEvent(ctx, sessionID, &assistantMsg, event); processErr != nil {
562 if processErr := a.processEvent(ctx, sessionID, &assistantMsg, event); processErr != nil {
572 if errors.Is(processErr, context.Canceled) {
563 if errors.Is(processErr, context.Canceled) {
573 a.finishMessage(context.Background(), &assistantMsg, message.FinishReasonCanceled, "Request cancelled", "")
564 a.finishMessage(context.Background(), &assistantMsg, message.FinishReasonCanceled, "Request cancelled", "")
@@ -576,9 +567,6 @@ loop:
576 }
567 }
577 return assistantMsg, nil, processErr
568 return assistantMsg, nil, processErr
578 }
569 }
579− case <-timer.C:
580− a.finishMessage(ctx, &assistantMsg, message.FinishReasonError, "Stream timeout", "No chunk received within timeout")
581− return assistantMsg, nil, ErrStreamTimeout
582 case <-ctx.Done():
570 case <-ctx.Done():
583 a.finishMessage(context.Background(), &assistantMsg, message.FinishReasonCanceled, "Request cancelled", "")
571 a.finishMessage(context.Background(), &assistantMsg, message.FinishReasonCanceled, "Request cancelled", "")
584 return assistantMsg, nil, ctx.Err()
572 return assistantMsg, nil, ctx.Err()
internal/llm/agent/errors.go−1
@@ -7,7 +7,6 @@ import (
7
7
8var (
8var (
9 ErrRequestCancelled = errors.New("request canceled by user")
9 ErrRequestCancelled = errors.New("request canceled by user")
10− ErrStreamTimeout = errors.New("stream chunk timeout")
11 ErrSessionBusy = errors.New("session is currently processing another request")
10 ErrSessionBusy = errors.New("session is currently processing another request")
12)
11)
13
12