Skip to content

Every collection of a turn is its own commit, and the session's last commit moves only with it, so a landing that fails loses nothing - #249

Merged
SitgesRun merged 1 commit into
stagingfrom
commit-per-collect
Nov 15, 2026
Merged

SitgesRun merged 1 commit into
stagingfrom
commit-per-collect

Conversation

@SitgesRun

@SitgesRun SitgesRun commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

This makes every collection of a turn its own commit, and moves the session's last commit only inside that commit's ref transaction. Design: ~/RunVid/exports/2026-11-15-commit-per-collect-design.md (approved; revised after a Codex read-only review). The docs PR #248 describes the same behaviour and lands with this one.

The bug it fixes (on staging)

collectTurn moved refs/pine-drama/result in fetchCapture before landTurnFiles. A landing that failed after writing a file left that file unrecorded. A later restore of it was never landed, and the turn settled with the file wrong.

The model

  • One rule for every collection. Every collection, while the turn runs and once after Pine's end, lands every path that any capture in acked..to changed (git log --name-only, new changesAlong), each as the newest capture holds it. It lands them as one pine-computer commit with the turn's trailers (commitEntriesToHistory), with acked moving in the same update-ref --stdin transaction.
  • Why a failure loses nothing. A landing that fails, once or several times in a row, leaves acked behind. Every path such a landing may have written is in the chain, so the next collection lands it from the newest capture.
  • The per-file 3-way rule. What the folder holds that no commit records is committed first, as client-found-changes-on-disk.
    • A file only the person changed is in no capture's changes, so it stays.
    • A file both sides changed keeps the person's version in history and gets the turn's. Nothing is blocked; media does not merge.
    • Precedent: codex-rs git-utils/src/apply.rs:55 applies with git apply --3way, and Aider commits dirty changes first.
  • A lost session still lands what was fetched. Once a session is gone, the captures fetched from it and not landed still land (landCaptures), from the project's own refs.
  • The put still snapshots the index, as on staging. A snapshot of HEAD has its own edge after a failed recording; both edges are in A hand edit is lost from history when its git add succeeds and its commit then fails #250.

Deleted

  • forgetCaptures, and its call in chats.ts;
  • the last flag;
  • the edited path, and its receipt pair, waiting for the end;
  • the stage-without-commit branch;
  • stagePaths and commitIndexPaths in the landing;
  • two applyChange tests that covered only the waiting.

Added, each for a bug the change would otherwise cause

  • Left-out paths during a turn. A running collection's left-out paths are told when it finds them, through the follower's own push. No later collection sees them again, and the timer used to discard what a running collection yields.
  • A settled turn's files. They are now the files of all the turn's commits, from the existing reader listHistory filtered by turnId. Without that, latestTurnFiles and the Chat's episode list would see only the last collection.

Not in this PR

#250 covers a gap that is on staging already: every stage-then-commit path leaves an edit staged and unrecorded when the stage succeeds and the commit then fails. The index-vs-HEAD snapshot edges are there too. It is planned for after the stable tag.

Codex review

  • 6c5cba6, 4 findings, all fixed:
  • 1a01624, 2 findings, both fixed:
    • the follow's failure path awaits the collector too;
    • the session-ended notice now says only what was written after the last collection is lost.
  • 9b045c1: no findings.

Tests

  • Failing-first. "collections whose landings fail lose nothing" locks git's index.lock and HEAD.lock, so two landings in a row fail, and the second one restores the file. On staging's code (763fffe, the same test with staging's API) it FAILED: 330 tests, 328 pass, 1 fail, on "the restore lands" ('for a moment' stayed).
  • Rewritten. The turn.test.ts and protocolFlow tests that asserted "no commit while running" or "one commit at the end" now assert one commit per collection, plus the 3-way cases: only the person changed a file, both changed it, and a removed file the turn writes again.
  • New test: "a capture fetched and not landed lands from the project's own refs once its session is gone".
  • This head 9b045c1: pine-dev PASSED in 97 s. npm test: 329 tests, 328 pass, 0 fail, 1 skipped. Render smoke: 30 of 30 pages (run 20261115T214326-9b045c18).

Size

9 files, +208/−196. Core and doc alone: 5 files, +114/−101.

doc/protocol.md changes 2.1, 2.3, 3 (the 3-way rule), 4.3 and 5.

…commit moves only with it, so a landing that fails loses nothing

A running turn's collections staged their files with no commit, and its end
made one commit of everything since the session's last commit. The last capture
fetched (refs/pine-drama/result) moved before its files landed, so a landing that
failed after writing a file left that file unrecorded, a later restore of it was
never landed, and the turn settled with the file wrong.

Now every collection, while the turn runs and once after Pine's end, is the
same: it lands every path that any capture since the session's last commit
changed (git log acked..to, changesAlong), each as the newest capture holds it,
in one pine-computer commit with the turn's trailers, and moves the session's
last commit in that commit's ref transaction. A landing that fails, once or
several times in a row, leaves the last commit behind, so the next collection
lands every path the failed ones may have written. What the folder holds that no
commit records is committed first as client-found-changes-on-disk, so a file the
person and the turn both changed keeps the person's version in history and gets
the turn's; a file only the person changed stays (git's 3-way rule per file;
codex-rs git-utils/src/apply.rs applies with git apply --3way).

Deleted: forgetCaptures, the `last` flag, the edited path and its receipt pair
waiting for the end, and the stage-without-commit branch. Once a session is gone,
the captures fetched from it and not landed still land (landCaptures), from the
project's own refs. A running collection's left-out paths are told when it finds
them, through the follower's own stream, which waits for the collection at the
turn's end, since no later collection sees them again; a settled turn's files are those of
all its commits, read by its trailer with listHistory. doc/protocol.md 2.1, 2.3,
3, 4.3 and 5 say so.

Signed-off-by: SitgesRun <169425442+SitgesRun@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant