Skip to content

Commit 5ff574d

Browse files
committed
Address review feedback to improve eval server behavior
1 parent 22f6bff commit 5ff574d

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

server/auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func (c *authCache) evict(token, orgName string) {
145145
}
146146

147147
// moveToEnd moves a key to the end of the LRU order.
148+
// O(n) scan over the order slice; fine for defaultAuthCacheMax (64).
148149
// Must be called with c.mu held.
149150
func (c *authCache) moveToEnd(key string) {
150151
for i, k := range c.order {

server/cors.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
)
88

99
// allowedOriginPattern matches braintrust.dev and braintrustdata.dev origins
10-
// including subdomains and preview deployments.
10+
// including subdomains and preview deployments. HTTP is allowed alongside HTTPS
11+
// to support local development proxies.
1112
var allowedOriginPattern = regexp.MustCompile(`^https?://([\w-]+\.)*(braintrust|braintrustdata)\.dev$`)
1213

1314
var corsAllowHeaders = strings.Join([]string{
@@ -40,6 +41,7 @@ func corsMiddleware(next http.Handler) http.Handler {
4041
w.Header().Set("Access-Control-Expose-Headers", corsAllowHeaders)
4142
w.Header().Set("Access-Control-Allow-Credentials", "true")
4243
w.Header().Set("Access-Control-Max-Age", corsMaxAge)
44+
w.Header().Set("Vary", "Origin")
4345
// Support Chrome Private Network Access
4446
w.Header().Set("Access-Control-Allow-Private-Network", "true")
4547
}

server/server.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
//
77
// Example:
88
//
9-
// srv := server.New(server.WithAddress(":8300"))
10-
//
11-
// server.Register(srv, "classify",
12-
// eval.T(classifyTask),
13-
// []eval.Scorer[string, string]{scorer},
14-
// server.RegisterOpts{ProjectName: "my-project"},
15-
// )
9+
// classify := &eval.Eval[string, string]{
10+
// Name: "classify",
11+
// Task: eval.T(classifyTask),
12+
// Scorers: []eval.Scorer[string, string]{scorer},
13+
// }
1614
//
15+
// srv := server.New(server.WithAddress(":8300"))
16+
// server.Register(srv, classify, server.RegisterOpts{})
1717
// log.Fatal(srv.Start())
1818
package server
1919

@@ -188,14 +188,18 @@ func (s *Server) Shutdown(ctx context.Context) error {
188188
srv := s.httpServer
189189
s.serverMu.Unlock()
190190

191+
// Drain active requests before closing the default session,
192+
// so in-flight evals using it can complete.
193+
var err error
194+
if srv != nil {
195+
err = srv.Shutdown(ctx)
196+
}
197+
191198
if s.defaultAuth != nil {
192199
s.defaultAuth.session.Close()
193200
}
194201

195-
if srv == nil {
196-
return nil
197-
}
198-
return srv.Shutdown(ctx)
202+
return err
199203
}
200204

201205
// handleHealth responds to GET / with a health check.

0 commit comments

Comments
 (0)