Skip to content

Assemble admitted v2 peer blocks before verified storage commit - #195

Closed
linroid wants to merge 2 commits into
torrent-v2-08-block-exchangefrom
torrent-v2-08-piece-assembly
Closed

linroid wants to merge 2 commits into
torrent-v2-08-block-exchangefrom
torrent-v2-08-piece-assembly

Conversation

@linroid

@linroid linroid commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

V2 peer blocks are assembled under an independent reservation before verified storage commit. The assembly accepts canonical blocks out of order and rejects invalid/duplicate ranges. Complete assemblies seal their admitted payload and retain credit until the store validates, writes and flushes it. This avoids a second full-size reservation, allowing a 16 MiB piece to commit within the default 32 MiB transfer budget. Ordinary mutable buffers retain the store’s defensive copy path.

Stacked on #194, under #162. Full event-loop/timer wiring, multi-peer scheduling, upload/hash serving and runtime integration remain unfinished.

Validation:

  • Original assembly head 908aa34a passed 442 JVM and 421 executed iOS tests, conformance and native-runtime guard.
  • Review fix 8013ac45 passes focused assembly/storage JVM tests and iOS compilation. The full-size regression failed before the fix and now passes, with cancellation coverage for reservation retention while awaiting storage admission.
  • Descendant inbox head 3a0f0cd7 includes the fix and passes 449 JVM and 428 executed iOS tests, both pinned v1 conformance scenarios and the native-runtime guard.
  • Real TCP integration connects v2 handshake, bounded requests, reverse-order blocks, assembly and authenticated disk commit. This controlled-peer test does not establish independent-client v2 interoperability or production release gates.

@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-12T17:51:43.768420Z 908aa34 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: 908aa34a27

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

val length = layout.v2Piece(index.toLong()).length.toInt()
val blocks = (length + PeerWire.BLOCK_SIZE - 1) / PeerWire.BLOCK_SIZE
// Includes payload, received flags, bounded missing-index snapshots and container allowance.
val lease = budget.reserve(length + blocks * 32 + 512) ?: return null

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 Reserve headroom for the store's commit copy

With the permitted 16 MiB piece length and the default 32 MiB transfer budget, this lease consumes 16 MiB plus 33,280 bytes for assembly bookkeeping. After delivery leases are released, TorrentV2PieceStore.commit() still reserves another full 16 MiB at TorrentV2PieceStore.kt:112, exceeding the budget by 33,280 bytes, so every full-size piece deterministically fails storage admission and is discarded. Creation must account for the commit copy's headroom, or the consuming commit must reuse the assembly's admitted buffer ownership.

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 8013ac4. Complete assemblies now seal their private admitted buffer and use the store’s owned-buffer path, retaining its reservation until validation/write/flush unwinds. Ordinary mutable caller buffers still use the defensive private copy, and both paths share the same integrity and flush/publication barrier. Closing a committing assembly cannot release credit early.

The new full 16 MiB piece test reproduced the prior failure (Payload buffer budget exhausted) under a 32 MiB budget and passes after the fix. Additional coverage verifies credit retention and cancellation while waiting for storage admission. Focused JVM/storage tests and iOS compilation pass. The descendant inbox head 3a0f0cd includes this fix and passes 449 JVM plus 428 executed iOS tests, including the full-size regression, TCP integration, both conformance scenarios and the native-runtime guard.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

  652 files  + 5    652 suites  +5   4m 17s ⏱️ +6s
2 711 tests +21  2 711 ✅ +21  0 💤 ±0  0 ❌ ±0 
3 597 runs  +35  3 597 ✅ +35  0 💤 ±0  0 ❌ ±0 

Results for commit 8013ac4. ± Comparison against base commit 45e5b9e.

@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 added a commit that referenced this pull request Sep 20, 2026
Consolidates #195–#209, preserving source 3cf0840.
Includes the foundation listener cancellation regression fix discovered by consolidation CI.
@linroid
linroid deleted the torrent-v2-08-piece-assembly 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