Skip to content

fix(checkpoint): honor cancellation and show progress in push + import loops - #1933

Closed
gtrrz-victor wants to merge 5 commits into
mainfrom
fix/checkpoint-push-import-cancellation
Closed

fix(checkpoint): honor cancellation and show progress in push + import loops#1933
gtrrz-victor wants to merge 5 commits into
mainfrom
fix/checkpoint-push-import-cancellation

Conversation

@gtrrz-victor

@gtrrz-victor gtrrz-victor commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

https://entire.io/gh/entireio/cli/trails/993

Summary

The git-refs checkpoint push drain and the agent-history import loop each iterate an unbounded, user-scaled collection (checkpoint refs / imported sessions) doing per-item work, but never observed context cancellation and gave no per-item progress. Surfaced while looking into auto-import on entire enable:

  1. No progress during the per-ref divergence push — just a spinner, so the user couldn't tell how much was left.
  2. Context cancel not propagated into the push loop — Ctrl-C during the user's git push was ignored.
  3. Unbounded work — many sessions/refs could keep the loop running for a long time with no way to stop.

What Changed

flushCheckpointRefsQueue (strategy/manual_commit_push.go)

  • Per-ref k/N progress counter in the divergence recovery loop (was a single spinner over the whole loop).
  • Cancellation short-circuit right after the batch push fails — a cancelled batch is not a divergence, so we bail cleanly instead of entering per-ref recovery.
  • ctx.Err() break inside the per-ref loop for a cancel that lands mid-recovery.
  • Only confirmed-pushed refs leave the queue, so the remainder is retried on the next push (no queue corruption, no force-push).

agentimport.Run (agentimport/agentimport.go)

  • ctx.Err() check at the top of the session loop so a large import stops cleanly between sessions. Already-written checkpoints stay put (idempotent by deterministic ID), so a re-run resumes where it left off.

runSelectedImports (setup_import.go) — from PR review

  • Treats context.Canceled from agentimport.Run as an abort of the whole enable auto-import phase: prints a single Import cancelled. note and returns, instead of continuing to the next agent (which would re-run Discover and emit another "context canceled" note per remaining agent).

Reaction to cancel is uniform: stop, keep only what actually landed, leave the rest for a retry, surface context.Canceled. Callers already handle it (pre-push logs and never blocks the user's push; doctor_migrate exits silently via errors.Is).

Deferred (not in this PR)

Issue 3's structural fix — parsing git push --porcelain output so a single diverged ref among thousands triggers one recovery instead of demoting the whole batch to per-ref recovery. Discussed but intentionally left for a follow-up.

Verification

  • go test ./cmd/entire/cli/agentimport/... ./cmd/entire/cli/strategy/... ./cmd/entire/cli/ — pass (incl. after merging main).
  • Regression tests: TestFlushCheckpointRefsQueue_CancelledContextStopsCleanly (push), TestRun_CancelledContextStopsBeforeScanning (import), TestRunSelectedImports_CancelStopsImportPhase (enable phase abort — asserts the second agent is never processed).
  • golangci-lint run on the touched packages — 0 issues. gofmt clean.
  • Merged latest main and resolved the manual_commit_push.go conflict (adopted main's reworded, cause-agnostic failure message and dest.target push-destination refactor while keeping the per-ref progress + cancellation handling).

…t loops

The git-refs checkpoint push drain and the agent-history import loop each
iterate an unbounded, user-scaled collection (checkpoint refs / imported
sessions) doing per-item work, but never observed context cancellation and
gave no per-item progress. With many items a Ctrl-C during the user's git
push (or a large `entire enable` import) was ignored, and the divergence
push path showed only a spinner with no sense of how much was left.

- flushCheckpointRefsQueue: add a per-ref "k/N" progress counter in the
  divergence recovery loop, a cancellation short-circuit right after the
  batch push fails (a cancelled batch is not a divergence), and a ctx.Err()
  break inside the per-ref loop for a cancel that lands mid-recovery. Only
  confirmed-pushed refs leave the queue, so the remainder is retried next push.
- agentimport.Run: check ctx.Err() at the top of the session loop so a large
  import stops cleanly between sessions. Already-written checkpoints stay put
  (idempotent by deterministic ID), so a re-run resumes where it left off.

Regression tests cover both cancellation paths.
Copilot AI lite review requested due to automatic review settings August 10, 2026 08:38
@gtrrz-victor
gtrrz-victor requested a review from a team as a code owner August 10, 2026 08:38

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

Improves long-running checkpoint-related loops (git-refs push drain and agent transcript import) by honoring context cancellation and surfacing clearer per-item progress, so users can reliably interrupt large operations and understand forward progress during divergence recovery.

Changes:

  • Add cancellation short-circuits and in-loop ctx.Err() checks to stop cleanly on Ctrl-C while preserving retry semantics.
  • Improve stderr progress output during per-ref divergence recovery with k/N counters and per-ref spinners plus a final synced summary.
  • Add regression tests covering pre-cancelled contexts for both the push drain and import loop.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
cmd/entire/cli/strategy/manual_commit_push.go Adds cancellation handling and clearer per-ref progress output in flushCheckpointRefsQueue divergence recovery.
cmd/entire/cli/strategy/refs_push_test.go Adds a regression test ensuring cancelled contexts stop cleanly and leave refs queued/unpushed.
cmd/entire/cli/agentimport/agentimport.go Adds a ctx.Err() guard at the top of the per-session loop to stop imports cleanly between sessions.
cmd/entire/cli/agentimport/agentimport_test.go Adds a regression test verifying cancelled imports do not scan sessions or write checkpoints.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@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.

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 4e6e57e. Configure here.

Comment thread cmd/entire/cli/agentimport/agentimport.go
gtrrz-victor and others added 4 commits August 10, 2026 11:04
runSelectedImports treated context.Canceled from agentimport.Run like any
soft per-agent failure and continued to the next agent — re-running Discover
per remaining agent and printing a 'context canceled' note for each. Stop the
whole phase on the first cancellation instead, printing a single 'Import
cancelled.' note. Already-written checkpoints stay put (idempotent on re-run).
…mport-cancellation

# Conflicts:
#	cmd/entire/cli/strategy/manual_commit_push.go
When Ctrl-C aborts the auto-import phase, an earlier agent in the loop may
already have imported local-only history. The early return skipped the
logged-out not-synced notice, so the user silently lost the warning that
their imported history won't reach the dashboard. Emit warnIfImportNotSynced
before returning on the cancellation path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
In the per-ref checkpoint push recovery loop, the mid-loop context.Err()
check overwrote firstErr unconditionally. If an earlier ref failed for a
genuine reason (auth, conflict) and the context was then cancelled, callers
like PushQueuedCheckpointRefs surfaced context.Canceled and hid the real
failure. Guard with `if firstErr == nil`, matching the per-ref push guard
below.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gtrrz-victor

Copy link
Copy Markdown
Contributor Author

Duplicated -> #1925

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