Skip to content

Add hidden checkpoint policy command#1508

Draft
pfleidi wants to merge 3 commits into
checkpoint-format-compatfrom
checkpoint-policy-command
Draft

Add hidden checkpoint policy command#1508
pfleidi wants to merge 3 commits into
checkpoint-format-compatfrom
checkpoint-policy-command

Conversation

@pfleidi

@pfleidi pfleidi commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Why

This is the second PR in the checkpoint-policy stack. It gives the repo a place to record the active checkpoint format and minimum required checkpoint format without turning that policy on in hooks or user command enforcement yet.

Stacked on #1507.

What changed

Adds a checkpoint policy model stored at refs/entire/policies/checkpoint, plus sync/update/push helpers that resolve the same checkpoint remote used by checkpoint storage. Adds a hidden entire checkpoint policy command to inspect or update the policy.

Usage examples

Inspect the effective policy:

entire checkpoint policy

Set the active checkpoint format written by the repo:

entire checkpoint policy --checkpoint-version branch-v1

Set the minimum checkpoint format required by the repo:

entire checkpoint policy --checkpoint-min-version branch-v1

Allow an intentional downgrade:

entire checkpoint policy --checkpoint-version branch-v1 --checkpoint-min-version branch-v1 --force

Decisions made during development

The command is hidden while the policy flow is still being split and reviewed.

The ref is singular and unversioned: refs/entire/policies/checkpoint, matching the checkpoint policy command shape and avoiding another versioned custom ref name.

Policy writes fetch the remote policy state first, evaluate downgrade and support checks against that state, update the local ref, then push only that policy ref.

The policy commit uses the existing checkpoint commit creation path, so signing follows the normal checkpoint commit signing setting when it is configured.

Technical tradeoffs

The policy reader accepts unsupported policy values so newer clients can publish future policy states without older clients corrupting or deleting them. Updates remain stricter: this CLI only allows setting versions it knows how to write or read.

Remote freshness is intentionally simple. The command compares the remote ref hash, fetches only when the hash differs, and avoids filesystem cache files or background refresh state.

Runtime enforcement is left out of this PR so reviewers can first inspect the policy storage and command surface independently.

Reviewer notes

This PR does not enforce the policy in hooks or user commands. That remains in the next stacked PR.


Note

Medium Risk
Policy updates push to the configured checkpoint remote and can change repo-wide format expectations, but the command is hidden and enforcement is not wired in yet.

Overview
Adds a checkpoint policy layer so repos can record which checkpoint format they write and the minimum format they require, stored at refs/entire/policies/checkpoint as policy.json commits on a dedicated ref (not on normal branches).

A new checkpointpolicy package handles read/write, remote sync (same checkpoint remote as checkpoint storage), updates with validation and downgrade guards (--force to override), and push of only the policy ref. Format helpers gain CanWrite, Compare, and ranked families; reads tolerate unknown future policy values while writes stay limited to CLI-supported versions.

Registers a hidden entire checkpoint policy subcommand: no flags syncs and prints effective checkpoint_version, checkpoint_min_version, and source; flags set versions, update locally, then push. No hook or command enforcement in this PR—that is deferred to a follow-up.

Reviewed by Cursor Bugbot for commit f3c10b3. Configure here.

Store the repo checkpoint policy in a dedicated git ref and expose a hidden command for inspecting and updating it.

The command syncs with the checkpoint remote before updates, rejects unsupported versions, and pushes only the policy ref.

Entire-Checkpoint: b7feda2b129a
Copilot AI review requested due to automatic review settings June 23, 2026 21:23
if err != nil && !errors.Is(err, errStopTraversal) {
return false
}
return found

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cancel during ancestry misclassified

Medium Severity

When the user cancels while isAncestorOf walks commit history, the helper returns false and drops the cancellation error. Sync then reports local-diverged instead of stopping cleanly, and updateBaseline can emit a false “diverges from remote” error even when local and remote share history.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4518d7b. Configure here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds repository-level checkpoint policy storage and a hidden CLI surface to inspect/update it, without yet enforcing policy during hooks or checkpoint operations. This fits into the broader checkpoint format compatibility work by introducing a durable “policy ref” that later PRs can consult.

Changes:

  • Registers a hidden entire policy command group with a visible entire policy checkpoint subcommand for inspecting/updating policy state.
  • Introduces checkpointpolicy storage + remote sync/update/push helpers for refs/entire/policies/checkpoint (persisted as policy.json in commits).
  • Extends checkpoint format handling with ordering (Compare) and explicit read/write support checks (CanRead / CanWrite), plus tests.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/entire/cli/root.go Registers the new hidden policy command group on the root command.
cmd/entire/cli/root_test.go Adds coverage asserting the policy group is hidden while the checkpoint subcommand remains invokable.
cmd/entire/cli/policy_group.go Implements the hidden policy group command and its git-repo precondition.
cmd/entire/cli/policy_checkpoint.go Implements entire policy checkpoint inspect/update flow (sync vs update+push).
cmd/entire/cli/policy_checkpoint_test.go Adds command-level tests for defaults, validation, downgrade behavior, push behavior, and cancellation silencing.
cmd/entire/cli/checkpointpolicy/update.go Adds update logic with baseline selection, downgrade rejection, and policy validation.
cmd/entire/cli/checkpointpolicy/update_test.go Adds tests for downgrade/force, local-ahead behavior, and divergence rejection.
cmd/entire/cli/checkpointpolicy/store.go Adds local read/write for policy commits and ref management for refs/entire/policies/checkpoint.
cmd/entire/cli/checkpointpolicy/store_test.go Adds tests for defaults, roundtrip read/write, malformed JSON, and preserving unsupported policy values on read.
cmd/entire/cli/checkpointpolicy/remote.go Adds remote hash check, sync (fetch-on-diff), and push helpers for the policy ref.
cmd/entire/cli/checkpointpolicy/remote_test.go Adds tests for sync behavior, divergence behavior, push rejection, and target resolution behavior.
cmd/entire/cli/checkpointpolicy/remote_internal_test.go Adds unit tests for remote hash parsing.
cmd/entire/cli/checkpointpolicy/policy.go Defines policy model/defaults/validation rules.
cmd/entire/cli/checkpointpolicy/policy_test.go Adds tests for defaults and validation failures.
cmd/entire/cli/checkpointpolicy/format.go Extends format parsing with family ranks, Compare, and write-support tracking.
cmd/entire/cli/checkpointpolicy/format_test.go Updates tests to cover CanWrite, Compare, and string roundtrips.

Comment on lines +104 to +110
fetched, err := fetchRemotePolicy(ctx, repo, target)
if err != nil {
return State{}, false, err
}
fetched.RemoteHash = remoteState.Hash
defer removeFetchRef(repo)
return fetched, true, nil
pfleidi added 2 commits June 23, 2026 16:53
Nest the checkpoint policy command under the checkpoint group and remove the hidden top-level policy group.

This makes the development command path entire checkpoint policy while preserving the existing hidden status.

Entire-Checkpoint: 21cc4b97e773
@pfleidi

pfleidi commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

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 f3c10b3. Configure here.

testutil.InitRepo(t, dir)
repo, err := git.PlainOpen(dir)
require.NoError(t, err)
return dir, repo

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing git config isolation

Low Severity

New checkpointpolicy remote/update tests call Sync, Update, and Push, which shell out to git via checkpoint/remote using the process environment, but the shared repo fixture never calls testutil.IsolateGitConfigEnv. That can inherit a developer global git config and trigger flaky background git gc during t.TempDir() cleanup.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by learned rule: Tests shelling out to git CLI must call testutil.IsolateGitConfigEnv(t)

Reviewed by Cursor Bugbot for commit f3c10b3. 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