Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Session IDs and dependent takes

A session fixture that creates something on the provider (a file, a stored response, a message whose ID later requests refer to) gets a new ID on every recording run. A test take whose requests contain an ID from the current _session.take is a dependent: if _session.take is re-recorded without it, the old take refers to an ID the new _session.take no longer serves.

What counts as an ID: a whole JSON string value in a _session.take response (full bodies and stream events; not object keys) shaped like a provider ID, i.e. 2 to 20 lowercase letters, _ or -, then at least 16 letters and digits with at least one of each (msg_01XFDUDYJgAACzvnptvVoYEL, file_011CNha8iCJcU1wXNR6q4V8w, chatcmpl-AbC123...), or a UUID. Model names, stop reasons and other words never match. A test take is a dependent when any of its requests contains such an ID anywhere in the path, query or body.

When _session.take has dependents, a recording run:

  • lists them at the start and asks for confirmation; headless runs (no TTY) refuse unless --yes or RETAKE_ASSUME_YES=1 is given;
  • writes every take to <name>.take.partial as usual, but renames them all at the end of the run instead of when each test passes;
  • renames them only if _session.take and every dependent were re-recorded (ran and passed). Otherwise it renames none, keeps every previous take unchanged, fails, and lists the tests that must be included:
retake: end-of-run finalization refused: 2 take(s) use IDs from the previous _session.take; no take was finalized and the previous takes are unchanged
retake: re-record them in one run; these tests must be included (1 missing):
retake:   tests/test_suite.py::test_b (tests/test_suite.py/test_b.take): not run
retake: the new recordings stay as .partial files; `retake clean` removes them

When all of them were re-recorded, the summary ends with finalized 4 take(s) at the end of the run (2 dependent(s) of _session.take re-recorded).

If Retake itself dies during such a run (killed, machine lost), nothing is renamed. retake finalize --takes-dir <dir> performs the end-of-run step on what the run left: it completes _session.take.partial (dropping a cut-off last line and adding a footer with "run_exit": null, since the run never exited; replay warns that the recording run did not finish, as it does for a non-zero exit), then renames every finished .partial that run wrote, if every dependent is among them. Unfinished .partial files (tests that never ended, refused recordings) and ones from earlier runs are left in place and listed. A passing test that made no requests in the crashed run keeps its previous take, since its removal was only pending in memory.

Leftover .partial files

A crash, a refused recording, or a refused end-of-run finalization leaves .partial files next to the takes. They are never replayed. retake clean --takes-dir <dir> lists and removes every *.take.partial under the takes directory; --dry-run only lists them. retake init adds *.take.partial and _resource.take to .gitignore in the current directory, and marks the takes directory’s blob files as binary in .gitattributes (tests/takes/_blobs/** binary, following --takes-dir), creating either file if needed; running it again changes nothing.

retake clean also removes blob files in _blobs/ that no take refers to (see Blobs); --dry-run lists them. If a take cannot be read, no blob is removed, since it could refer to any of them.

retake clean only deletes local files. Resources a removed .partial created on the provider are first copied to _resource.take, so retake reap can still delete them.