# Journals

**Who this page is for:** anyone who reads runs in the Workbench from more than one place: the
project's own runs, the forks made in the Workbench, and a journal recorded somewhere else, such
as a deployed harness or a colleague's computer.

A **journal** is the ordered record of every event a run handled; a run can be read back,
replayed and continued from it. The Workbench reads runs from three kinds of journal, and says
on every run page which one it is reading:

| Kind | Key | What it is | Written by the Workbench? |
|---|---|---|---|
| The project's journal | `project` | The journal the project names, where its runs and its eval trials are recorded. | Only when you answer or continue a run there, after confirming. |
| A fork | `fork:<id>` | A copy of a run up to one moment, made in the Workbench, in `.gvn/workbench/forks/<id>.sqlite`. | Yes: answering and continuing a fork write to it. |
| An opened journal | `opened:<id>` | A journal file recorded elsewhere, opened here to be read. | Never. |

- **You will be able to:** choose which journal the runs page reads, open a journal file
  recorded elsewhere, forget it, and delete a fork.
- **Read first:** [Reading a run](runs.md) and [Forks and answers](forks-and-answers.md).
- **Time:** about 5 minutes.

## Where journals come from

```mermaid
flowchart LR
    project[("The project's journal<br/>.gvn/journal.sqlite")]
    forks[(".gvn/workbench/forks/<br/>1.sqlite · 2.sqlite · …")]
    elsewhere[("A journal file<br/>copied from a deployment")]
    wb["The Workbench<br/>reads every run<br/>the same way"]
    project --> wb
    forks --> wb
    elsewhere -- "opened, read only" --> wb
    project -- "Fork here" --> forks
    elsewhere -- "Fork here" --> forks
```

Every journal is read through gvn's journal interface (`gvn.harness.ports.Journal`). The list
of runs comes from `Journal.runs`, which gives the ids of the runs a journal holds, in order, a
page at a time; each run is then read record by record as [Reading a run](runs.md) describes.
So a run reads the same wherever it was recorded, as long as the project offers the harness or
the version that rebuilds it.

## Choosing a journal

**Runs** has a journal chooser: read runs from the project's journal, from any fork, or from
any opened journal. Each choice says what kind it is and where its file is; a fork says which
run and moment it was forked from. The address of a run page names the journal (`?journal=`;
left out for the project's), so a link to a run in a fork opens that fork.

**Waiting on you** reads the project's journal and every fork. Opened journals are not in it:
their runs are never answered here.

## A journal recorded elsewhere

A harness deployed with a SQLite journal (`gvn.adapters.sqlite.SqliteJournal`) leaves a file
holding every run it drove. Copy that file to your computer and open it in the Workbench: give
its path, absolute or relative to the project's folder, under the runs page's journal chooser.
The Workbench checks that the file exists and is a journal gvn's `SqliteJournal` wrote, and lists
it as an opened journal from then on. Opening the same file again gives the same entry.

An opened journal is only read. Nothing in the Workbench writes to it: its runs are not
answered or continued there, and a fork of one of its runs copies the run into a fork of its
own. To try another answer on a run recorded in production, open its journal, fork the run, and
answer the fork.

What an opened journal's runs show depends on the project: the project's harnesses and
versions are what rebuild a run. A run recorded by code the project no longer offers is still
listed, and its records are shown as the journal holds them.

Forgetting an opened journal removes it from the list and leaves its file where it is. The list
of opened journals is kept in `.gvn/workbench/opened.json`.

## Deleting a fork

A fork is deleted from its own run page or from the journal chooser, after you confirm. Its
journal file and its note are removed, and nothing else: the run it came from is unchanged.

## In code

The Workbench's journal reading is gvn's, so the same can be done from Python with any journal:

```python {.no-run}
from gvn.adapters.sqlite import SqliteJournal
from gvn.runtime.inspection import Inspector

from release_review.review import ReleaseReview


async def summarise(path: str) -> None:
    journal = SqliteJournal(path=path)
    for run_id in await journal.runs(limit=50):
        inspection = await Inspector(journal).recorded(run_id, ReleaseReview)
        print(run_id, inspection.finished(), len(inspection))
```

[Inspecting a run](../guides/inspecting-a-run.md) shows what an inspection holds.

## Recap

- Three kinds of journal: the project's (`project`), forks (`fork:<id>`) and opened files
  (`opened:<id>`); every run page says which it reads.
- A journal recorded elsewhere opens as a SQLite file, is only read, and is forked to try
  anything.
- Forgetting an opened journal leaves its file; deleting a fork removes its file and note only.

**Next:** [Files and safety](files-and-safety.md).
