| 288 | } |
| 289 | |
| 290 | async function benchmarkChildPrompt( |
| 291 | parent: Session.Info, |
| 292 | child: Session.Info & { benchmark: BenchmarkSchema.ChildSession }, |
| 293 | input: PromptInput, |
| 294 | ) { |
| 295 | return SessionBenchmark.withWorktreeLock(async () => { |
| 296 | try { |
| 297 | const parentLatest = await Session.get(parent.id) |
| 298 | const isApplied = |
| 299 | SessionBenchmark.isParent(parentLatest) && parentLatest.benchmark.appliedSessionID === child.id |
| 300 | if (isApplied) { |
| 301 | const message = await runPrompt({ |
| 302 | ...input, |
| 303 | sessionID: child.id, |
| 304 | model: child.benchmark.model, |
| 305 | messageID: undefined, |
| 306 | }) |
| 307 | const snapshot = await SessionBenchmark.latestSnapshot(child.id) |
| 308 | await SessionBenchmark.updateChildSnapshot(child.id, snapshot) |
| 309 | return message |
| 310 | } |
| 311 | if (!SessionBenchmark.isParent(parentLatest)) { |
| 312 | throw new Error("Parent session is no longer a benchmark parent.") |
| 313 | } |
| 314 | const worktree = await SessionBenchmark.ensureChildWorktree(parentLatest, child) |
| 315 | const eventDirectory = Instance.directory |
| 316 | return await Instance.provideContext( |
| 317 | { |
| 318 | directory: worktree, |
| 319 | worktree, |
| 320 | project: Instance.project, |
| 321 | eventDirectory, |
| 322 | }, |
| 323 | async () => { |
| 324 | const message = await runPrompt({ |
| 325 | ...input, |
| 326 | sessionID: child.id, |
| 327 | model: child.benchmark.model, |
| 328 | messageID: undefined, |
| 329 | }) |
| 330 | const snapshot = await SessionBenchmark.latestSnapshot(child.id) |
| 331 | await SessionBenchmark.updateChildSnapshot(child.id, snapshot) |
| 332 | return message |
| 333 | }, |
| 334 | ) |
| 335 | } catch (error) { |
| 336 | const message = error instanceof Error ? error.message : String(error) |
| 337 | await SessionBenchmark.updateChildSnapshot(child.id, undefined, message) |
| 338 | throw error |
| 339 | } |
| 340 | }) |
| 341 | } |
| 342 | |
| 343 | function start(sessionID: string) { |
| 344 | const s = state() |