# Reading history

## Read the history on another page

A reader page names the history in a source of its own:

```json
"sources": { "kept": { "dataset": "parcel-deliveries" } }
```

It takes `derive`, as an http source does, and its cards use `ref`, `map`, `empty` and `when` as usual. There's no `every`: the source is refreshed when the history changes, without asking the service. A quiet page scan does not trigger a new read. The previously shown value stays visible while its replacement is prepared. The answer:

```json
{ "kept": {
    "rows": [
      { "key": "ups:EX10000001", "date": "2026-11-04", "date_kind": "wall", "time": "14:12:00",
        "first_seen": "2026-11-01T09:30:00Z", "last_seen": "2026-11-05T09:30:00Z",
        "row": { "carrier_code": "ups", "tracking_number": "EX10000001", "description": "Desk lamp",
                 "status_code": 0, "events": [ … ] } } ],
    "selected_count": 18, "total_count": 120, "undated_count": 3,
    "epoch": { "number": 1, "started": "2026-08-14T16:02:11Z", "label": "parcel · api.parcel.app" },
    "coverage": { "recording_since": "2026-08-14T16:02:11Z", "last_success": "2026-11-07T15:30:02Z",
                  "earliest_row_date": "2026-06-02",
                  "interruptions": [ { "from": "2026-09-20T22:00:04Z", "to": "2026-09-23T07:41:55Z" } ],
                  "imported": [ { "at": "2026-08-14T16:10:40Z", "rows": 32, "earliest": "2026-06-02" } ],
                  "imports_omitted": 0 } } }
```

| Field | Meaning |
| --- | --- |
| `rows` | The rows of the current history, in date order with undated rows last. On a page with a [period](https://legatobar.com/docs/periods.md#periods), only those dated in it. |
| `rows[].key` | The row's key. |
| `rows[].date`, `date_kind` | The row's date and its kind, `day`, `wall` or `moment` (see [Dates](https://legatobar.com/docs/history-dates.md#dates)). Undated rows have neither. |
| `rows[].time` | A `wall` date's printed time, `14:12:00`. Only on `wall` dates. |
| `rows[].first_seen`, `last_seen` | When Legato first kept the row, and when it last saw it in an answer (or had it added). |
| `rows[].row` | The item as kept: its `fields`, after `remove_after`. A field is at `row.carrier_code`, not `carrier_code`. |
| `selected_count` | How many rows `rows` has. |
| `total_count`, `undated_count` | All the rows in the current history, whatever the period, and how many of them are undated. |
| `epoch` | The current history: its `number`, when it `started`, and its `label`. |
| `coverage` | What the history covers. See [Coverage](https://legatobar.com/docs/history-coverage.md#coverage). |

Times Legato recorded (`first_seen`, `started`, `recording_since` and the rest) are ISO 8601 in UTC; the [`ago` and `day` filters](https://legatobar.com/docs/mapping.md#mapping) show them in the Mac's time.

- **The period filters the rows, not the collecting.** Picking 365 days on the reader reads more of what's kept; it doesn't change what the owner keeps. Status, gauge and fleet cards read the default choice, as with any source.
- **Every row in the period is read.** Counts, sums and averages cover all of them. A card's `limit` only shortens what it shows, and the 500-row limit of `rows list` doesn't apply to pages.
- **Undated rows come only without a period.** A reader page with no period row gets every row of the current history, undated ones included.
- **Only readers read.** A page that isn't the owner or a reader gets "This page can't read the history parcel-deliveries; the page that keeps it lists its readers" on its cards. A history nothing keeps yet gives "No page keeps the history parcel-deliveries on this Mac".
- **A reader is a page with a card on the dataset source.** Being listed in `readers`, or granted in Settings, lets a page read; it reads once a card uses the source.
- A page with [params](https://legatobar.com/docs/detail-pages.md#one-page-for-every-item) can read a history.

Cards on a dataset source can also say:

| Message | Cause |
| --- | --- |
| History is updating; trying again | The history or the page's rules changed while it was being read, often just after a page is saved. The card keeps its answer and tries again in 2 seconds. |
| History couldn't open: … | Legato couldn't open its history database, for example on a full disk. Settings → History shows the same reason. |
| Can't read history | Any other failure to read. |

### Only what the page needs: `row`

A history of large rows (a delivery with a hundred events) is slow to read whole: every card waits while Legato reads every event of every row in the period. When a page needs only a few values from each row, it says which, with `row`:

```json
"sources": { "kept": {
  "dataset": "parcel-deliveries",
  "row": {
    "carrier": "row.carrier_code",
    "description": "row.description",
    "days": { "days_between": [
      { "date": { "first": "date", "of": "row.events", "where": { "path": "event", "contains": "Picked up" },
                  "sort": { "by": "date", "as": "date" } } },
      "date" ] } },
  "derive": [ { "name": "mean", "value": { "avg": "row.days", "of": "kept.rows", "round": 1 } } ] } }
```

- **Each name is a rule read on the kept row,** as a rule on `kept.rows` would read it: `row.…` for the item as kept, and `key`, `date`, `date_kind` and `time`. Each row's `row` in the answer then holds only those values: `row.carrier`, `row.description`, `row.days`.
- **Nothing else changes.** Every row in the period is still read, so counts, sums, averages, groups and lists are what they'd be without `row`. `key`, `date`, `first_seen`, `last_seen`, the counts, `epoch` and `coverage` are as before.
- **Why it's fast:** a row's values depend on nothing but the row, so Legato keeps them on this Mac beside it and reads them instead of the whole row. They're made again when the row changes, when the page's `row` changes, and after an update of Legato or a change of the Mac's time zone, language, region, calendar or 12/24-hour setting. Each read makes values in the settings it started with, whatever changes while it runs. Until then a read makes the missing ones itself, so a page's first read after one of those is as slow as without `row`, once.
- **What a row rule can't use.** Each is an error on the cards that use the source (`delivery-times.json: cards/…/source.row.days: …`); the page itself loads, except for `{param.…}`, which stops it:
  - `first_seen` and `last_seen`, which change on every fetch: read them in `derive`, beside `row`;
  - `{ "answer": … }` and `lookup`, which read outside the row;
  - `{param.…}` and `{period.…}`: filter by them in `where` or `derive`;
  - templates, anywhere in a rule (`template`, and templates in `values` or `default`): a missing value reads as "—" on a stat or facts card and as a dash inside other text, which a kept value can't know. Name the template's inputs in `row` and write the template in `derive` or the card's `map`; it then reads exactly as it did over whole rows;
  - `match`, whose search runs under a time limit: a value kept after a timeout would stay wrong;
  - `in_list`, which reads a [list](https://legatobar.com/docs/lists.md#lists) from Settings → Lists: the list can change there, which a kept value can't know. Test it in `derive`.
- **Up to 16 names.** `row` is worked out before `derive`, so it can't read derived values; `derive` and the cards read `row`'s.
- **Limits of the kept values, never of the history:** up to 4 different `row`s for a history; a row's values up to 1 KB; 32 MB of values for one history and 128 MB for all of them. Over a limit, the values of the `row` read longest ago go first, and what still doesn't fit is made on each read, still complete. Kept values never take space from History's own limits, and when History storage is full they're all removed first.
- **In the background,** Legato makes missing values in small batches, and gives way to a page that's reading. A value it hasn't made yet is worked out from the whole row when a page reads it, so the answer is always complete.
- **They aren't history.** Export and `rows list` show rows as kept; deleting a row or a history deletes its values, a new history (another account) starts without any, and values no page uses any more are removed. Removal overwrites them on disk as History's other deletions do.

**Details** shows "Keeps history on this Mac (parcel-deliveries)" on the source that collects and "Reads the history parcel-deliveries, kept on this Mac" on a reader's. A collecting source no card uses is listed as a source of its own, with no cards.

