Deletes two structs that each repeat another struct field for field. `chatloop.CompactionOptions` repeated 21 fields of `GenerateCompactionOptions`, and `normalizedCompactionGenerateConfig` copied them one by one, so each new option had to be added in three places, as #30766 did for `Logger`. `compactionOutcome` in `chatd` repeated the 11 fields of `chatloop.CompactionResult` only so that `generateCompaction` could convert one into the other. The PR also deletes `TestGenerateCompactionSummaryUsesToolDefinitions`, which repeats `TestGenerateCompactionSummaryPreservesCallOptions`. ## Why it is safe - `publishCompactionError`, `startCompactionDebugRun`, and `generateCompactionSummary` now take `GenerateCompactionOptions`. Every read of the normalized config, in `GenerateCompaction` and in those helpers, uses one of the 21 fields that the copier copied without change. None reads the 7 fields that only `GenerateCompactionOptions` has. - `normalizedCompactionGenerateConfig` applies the same four defaults and the same threshold gate to its parameter, which is already a copy. So `GenerateCompaction` still reports the requested `ThresholdPercent` and `ContextLimit` from its own `opts`. If it read `config.ThresholdPercent` instead, `TestGenerateCompaction_RecordsRequestedTrigger` would fail. - Go allows the `compactionOutcome(outcome)` conversion only because the two structs have identical fields, so `buildCompactionMessagesInput` can hold the `chatloop.CompactionResult` itself. The four `TestBuildCompactionMessages_*` tests that build it keep their assertions. - Six mutants of the summary call each fail the deleted test on #30766: no tools, no call options, no summary prompt, one tool dropped, the caller's history changed, and tool descriptions stripped. The kept test failed only the first five, because its tool had no description. With that description moved into it, the kept test fails all six. - `git grep -w CompactionOptions` and `git grep compactionOutcome` find no matches. ## Review focus `generateCompactionSummary` keeps its `model` and `messages` parameters, so its 15 direct test calls change only the type name. It now also receives `Model` and `Messages` fields with the same values, and it does not read them. ## Validation - `go test -race -count=1 ./coderd/x/chatd/chatloop/` passes. - `go test -count=1 -p 4 -parallel 4 ./coderd/x/chatd/...` passes (20 packages). - `golangci-lint run ./coderd/x/chatd/...` reports 0 issues, and the pre-commit hook passed. ## Stack #30766 has merged, so this PR now targets `main` by itself. > Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package chatd
|
|
|
|
import (
|
|
"database/sql"
|
|
"time"
|
|
|
|
"charm.land/fantasy"
|
|
)
|
|
|
|
type runnerActionKind string
|
|
|
|
const (
|
|
runnerActionKindEnterRequiresAction runnerActionKind = "enter_requires_action"
|
|
runnerActionKindFinishTurn runnerActionKind = "finish_turn"
|
|
runnerActionKindFinishError runnerActionKind = "finish_error"
|
|
runnerActionKindFinishInterruption runnerActionKind = "finish_interruption"
|
|
)
|
|
|
|
// stepData is the durable content produced by one provider attempt.
|
|
type stepData struct {
|
|
Content []fantasy.Content
|
|
Usage fantasy.Usage
|
|
ContextLimit sql.NullInt64
|
|
Runtime time.Duration
|
|
ProviderResponseID string
|
|
|
|
// BatchRuntime is the local-tool batch window. Model steps use Runtime.
|
|
BatchRuntime time.Duration
|
|
// BatchBilledCalls counts the calls whose intervals produced
|
|
// BatchRuntime. Audit metadata for the batch usage record.
|
|
BatchBilledCalls int
|
|
|
|
ToolCallCreatedAt map[string]time.Time
|
|
ToolResultCreatedAt map[string]time.Time
|
|
ReasoningStartedAt []time.Time
|
|
ReasoningCompletedAt []time.Time
|
|
}
|
|
|
|
// pendingDynamicToolCall describes a dynamic tool call parked for a user.
|
|
type pendingDynamicToolCall struct {
|
|
ToolCallID string
|
|
ToolName string
|
|
Args string
|
|
}
|
|
|
|
type compactionStatus int
|
|
|
|
const (
|
|
compactionStatusNotNeeded compactionStatus = iota
|
|
compactionStatusNeeded
|
|
compactionStatusAfterCompaction
|
|
compactionStatusStillOverLimit
|
|
)
|