Repository navigation
Add timeout, retry and clear errors to get_maap_pgt_token - #21
Merged
Merged
Conversation
- 5s connect / 30s read timeout; up to 6 attempts with exponential backoff and jitter on connect errors, timeouts and 5xx - 4xx and malformed responses fail immediately with PgtTokenError - on failure, message goes to stderr (stdout is captured into MAAP_PGT), _alt_error.txt is written for the HySDS job `error` field, and the script exits 78; dps_wrapper.sh propagates the exit code - resolve MAAP_API_HOST at call time instead of import time Closes #8 Claude-Session: https://claude.ai/code/session_0171HvL7yCdP2wCuxh7UngYP
Replace the hand-rolled retry loop with a requests session mounting an HTTPAdapter(Retry(...)): exponential backoff with jitter (backoff_jitter needs urllib3>=2), retries on connect errors, timeouts and 5xx. Pin urllib3>=2 in the Dockerfile and CI. Retry behaviour is tested against a local flaky HTTP server. Claude-Session: https://claude.ai/code/session_0171HvL7yCdP2wCuxh7UngYP
This was referenced Oct 16, 2026
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.
Closes #8
Changes
get_maap_pgt_token.py: requests go through a session withHTTPAdapter(Retry(...)):(5, 30)s timeout, up to 5 retries (6 attempts), exponential backoff with jitter (backoff_factor=1,backoff_jitter=1,backoff_max=30), retrying connect errors, timeouts and 5xx.raise_on_status=Falseso the final response is turned into a clearPgtTokenError. 4xx (not retried), a missingsession_keyand non-JSON bodies also raisePgtTokenError.MAAP_PGT, so the old stdout print never reached_stderr.txt),_alt_error.txtis written so HySDS uses it as the joberror, and the script exits with code 78.dps_wrapper.sh:|| exit $?so the failure code propagates out of the command substitution.MAAP_API_HOSTis now read at call time rather than import time.urllib3>=2added to the Dockerfilepip installand the CI test job:Retry(backoff_jitter=...)needs urllib3 2.x. Resolving the image's unpinned deps for Python 3.12 gave urllib3 2.8.0 already; the pin guards against a future downgrade. The local Python 3.9.venvhas urllib3 1.26 and cannot run these tests.Notes
job_worker.py: any non-zero code yields "Got non-zero exit code: N", and_alt_error.txtin the job dir overrideserror. Codes 126/127/130/137/143 and -15 are avoided. That guidance is from reading the code, not from a run on HySDS._alt_error.txtis written; not verified in the container.Tests
tests/test_get_maap_pgt_token.py: retry behaviour is tested against a local flaky HTTP server (5xx then success, exhaustion after 6 attempts, 4xx not retried, connection errors), plus error messages,_alt_error.txt/stderr, and exit code 78 with clean stdout. Full suite: 73 passed on Python 3.12 / urllib3 2.8.0.