Skip to content

fix(runner): wait after an empty or refused claim - #16

Merged
zeekay merged 3 commits into
mainfrom
job/claim-wait
Nov 27, 2026
Merged

zeekay merged 3 commits into
mainfrom
job/claim-wait

Conversation

@jamessburnss1313-dev

@jamessburnss1313-dev jamessburnss1313-dev commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What a customer would see. When the server answers the claim call at once (an empty answer, or a 403/404), every linked machine calls the claim endpoint in a tight loop. Each pass of the 403/404 case also re-registers the machine and mints a key; each pass of the empty case also starts a token process.

Cause. src/runner/mod.rs, run_loop, in the claim match (about lines 436-470 on main):

  • ClaimPoll::Empty only dropped the permit and looped.
  • ClaimPoll::Forbidden slept only when the re-mint failed; after a successful re-mint it went round again at once.

Fix. One fixed wait, the one the error arm already used, now a named constant RETRY_WAIT (3 s).

  • An empty claim that came back in under 1 s (HELD) waits RETRY_WAIT. A held long poll does not wait.
  • A successful re-mint after 403/404 waits RETRY_WAIT.
  • No state between passes; the permit is released before the sleep; a claimed run is never delayed. A new job waits at most 3 s in these bad states.

Tests (each really sleeps 3 s; tokio test-util is not enabled in this crate):

  • Empty at once (an_instantly_empty_claim_waits_before_the_next), expects 1 to 5 claims in 3 s. On main's loop: saw 17683 claims. With the fix: passes.
  • Refused with 403 (a_refused_claim_waits_before_the_next), same bound, using a small test-only mock switch (refuse_claims). Before the fix: saw 12 claims. With the fix: passes.
  • cargo test --lib: 379 passed. cargo clippy --all-targets -- -D warnings: clean. cargo test --test filesize: ok.

Not tested. A real linked machine. Whether the live API ever answers empty at once (the only evidence is the test mock). cargo fmt --check (rustfmt not installed on the build machine).

Found in review of #13. Reviewed by a second agent; its findings are applied in this version. Nothing merged; production is Zach's call.

Risk. Low. Up to 3 s extra before the next claim after a fast empty or refused answer; a long-polling server is unaffected.

How to revert. Revert the two commits, or close this pull request.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T02:24:02.573820Z
We couldn’t complete this review. Comment @codex review to try again.
e7574b3 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

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.

@jamessburnss1313-dev jamessburnss1313-dev changed the title fix(runner): wait after an instantly-empty claim fix(runner): wait after an empty or refused claim Nov 26, 2026

zeekay commented Nov 27, 2026

Copy link
Copy Markdown
Member

Useful load-shedding fix; CI/CD run 45743205264 shows the Rust test gate ran successfully. However current main 103ffaf is five commits beyond merge base 8807647, so please rebase and rerun. Strengthen the 3-second wall-clock tests: the allowed 1..6 claim count permits multiple retries before the intended 3s delay; use deterministic timing or assert minimum inter-claim interval, verify genuine long polls do not receive extra delay, and consider bounded jitter for synchronized fleet retries. Hold merge until fresh CI and review.

jamessburnss1313-dev and others added 3 commits November 26, 2026 19:31
Symptom: when the server answers a claim with "nothing for you" at once
instead of holding the call about 25 s, the claim loop calls it again
immediately. Every linked machine hammers the API, and each pass also
starts a token process.

Cause: src/runner/mod.rs, run_loop, the ClaimPoll::Empty arm only dropped
the permit and looped.

Fix: time each claim. An Empty claim that came back in under 1 s (HELD)
waits RETRY_WAIT (3 s) before the next, the same wait the error arm
already used, now one named constant. No state is carried between passes,
the permit is released before the sleep, and a claimed run is not delayed.

Testing: runner test with the mock answering empty at once, expecting 1 to
5 claims in 3 s. On main's loop it saw 17683 claims; with the fix it
passes. The test really sleeps 3 s (tokio test-util is not enabled here).
Risk: low. A new job can wait up to 3 s longer when the server answers
empty at once; a long-polling server is unaffected.
How to revert: git revert this commit.
Symptom: when the server answers every claim with 403 or 404, the claim
loop re-registers the machine and mints a new key on each pass with no
pause.

Cause: src/runner/mod.rs, run_loop, the ClaimPoll::Forbidden arm waited
only when the re-mint failed; after a successful re-mint it went round
again at once.

Fix: sleep RETRY_WAIT after a successful re-mint, as the other arms do.

Testing: runner test with a test-only mock switch that answers every claim
403 (key minting still succeeds), expecting 1 to 5 claims in 3 s. Before
the fix it saw 12; after, it passes. lib 379 passed, clippy -D warnings
clean, filesize ok.
Risk: low. A machine whose claim key is refused waits 3 s before retrying.
How to revert: git revert this commit.
@zeekay

zeekay commented Nov 27, 2026

Copy link
Copy Markdown
Member

Rebased onto main (7ee41fc) at 05df364e:

  • Added bounded jitter (0..500ms) on RETRY_WAIT (3s) to prevent synchronized fleet retry bursts.
  • Replaced loose count bounds with recorded inter-claim arrival intervals (>= 2.9s gap enforced on both instant-empty and 403-refused claims) plus a_held_long_poll_claim_does_not_add_retry_wait verifying genuine long polls (>= 1s) re-poll immediately without extra delay.
  • cargo test --locked: 395 lib + 1 filesize + 3 signals passed (0 failed).
  • cargo clippy --all-targets -- -D warnings: 0 warnings.

@zeekay
zeekay merged commit de4c3a3 into main Nov 27, 2026
1 check passed
@zeekay
zeekay deleted the job/claim-wait branch November 27, 2026 03:34
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.

2 participants