Repository navigation
feat(cmd): add poolclean to prune unusable entries from a proxy file - #147
Open
leonsong09 wants to merge 2 commits into
Open
leonsong09 wants to merge 2 commits into
leonsong09 wants to merge 2 commits into
Conversation
leonsong09
force-pushed
the
feat/poolclean
branch
from
October 24, 2026 04:27
4958f7c to
8b82e60
Compare
Closed
The gateway marks a failing proxy unhealthy at runtime, but the file it was loaded from is left untouched. Every restart therefore retries the same dead entries and pays their connect timeouts again before reaching a working one, and a file assembled from public subscription lists can carry dozens of them. poolclean is the offline counterpart. It probes each entry and rewrites the file without the ones that failed. The failure rule is the gateway's own: only a route failure counts. Any HTTP response, including 403 and 429, keeps the entry, because reaching opencode.ai and being rate limited proves the proxy works. Deleting on 429 would discard exactly the entries the pool needs most. direct and #pool entries are never touched. A candidate must fail every round and then also fail when re-tested on its own, so a proxy that is merely busy survives. Nothing is written without --write, comments and other lines are preserved, and the file is replaced atomically. config.ProxyFileOf reads just the proxyfile field, so pruning does not require the rest of the configuration to be valid: a list can be cleaned before the gateway has keys. Co-Authored-By: GenericAgent <bot@gaagent.ai>
A run that suddenly calls most of the pool dead is far more likely to be a
network or upstream problem than a genuine mass failure, and rewriting the file
on that signal would be unrecoverable without a backup. Refuse the write when
the confirmed-dead share crosses --max-drop-ratio (default 0.5), leave the file
untouched, and exit 2 so a wrapper can tell this verdict apart from a crash.
--force overrides it for the case where the pool really is down.
Every run now ends with a single summary line so a scheduled job can gate on
the shape of the pool instead of scraping the per-entry listing:
summary: entries=120 ok=107 dead=12 skipped=1 confirmed=7 ratio=6% remaining=113
The line is printed on all three exits (nothing to remove, candidates all
survived confirmation, and the normal write path), so its absence means the run
died rather than that it found nothing.
Also document what the default probe target can and cannot see: /zen/v1/models
answers 200 even to an exit whose IP the free tier already blocks, so a
blocked-but-reachable proxy is deliberately kept. Pointing --target at
/zen/v1/chat/completions gives a stricter answer at the cost of treating every
shared-exit 403 as a reason to delete.
Co-Authored-By: GenericAgent <bot@gaagent.ai>
leonsong09
force-pushed
the
feat/poolclean
branch
from
November 7, 2026 09:10
8b82e60 to
71c7124
Compare
Author
|
Rebased onto Local verification (same commands as
The workflow shows |
Suydev
added a commit
to Suydev/opencode2api
that referenced
this pull request
Nov 13, 2026
…e entries from a proxy file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
A new command,
cmd/poolclean, that removes proxy entries which are provablyunusable from a proxy file.
The gateway already marks a failing proxy unhealthy at runtime, but the file it
was loaded from is never touched. Every restart therefore retries the same dead
entries and pays their connect timeouts again before reaching a working one.
With a file assembled from public subscription lists this is not a rare case.
How it decides
The failure rule is deliberately the gateway's own (
isProxyFailureininternal/gateway), not a new one:gets
403or429is a working proxy that is being rate limited. Removingit would discard exactly the entries a pool needs most.
directand#poolentries are never touched.Two guards against false positives:
-rounds, default 2).-confirm, default 2), with no otherprobe competing for bandwidth. Any pass keeps it. In a real run over a
120-entry pool, 3 candidates were flagged by the batch pass and all 3 were
saved here - batch probing alone would have removed working proxies.
Safety
--write.os.Rename), so an interrupted run cannottruncate the pool.
One small addition to
internal/configProxyFileOf(path)reads only theproxyfilefield, reusing the existingstripJSONComments.config.Loadvalidates the whole gateway configuration,which pruning has no business requiring - a list can be cleaned before the
gateway has keys or a listen address, and cleaning must not fail on an unrelated
field. No existing behaviour changes.
Verification
Manual run against a synthetic file (
# comment, a dead port,direct, a liveproxy with a trailing comment, a
#poolentry):After
--write, the file kept the comment,direct, the live entry with itstrailing comment, and the
#poolentry; only the dead line was removed.Scope
New command plus one additive helper. No changes to the gateway's runtime
behaviour, so this does not interact with the in-flight streaming PRs (#133,
#137).