Skip to content

Retry transient Neon search failures in neongetter; bump to 0.15.1 - #205

Merged
jantman merged 2 commits into
mainfrom
neongetter-retry
Nov 20, 2026
Merged

jantman merged 2 commits into
mainfrom
neongetter-retry

Conversation

@jantman

@jantman jantman commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

neongetter now retries transient failures of the Neon CRM account search, so a single slow or failing Neon response no longer marks mac-neongetter.service as failed. This PR also bumps the version to 0.15.1, which releases a new image.

Why

neongetter runs every 15 minutes. Between 2026-11-16 and 11-20 it failed 12 times:

  • 11 were ReadTimeout (read timeout=30) from api.neoncrm.com.
  • 1 was HTTP 500 from /v2/accounts/search.

The next run succeeded every time. Each failure still marked the unit failed and fired a "Failed Systemd Units" alert.

Change

  • _get_users_page now calls _post_search, which makes up to 3 attempts (SEARCH_ATTEMPTS) and sleeps 10s, then 20s, between them (SEARCH_BACKOFF_SEC).
  • It retries requests.ConnectionError, requests.Timeout and HTTP 429/5xx, logging each retry at WARNING.
  • Any other 4xx is returned immediately and fails in raise_for_status(), as before.
  • After the last attempt it re-raises the exception, or returns the 5xx/429 response so raise_for_status() raises. A real outage still fails the unit.
  • The search is read-only, so repeating the POST is safe.
  • The existing HTTPAdapter(max_retries=3) only retries connection setup, so it is left unchanged.

Tests

TestSearchRetry in tests/test_neongetter.py, using responses with time.sleep patched, covers five cases:

  • a timeout, then a 500, then success
  • a 429, then success
  • 3 timeouts, which raises
  • 3 HTTP 500s, which raises HTTPError
  • a 403, which is not retried

Results:

  • nox -s tests: 353 passed, with neongetter.py at 99% coverage.
  • nox -s pre-commit and nox -s mypy both pass.
  • An independent review found no correctness issues.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KQ8DrMbV7veQfdQT7K6tD1

jantman and others added 2 commits November 20, 2026 18:48
neongetter runs every 15 minutes and failed about 12 times between
2026-11-16 and 11-20 (11 read timeouts, 1 HTTP 500 from
/v2/accounts/search). The next run always succeeded, but each failure
marked the systemd unit failed and fired a "Failed Systemd Units" alert.

The account search POST in _get_users_page now goes through a new
_post_search helper that retries connection errors, timeouts and HTTP
429/5xx, up to 3 total attempts with linear backoff (10s, then 20s).
Other 4xx responses are not retried. Each retry is logged at WARNING.
After the last attempt the exception is raised (or the last response is
returned so raise_for_status() fails as before), so a real outage still
fails the unit. Worst case added time is 30s of sleep plus the extra
30s read timeouts, far below the 15-minute timer interval. The search is
a read-only query, so repeating the POST is safe.

The existing HTTPAdapter(max_retries=3) only retries connection
failures, never read timeouts or status codes, so it is left alone. A
urllib3 Retry was not used because the tests mock HTTP with `responses`,
which bypasses the adapter, and a plain loop also allows WARNING logs.

Adds unit tests for retry-then-succeed (timeout then 500), HTTP 429,
exhausted timeouts, exhausted 500, and a non-retried 403. The repo has
no CHANGELOG and bumps the version in separate commits, so neither is
touched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KQ8DrMbV7veQfdQT7K6tD1

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code review
From Claude, via the Claude PR Review workflow -- hence github-actions[bot].

Adds retry with linear backoff for the Neon account search POST in neongetter, plus tests and a version bump. The logic looks correct; no issues found.

No issues found. Checked for bugs and CLAUDE.md compliance.


🔎 10s · 5 turns · $0.1067 · run log

@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissBranchBrPartCoverMissing
src/dm_mac
   __init__.py75060100% 
   cli_utils.py15000100% 
   neon_fob_adder.py2321560593%78->79, 79, 116–117, 124, 208->205, 269->270, 270, 333–334, 341, 364–367, 440->445, 454–456, 551->549
   neongetter.py231160399%313->314, 314, 455->459, 535->537
   slack_handler.py2200560100% 
   utils.py25040100% 
   webhook.py620100100% 
src/dm_mac/models
   __init__.py0000100% 
   api_schemas.py49000100% 
   machine.py648152141696%670->671, 671, 677->exit, 750->751, 751, 799->801, 1110->1111, 1111–1113, 1176->1178, 1228->1229, 1229–1238, 1401->exit
   users.py1030320100% 
src/dm_mac/views
   __init__.py0000100% 
   api.py41000100% 
   machine.py1030120100% 
   prometheus.py132012199%67->69
TOTAL1936314662598% 
Tests Skipped Failures Errors Time
353 0 💤 0 ❌ 0 🔥 25.169s ⏱️

@jantman
jantman merged commit 7788d6f into main Nov 20, 2026
17 checks passed
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