Skip to content

store session snapshots in custom git refs - #206

Open
CNSeniorious000 wants to merge 4 commits into
mainfrom
store-session-snapshots-in-git-refs
Open

CNSeniorious000 wants to merge 4 commits into
mainfrom
store-session-snapshots-in-git-refs

Conversation

@CNSeniorious000

Copy link
Copy Markdown
Member

Problem

The org's Free artifact allowance ran out: 396.74 GB-h accrued in November, 93.8% from promplate/platform. Session snapshots were the driver — the same ref-main session uploaded 88.5 MiB and 101 MiB on consecutive days. The obvious fix (prune tool output before the newest compaction checkpoint) is unacceptable: the reviewer greps its own earlier session JSONL to reuse previous tool-call results, so clearing tool output removes context it relies on (#202 was closed for this reason).

Change

session-ref-prefix (empty keeps artifacts; for example agent-sessions) moves snapshots to custom git refs in the same repository:

  • One ref per session: refs/<prefix>/<sha256(model + NUL + session-key)>.
  • Append-only: every save adds a commit with the complete current snapshot; nothing is pruned.
  • Raw files, not an archive: each file is split into 16 MiB chunks plus a manifest (path, size, SHA-256). Restore fetches only that ref at depth 1, reassembles the files byte-for-byte, and verifies every chunk and file before writing.
  • Restore prefers the ref; when it is absent it falls back to an artifact, then the legacy cache. Fork restore follows the same order.
  • A save is based on the commit this run restored (SESSION_REF_BASE); if the ref moved meanwhile, the run keeps the newer snapshot instead of overwriting it.
  • Fix PR ready uses the commit this save pushed as its proof.
  • Restore accepts only sessions/**, last-thread-id and check-runs.jsonl; config, auth and hooks cannot be injected through a snapshot.
  • find distinguishes "no such ref" (git status 2) from network/permission errors and fails on the latter, so a transient error cannot silently fall back to stale state.
  • encrypt-snapshots is rejected early in this mode (per-file encryption would defeat CAS and is not implemented yet).
  • Uses the App installation token through the refreshed GH_CONFIG_DIR, not the job's GITHUB_TOKEN.

Verification

  • rb-hq smoke test (temporary private repo, deleted afterwards): custom-ref push accepted; a workflow on on: push did not run for the custom ref; ls-remote and git/matching-refs can read it; git fetch --depth 1 works; a shallow client can append and push back.
  • bun test scripts/session-ref.test.ts: 7 pass (round trip, multi-chunk, empty file, append history, idempotent save, missing ref, path traversal, corrupt manifest, stale-writer refusal).
  • bun test scripts/recovery.test.ts: 66 pass; snapshot tests: 101 pass.
  • The full suite on macOS has the same pre-existing injected-log/hosted failures as main.

Reviews

  • Codex CLI (2 rounds): found hooks.json injection through restore (fixed with a path whitelist), suffix-matching refs (fixed with an exact refspec and exact ls-remote filter), lost snapshots after a failed push (fixed with expected/candidate logic), partial restore receipts (fixed with staging and verification), find-versus-error fallback (fixed), fork gate (fixed), GH_TOKEN precedence (fixed), prefix validation (fixed), autocrlf (fixed).
  • Kimi (2 rounds): same migration/rollback and base-version concerns; addressed in code and README.
  • MiMo: unavailable — the gateway returned reasoning-only/empty content, 524/500 or connection errors.

Limits / follow-ups

  • Custom refs are readable by anyone with repository read access and live forever; snapshots contain tool output. Repository growth must be watched; changing the prefix starts a new namespace. encrypt-snapshots support (per-chunk AEAD with reuse) is a follow-up.
  • GitHub's 2 GiB single-push limit and 100 MiB file limit are handled by chunking, but an enormous first migration may need splitting.
  • Once a session has a ref, the ref is authoritative; rollback means renaming or deleting the ref, not just removing the input.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T17:09:13.902605Z 90d9903 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9619e76e-b026-40ab-9a1f-696da4874011
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@muspi-merol-review

Copy link
Copy Markdown
Contributor

Found that a ref advancing between lookup and restore could drop a completed review’s checkpoint, and that a runner’s global ignore rules could produce a successful save with no manifest. Fixed both in ee0d21e. The save now uses the commit it actually restored, preserves the snapshot’s exact bytes, and rejects branch and tag namespaces.

@muspi-merol-review

Copy link
Copy Markdown
Contributor

Found that a runner’s Git settings could send plaintext snapshots to a different repository after the visibility check passed. Fixed it in 4b79fc1. The action now checks the URLs Git will use for fetch and push and stops before transferring data if either differs from the verified repository’s HTTPS URL.

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