Add GetTransaction/CancelTransaction to npackd - #10
Merged
Merged
Conversation
Install and Update accept "async": true to return {"transaction_id":
N} immediately instead of blocking until completion; GetTransaction
polls a transaction's status (running/succeeded/failed/cancelled).
CancelTransaction is cooperative rather than raw task abortion: a
shared AtomicBool cancellation flag is threaded through
InstallRefOptions/ResolverState and checked only at the start of
processing each package (before starting the next package in a
dependency graph, or the next package in an Update loop) -- never
mid-download or mid-install of a package already in progress, so a
cancelled transaction cannot leave the store half-installed.
Verified end-to-end over a real socket: an async Update against an
empty store completes and reports succeeded via GetTransaction, and
cancelling an in-flight async Install against a real relay before its
resolve step starts reports cancelled.
Streamed progress events (e.g. per-file download progress) remain
future work.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
InstallandUpdateaccept"async": trueto return{"transaction_id": N}immediately instead of blocking until completion.GetTransaction { transaction_id }polls a transaction's status:running,succeeded(withresult),failed(witherror), orcancelled.CancelTransaction { transaction_id }requests cancellation — cooperative, not forcible. A sharedAtomicBoolcancellation flag is threaded throughInstallRefOptions/ResolverStateand checked only at the start of processing each package (before starting the next package in a dependency graph, or the next package in anUpdateloop) — never mid-download or mid-install of a package already in progress, so a cancelled transaction cannot leave the store half-installed.async)Install/Updatecalls are unaffected — same behavior as before, just now with an unusedcancel: None.Why cooperative cancellation
The previous PR's follow-up notes flagged that raw
tokiotask abortion is unsafe here: aborting mid-file-write or mid-manifest-write could leave the package store in a half-installed, inconsistent state. This checks a flag only at package boundaries, which is the same "unit of work" granularity the existing dependency-cycle/already-installed checks use.Test plan
cargo fmt --all -- --checkcargo clippy --all-targets --all-features(no warnings)cargo test(50 passing), including:install_remote_package_respects_cancellation_before_starting_a_package— a pre-cancelled flag causes an immediate, clean bail before any network/filesystem worktransactions_report_running_then_succeeded_and_reject_unknown_idscancel_transaction_stops_a_cooperative_taskUpdateagainst an empty store →{"transaction_id":1}→GetTransactionreportssucceededwith the same arrayUpdatewould have returned synchronouslyInstallof npack's own real release against a real relay, cancelled immediately →GetTransactionreportscancelledbefore any download startedNot in this PR
Streamed progress events (e.g. per-file download progress) — a client still only sees
runninguntil the transaction finishes, not incremental progress. Tracked in the roadmap as remaining Phase 2 work.🤖 Generated with Claude Code