Repository navigation
feat: manage service timestamps - #237
Conversation
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]>
Reviewer's GuideThe 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 Flow diagram for timestamp handling during service replacementflowchart 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
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
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]>
Summary
The registry now manages the timestamps of services:
createdAtis set when a service is registered and kept on updates (services stored without it stay without it).updatedAtis set on registration and on every update (eachPUT).createdAton registration and on updates,updatedAtonly 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.createdAtis part of the compare-and-swap of replacements, so a concurrent change isn't reverted.now()andformat_time()move fromverification.pytocloud_registry/utils.py, for reuse.Docs: the API description (
ExternalServiceRegister) anddocs/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): passedcoverage 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 pytestagainst MongoDB 7.0.34: 1144 passed, 228 skippedmkdocs build --strict: passedDeclined review findings
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).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:
createdAtandupdatedAttimestamps automatically during registration and updates, with administrator support for imported timestamps.Bug Fixes:
createdAtduring concurrent replacements and avoid restoring invalid or absent timestamps on legacy services.Enhancements:
Documentation:
Tests: