Skip to content

fix(proxies): start a copy the cap released once its box is back - #637

Closed
GeiserX wants to merge 2 commits into
mainfrom
fix/proxy-cap-release-retry
Closed

GeiserX wants to merge 2 commits into
mainfrom
fix/proxy-cap-release-retry

Conversation

@GeiserX

@GeiserX GeiserX commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Problem

When a proxy's cap is lifted (a reset on the day, a reset by hand, or the cap turned off or raised), every copy the cap had stopped gets one start attempt. If that copy's box is offline at that moment, the start fails and nothing tries again. The copy stays stopped and keeps its "stopped by the cap" mark until the next reset, which can be a month later, even though the box comes back a few minutes after.

There is a second path with the same gap. A stop lands, the cap is lifted while the stop is on its way, and the start back up fails. That copy was left stopped without the mark, so even the next reset would not start it.

Fix

  • Every heartbeat from a box checks each of its copies against two things: the proxy is no longer capped, and the copy is still marked as stopped by the cap and not running. Each copy that passes is started in the background. On success the mark is cleared, but only while the proxy is still uncapped. A start already on its way is not sent twice.
  • Before starting, the copy and the proxy are read again under the proxy's state lock. A copy the cap stopped again, or one the owner started or stopped by hand since (both clear the mark), is left alone.
  • The mid-stop path now sets the mark when its start fails, so that box's next heartbeat starts the copy.
  • docs/proxies.md says a copy whose box was offline at the reset is started when that box next reports.

Tests

TestReleasedCopiesThatDidNotStart in tests/test_proxies.py, against a real database:

  • The cap is lifted while the box is offline, so the copy stays marked. The box's next heartbeat starts it and clears the mark.
  • No start happens when the proxy is capped again, when the mark was cleared by hand, or when the copy is already running.
  • The mid-stop path marks the copy when its start fails.

Against main, the first and the last fail. On main the heartbeat never sends the start, and the mid-stop path leaves stopped_by_cap at 0. The whole file passes: 89 tests.

When a cap reset or a cap change lifted the stop, each copy the cap had
stopped was started once. If its box was offline at that moment, the start
failed and nothing tried again: the copy stayed stopped, marked as stopped
by the cap, until the next reset.

Each heartbeat now starts the copies of that box that are still marked and
not running, once the proxy is no longer capped. The same mark is set when a
stop lands, the cap is lifted meanwhile, and the start back up fails.
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4f339d9 and 1254c7c.

Files selected for processing: 3

  • app/main.py
  • docs/proxies.md
  • tests/test_proxies.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.98%. Comparing base (4f339d9) to head (1254c7c).

Files with missing lines Patch % Lines
app/main.py 88.88% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #637      +/-   ##
==========================================
+ Coverage   93.97%   93.98%   +0.01%     
==========================================
  Files          74       74              
  Lines       15678    15704      +26     
==========================================
+ Hits        14733    14760      +27     
+ Misses        945      944       -1     
Files with missing lines Coverage Δ
app/main.py 94.93% <88.88%> (+0.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GeiserX

GeiserX commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Landed in #653 (f681889), which combined this fix with the others into one release.

@GeiserX GeiserX closed this Nov 7, 2026
@GeiserX
GeiserX deleted the fix/proxy-cap-release-retry branch November 7, 2026 21:41
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