Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion internal/assistant/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func TestParseSSEResultFailureCases(t *testing.T) {
}

for _, testCase := range tests {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 3 additions & 3 deletions internal/assistant/context_usage.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package assistant

import "maps"

func cloneIntMapForUsage(values map[string]int) map[string]int {
if len(values) == 0 {
return nil
}
cloned := make(map[string]int, len(values))
for key, value := range values {
cloned[key] = value
}
maps.Copy(cloned, values)

return cloned
}
5 changes: 2 additions & 3 deletions internal/assistant/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package assistant
import (
"context"
"log/slog"
"maps"

"github.com/omarluq/librecode/internal/database"
"github.com/omarluq/librecode/internal/extension"
Expand Down Expand Up @@ -319,9 +320,7 @@ func contextBuildLifecyclePayload(

func cloneAnyMap(values map[string]any) map[string]any {
cloned := make(map[string]any, len(values))
for key, value := range values {
cloned[key] = value
}
maps.Copy(cloned, values)

return cloned
}
Expand Down
5 changes: 2 additions & 3 deletions internal/assistant/lifecycle_diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package assistant
import (
"context"
"fmt"
"maps"
"sort"
"time"

Expand All @@ -29,9 +30,7 @@ func (runtime *Runtime) emitLifecycleDiagnostics(
if len(result.Errors) > 0 {
payload[lifecycleErrorsKey] = append([]string{}, result.Errors...)
}
for key, value := range extra {
payload[key] = value
}
maps.Copy(payload, extra)

runtime.emit(ctx, string(name)+"_diagnostic", payload)
}
Expand Down
9 changes: 3 additions & 6 deletions internal/assistant/provider_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package assistant

import (
"context"
"maps"
"strings"

"github.com/samber/oops"
Expand Down Expand Up @@ -138,9 +139,7 @@ func providerPayloadFromLifecycle(payload, fallback map[string]any) map[string]a

func mergeProviderHeaders(headers, additions map[string]string) map[string]string {
merged := cloneStringMap(headers)
for key, value := range additions {
merged[key] = value
}
maps.Copy(merged, additions)

return merged
}
Expand Down Expand Up @@ -176,9 +175,7 @@ func cloneStringMap(values map[string]string) map[string]string {
return map[string]string{}
}
cloned := make(map[string]string, len(values))
for key, value := range values {
cloned[key] = value
}
maps.Copy(cloned, values)

return cloned
}
31 changes: 22 additions & 9 deletions internal/assistant/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,37 @@ func ShouldRetryModelError(err error) bool {
if errors.Is(err, context.DeadlineExceeded) {
return retryableDeadlineExceeded(message)
}
if code, ok := providerErrorCode(err); ok {
if nonRetryableProviderCode(code) {
return false
}
if retryableProviderCode(code) {
return true
}
if retry, ok := retryDecisionFromProviderCode(err); ok {
return retry
}
if status, ok := providerErrorStatus(err); ok {
return retryableStatus(status)
}
var netErr net.Error
if errors.As(err, &netErr) {
if retryableNetworkError(err) {
return true
}
return retryableProviderMessage(message)
}

func retryDecisionFromProviderCode(err error) (retry, known bool) {
code, ok := providerErrorCode(err)
if !ok {
return false, false
}
if nonRetryableProviderCode(code) {
return false, true
}
if retryableProviderCode(code) {
return true, true
}
return false, false
}

func retryableNetworkError(err error) bool {
netErr, ok := errors.AsType[net.Error](err)
return ok && netErr != nil
}

func retryableDeadlineExceeded(message string) bool {
// Match provider/client timeout details, not wrapper call-site labels such as
// "request provider response", so caller-owned deadlines remain non-retryable.
Expand Down
Loading
Loading