Skip to content

Explicit push and pull: hooks record locally, save is commit - #9

Merged
frenchie4111 merged 6 commits into
mainfrom
feat/explicit-push
Nov 20, 2026
Merged

frenchie4111 merged 6 commits into
mainfrom
feat/explicit-push

Conversation

@frenchie4111

@frenchie4111 frenchie4111 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Hooks used to publish each turn's edit record, file index and transcript to whatever LOCH_STORE named. Against an unreachable S3, every Stop waited on the 20s timeout (end took 8.3s). Codex kills SessionEnd at 3s, so the last turn never left the machine. This PR moves loch to git's model: everything is recorded locally, and a remote is reached only by an explicit step.

Changes

  1. Hooks never touch the network (df39fd6). Hooks and backfill write only to ~/.loch/store. blame, log and ask read only that store. hooks_never_wait_on_a_remote runs stop and end against an endpoint that accepts connections and never answers. Both finish in under 3s, and the same endpoint stalls a real S3 call. Refuse bundles whose session id isn't a plain file name; pin Codex review findings #8's SessionEnd test now asserts the fix.
  2. Named remotes (5fc013f). loch remote add|remove|list stores them in ~/.loch/config. The default is origin, else the only remote. With several remotes and no origin, a command fails as ambiguous-remote instead of guessing. Unknown URI schemes are refused: ssh://host used to become a local directory a push would "succeed" into.
  3. push and pull (f4f2fdf).
    • Push covers the current project's sessions and bundles (a bundle counts if any session in it ran there); --all widens it to every project, --dry-run sends nothing, and --force ignores the markers.
    • What a push has sent is remembered locally (key -> hash), so the remote never gets a manifest. Bundles and index entries commute. Edit records are merged by turn on every hook, pull and push, so a session recorded on two machines keeps both machines' turns.
    • Transcripts are redacted on the way out; the local copy stays verbatim. One that fails redaction is skipped and named in redactionFailed, and the push ends redaction-failed after sending the rest.
    • Tombstones (tombstones/bundle/<ref>, tombstones/session/<agent>/<id>) stop a push from bringing back something deleted on the remote. Push checks them again after uploading, to withdraw anything a racing delete covered. A pull forgets loch's local copies of what they cover, never the agent's own transcript.
    • Keys from a remote are untrusted: FileStore refuses ., .. and empty segments, and pull takes a record only for a known agent and a safe id, with contents matching its key.
    • FileStore writes are now atomic.
  4. The store commands, git style (e2192ac).
    • save is local. save --push [<remote>] sends that one bundle.
    • restore looks locally, then fetches the single bundle from the remote, checks it hashes to the ref, and keeps a copy.
    • list --saved shows this machine's bundles and list --remote is the equivalent of ls-remote.
    • delete is local. With --remote it writes the tombstone on the remote first, then deletes there and here. --session <id> does the same for a session's record, file index and transcripts.
    • reindex --remote repairs the remote's index.

Breaking

  • JSON schema is 3. save no longer uploads to LOCH_STORE, and its store now names the local store. blame, log, ask and backfill no longer take --store.
  • --store <uri> still works on save, restore, list, delete and reindex, meaning what callers intended (--remote <uri>, or save --push <uri>).
  • A plain save with LOCH_STORE set is warned that it didn't upload: stderr in text mode, "deprecated": "LOCH_STORE" in JSON. LOCH_REMOTE is the new variable.
  • Ness/Harness "send worktree to remote" must switch to save --push. restore on the destination machine then fetches the bundle.
  • New codes: no-remote, ambiguous-remote, unknown-remote, remote-exists, invalid-uri, config-unreadable, session-not-found.

Not in this PR

  • An ssh:// remote (a loch helper run on the far side over a single connection) is planned as a follow-up.
  • No run against a real S3 bucket. The tests exercise only file-store remotes.
  • Tombstones apply to every remote. That choice still needs testing against real use.

Testing

cargo fmt --check, cargo clippy --release --all-targets -- -D warnings and cargo test --release all pass. New tests are in tests/remote.rs, tests/trace.rs (push/pull, redaction, scope, tombstones, refused keys, LOCH_STORE fallback) and tests/codex.rs (save/push/restore between machines, hash check, bundle and session deletes, a push failing after the save). CLAUDE.md is updated.

🤖 Generated with Claude Code

frenchie4111 and others added 6 commits November 20, 2026 12:47
The hooks published each turn's edit record, its file index and the
transcript to whatever LOCH_STORE named. With S3 unreachable every Stop
waited on the 20s timeout (end took 8.3s), and Codex kills SessionEnd
at 3s, so the last turn never left the machine. Hooks and backfill now
write to ~/.loch/store alone, and blame, log and ask read only that;
getting records to and from a remote becomes an explicit push and pull.

blame, log, ask and backfill lose --store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
~/.loch/config maps names to store URIs, git style. A command that
reaches past this machine names a remote or a URI, else takes
LOCH_REMOTE, then the deprecated LOCH_STORE (with a warning), then
`origin`, then the only remote. Several remotes and no origin is
ambiguous-remote rather than a guess, since a push to the wrong one
publishes transcripts.

A scheme the store doesn't know (ssh://, http://) is invalid-uri:
create_store takes anything else as a relative path, so ssh://host
would have become a local directory a push silently succeeded into.
Relative paths are kept absolute. A config that won't parse is
config-unreadable and is never overwritten.

Nothing uses a remote yet; push and pull come next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
push sends every saved bundle with its branch entries, and the current
project's edit records, file index and transcripts (--all for every
project's), to a remote. pull fetches records that know more turns than
this machine's copy, with their transcripts. blame, log and ask go on
reading only the local store.

What a push has sent is remembered locally (~/.loch/pushed/<uri hash>,
key -> hash of the local bytes), so the remote gets no manifest and
pushes from several machines still commute. Transcripts are redacted on
the way out; the local copy stays verbatim.

Tombstones (tombstones/bundle/<ref>, tombstones/session/<agent>/<id>)
stop a push from sending what a remote deleted, are checked again after
uploading to withdraw what a racing delete covered, and make a pull
forget loch's local copies. Nothing writes them yet; delete --remote
will.

A remote's keys are untrusted: FileStore refuses empty, . and ..
segments, and pull takes a record only for a known agent, a safe id,
and contents that match its key. FileStore writes are now atomic, since
the local store is written by hooks and pull while either may be killed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
save is commit: it packs the bundle into ~/.loch/store, and
save --push [<remote>] sends that bundle afterwards. restore looks here
first, then fetches the one bundle from the remote, checks it hashes to
the ref and keeps it. list --saved lists this machine's bundles and
list --remote is ls-remote. delete is local; with --remote it writes a
tombstone on the remote first, deletes there, and tombstones and deletes
here. delete --session <id> does the same for a session's record, file
index and transcripts. reindex takes --remote.

--store <uri> keeps working as --remote <uri> (save --push <uri>), the
meaning callers had. A plain save with LOCH_STORE set is warned that it
no longer uploads, and the JSON schema goes to 3. New code:
session-not-found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… transcript

- push sends a bundle only if one of its sessions ran in this project
  (--all for every bundle). Sending every bundle on the machine put one
  client's transcripts on another's remote.
- Edit records merge by turn instead of being replaced. The hook starts
  from its working copy merged with the store's (which pull fills), pull
  merges into the local copy, and push merges the remote's copy in before
  uploading. A session restored under its own id and resumed no longer
  erases the other machine's turns, here or on the remote.
- A transcript whose redaction fails is skipped and named in
  redactionFailed; the rest is still sent and the push ends
  redaction-failed, instead of every later push being blocked.
- push --force ignores the markers, for a remote emptied by hand.
- The local store is compared resolved, so a symlink to it isn't taken
  for a remote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A scoped push unpacked every local bundle on every push to place it in a
project. A ref is the hash of the bundle's bytes, so its sessions' cwds
never change; they are kept in ~/.loch/cache/bundle-cwds/<ref>.json.

merge_with_remote PUT the merged record's file entries before the
record, duplicating what the plan already queues after it and breaking
the record-before-index order. Dropped.

CLAUDE.md notes the other side of merging records: a turn removed on one
machine comes back from another copy, and only a tombstone removes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frenchie4111
frenchie4111 merged commit 7499a5b into main Nov 20, 2026
2 checks passed
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