( ctx context.Context, chat database.Chat, status database.ChatStatus, runResult runChatResult, logger slog.Logger, afterFinalize func(context.Context, string), )
| 9656 | } |
| 9657 | |
| 9658 | func (p *Server) finalizeSuccessfulTurnStatusLabelWithAfterFunc( |
| 9659 | ctx context.Context, |
| 9660 | chat database.Chat, |
| 9661 | status database.ChatStatus, |
| 9662 | runResult runChatResult, |
| 9663 | logger slog.Logger, |
| 9664 | afterFinalize func(context.Context, string), |
| 9665 | ) { |
| 9666 | // This helper runs during processChat cleanup, while processChat is |
| 9667 | // still counted in p.inflight. Do not take inflightMu here because |
| 9668 | // drainInflight holds it while waiting. |
| 9669 | p.inflight.Go(func() { |
| 9670 | finalizeCtx := context.WithoutCancel(ctx) |
| 9671 | statusLabel := p.generateFinalTurnStatusLabel(finalizeCtx, chat, status, runResult, logger) |
| 9672 | logger.Debug(finalizeCtx, "generated chat turn status label", |
| 9673 | slog.F("chat_id", chat.ID), |
| 9674 | slog.F("status", status), |
| 9675 | slog.F("label_length", len(statusLabel)), |
| 9676 | ) |
| 9677 | |
| 9678 | p.updateLastTurnSummary(finalizeCtx, chat, chat.UpdatedAt, statusLabel, logger) |
| 9679 | |
| 9680 | afterFinalize(finalizeCtx, statusLabel) |
| 9681 | }) |
| 9682 | } |
| 9683 | |
| 9684 | func (p *Server) generateFinalTurnStatusLabel( |
| 9685 | ctx context.Context, |
no test coverage detected