SaveRunSessions saves all eval sessions to a SQLite database file. The database follows the same schema as the main session store, allowing the sessions to be loaded and inspected using standard session tools.
(ctx context.Context, run *EvalRun, outputDir string)
| 19 | // The database follows the same schema as the main session store, |
| 20 | // allowing the sessions to be loaded and inspected using standard session tools. |
| 21 | func SaveRunSessions(ctx context.Context, run *EvalRun, outputDir string) (string, error) { |
| 22 | dbPath := filepath.Join(outputDir, run.Name+".db") |
| 23 | |
| 24 | // Create output directory if needed |
| 25 | if err := os.MkdirAll(outputDir, 0o700); err != nil { |
| 26 | return "", fmt.Errorf("creating output directory: %w", err) |
| 27 | } |
| 28 | |
| 29 | // Create a new SQLite session store for this eval run |
| 30 | store, err := session.NewSQLiteSessionStore(ctx, dbPath) |
| 31 | if err != nil { |
| 32 | return "", fmt.Errorf("creating session store: %w", err) |
| 33 | } |
| 34 | defer func() { |
| 35 | if closer, ok := store.(interface{ Close() error }); ok { |
| 36 | _ = closer.Close() |
| 37 | } |
| 38 | }() |
| 39 | |
| 40 | // Save each result's session to the database |
| 41 | for i := range run.Results { |
| 42 | result := &run.Results[i] |
| 43 | if result.Session == nil { |
| 44 | continue |
| 45 | } |
| 46 | |
| 47 | if err := store.AddSession(ctx, result.Session); err != nil { |
| 48 | return "", fmt.Errorf("saving session for %q: %w", result.Title, err) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return dbPath, nil |
| 53 | } |
| 54 | |
| 55 | // SessionFromEvents reconstructs a session from raw container output events. |
| 56 | // This parses the JSON events emitted by docker agent run --exec --json and builds a session |