Skip to content

fix(scripts): add timeout and status handling to GitHub workflow cancellation script#6

Open
outwrit wants to merge 1 commit into
masterfrom
devin/issue-2-remediation
Open

fix(scripts): add timeout and status handling to GitHub workflow cancellation script#6
outwrit wants to merge 1 commit into
masterfrom
devin/issue-2-remediation

Conversation

@outwrit

@outwrit outwrit commented Jun 3, 2026

Copy link
Copy Markdown
Owner

SUMMARY

Fixes #2

The request() helper in scripts/cancel_github_workflows.py called requests.request() without a timeout and assumed every response body was valid JSON. This could hang indefinitely in CI/local usage or produce confusing JSONDecodeError tracebacks when the API returned non-2xx with a non-JSON body.

Changes to request():

  • Add REQUEST_TIMEOUT = 30 (seconds) to every API call
  • Call resp.raise_for_status() before consuming the body
  • Handle requests.exceptions.TimeoutClickException("… request timed out …")
  • Handle requests.exceptions.HTTPError → extract GitHub message from JSON when available, fall back to resp.text
  • Handle empty response bodies (e.g., 202 from the cancel endpoint) → return {}
  • Handle non-JSON success bodies → ClickException("… invalid JSON …")
  • Remove # noqa: S113 (no longer needed)

Existing Click CLI behavior and error style are preserved.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — script-only change

TESTING INSTRUCTIONS

python -m py_compile scripts/cancel_github_workflows.py
python -m pytest tests/unit_tests/scripts/cancel_github_workflows_test.py -v --noconftest --rootdir=tests/unit_tests/scripts
ruff check scripts/cancel_github_workflows.py tests/unit_tests/scripts/cancel_github_workflows_test.py
pre-commit run mypy --files scripts/cancel_github_workflows.py

Validation results:

  • py_compile: passed
  • pytest: 7/7 passed
  • ruff check + ruff format --check: passed
  • mypy (script only): passed
  • pre-commit run (all hooks except mypy): all passed

ADDITIONAL INFORMATION

…ellation script

- Add REQUEST_TIMEOUT (30s) to every GitHub API call
- Call raise_for_status() before consuming response body
- Handle empty response bodies (e.g., 202 from cancel endpoint)
- Surface Timeout and HTTPError as ClickException with clear messages
- Handle non-JSON error responses gracefully
- Remove noqa: S113 (no longer needed with explicit timeout)
- Add focused unit tests for the request() helper

Fixes #2

Co-Authored-By: bot_apk <apk@cognition.ai>
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.

Add timeouts and status handling to GitHub workflow cancellation script

1 participant