Skip to content

feat: manage service timestamps - #237

Merged
uniqueg merged 4 commits into
devfrom
feat/service-timestamps
Oct 25, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/service-timestamps

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Summary

The registry now manages the timestamps of services:

  • createdAt is set when a service is registered and kept on updates (services stored without it stay without it).
  • updatedAt is set on registration and on every update (each PUT).
  • Timestamps sent by non-admins are ignored, not an error, so clients that send services back as they got them keep working. Like all fields, they must still be strings (request schema).
  • Admins may set them, e.g., to keep the timestamps of imported services: createdAt on registration and on updates, updatedAt only when they register a service (on updates, it is always set, so admins editing a service as read, also a stale copy, never move it back). Admin values must be RFC 3339 date-times and are stored as sent.
  • createdAt is part of the compare-and-swap of replacements, so a concurrent change isn't reverted.
  • now() and format_time() move from verification.py to cloud_registry/utils.py, for reuse.

Docs: the API description (ExternalServiceRegister) and docs/api.md ("Timestamps") describe the deviation from the GA4GH meaning: in the registry, the timestamps describe the entry (registered, last changed), not the deployment. docs/upgrading.md ("Stored services") covers services stored with timestamps set by their owners.

Not marked as breaking: requests that worked before still work (sent timestamps are ignored rather than rejected), and responses keep their schema. Clients that relied on setting their own timestamps will see the registry's instead; the release notes should mention it.

Closes #236

Verification

  • pre-commit run --all-files (all hooks, incl. ruff, mypy, semgrep, gitleaks, actionlint, ast-grep): passed
  • coverage run --source cloud_registry,scripts -m pytest (mongomock): 1144 passed, 228 skipped (chart tests, no Helm locally); coverage 100%
  • MONGODB_TEST_URI=mongodb://127.0.0.1:27235 pytest against MongoDB 7.0.34: 1144 passed, 228 skipped
  • mkdocs build --strict: passed
  • Not run locally: chart tests (no Helm), the Docker Compose smoke test and image scan (CI covers them)
  • CI: all checks passed (CI passed, Test (mongomock), Test (MongoDB 7.0), Chart, Docs, Lint, Smoke test, Scan image, CodeQL, codecov/patch and codecov/project, Read the Docs)

Declined review findings

  • Move the timestamp rules of RegisterService._replace() into a helper (quality, low): the rules are a few lines next to the compare-and-swap they depend on; each case has a parametrized test (TestTimestamps.test_update).
  • Normalize admin timestamps to UTC milliseconds (adversarial, low): documented instead, as admins import values as they were; the registry's own values are normalized.
  • Relax the schema type of the timestamps, so that non-strings from non-admins are ignored too (adversarial, medium): documented instead ("must be strings"), keeping the request schema as specified; clients send back strings.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Manage service timestamps according to registry registration and update activity while preserving compatibility for existing clients and stored services.

New Features:

  • Manage service createdAt and updatedAt timestamps automatically during registration and updates, with administrator support for imported timestamps.

Bug Fixes:

  • Preserve createdAt during concurrent replacements and avoid restoring invalid or absent timestamps on legacy services.

Enhancements:

  • Centralize timestamp generation and formatting utilities for reuse across services and verification records.

Documentation:

  • Document the registry-specific timestamp semantics, administrator behavior, and handling of services stored before timestamp management.

Tests:

  • Add comprehensive coverage for timestamp assignment, preservation, administrator overrides, legacy services, and concurrent updates.

uniqueg and others added 3 commits October 25, 2026 20:18
The registry sets createdAt when a service is registered and keeps it on
updates, and sets updatedAt on registration and on every update.
Timestamps sent by non-admins are ignored (not an error, so clients that
send services back as they got them keep working); admins may set them,
e.g., to keep the timestamps of imported services. Services stored
without createdAt are kept without it.

createdAt is part of the compare-and-swap of replacements, so that a
concurrent change of it is not reverted. The time helpers of
verifications move to cloud_registry.utils for reuse.

The API description and docs describe the deviation from the GA4GH
meaning (deployment times): in the registry, the timestamps describe the
entry.

Closes #236

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Admins may set timestamps, but an admin who sends a service back as
read (e.g., to edit it) now gets a new updatedAt: an updatedAt equal to
the stored one is replaced like a missing one. The docs say that sent
timestamps must still be strings, and that admins' values are stored as
sent. Also review clean-ups in the tests and comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An admin's updatedAt is now only kept when the admin registers a service
(e.g., imports it); every update sets it. This also covers stale
round trips, where the updatedAt that the admin read no longer matches
the stored one. The docs say that admins send a valid createdAt, or
none, when updating services stored with invalid ones.

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

sourcery-ai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The registry now owns service timestamps by generating normalized values for regular clients, preserving or accepting admin-provided values according to registration/update rules, and protecting createdAt during concurrent replacements; shared time helpers, API documentation, migration guidance, and comprehensive tests were updated accordingly.

Flow diagram for timestamp handling during service replacement

flowchart TD
    A[PUT service registration] --> B{Existing service?}
    B -->|No| C[Set createdAt if absent]
    C --> D[Set updatedAt unless admin supplied one]
    B -->|Yes| E[Compare createdAt with stored value]
    E --> F{Concurrent change?}
    F -->|Yes| G[Retry replacement]
    F -->|No| H[Preserve stored createdAt]
    H --> I[Set updatedAt to current time]
    D --> J[Store service]
    I --> J
Loading

File-Level Changes

Change Details Files
Centralize service timestamp ownership and lifecycle handling in registration and replacement logic.
  • Strip non-admin timestamps before validation and let the registry generate normalized UTC millisecond values.
  • Preserve existing createdAt, including its absence, across updates while always refreshing updatedAt.
  • Include createdAt in replacement compare-and-swap reads and predicates to prevent concurrent changes from being overwritten.
  • Allow admins to import valid timestamps, retaining them on initial registration but refreshing updatedAt on replacements.
cloud_registry/ga4gh/registry/server.py
cloud_registry/ga4gh/registry/service.py
Move reusable time generation and formatting utilities into the shared utilities module.
  • Add database-precision UTC now() and RFC 3339 format_time() helpers.
  • Update verification timestamp handling to use the shared helpers.
cloud_registry/utils.py
cloud_registry/ga4gh/registry/verification.py
Document the registry-specific timestamp semantics and compatibility behavior.
  • Describe timestamps as registration-entry and last-change times rather than GA4GH deployment times.
  • Document ignored non-admin values, admin import behavior, validation, and legacy stored-service handling.
  • Update the OpenAPI schema descriptions and registration validation text.
cloud_registry/api/additions.openapi.yaml
docs/api.md
docs/upgrading.md
Expand coverage for timestamp behavior across service registration, updates, concurrency, utilities, and verification.
  • Test generated, ignored, preserved, admin-supplied, invalid, and legacy timestamp cases.
  • Test concurrent createdAt changes and timestamp behavior through the HTTP API.
  • Adapt verification and service response assertions to account for registry-managed timestamps.
tests/conftest.py
tests/ga4gh/registry/test_service.py
tests/ga4gh/registry/test_verification.py
tests/test_app.py
tests/test_utils.py
tests/test_verification.py

Assessment against linked issues

Issue Objective Addressed Explanation
#236 Have the registry manage service timestamps: set createdAt on creation and preserve it on updates, set updatedAt on creation and every update, and ignore timestamps supplied by non-admins without rejecting valid string fields. ✅
#236 Allow admins to explicitly set timestamps, including for imported services, while validating admin-supplied values as RFC 3339 date-times. ✅
#236 Document that registry timestamps describe when a service entry was registered or changed in the registry, rather than the service’s deployment, including relevant stored-service behavior. ✅

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 25, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #237   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines         1362      1375   +13     
=========================================
+ Hits          1362      1375   +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 25, 2026 19:57

@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 3 issues

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

## Individual Comments

### Comment 1
<location path="cloud_registry/ga4gh/registry/service.py" line_range="460" />
<code_context>
+                for field in ("url", KEY, VERIFIED, CREATED):
                     query[field] = stored.get(field, {"$exists": False})
+                if CREATED in stored:
+                    replacement.setdefault(CREATED, stored[CREATED])
                 unchanged = (
                     stored.get("url") == self.data["url"] and stored.get(KEY) == key
</code_context>
<issue_to_address>
**Invalid creation time survives updates**

When an admin updates a service with an invalid stored `createdAt` and omits that field, `check_date_times(self.data)` does not validate the stored value, and `_replace()` copies it into the replacement, so the invalid `createdAt` remains stored and is returned on reads.

Validate the stored `createdAt` and avoid copying it into the replacement when it is invalid.

Also at `docs/upgrading.md:115-116`, `cloud_registry/ga4gh/registry/service.py:453`.
</issue_to_address>

### Comment 2
<location path="cloud_registry/api/additions.openapi.yaml" line_range="840" />
<code_context>
           type: string
           format: date-time
-          description: 'Timestamp describing when the service was first deployed and available (RFC 3339 format)'
+          description: |
+            When the service was registered (RFC 3339 format), set by the registry and kept on updates; unlike in the GA4GH specification, not when it was first deployed.
           example: '2019-06-04T12:58:19Z'
</code_context>
<issue_to_address>
**GET timestamp descriptions are misleading**

When a client uses the OpenAPI schema to interpret timestamps returned by service GET endpoints, the changed descriptions apply to `ExternalServiceRegister`, while GET responses use `ExternalService` and `Service`, whose timestamp descriptions retain the GA4GH deployment-time meaning, so clients get the wrong meaning for returned timestamps.

Update the `Service` schema descriptions used by GET responses to document the registry's entry-time semantics for `createdAt` and `updatedAt`.

Also at `cloud_registry/api/additions.openapi.yaml:841`, `cloud_registry/api/additions.openapi.yaml:847`.
</issue_to_address>

### Comment 3
<location path="tests/test_app.py" line_range="1903" />
<code_context>
     "documentationUrl": HTTP_SCHEMES,
     "organization.url": HTTP_SCHEMES,
 }
+# Timestamps of services, which the registry sets (cf. `RegisterService`):
+# when the service was registered, and when it was last changed
</code_context>
<issue_to_address>
**Admin edit keeps stale timestamp**

When the third PUT follows the second PUT, so the stored `updatedAt` is already `FORMATTED_LATER`, `test_service_timestamps_admin`'s final assertion compares `updatedAt` with `FORMATTED_LATER`, which the preceding PUT already stored. An API path that skips refreshing `updatedAt` when an admin supplies `createdAt` still passes, though callers see a stale update time.

Use a distinct clock value for the third PUT and assert that `updatedAt` changes to it.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and the registry now replaces non-admin-supplied timestamps with its own registration and update times, and updates always replace updatedAt. If that timestamp policy is wrong, it silently affects every registration or update and persists in stored records; reverting the code would not restore the timestamps it replaced.

Blocking findings: cloud_registry/ga4gh/registry/service.py:460, cloud_registry/api/additions.openapi.yaml:840, tests/test_app.py:1903


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

Comment thread tests/test_app.py Resolved
A stored createdAt that isn't an RFC 3339 date-time (e.g., set by an
owner before timestamps were checked) is no longer kept on updates. The
descriptions of GET /services and GET /services/{serviceId} now say what
the timestamps mean in the registry, and the admin timestamps test uses
a distinct time for each update.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit bed9298 into dev Oct 25, 2026
19 checks passed
@uniqueg
uniqueg deleted the feat/service-timestamps branch October 25, 2026 20:11
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.

feat: manage service timestamps

1 participant