Skip to content

feat(cli): add ability for user to cancle file transfer in CLI via CTRL+C#2341

Open
LevinCeglie wants to merge 8 commits into
devfrom
feat/cli_file_transfer_cancel
Open

feat(cli): add ability for user to cancle file transfer in CLI via CTRL+C#2341
LevinCeglie wants to merge 8 commits into
devfrom
feat/cli_file_transfer_cancel

Conversation

@LevinCeglie

@LevinCeglie LevinCeglie commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

This PR implements robust cancelation logic for file transfers via the CLI. With these changes, the user can interrupt file uploads and downloads using CTRL+C (KeyboardInterrupt) and the CLI will gracefully cancel the transfers and still create a summary.

@LevinCeglie
LevinCeglie force-pushed the feat/cli_file_transfer_cancel branch from c003810 to 602335d Compare July 14, 2026 07:34
@LevinCeglie LevinCeglie changed the title feat(cli): UNFINISHED, trying to implement ability to cancel file tra… feat(cli): add ability for user to cancle file transfer in CLI via CTRL+C Jul 14, 2026
@LevinCeglie
LevinCeglie marked this pull request as ready for review July 14, 2026 09:11
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds CLI cancellation support for file transfers. The main changes are:

  • Cancellation events passed into upload and download workers.
  • Cancel-aware retry waits and transfer callbacks.
  • Cleanup logic for interrupted downloads.
  • Canceled transfer counts in upload and download summaries.
  • Exit code 130 for interrupted CLI transfers.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The latest cleanup logic preserves resumed download data while removing interrupted overwrite output.
  • The CLI now reports interrupted transfers and exits with the expected cancellation code.

Important Files Changed

Filename Overview
cli/kleinkram/api/file_transfer.py Adds transfer cancellation state, worker cleanup, retry interruption, canceled result states, and partial-file cleanup.
cli/kleinkram/cli/_download.py Adds canceled download counts to summaries and exits with code 130 after cancellation.
cli/kleinkram/cli/_upload.py Adds canceled upload counts to summaries and exits with code 130 after cancellation.
cli/kleinkram/errors.py Adds a cancellation marker error for transfer workers.

Reviews (5): Last reviewed commit: "fix(cli): fix data deletion of cleanup d..." | Re-trigger Greptile

Comment thread cli/kleinkram/api/file_transfer.py Outdated
Comment thread cli/kleinkram/api/file_transfer.py Outdated
Comment thread cli/kleinkram/api/file_transfer.py Outdated
except KeyboardInterrupt:
logger.info("Upload interrupted by user, cancelling...")
interrupted = True
cancel_event.set()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Running workers still block shutdown(wait=False, cancel_futures=True) only cancels work that has not started. Any worker already inside the S3 or HTTP transfer continues running on a non-daemon executor thread, which keeps the Python process alive after the summary is printed and exit code 130 is raised. A Ctrl+C can still appear to hang until those in-flight transfer calls return.

Prompt To Fix With AI
This is a comment left during a code review.
Path: cli/kleinkram/api/file_transfer.py
Line: 681

Comment:
**Running workers still block** `shutdown(wait=False, cancel_futures=True)` only cancels work that has not started. Any worker already inside the S3 or HTTP transfer continues running on a non-daemon executor thread, which keeps the Python process alive after the summary is printed and exit code 130 is raised. A Ctrl+C can still appear to hang until those in-flight transfer calls return.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

not an issue, cancel_event is checked every chunk during download and during each boto3_cb callback during upload.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's a fair point — if cancel_event is checked on every chunk (download) and every boto3_cb callback (upload), in-flight workers will exit their inner loops promptly after the event is set. That does effectively address the blocking concern; shutdown(wait=False) just avoids waiting for the already-cooperating threads to finish their current loop iteration.

I'll withdraw the concern. Thanks for the clarification.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

Comment thread cli/kleinkram/api/file_transfer.py Outdated
@LevinCeglie
LevinCeglie force-pushed the feat/cli_file_transfer_cancel branch from 6ad4311 to c7ff0a9 Compare July 14, 2026 12:49
Comment thread cli/kleinkram/api/file_transfer.py Outdated
@LevinCeglie
LevinCeglie force-pushed the feat/cli_file_transfer_cancel branch from c7ff0a9 to 9e4dfaf Compare July 14, 2026 12:55
@LevinCeglie
LevinCeglie requested a review from wp99cp July 14, 2026 12:58
LevinCeglie added a commit that referenced this pull request Jul 17, 2026
LevinCeglie added a commit that referenced this pull request Jul 17, 2026
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.

feat: add ability to cancel file transfer via KeyboardInterrupt in CLI

1 participant