Skip to main content
When one attempt is not enough, run three and keep the best. This file gives three candidates the same task, each in its own worktree of a Git repository. Each writes its implementation and a test, and runs the test. A judge scores every candidate that passed. The winner is merged back onto the branch. The losers are discarded with their worktrees, and the file proves that nothing of theirs is left behind. The candidates here are functions, so the file runs offline and always gives the same answer. Put an engine in the candidate job and the shape is a tournament of models.

What happens

  1. A temporary repository is seeded with one placeholder file.
  2. tournament starts three candidate jobs, each in an isolated worktree on its own branch. Every candidate writes src/retry.ts and a test, then runs the test with Node. A failed test fails the candidate.
  3. The judge reads each passing candidate’s source and scores it: one point for passing, one for a named attempts cap, one for stopping when the caller aborts.
  4. The highest score lands on main. The candidate branches are deleted.

The file

What it prints

The third candidate wins: it is the only one with both the attempts cap and the abort check, so it scores three. Its source is what src/retry.ts holds on main afterwards. The branch list is empty because a losing candidate’s branch and worktree are removed when the tournament ends.

Gotchas

  • Every candidate must pass its own test to be scored. A candidate that throws scores zero, whatever its source looks like. The judge only reads the workspaces of candidates whose job passed.
  • The judge reads files, not claims. The score comes from the candidate’s source on disk. A candidate’s outcome data is not the evidence.
  • Ties go to the first candidate. Give the judge enough resolution to separate the attempts you care about.

Source

The file is examples/tournament.ts. The tournament helper is exported by @obversa/runtime; its options are name, n, candidate (a function from the candidate index to a job) and judge (a function from an outcome and its context to a number).