Handle numeric-string timestamps in thermostat MetricSample payloads#3791
Handle numeric-string timestamps in thermostat MetricSample payloads#3791MontrealAI wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f880531c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if re.match(r"^[+-]?\d+(\.\d+)?$", normalized): | ||
| timestamp = datetime.fromtimestamp(float(normalized), tz=timezone.utc) |
There was a problem hiding this comment.
Guard numeric-string epoch parsing against out-of-range values
The new numeric-string path calls datetime.fromtimestamp without a try/except, so a large numeric string (common if a producer sends epoch milliseconds, e.g. "1714560000000") raises ValueError: year ... out of range and bubbles out of from_payload. Before this change, string timestamps that couldn’t be parsed fell back to now, so ingestion wouldn’t crash. This is a regression for any upstream that emits numeric strings outside the supported seconds range; consider catching ValueError/OverflowError here or normalizing ms/µs before calling fromtimestamp.
Useful? React with 👍 / 👎.
Motivation
MetricSample.from_payloadpreviously treated string timestamps as ISO only, causing numeric-string epoch values to be mis-parsed and fallback to the current time.thermostatworkflows that consume external telemetry.Description
MetricSample.from_payloadinservices/thermostat/metrics.py.Zsuffix handling as a fallback when the string is not numeric.test_metric_sample_parses_numeric_string_timestampinservices/thermostat/tests/test_metrics.pyto cover the new behavior.Testing
pytest -q services/thermostat/tests/test_metrics.py, which passed (3 passed).pytest -qproduced245 passed, 1 skippedbefore this change).Codex Task