Skip to content

Remove the PRISM first-job admission lock convoy - #171

Merged
kiwidream merged 2 commits into
2.x.xfrom
remove-prism-admission-lock-convoy
Aug 20, 2026
Merged

kiwidream merged 2 commits into
2.x.xfrom
remove-prism-admission-lock-convoy

Conversation

@kiwidream

@kiwidream kiwidream commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Closes #159.

Problem

A reconnect herd made first-job progress through the fleet-wide coordinator lock for per-connection anchoring, admission-map bookkeeping, and an O(N) current-tip coverage scan repeated after every delivery. At 1,024 sessions that formed an O(N²) lock convoy and could leave a subset of miners without re-established work.

Design

  • Keep client.tip_work_delivered as a first-write-per-tip anchor under the existing per-client job-update lock. Delivery no longer takes the coordinator lock or runs a fleet census, and same-tip refreshes cannot slide the stale-grace anchor.
  • Move the complete first-job admission domain—pending ownership, exact capacity, replacement/coalescing/cancellation, counters, and delivery timestamp—behind one dedicated innermost lock owned by JobDeliveryService.
  • Expose the legacy coordinator-facing pending map as a strictly immutable, lock-protected view. Construction/tests seed by whole-map assignment, which is adopted under the owning lock.
  • Commit admission state before cancelling futures; run inline cancellation callbacks, disconnects, socket work, executor waits, and other callbacks only after releasing the admission lock. The lock never acquires the coordinator lock.
  • Move the sole O(N) current-tip coverage reset to the existing observability refresh census instead of repeating it for every delivered job.

1,024-session acceptance

The landed #170 driver was run twice as matched baseline/fixed pairs on the same eight-core host with the same command and default positive/negative controls:

--connections 1024 --mode herd --settle-seconds 50 --measure-seconds 30 --herd-return-seconds 50 --connect-timeout-seconds 50 --ledger memory --difficulty-mode resume --json

Pair Baseline re-established Fixed re-established Fixed census wall Rejections / watchdog misses
1 936 / 1,024 1,024 / 1,024 25.820 s 0 / 0
2 821 / 1,024 1,024 / 1,024 28.064 s 0 / 0

All four runs passed their controls and had empty stderr. Fixed-run positive controls reached 7.45 and 7.33 cores; negative controls measured 1.02 and 1.01 cores. Both fixed runs also reported zero accept errors and zero sessions left behind.

Verification

  • 91 focused admission, reconnect, job-delivery, initial-delivery, and tip-refresh tests passed.
  • The new 11-test admission-lock module passed six consecutive runs; eight tests fail against the unmodified production tree, proving the regressions are load-bearing.
  • Full Linux discovery passed: 2,335 tests, two skips, one expected failure.
  • Docker compile passed across docker, lab, tests, examples, and scripts.
  • Docker Ruff with E4,E7,E9,F passed on every changed path with the repository's pre-existing forward-reference F821 findings excluded. The unexcluded findings on changed paths are byte-identical to the base tree.
  • The final commit has a verified GPG signature.

Sequencing and residual risk

This lands last, after #170, #168, and #167. It is based directly on the resulting 2.x.x tip and is intentionally not stacked on #166; the admission/observability delta does not depend on that open PR.

The historical 30–82% coordinator-lock contention range was not reproduced by this synthetic driver. Global contention remained low but rose from 0.40%/0.74% in the two baselines to 1.02%/1.03% in the fixed runs because the fixed tree completed all 1,024 sessions and therefore executed more downstream work. The acceptance result is the per-session census, not a claim that every remaining coordinator-lock site is optimized. Coverage-failure reset now occurs at the observability refresh cadence rather than synchronously on an individual delivery.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@blacksmith-sh

This comment has been minimized.

@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: 7dd52ce8e8

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

Comment thread lab/prism/job_delivery.py
Comment on lines +916 to +919
and len(self._pending_initial_jobs) >= capacity
):
self.initial_job_queue_rejection_count += 1
reject = True

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 capacity before accepting reauthorization

When an already-working miner reauthorizes while the initial-job queue is nearly full, the mining.authorize pre-check can observe available capacity, release the coordinator lock, mutate the authorization generation, and send a success response; another connection can then claim the last admission slot before this authoritative check runs. This branch consequently rejects and disconnects the reauthorized miner because its old job is no longer current, defeating the pre-check's stated guarantee of preserving a working session. Reserve the slot during the pre-check or make reauthorization and admission a single atomic operation.

Useful? React with 👍 / 👎.

@kiwidream
kiwidream merged commit cf0d019 into 2.x.x Aug 20, 2026
11 checks passed
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