Skip to content

collect_submit: refuse mistyped endpoints and oversized PoW asks - #748

Merged
joshuaswarren merged 1 commit into
joshuaswarren:mainfrom
only21mil:fix/collect-submit-url-pow-cap
Nov 23, 2026
Merged

joshuaswarren merged 1 commit into
joshuaswarren:mainfrom
only21mil:fix/collect-submit-url-pow-cap

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

Problem

When --submit has no scheme, or the endpoint answers pow_invalid with a huge min_difficulty, both collectors exit with a ValueError traceback or hang, instead of printing [submit] FAILED and exiting 4.

  • submit() and submit_payload() build the Request outside _request's try, so urllib's ValueError for no scheme or an unclosed [ escapes the collectors' except SubmitError.
  • Both retry loops pass any larger min_difficulty to pure-Python solve_pow (about 2^bits hashes); an ask of 1000000 never returns.

Change

  • _endpoint_base() accepts only http or https with a host, a valid port and no whitespace, control character, ? or #, or raises SubmitError before any request.
  • MAX_POW_DIFFICULTY = 24, client-only (server floor 18, limit 64). At 24 bits solve_pow averaged 5.0 s, worst 21.3 s, over 8 digests on one core.

Verification

Tested by: AI agent.

  • Setup: Linux x86_64, Python 3.14.4, vulkaninfo installed.
  • Steps: collect_quick.py --submit with no scheme → collect_deep.py --submit a loopback server answering 404 to the probe and 403 pow_invalid (min_difficulty 1000000) to each initiate.

Before (5ef30346c, main):

provenance: mlx-omarchy None mx=None verified=no-mlx harness=5ef30346c files=unresolved
$ timeout 20 python3 scripts/collect_quick.py --submit example.invalid-no-scheme 2>&1 | grep -E 'FAILED:|^\w+Error:'
ValueError: unknown url type: 'example.invalid-no-scheme/v1/submit/9e0e39b8a68307a09cc44bb4e89c756372960a3de5004b7e1a112078da31796e'
exit=1
$ timeout 20 python3 scripts/collect_deep.py --submit http://127.0.0.1:46395 2>&1 | grep -E 'FAILED:|^\w+Error:'
exit=124

After (6536f2ce8):

provenance: mlx-omarchy None mx=None verified=no-mlx harness=6536f2ce8 files=unresolved
$ timeout 20 python3 scripts/collect_quick.py --submit example.invalid-no-scheme 2>&1 | grep -E 'FAILED:|^\w+Error:'
[submit] FAILED: invalid submit endpoint 'example.invalid-no-scheme': expected an http:// or https:// URL with a host
exit=4
$ timeout 20 python3 scripts/collect_deep.py --submit http://127.0.0.1:46395 2>&1 | grep -E 'FAILED:|^\w+Error:'
[submit] FAILED: endpoint asked for proof-of-work difficulty 1000000, above the collector's limit of 24: server said: {"error": "pow_invalid", "detail": {"min_difficulty": 1000000}} (HTTP 403, request unknown)
exit=4

6536f2ce8 is on 2aef87273 and merges cleanly into 5ef30346c; the merge gives the same output.

Links

Not shown

  • A submit to the live endpoint.
  • The macOS legs of collectors.yml.
Checks run by AI agent

_retry_difficulty() replaces _min_difficulty() and the check both retry loops repeated; asks up to the cap retry as before.

scripts/test_collect.py adds five tests to SubmitProtocol, each covering submit and submit_payload:

  • 16 malformed endpoints raise SubmitError and send no request;
  • an endpoint with a port, a path and a trailing slash is still used;
  • an ask of 25 or 1000000 bits raises SubmitError without calling solve_pow above the cap;
  • an ask of exactly 24 bits is solved and retried;
  • collect_quick.maybe_submit and collect_deep.maybe_submit return 4 and print [submit] FAILED: invalid submit endpoint.

Against the base code (2aef87273; collect_submit.py is unchanged on 5ef30346c) on Python 3.11.18 and 3.14.4 they give 26 failures and 10 errors across subtests: the malformed-endpoint and collector tests fail on behavior, and both PoW tests stop at the missing MAX_POW_DIFFICULTY. With that constant added to base, the above-cap test still fails (base calls solve_pow with 25 and 1000000 bits); the at-cap and accepted-endpoint tests are boundary guards that pass on base. All five pass on the candidate.

The other collector gives the same result and exit code for each endpoint (collect_deep.py with no scheme, collect_quick.py against the loopback server), on 5ef30346c, 6536f2ce8 and a local merge of the two.

collectors.yml Linux steps on 6536f2ce8, run in sequence:

Step Python 3.14.4 Python 3.11.18
scripts/test_collect.py 202 OK 202 OK
scripts/test_collect_macos.py 50 OK 50 OK
unittest discover -s tests -p test_mlx_provenance.py 6 OK 6 OK
scripts/bench_matrix.py --self-test OK OK
pytest -q qualification-kit/... 49 passed 49 passed
pytest tests -q 1,847 passed, 179 skipped 1,847 passed, 179 skipped
pytest -q tests/coreml/test_import_contract.py 1 passed 1 passed
--no-deps closure (3.14 leg only) ok n/a
Installer-backed CPU regressions (3.11 leg only) n/a 42 passed, cases=42 skipped=0

Generated with Claude Opus 5.5 in T3 Code Nightly

A --submit URL without a scheme, or with an unclosed IPv6 bracket, made
urllib raise ValueError while building the request, outside the
SubmitError the collectors catch, so the contributor saw a traceback.
Validate the endpoint once (http or https, a host, a valid port, no
whitespace, control character, query or fragment) and raise SubmitError
before any request.

A pow_invalid answer could ask for any difficulty, and solve_pow would
then spin forever. Cap the ask at MAX_POW_DIFFICULTY (24 bits) and
refuse a higher one with the server's answer in the error.
@joshuaswarren

Copy link
Copy Markdown
Owner

GREEN at 6536f2c
Model: cognition/swe-2

@kilo-code-bot

kilo-code-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • scripts/collect_submit.py
  • scripts/test_collect.py

Reviewed by free · Input: 160.2K · Output: 1.2K · Cached: 50.4K

@joshuaswarren

Copy link
Copy Markdown
Owner

GREEN at 6536f2c
Model: zai/glm-5.3-flash

@joshuaswarren
joshuaswarren merged commit 3a2ca65 into joshuaswarren:main Nov 23, 2026
5 checks passed
@joshuaswarren

Copy link
Copy Markdown
Owner

Thanks @only21mil — the submit endpoint now reports a clean FAILED + exit 4 on a bad endpoint instead of letting a ValueError escape. Merged at 3a2ca65.

@only21mil

Copy link
Copy Markdown
Contributor Author

You're welcome my friend

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