MCPcopy Index your code
hub / github.com/coder/coder / prepareChatTurnDebugRun

Function prepareChatTurnDebugRun

coderd/x/chatd/chatd.go:3501–3600  ·  view source on GitHub ↗
(
	ctx context.Context,
	logger slog.Logger,
	chat database.Chat,
	modelConfig database.ChatModelConfig,
	debugSvc *chatdebug.Service,
	debugProvider string,
	debugModel string,
	triggerMessageID int64,
	historyTipMessageID int64,
	triggerLabel string,
)

Source from the content-addressed store, hash-verified

3499}
3500
3501func prepareChatTurnDebugRun(
3502 ctx context.Context,
3503 logger slog.Logger,
3504 chat database.Chat,
3505 modelConfig database.ChatModelConfig,
3506 debugSvc *chatdebug.Service,
3507 debugProvider string,
3508 debugModel string,
3509 triggerMessageID int64,
3510 historyTipMessageID int64,
3511 triggerLabel string,
3512) (context.Context, func(error, any)) {
3513 finishDebugRun := func(error, any) {}
3514 if debugSvc == nil {
3515 return ctx, finishDebugRun
3516 }
3517
3518 seedSummary := chatdebug.SeedSummary(
3519 chatdebug.TruncateLabel(triggerLabel, chatdebug.MaxLabelLength),
3520 )
3521 rootChatID := uuid.Nil
3522 if chat.RootChatID.Valid {
3523 rootChatID = chat.RootChatID.UUID
3524 }
3525 parentChatID := uuid.Nil
3526 if chat.ParentChatID.Valid {
3527 parentChatID = chat.ParentChatID.UUID
3528 }
3529
3530 // Debug instrumentation must never block the user turn. Detach
3531 // from the chat-processing context and bound the insert so a slow
3532 // or locked DB makes debug logging degrade silently rather than
3533 // stalling chatloop.Run. Matches the pattern used by
3534 // prepareManualTitleDebugRun.
3535 createRunCtx, createRunCancel := context.WithTimeout(
3536 context.WithoutCancel(ctx), debugCreateRunTimeout,
3537 )
3538 run, createRunErr := debugSvc.CreateRun(createRunCtx, chatdebug.CreateRunParams{
3539 ChatID: chat.ID,
3540 RootChatID: rootChatID,
3541 ParentChatID: parentChatID,
3542 ModelConfigID: modelConfig.ID,
3543 TriggerMessageID: triggerMessageID,
3544 HistoryTipMessageID: historyTipMessageID,
3545 Kind: chatdebug.KindChatTurn,
3546 Status: chatdebug.StatusInProgress,
3547 Provider: debugProvider,
3548 Model: debugModel,
3549 Summary: seedSummary,
3550 })
3551 createRunCancel()
3552 if createRunErr != nil {
3553 logger.Warn(ctx, "failed to create chat debug run",
3554 slog.F("chat_id", chat.ID),
3555 slog.Error(createRunErr),
3556 )
3557 return ctx, finishDebugRun
3558 }

Callers 1

runChatMethod · 0.85

Calls 8

SeedSummaryFunction · 0.92
TruncateLabelFunction · 0.92
ContextWithRunFunction · 0.92
ClassifyErrorFunction · 0.92
CreateRunMethod · 0.80
FinalizeRunMethod · 0.80
ErrorMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected