Skip to content

fix: keep probes independent of the database - #269

Merged
uniqueg merged 5 commits into
devfrom
fix/267-resume-hook
Oct 28, 2026
Merged

uniqueg merged 5 commits into
devfrom
fix/267-resume-hook

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Found in the pre-release review of 0.6.0 (M2): the rename resume hook from #262 ran before every request, so the probe path (/ga4gh/registry/v1/ui/, also the image's HEALTHCHECK), the spec and /service-info depended on MongoDB. While MongoDB was unreachable, the first request per worker every 10 seconds waited 30 seconds (pymongo's server selection timeout) and then returned 500, longer than the probes' 5-second timeout.

  • Interrupted renames are resumed only before requests of the registry's own operations (Connexion endpoints named after cloud_registry.* operation IDs), not before the Swagger UI, the spec, the service info or FOCA's admin API.
  • Database errors in the hook are logged (Interrupted renames not checked; tried again later: ...) instead of failing the request; the next check is due after the interval.
  • The check for stale locks runs under pymongo.timeout(2.0); resuming itself, which takes several writes, is not limited. One filter of stale locks (locks.stale()) serves the check, resume_renames() and remove_stale_changes().
  • Docs: the chart README (Probes) and docs/api.md (Renaming services) say which requests resume renames.

Closes #267

Verification

Regression tests first (tests/test_rename.py): with get_collection failing with ServerSelectionTimeoutError, /ui/, the spec, /service-info and the admin API returned 500 before the fix and don't now; API requests still resume renames, also after a failed check or resume; only the check runs under the short timeout; recent locks aren't resumed; every route of the app is classified correctly (operations vs. UI/spec/service info/admin API).

Locally (Python 3.13):

  • coverage run -m pytest (mongomock): 1406 passed, 257 skipped (Helm not installed), coverage 100%
  • pytest against MongoDB 7.0.34 (MONGODB_TEST_URI): 1408 passed, 255 skipped
  • pre-commit run --all-files (ruff, semgrep, gitleaks, actionlint, ast-grep, mypy): passed
  • mkdocs build --strict: passed
  • Not run locally: Helm lint and chart tests (no Helm), Docker smoke test; CI runs them.
  • CI: all checks passed (incl. Chart, Smoke test, Scan image after ci: accept msgpack CVE vendored by pip #273, Test with MongoDB 7.0); Sourcery's one finding (timeout test) fixed in b72ce4e.

Declined review findings

  • Resuming renames (after a successful check) isn't time-limited, so a database that fails between the check and the resume can still delay one API request per worker and interval by up to 30 seconds (adversarial, low): intended, as resuming takes several writes and a cumulative limit could keep large renames from ever finishing; only registry operations are affected, which need the database anyway.
  • The check case of the failure test doesn't show that the timeout bounds a slow database (quality, low): mongomock ignores pymongo.timeout; the spy test checks that it is applied to the check only. The adversarial reviewer verified against an unreachable server that count_documents under pymongo.timeout(2.0) raises after 2 seconds.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 3 commits October 28, 2026 06:30
Resume interrupted renames only before requests of the registry's
operations, not before the Swagger UI (the probe path), the spec, the
service info or FOCA's admin API. Log database errors in the hook
instead of failing the request, and check for stale locks with a
2-second timeout instead of pymongo's 30-second server selection
timeout. Correct the probe and rename docs.

Closes #267

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Use one filter of stale locks for the check before requests and for
resuming renames. Test that exactly the registry's operations resume
renames, that failures while resuming are logged, and that only the
check runs with the short timeout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR decouples probes and non-registry endpoints from MongoDB by limiting interrupted-rename recovery to registry operations, bounding only the stale-lock check, and handling database failures as logged, retryable conditions. It also centralizes stale-lock filtering, documents the behavior, and adds comprehensive route and failure regression tests.

Sequence diagram for database-independent probe requests

sequenceDiagram
    participant Client
    participant App
    participant ProbeEndpoint
    participant MongoDB

    Client->>App: GET /ui/ or /service-info
    App->>ProbeEndpoint: Handle request
    ProbeEndpoint-->>Client: 200 response
    Note over App,MongoDB: No resume_renames_periodically call
    MongoDB--xApp: Unavailable
Loading

File-Level Changes

Change Details Files
Restrict interrupted-rename recovery to registry operation requests so probes and non-registry endpoints remain database-independent.
  • Classify requests by Connexion operation endpoint prefix.
  • Skip recovery for the Swagger UI, API specs, service info, admin API, static assets, and unmatched routes.
  • Update application comments and probe/API documentation to describe the request scope.
cloud_registry/app.py
cloud_registry/ga4gh/registry/rename.py
deployment/README.md
docs/api.md
Make periodic rename recovery resilient to unavailable or slow MongoDB connections.
  • Check for stale locks before invoking the multi-write recovery process.
  • Apply a two-second MongoDB timeout only to the stale-lock check.
  • Catch and log PyMongo failures while leaving the request successful and allowing a later retry.
  • Avoid recovery when no stale locks exist.
cloud_registry/ga4gh/registry/rename.py
Centralize the stale-lock query used by cleanup and rename recovery.
  • Add a shared stale-lock filter helper.
  • Reuse it for stale change removal and interrupted rename queries.
cloud_registry/ga4gh/registry/locks.py
cloud_registry/ga4gh/registry/rename.py
Add regression coverage for endpoint classification and database failure behavior.
  • Verify all application routes are classified as registry operations or excluded endpoints.
  • Test probe and non-registry requests with an unavailable database.
  • Test retry behavior after failed checks or resume attempts.
  • Verify timeout scope and that recent locks are not resumed.
tests/test_rename.py

Assessment against linked issues

Issue Objective Addressed Explanation
#267 Run interrupted-rename recovery only before the registry’s own operation endpoints, keeping the UI, specification, service-info endpoint, and FOCA admin API independent of the database. ✅
#267 Keep registry requests from failing due to database errors during rename recovery, and bound the stale-lock check with a short timeout. ✅
#267 Keep probe and rename-recovery documentation accurate and add regression coverage for the affected routes and failure cases. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (117a69c) to head (b72ce4e).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #269   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines         1976      1989   +13     
=========================================
+ Hits          1976      1989   +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 28, 2026 07:01

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_rename.py" line_range="1015-1020" />
<code_context>
+    original = pymongo.timeout
+
+    @contextmanager
+    def spy(seconds: float | None) -> Iterator[None]:
+        timeouts.append(seconds)
+        active.append(True)
+        with original(seconds):
+            yield
+        active.pop()
+
+    resumed: list[bool] = []
</code_context>
<issue_to_address>
**Timeout test misses an unbounded check**

When the implementation enters the timeout context but performs the stale-lock query after leaving it, `test_resume_before_requests_timeout` observes only that `pymongo.timeout` was entered and that resuming happened after it; it never observes whether `count_documents` ran inside the context, so the stale-lock check can run unbounded and the test still passes.

Spy on the stale-lock query and assert it runs while the timeout context is active.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: tests/test_rename.py:1020


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/test_rename.py Resolved
@uniqueg
uniqueg merged commit 0b898c2 into dev Oct 28, 2026
19 checks passed
@uniqueg
uniqueg deleted the fix/267-resume-hook branch October 28, 2026 07:13
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.

fix: keep probes independent of the database

1 participant