( 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, )
| 3499 | } |
| 3500 | |
| 3501 | func 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 | } |
no test coverage detected