Skip to content

fix(torrent): forget a finished task's sidecar when its output was relative - #617

Merged
linroid merged 1 commit into
mainfrom
fix/torrent-relative-cleanup
Oct 23, 2026
Merged

linroid merged 1 commit into
mainfrom
fix/torrent-relative-cleanup

Conversation

@linroid

@linroid linroid commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Found while downloading public torrents (Debian netinst, Internet Archive's Big Buck Bunny, WebTorrent's Sintel) with ketch <url> into the current directory. Every v1 torrent ended with:

[WARN] [TorrentSource] Kept the bookkeeping of taskId=…: IllegalArgumentException: Ownership journal belongs to another task

and left its hidden .ketch-<hash>-<task>/ sidecar (checkpoint, ownership, and .piece files for boundary pieces of skipped files) in the download folder. The CLI removes the task once it finishes precisely so this sidecar doesn't clutter the folder. With an absolute destination it was cleaned up; with a relative one (the default, ./) it never was. v2 and hybrid torrents were fine.

Why

TorrentPieceStore resolves its output parameter into the property private val output = absolute(output). But inside the journal by lazy { … } initializer, a bare output names the constructor parameter, which shadows the property there. So the journal was bound to the path as given:

  • The engine always passes an absolute path, so downloads wrote an absolute binding.
  • TorrentDownloadSource.forget/cleanup reopen the store with context.outputPath, which is relative for a relative destination. The binding they computed (output: payload.bin) never matched the journal, the check threw, and the sidecar was kept.

What changes

  • The journal is bound to the resolved output (this.output, with a comment on the shadowing).
  • TorrentOwnershipJournal takes legacyBindings: journals written by earlier versions were bound to the output as given, which can differ from the resolved path when a folder in it is a symlink (Android's /sdcard, macOS's /tmp). They still load, and the next compaction rewrites them with the current binding, so existing tasks keep resuming.

Verification

  • ketch <file>.torrent with a relative destination on a local web-seed torrent: no warning, no sidecar left, payload hash matches. Before: the warning, plus the sidecar left behind. A multi-file torrent with one file selected also leaves only that file.
  • New tests: TorrentCheckpointTest.forget_storeReopenedThroughAnotherSpellingOfItsOutput_removesTheSidecar (fails before the fix with the production error) and TorrentOwnershipJournalTest.legacyBindingLoadsAndCompactionRebindsIt.
  • ./gradlew :library:torrent:jvmTest passes.

…lative

Every v1 torrent `ketch <url>` downloaded into the current directory left
its .ketch-<hash>-<task> sidecar (checkpoint, ownership journal, boundary
pieces) behind, warning "Kept the bookkeeping … Ownership journal belongs
to another task". The journal's binding read the store's constructor
parameter, which shadows the resolved output property inside the lazy
initializer, so a store reopened through a relative path computed another
binding than the engine's, which always passes an absolute one.

The binding now names the resolved output. Journals written before, bound
to the output as given, still load and are rebound by the next compaction.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T14:46:03.482698Z 4b7d706 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 23, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 2 193 files  ± 0   2 221 suites  ±0   58m 15s ⏱️ +32s
15 257 tests + 6  14 989 ✅ + 6  268 💤 ±0  0 ❌ ±0 
18 612 runs  +10  18 344 ✅ +10  268 💤 ±0  0 ❌ ±0 

Results for commit 4b7d706. ± Comparison against base commit c540080.

♻️ This comment has been updated with latest results.

@linroid
linroid merged commit fd06e90 into main Oct 23, 2026
24 of 28 checks passed
@linroid
linroid deleted the fix/torrent-relative-cleanup branch October 23, 2026 15:42
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.

1 participant