Skip to content

Drive v2 downloads from peer events through verified storage - #206

Closed
linroid wants to merge 2 commits into
torrent-v2-08-peer-poolfrom
torrent-v2-08-session-loop
Closed

linroid wants to merge 2 commits into
torrent-v2-08-peer-poolfrom
torrent-v2-08-session-loop

Conversation

@linroid

@linroid linroid commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

A v2 download can now progress automatically from peer availability to verified file storage. The new session loop consumes the shared peer event stream and commit completions, selects rare pieces, establishes interest, dispatches block plans without waiting for socket writes, and transfers complete assemblies to the storage worker.

Only verified, flushed commits publish completion. Corrupt pieces are retried; a departing peer's blocks become available after its actor joins; disk failures stop the session. The last peer may depart while a commit is pending, and the loop still waits for that result. Availability/interest counts belong to the session, so it does not read mutable peer actor state or scan the full torrent on every block response. Admission pressure uses a bounded retry timer; healthy idle peers do not poll.

Stacked on #205, including its intentional-stop review fix; part of #162. This internal full-metainfo path uses initialized matching storage and negotiated peers. Discovery, magnet resolution, complete hash serving/seeding, corrupt-peer reputation, public runtime registration, independent-client v2 interoperability and performance gates remain outstanding.

Validation at fe5d73c57da3654ee46544abd891ffc951e2d073: 489 JVM and 468 executed iOS simulator tests, zero failures/errors/skips; both pinned v1 conformance scenarios and native dependency guard passed. New integration tests use deterministic framed peers and real file storage to cover selected output, corruption retry, peer failure/reassignment, disk failure, all peers exhausted, last-peer departure during blocked storage, and previously verified selection without peers.

Review follow-up 979922d5: after joined peer departure, unavailable incomplete assemblies without live assignments are evicted so they cannot occupy every active slot. Live requests and completed assemblies retain ownership. A deterministic one-slot/disjoint-availability regression times out with eviction disabled and passes with the fix. The dependent TCP branch at 50fc348c89a4b9bbaf988858bf2107754e15b2c6 includes this fix and passed 494 JVM / 473 executed iOS tests, both pinned v1 conformance scenarios, and the native dependency guard.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 12, 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-09-12T19:47:10.991828Z fe5d73c 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe5d73c57d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

view.inFlight == pipeline || view.admissionBlocked) continue
var plan = pieces.planNext(peer.blocks) { rarity.has(peer, it) }
if (plan == null) {
val index = rarity.pick(peer) { pieces.canBegin(it) }

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 Badge Evict unavailable assemblies before enforcing the active limit

When a peer disconnects after partially filling maxActive assemblies and the remaining peers advertise only other wanted pieces, detachPeer releases the requests but leaves those assemblies counted as active. The pieces.canBegin predicate therefore rejects every piece the remaining peers can provide; because no peer is admission-blocked and no further event is required, the session can wait indefinitely instead of continuing with available pieces.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 979922d. After joined peer departure, the session removes its availability/assignments and evicts only incomplete assemblies that no remaining peer advertises and that have no live assignments. This releases active slots without dropping completed assemblies waiting for storage. The regression uses one active slot, disjoint peer availability, a partial-piece disconnect, and a later Have: it times out with eviction disabled and passes with the fix. A separate test preserves live requests and completed assemblies. JVM focused tests and iOS compilation passed; full combined JVM/iOS validation is running in the dependent TCP-test branch.

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

  692 files  + 5    692 suites  +5   4m 1s ⏱️ -1s
2 852 tests +24  2 852 ✅ +24  0 💤 ±0  0 ❌ ±0 
3 832 runs  +40  3 832 ✅ +40  0 💤 ±0  0 ❌ ±0 

Results for commit 979922d. ± Comparison against base commit cecc58a.

♻️ This comment has been updated with latest results.

@linroid

linroid commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #236 (V2 scheduling and download execution) in the consolidated eight-PR stack for #162.

The replacement preserves this PR's code and subsequent fixes; its description links the original head and review discussions. The only additional consolidation fix is the CI-discovered listener cancellation regression, documented on the replacement. All eight replacements have passed their required CI checks.

Closing without merging. This branch and its discussions remain available for reference. Review index: #162 (comment)

@linroid linroid closed this Sep 20, 2026
@linroid
linroid deleted the torrent-v2-08-session-loop branch September 20, 2026 11:13
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