Skip to content

fix: use int64 nanosecond timestamps and preserve CreatedAt in PolicyStatusRun (OBS-2547 OBS-2219)#309

Merged
leoparente merged 6 commits intodevelopfrom
fix/obs2547-policy-run-timestamp
Apr 7, 2026
Merged

fix: use int64 nanosecond timestamps and preserve CreatedAt in PolicyStatusRun (OBS-2547 OBS-2219)#309
leoparente merged 6 commits intodevelopfrom
fix/obs2547-policy-run-timestamp

Conversation

@leoparente
Copy link
Copy Markdown
Contributor

Summary

  • Change PolicyStatusRun timestamp fields (CreatedAt, UpdatedAt) from time.Time to int64 nanosecond Unix timestamps for consistency with backend expectations
  • Preserve backend CreatedAt in the UpdateRuns new-run path instead of overwriting it with the current time
  • Fix misleading timestamp comments in test files

Test Plan

  • go test ./agent/backend/... passes
  • go test ./agent/policies/... passes
  • Policy run timestamps are stored as int64 nanoseconds in Redis
  • CreatedAt is not overwritten when a new run is created via UpdateRuns

🤖 Generated with Claude Code

leoparente and others added 4 commits April 7, 2026 17:11
All backends (device-discovery, network-discovery, snmp-discovery, worker)
emit created_at/updated_at as nanosecond integers. The previous time.Time
type caused json.Unmarshal to fail mid-array, dropping every policy after
the first from GetPolicyStatus() results.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Now that convertToRunData correctly converts nanosecond timestamps to
time.Time, UpdateRuns no longer needs to override CreatedAt with
time.Now() for all new runs. Use the backend's actual run start time
when available; fall back to now only when CreatedAt is zero.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use unambiguous past date in BackendCreatedAtPreserved test
- Add UpdatedAt assertion to ZeroCreatedAtFallsBackToNow test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@leoparente leoparente changed the title fix: use int64 nanosecond timestamps and preserve CreatedAt in PolicyStatusRun (OBS-2547) fix: use int64 nanosecond timestamps and preserve CreatedAt in PolicyStatusRun (OBS-2547 OBS-2219) Apr 7, 2026
@leoparente leoparente self-assigned this Apr 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

Vulnerability Scan: Passed

Image: orb-agent:scan

Source Library CVE Severity Installed Fixed Title
Python pip CVE-2026-1703 ⚪ LOW 25.3 26.0 pip: pip: Information disclosure via path traversal when installing crafted whee

Commit: 1e7b964

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60db88531c

ℹ️ 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".

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

Go test coverage

STATUS ELAPSED PACKAGE COVER PASS FAIL SKIP
🟢 PASS 1.02s github.com/netboxlabs/orb-agent/agent 45.2% 6 0 0
🟢 PASS 31.88s github.com/netboxlabs/orb-agent/agent/backend 75.7% 44 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/backend/devicediscovery 66.5% 4 0 0
🟢 PASS 0.05s github.com/netboxlabs/orb-agent/agent/backend/mocks 0.0% 0 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/backend/networkdiscovery 58.3% 4 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/backend/opentelemetryinfinity 45.2% 2 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/backend/pktvisor 66.5% 2 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/backend/snmpdiscovery 58.3% 4 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/backend/worker 67.8% 7 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/config 100.0% 6 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/configmgr 51.6% 48 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/configmgr/fleet 65.3% 152 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/otlpbridge 50.2% 10 0 0
🟢 PASS 1.02s github.com/netboxlabs/orb-agent/agent/policies 99.1% 25 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/policymgr 71.6% 11 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/redact 81.6% 84 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/secretsmgr 47.1% 65 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/telemetry 81.7% 19 0 0
🟢 PASS (cached) github.com/netboxlabs/orb-agent/agent/version 62.5% 5 0 0

Total coverage: 59.8%

time.Unix(0, 0) is not the zero time.Time, so a zero/omitted int64
timestamp was bypassing the IsZero() fallback in UpdateRuns and being
stored as 1970-01-01. Introduce nsToTime() which maps 0 -> time.Time{}
so missing timestamps still trigger the time.Now() fallback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@leoparente
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cbaf0d48fb

ℹ️ 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".

When the agent first observes a run that is already in a terminal state
(e.g. after an agent restart), UpdatedAt was unconditionally set to
poll time. This permanently distorted UpdatedAt − CreatedAt and produced
incorrect run duration/age metrics for historical runs.

Fix: for new runs in a terminal status with a non-zero backend UpdatedAt,
use the backend value instead of now. In-progress new runs continue to
use now so elapsed time tracking works correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@leoparente
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ 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".

@leoparente leoparente merged commit 23f48de into develop Apr 7, 2026
7 checks passed
@leoparente leoparente deleted the fix/obs2547-policy-run-timestamp branch April 7, 2026 20:40
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.

2 participants