Skip to content

fix(session): stamp spawn timestamps in UTC#215

Open
codebanditssss wants to merge 1 commit into
mainfrom
fix/session-utc-timestamps
Open

fix(session): stamp spawn timestamps in UTC#215
codebanditssss wants to merge 1 commit into
mainfrom
fix/session-utc-timestamps

Conversation

@codebanditssss

@codebanditssss codebanditssss commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Closes #214.

Problem

ao session get showed created and updated in different timezones. Two clocks defaulted to local time.Now while the rest of the codebase writes UTC:

  • the session manager clock → spawn-stamped CreatedAt/UpdatedAt
  • the lifecycle manager clock → activity-driven LastActivityAt/UpdatedAt

A real spawn made the second one visible: after the first fix createdAt came back UTC, but updatedAt/lastActivityAt were still local (+05:30) the moment the agent reported activity.

Change

Default both clocks to UTC, matching the codebase convention.

Test

  • TestSpawn_StampsUTCTimestamps (session manager): spawn-stamped CreatedAt/UpdatedAt are UTC.
  • TestMarkSpawned_StampsUTCActivity (lifecycle): activity-driven LastActivityAt is UTC.
  • go build ./..., full go test ./..., gofmt, and golangci-lint all clean.
  • End-to-end: after spawn + activity, ao session get shows created and updated both ending in Z.

@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes mixed-timezone timestamps in ao session get by defaulting both the session manager and lifecycle manager clocks to time.Now().UTC() instead of the local-time time.Now.

  • session_manager/manager.go: The nil-clock default in New is now func() time.Time { return time.Now().UTC() }, ensuring CreatedAt/UpdatedAt stamped at spawn are always UTC — consistent with every downstream write (rename, activity) that already called .UTC().
  • lifecycle/manager.go: Same UTC fix applied to the hardcoded clock in New, aligning LastActivityAt/UpdatedAt written by activity events with spawn timestamps.
  • Tests: TestSpawn_StampsUTCTimestamps and TestMarkSpawned_StampsUTCActivity assert the Location() of each stamped field is time.UTC.

Confidence Score: 5/5

Safe to merge — the change is a two-line default clock fix with no effect on callers that inject their own clock.

Both managers now default to UTC, matching every other write path. The fix is minimal, well-scoped, and directly verified by two new tests that assert Location() == time.UTC on every affected timestamp field. No logic beyond the clock default is touched.

No files require special attention. The only remaining nit (stale godoc on New in session_manager/manager.go) was flagged in a previous review round.

Important Files Changed

Filename Overview
backend/internal/session_manager/manager.go Default clock changed from time.Now to func() time.Time { return time.Now().UTC() } to fix mixed-timezone timestamps at spawn. Doc comment on New still references the old time.Now default.
backend/internal/lifecycle/manager.go Clock in New hardened to UTC (same fix as session_manager) so activity-driven LastActivityAt/UpdatedAt are timezone-consistent with spawn timestamps.
backend/internal/session_manager/manager_test.go New TestSpawn_StampsUTCTimestamps verifies CreatedAt and UpdatedAt locations are time.UTC after spawn.
backend/internal/lifecycle/manager_test.go New TestMarkSpawned_StampsUTCActivity verifies LastActivityAt.Location() is time.UTC after MarkSpawned.

Sequence Diagram

sequenceDiagram
    participant CLI as ao CLI
    participant SM as session_manager.New
    participant LC as lifecycle.New
    participant Store as Store

    Note over SM: clock = func() time.Time { return time.Now().UTC() }
    Note over LC: clock = func() time.Time { return time.Now().UTC() }

    CLI->>SM: Spawn(config)
    SM->>Store: "CreateSession(rec) CreatedAt=clock()[UTC] UpdatedAt=clock()[UTC]"
    SM->>LC: MarkSpawned(id, metadata)
    LC->>Store: "UpdateSession(rec) LastActivityAt=clock()[UTC] UpdatedAt=clock()[UTC]"

    CLI->>SM: Rename / Activity
    SM->>Store: "UpdateSession(rec) UpdatedAt=time.Now().UTC()"

    CLI->>CLI: ao session get → all timestamps end in Z
Loading

Reviews (3): Last reviewed commit: "fix(session): stamp session timestamps i..." | Re-trigger Greptile

Comment thread backend/internal/session_manager/manager_test.go
Two clocks defaulted to local time.Now while the rest of the codebase writes
UTC, so ao session get showed created and updated in different timezones:

- session manager clock → spawn-stamped CreatedAt/UpdatedAt
- lifecycle manager clock → activity-driven LastActivityAt/UpdatedAt

A real spawn made this visible: createdAt came back UTC but updatedAt/
lastActivityAt were local once the agent reported activity. Default both clocks
to UTC.

Closes #214
@codebanditssss codebanditssss force-pushed the fix/session-utc-timestamps branch from 2bd891e to 8fa06ec Compare June 12, 2026 22:17
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.

ao session get shows created (local) and updated (UTC) in different timezones

1 participant