mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: configure acquire chat batch size (#23196)
## Summary - add a hidden deployment config option for chat acquire batch size (`CODER_CHAT_ACQUIRE_BATCH_SIZE` / `chat.acquireBatchSize`) - thread the configured value into chatd startup while preserving the existing default of `10` - clamp the deployment value to the `int32` range before passing it into chatd - regenerate the API/docs/types/testdata artifacts for the new config field ## Why `chatd` currently acquires pending chats in batches of `10` via a compile-time default. This change makes that batch size operator-configurable from deployment config, so we can tune acquisition behavior without another code change.
This commit is contained in:
+11
-3
@@ -58,11 +58,11 @@ const (
|
||||
// of 5 means recovery runs at 1/5 of the stale-after duration.
|
||||
staleRecoveryIntervalDivisor = 5
|
||||
|
||||
// maxChatsPerAcquire is the maximum number of chats to
|
||||
// DefaultMaxChatsPerAcquire is the maximum number of chats to
|
||||
// acquire in a single processOnce call. Batching avoids
|
||||
// waiting a full polling interval between acquisitions
|
||||
// when many chats are pending.
|
||||
maxChatsPerAcquire int32 = 10
|
||||
DefaultMaxChatsPerAcquire int32 = 10
|
||||
|
||||
defaultSubagentInstruction = "You are running as a delegated sub-agent chat. Complete the delegated task and provide clear, concise assistant responses for the parent agent."
|
||||
)
|
||||
@@ -98,6 +98,7 @@ type Server struct {
|
||||
|
||||
// Configuration
|
||||
pendingChatAcquireInterval time.Duration
|
||||
maxChatsPerAcquire int32
|
||||
inFlightChatStaleAfter time.Duration
|
||||
}
|
||||
|
||||
@@ -1174,6 +1175,7 @@ type Config struct {
|
||||
ReplicaID uuid.UUID
|
||||
SubscribeFn SubscribeFn
|
||||
PendingChatAcquireInterval time.Duration
|
||||
MaxChatsPerAcquire int32
|
||||
InFlightChatStaleAfter time.Duration
|
||||
AgentConn AgentConnFunc
|
||||
CreateWorkspace chattool.CreateWorkspaceFn
|
||||
@@ -1199,6 +1201,11 @@ func New(cfg Config) *Server {
|
||||
inFlightChatStaleAfter = DefaultInFlightChatStaleAfter
|
||||
}
|
||||
|
||||
maxChatsPerAcquire := cfg.MaxChatsPerAcquire
|
||||
if maxChatsPerAcquire <= 0 {
|
||||
maxChatsPerAcquire = DefaultMaxChatsPerAcquire
|
||||
}
|
||||
|
||||
workerID := cfg.ReplicaID
|
||||
if workerID == uuid.Nil {
|
||||
workerID = uuid.New()
|
||||
@@ -1219,6 +1226,7 @@ func New(cfg Config) *Server {
|
||||
providerAPIKeys: cfg.ProviderAPIKeys,
|
||||
instructionCache: make(map[uuid.UUID]cachedInstruction),
|
||||
pendingChatAcquireInterval: pendingChatAcquireInterval,
|
||||
maxChatsPerAcquire: maxChatsPerAcquire,
|
||||
inFlightChatStaleAfter: inFlightChatStaleAfter,
|
||||
}
|
||||
|
||||
@@ -1272,7 +1280,7 @@ func (p *Server) processOnce(ctx context.Context) {
|
||||
chats, err := p.db.AcquireChats(acquireCtx, database.AcquireChatsParams{
|
||||
StartedAt: time.Now(),
|
||||
WorkerID: p.workerID,
|
||||
NumChats: maxChatsPerAcquire,
|
||||
NumChats: p.maxChatsPerAcquire,
|
||||
})
|
||||
acquireCancel()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user