Skip to content

(Do not merge) One-time migration script for v2 checkpoints to v1#1257

Draft
computermode wants to merge 2 commits into
mainfrom
tmp-migrate-v2-script
Draft

(Do not merge) One-time migration script for v2 checkpoints to v1#1257
computermode wants to merge 2 commits into
mainfrom
tmp-migrate-v2-script

Conversation

@computermode
Copy link
Copy Markdown
Contributor

@computermode computermode commented May 22, 2026

Example command:

To see all the checkpoints to migrate:

./scripts/migrate-v2-checkpoints-to-v1.sh \
  --repo path/to/repo \
  --since <commit sha> --list

To go through a dry run:

./scripts/migrate-v2-checkpoints-to-v1.sh \
  --repo path/to/repo \
  --since <commit sha> --dry-run

To create the commit that copies the checkpoints from v2 to v1:

./scripts/migrate-v2-checkpoints-to-v1.sh \
  --repo path/to/repo \
  --since <commit sha> --apply

To validate:
git show --stat refs/heads/entire/checkpoints/v1

To push after:
git push origin refs/heads/entire/checkpoints/v1:refs/heads/entire/checkpoints/v1


Note

Medium Risk
Adds a one-off migration script that can create and update the refs/heads/entire/checkpoints/v1 ref based on parsed commit trailers and checkpoint refs; misuse could write incorrect history or overwrite the local ref.

Overview
Introduces scripts/migrate-v2-checkpoints-to-v1.sh, a standalone tool to plan or apply migration of legacy v2 checkpoint artifacts back into the v1 checkpoint tree.

The script scans commits after a given --since (optionally constrained by --head) for Entire-Checkpoint trailers, maps those checkpoint IDs to v2 data under refs/entire/checkpoints/v2/full/* (raw transcripts + hashes), and pulls companion session/prompt metadata from refs/entire/checkpoints/v2/main when available.

It supports --list (checkpoint IDs + commit IDs), --dry-run (print every source artifact), and --apply, which builds a new v1 tree, rewrites checkpoint-level metadata.json to include discovered sessions, and writes a single migration commit updating refs/heads/entire/checkpoints/v1.

Reviewed by Cursor Bugbot for commit 1ea7f14. Configure here.

Entire-Checkpoint: c9bc625237a6
Entire-Checkpoint: e25de9aab773
Copilot AI review requested due to automatic review settings May 22, 2026 23:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a standalone, one-time Bash script to migrate legacy v2 checkpoint artifacts (raw transcripts + companion metadata) into the v1 checkpoint tree and optionally write a single migration commit updating refs/heads/entire/checkpoints/v1.

Changes:

  • Introduces scripts/migrate-v2-checkpoints-to-v1.sh with modes to list, dry-run, or apply a migration.
  • Scans git history for Entire-Checkpoint: <12-hex> trailers and maps them to v2 full/* and main ref artifacts.
  • (On --apply) rewrites checkpoint-level metadata.json to include discovered session entries and writes a migration commit.

main_metadata_file=""

show_help() {
sed -n '3,/^$/p' "$0" | sed -E 's/^# ?//'
Comment on lines +139 to +140

git log HEAD --branches --remotes --format='__ENTIRE_COMMIT__%H%n%B' --not "$since" |
Comment on lines +80 to +93
tree_path_exists() {
local ref_name="$1"
local path="$2"
git cat-file -e "${ref_name}:${path}" 2>/dev/null
}

list_numeric_dirs() {
local ref_name="$1"
local path="$2"
local entries
entries=$(git ls-tree -d --name-only "${ref_name}:${path}" 2>/dev/null || true)
printf '%s\n' "$entries" | sed -nE '/^[0-9]+$/p'
}

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1ea7f14. Configure here.

END {
print count + 0
}
' "$raw_checkpoint_ids_file" "$checkpoint_ids_file")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty first file breaks NR==FNR diagnostic counts

Low Severity

The NR == FNR awk idiom in compute_plan_counts silently produces wrong results when the first file is empty. If raw_checkpoint_ids_file is empty (no raw transcripts found in any full ref) or main_metadata_file is empty (e.g., V2_MAIN_REF doesn't exist), awk treats the second file as the first, routing all its lines into the lookup-building block instead of the counting block. This makes missing_raw_checkpoints, missing_metadata_checkpoints, and missing_metadata_sessions all incorrectly report 0, suppressing the corresponding warning messages that inform the user about skipped checkpoints or missing metadata.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1ea7f14. Configure here.

local entries
entries=$(git ls-tree -d --name-only "${ref_name}:${path}" 2>/dev/null || true)
printf '%s\n' "$entries" | sed -nE '/^[0-9]+$/p'
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three helper functions defined but never called

Low Severity

tree_path_exists, list_numeric_dirs, and v1_raw_artifact_name are defined but never invoked anywhere in the script. The artifact-name mapping logic in v1_raw_artifact_name is duplicated inline within the awk block of write_full_artifact_index. These dead functions add noise for anyone reading or maintaining the script.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1ea7f14. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants