Skip to content

Torrent v2 01e: admit session state before storage allocation - #167

Closed
linroid wants to merge 2 commits into
torrent-v2-01-admissionfrom
torrent-v2-01-session-admission
Closed

linroid wants to merge 2 commits into
torrent-v2-01-admissionfrom
torrent-v2-01-session-admission

Conversation

@linroid

@linroid linroid commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Apply session admission before constructing storage indexes or decoding checkpoint state. A torrent must fit the file-count limit, piece-count limit, individual state allowance, and remaining aggregate capacity. Failure returns any reservation without creating payload storage.

Stack: based on #166 (torrent-v2-01-admission), following #163–#165. This is the session-admission slice of roadmap #162 step 01.

The state allowance accounts conservatively for retained metadata, file/path indexes, scheduler arrays and candidate lists, checkpoint parsing, and checking scratch buffers. Peer/wire buffers remain separately charged. A session retains its reservation while paused; construction failure returns it immediately, and removal/runtime cancellation returns it after all session child jobs finish. Every partition can be full without consuming metadata exchange headroom.

Validation: full torrent JVM conformance and native-runtime guard passed before the workflow-only restack. Tests exercise combined count/memory limits, exhaustion, rejection before filesystem creation, failed-construction rollback, pause retention, removal/readmission, and non-suspending shutdown. CI validates the updated head.

Admission estimates are not measured heap/RSS. Production profiles, deterministic fault harness, performance baseline, and the remaining production release gates stay open in #162.

@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-12T12:11:49.651170Z 78e2801 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: 78e2801428

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

SupervisorJob(parent.coroutineContext[Job]) + Dispatchers.Default)
init {
// Parent cancellation also ends ownership; wait for all session children before returning credit.
checkNotNull(scope.coroutineContext[Job]).invokeOnCompletion { stateLease?.close() }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain admission until removal completes

When removeTorrent(..., deleteFiles = true) encounters an exception or cancellation in store.restore(), recoverOwnership(), or cleanup(), scope.cancel() has already completed this handler and returned the lease, but KotlinTorrentEngine.removeTorrent() never reaches its map removals. The running engine therefore still retains the session and its indexed state while subsequent torrents can consume the supposedly freed capacity, defeating the aggregate state ceiling after a filesystem cleanup failure. Release the lease only after the session is detached, or keep it charged when teardown aborts.

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 1c7f7b2. Admission now belongs to the runtime registry: failed deletion keeps the session charged, successful detachment returns its lease, and runtime completion releases remaining leases after child jobs finish. A failed cleanup remains retryable rather than silently succeeding because network shutdown already occurred. The regression test exercises two failed deletions, blocked readmission, and explicit keep-data removal. All 304 local torrent tests and the native-runtime guard pass; updated-head CI is running.

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

  470 files  + 5    470 suites  +5   4m 12s ⏱️ +19s
2 317 tests +15  2 317 ✅ +15  0 💤 ±0  0 ❌ ±0 
2 923 runs  +25  2 923 ✅ +25  0 💤 ±0  0 ❌ ±0 

Results for commit 1c7f7b2. ± Comparison against base commit f957d62.

♻️ This comment has been updated with latest results.

@linroid

linroid commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #231 (Contracts, verification infrastructure and resource limits) 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-01-session-admission branch September 20, 2026 11:12
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