(ctx context.Context, cfg *config.Config, req types.AIRequest, row requests.RequestRow, deps Dependencies)
| 78 | } |
| 79 | |
| 80 | func replayExact(ctx context.Context, cfg *config.Config, req types.AIRequest, row requests.RequestRow, deps Dependencies) (types.AIResponse, error) { |
| 81 | var snap types.PolicySnapshot |
| 82 | if len(row.PolicySnapshot) > 0 { |
| 83 | _ = json.Unmarshal(row.PolicySnapshot, &snap) |
| 84 | } |
| 85 | backend := strings.TrimSpace(snap.PrimaryBackend) |
| 86 | if backend == "" { |
| 87 | backend = strings.TrimSpace(row.SelectedBackend) |
| 88 | } |
| 89 | if backend == "" { |
| 90 | return types.AIResponse{}, errors.New("exact replay: missing primary backend in ledger snapshot") |
| 91 | } |
| 92 | |
| 93 | if req.RequestType == types.RequestTypeRAG { |
| 94 | if err := runRAGRetrieve(ctx, cfg, &req, deps.Retrieval, deps.Rerank); err != nil { |
| 95 | return types.AIResponse{}, err |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | primary := types.RouteDecision{ |
| 100 | BackendName: backend, |
| 101 | Reason: "replay_exact", |
| 102 | EstimatedCost: snap.EstimatedCost, |
| 103 | } |
| 104 | execRes, err := deps.Reliability.ExecuteWithFallbackOpts(ctx, req, primary, nil, types.ReliabilityExecuteOptions{ |
| 105 | ForcePrimaryBackend: backend, |
| 106 | NoFallback: true, |
| 107 | }) |
| 108 | if err != nil { |
| 109 | return types.AIResponse{}, err |
| 110 | } |
| 111 | return buildResponse(cfg, req, "replay_exact", primary, execRes, row.RequestID, row.TraceID), nil |
| 112 | } |
| 113 | |
| 114 | func replayCurrent(ctx context.Context, cfg *config.Config, req types.AIRequest, deps Dependencies) (types.AIResponse, error) { |
| 115 | pol, err := deps.Policy.Evaluate(ctx, req) |
no test coverage detected