Revision: 1 Last modified: 2026-12-04T00:00:00Z
Library: scripts/pr/lib/journal.sh (sourced by scripts/pr/lib/steps.sh; never executed on its own).
Engine guide: docs/scripts/pr_deliver.md. Manual: docs/manuals/pr_delivery_engine_manual.md.
Make an interrupted pull-request delivery RESUMABLE, and make "what did this run actually do" answerable without asking the provider. Every state the engine is about to reach is appended to a per-task journal BEFORE the mutation is attempted, so a crash can never lose the fact that a branch, a push or a pull request already exists.
Two files per task, both under the journal directory:
| File | Shape | Read cost |
|---|---|---|
<task>.jsonl |
append-only event stream, one JSON object per line | O(history) — used for history and pr_journal_get |
<task>.state |
atomic snapshot of the LAST event (temp → sync → rename) |
O(1) — what pr_journal_state reads |
bash4+;sed,find,mktemp;syncis used when present and skipped when absent.- The journal directory must resolve to an absolute path (see Edge cases).
- No provider, no credential and no network: the journal is local state only.
The library is sourced, so every call is a plain shell function:
. "$PR_SELF_DIR/lib/journal.sh"
pr_journal_init "$task" # sets PR_JOURNAL_FILE / PR_JOURNAL_SNAPSHOT
pr_journal_append pushed head="$sha" branch="$branch"
pr_journal_state # -> "pushed"
pr_journal_get head # -> the head recorded by the LAST event carrying it
pr_journal_list # every <task>.jsonl in the directory, sortedChoosing where it lives — first match wins:
PR_JOURNAL_DIR=/var/tmp/pr-journal bash scripts/pr/pr_deliver.sh status # 1. environment
delivery_journal_dir=/var/tmp/pr-journal # 2. key in config/delivery.conf
# 3. $HOME/.local/state/helix-pr-delivery/<owner__repo>Read one task's history without any provider contact:
$ bash scripts/pr/pr_deliver.sh status --task CON-641
JOURNAL: go_posted
JOURNAL-PR: 128
JOURNAL-HEAD: 4f2c1a9…- A relative journal directory is refused (
pr_journal_initprints to stderr and returns 1). A journal whose location depends on the caller's working directory would silently scatter one task's history across several files. - No journal yet is not an error:
pr_journal_statereturns 1 and prints nothing, andstatusreportsno delivery journal in <dir>. Callers must treat that as "nothing recorded", never as "done". - Appending before
pr_journal_initprintsjournal: not initialisedand returns 1 — the engine never writes a journal it has not pointed at a task. - A torn last line is impossible to observe through
pr_journal_state: it reads the snapshot, which is replaced byrename(2)only after its ownsync. The.jsonlis the append log; a hard stop can leave a partial trailing line there, andpr_journal_getignores lines that do not parse as"key":"value". pr_journal_getreturns the value from the LAST event that carried the key, not the first. The journal is append-only, so a later event wins by construction.syncis best-effort (command -v syncguard): on a host without it the write is still ordered by the filesystem, and the atomic rename keeps the snapshot self-consistent.
pr_json_escapeescapes\ " \n \r \tso a single-line JSON object is always produced withoutjq.pr_journal_append STATE [key=value …]writes one line{"at":"<UTC>","state":"<s>",…}to the.jsonl, callssyncon it, then writes the same line to<snapshot>.tmp.$$, syncs it, and renames it over<snapshot>. Any failure to write the snapshot removes the temp file and leaves the previous snapshot.- The journal records state and identifiers only — never a credential (the engine redacts output through
pr_redactinlib/common.sh, and no adapter passes a token here). - States written by
lib/steps.sh:preflighted,branch_ready,committed,pushed,pr_opened,reviewed,approval_recorded,go_posted,merge_ready,merging,merge_called,merged,parity_ok,cleaned,done, plus the terminal-for-this-runrefused,blocked,failedand thestale_branchevent.
steps.sh— the only writer, and the state machine the states belong to.lock.sh— takes its lock directory from the same journal directory.common.sh—pr_now,pr_say,pr_outand the redaction this library relies on.pr_deliver.md—statusandrecover, the two subcommands that read a journal.
2026-12-04 — read against scripts/pr/lib/journal.sh (133 lines) at the revision this page was written.
The status transcript above is the shape the engine prints (TASK: / JOURNAL: / JOURNAL-PR: /
JOURNAL-HEAD: / PROVIDER:), not a captured run of a specific task.