Skip to content

fix(admission): Release the job slot when job creation fails - #289

Merged
pterw merged 1 commit into
mainfrom
fix/admission-slot-leak
Oct 31, 2026
Merged

pterw merged 1 commit into
mainfrom
fix/admission-slot-leak

Conversation

@pterw

@pterw pterw commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes F-B23-65. admit() in scrobblescope/routes/admission.py took a job slot and then called jobs.create(params) outside its try, so if jobs.create raised, nothing released the slot: the semaphore stayed one short for the life of the process, and enough such failures would make the app refuse every job as at capacity until a restart. jobs.create now sits in its own small try that releases the slot and re-raises the same exception unchanged. The start_job_thread failure path is untouched (start_job_thread already releases the slot there, so moving jobs.create into that existing try would have released it twice).

An outside agent (DeepSeek) wrote the patch in an isolated worktree from a spec-tight prompt; a before-and-after snapshot of the main checkout confirmed it wrote nothing outside its worktree. An independent review approved it and reproduced the red proof; of seven planted defects the test caught six. The landing strengthened the test to catch the seventh (re-raising a different exception: the test now asserts the propagated error is the same object) and dropped an assertion that could never fail. One new test, test_a_create_failure_frees_the_slot_once_and_propagates, because no existing test reached this path.

Was stacked on PR #288 (pin the pip-audit action, now merged); retargeted to main, so this PR's own change is the one commit fb71af6d.

State

Task What Commit Review
1 Release the slot when jobs.create raises fb71af6 patch approved; landing byte-checked against it

Validation at this head

Head fb71af6d. Scoped gates (owner ruling 2026-10-31), run by an independent gate runner at this head: suite-core 907 passed (the root test files, where tests/test_admission.py and the route tests live), pre-commit run --all-files (all 10 hooks pass) and doc_state_sync.py --check pass. Full pytest -q at landing: 3159 passed (pinned). Red proof: the new test fails on the unpatched admission.py ("Expected 'release' to have been called once. Called 0 times.") and passes at this head.

Codex: waived by the owner until the usage limits reset. CI: green at this head on all four jobs (run 41229350731: checks 2999 passed, 4 skipped, 156 deselected; browser ran). Codacy 0 new issues, qlty no blocking issues, no open review threads.

Checklist

  • pytest -q passes (update SESSION_CONTEXT Section 1 if test count changed)
  • pre-commit run --all-files passes (all hooks)
  • python scripts/doc_state_sync.py --check exits 0
  • PLAYBOOK Section 3 reflects current WP/task state
  • PLAYBOOK Section 4 has a dated log entry:
    - Batch WP: inside DOCSYNC:CURRENT-BATCH-START/END markers
    - Side task: after DOCSYNC:CURRENT-BATCH-END marker
  • Changes are within scope of the active batch definition
    (or deviation is logged in the Section 4 entry)

admit() took a job slot and then called jobs.create outside any try,
so a raise there left the semaphore one permit short with no owner to
return it. jobs.create now has its own try that releases the slot and
re-raises unchanged. The test asserts the very same error propagates
and the slot is released once. Resolves F-B23-65.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@pterw
pterw changed the base branch from ci/pin-pip-audit-action to main October 31, 2026 18:27
@pterw
pterw marked this pull request as ready for review October 31, 2026 18:32
@chatgpt-codex-connector

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 ⚠️ Failed 2026-10-31T18:32:04.524874Z
We couldn’t complete this review. Comment @codex review to try again.
fb71af6 Draft marked ready
ℹ️ 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@pterw
pterw merged commit d9c02c3 into main Oct 31, 2026
6 checks passed

@graphify-labs graphify-labs 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.

Graphify reviewed this change.

Code graph out of date: Health delta baseline: last indexed commit be14bc2, 2 commit(s) behind this PR's base. Impact and hotspot numbers below may be wrong.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).

Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).

Not verified on this run: admit (vacuous: never exercised).


Graphify review — findings

Fixes a job-slot leak in admit(): jobs.create now runs in its own small try that calls release_job_slot() and re-raises the original exception, so a failed create no longer leaves the semaphore one permit short. The release is imported straight from scrobblescope.worker rather than going through the routes facade, so a test or caller patching the slot functions on the facade won't intercept this path. The existing START_FAILED handling stays separate to avoid a double release, and the new test checks the slot is freed once and the same error propagates. The rest is bookkeeping: F-B23-65 moves to the findings archive, the PLAYBOOK gets a log entry, and the pinned test count goes from 3158 to 3159.

Worth a look

  • create-failure path bypasses the routes facade for slot release — scrobblescope/routes/admission.py:53 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 119 functions depend on the 116 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: admit() — 9 callers, 5 callees

Verification — 119 functions in the blast radius were not formally verified this run (proofs are advisory here).

Health delta baseline: last indexed commit be14bc2, 2 commit(s) behind this PR's base.

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 119 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify admit.

The verifier did not have enough to check admit, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: not verifiable: all 256 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

· 1 more finding(s) on lines outside this diff (see the check run).

@pterw
pterw deleted the fix/admission-slot-leak branch October 31, 2026 20:10
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