Skip to content

fix(usage): handle Daylight saving time (DST) hour boundaries - #61335

Closed
rex993 wants to merge 1 commit into
openclaw:mainfrom
rex993:codex/pr-usage-daylight-saving-time-hour-boundaries
Closed

rex993 wants to merge 1 commit into
openclaw:mainfrom
rex993:codex/pr-usage-daylight-saving-time-hour-boundaries

Conversation

@rex993

@rex993 rex993 commented Apr 5, 2026

Copy link
Copy Markdown

Summary

This fixes a Control UI Usage-page freeze when a long session spans a local Daylight saving time (DST) transition.

Today the hour-slicing code computes a local :59:59.999 hour end from the current wall-clock time. In a repeated local hour at Daylight saving time (DST) fallback, that can resolve to an earlier instant and stop cursor progress.

This change switches Usage hour slicing and selected-hour filtering to monotonic next-hour-boundary stepping so aggregation always moves forward in the selected timezone.

Why

This fixes cases where:

  • Usage is rendered in local time
  • a session spans a Daylight saving time (DST) fallback or spring-forward boundary
  • the page builds hour buckets or applies a selected-hour filter

Without this change, the Control UI can wedge the browser main thread while rendering Usage data for long sessions.

Changes

  • replace the ambiguous local end-of-hour calculation with getNextHourStart() plus bounded next-hour stepping in ui/src/ui/views/usage-metrics.ts
  • convert session hour slicing to half-open intervals [cursor, nextBoundary) so exact boundaries do not create zero-duration buckets
  • route the selected-hour filter in ui/src/ui/views/usage.ts through the same DST-safe helper instead of maintaining a duplicate loop
  • add focused node-side regression coverage for Daylight saving time (DST) fallback, Daylight saving time (DST) spring-forward, peak-error aggregation, and full Usage render with an hour filter

Testing

AI-assisted: yes
Built and tested in: Codex App
Model: GPT-5.4
Reasoning effort: Extra High
Testing: focused local test

  • pnpm --dir ui exec vitest run --config vitest.node.config.ts src/ui/views/usage-metrics.node.test.ts

@rex993
rex993 marked this pull request as ready for review April 5, 2026 12:43
@greptile-apps

greptile-apps Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a browser main-thread freeze on the Usage page when a session spans a DST clock change. It replaces the ambiguous local :59:59.999 end-of-hour calculation (setToHourEnd) with monotonic getNextHourStart stepping (setHours(h+1, 0, 0, 0)), converts hour slicing to half-open intervals [cursor, nextBoundary), and moves sessionTouchesHours into usage-metrics.ts with proper timeZone threading. The getNextHourBoundaryMs monotonicity guard (falling back to endMs on any non-monotonic transition) ensures the loops always terminate. Focused regression tests cover DST fallback, spring-forward, peak-error aggregation, and hour-filtered rendering.

Confidence Score: 5/5

Safe to merge; the DST-safe stepping is correct and all edge cases are handled with no blocking issues.

All findings are P2 or lower. The core logic replacing setToHourEnd with setHours(h+1,0,0,0) is the standard JS approach for DST-safe hour advancing. Loop termination is guaranteed in all cases by the monotonicity guard that falls back to endMs. Regression tests explicitly cover DST fallback, spring-forward, exact boundaries, and the hour filter path.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(usage): handle Daylight saving time ..." | Re-trigger Greptile

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

Copy link
Copy Markdown
Contributor

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: 4fc7ce4206

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

});

afterEach(() => {
process.env.TZ = ORIGINAL_TZ;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Restore TZ by deleting env var when unset

If ORIGINAL_TZ is undefined (a common default in CI), process.env.TZ = ORIGINAL_TZ writes the literal string "undefined" instead of unsetting the variable. That leaks an invalid timezone into later tests running in the same Vitest worker and can cause unrelated local-time assertions to fail intermittently. Restore with delete process.env.TZ when there was no original value.

Useful? React with 👍 / 👎.

@rex993
rex993 force-pushed the codex/pr-usage-daylight-saving-time-hour-boundaries branch from 4fc7ce4 to 813b502 Compare April 5, 2026 12:55
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Apr 5, 2026
@rex993
rex993 force-pushed the codex/pr-usage-daylight-saving-time-hour-boundaries branch from 813b502 to 3d9604e Compare April 5, 2026 13:00
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Apr 5, 2026
@rex993
rex993 force-pushed the codex/pr-usage-daylight-saving-time-hour-boundaries branch from 3d9604e to a05a1c8 Compare April 5, 2026 22:47
@rex993
rex993 force-pushed the codex/pr-usage-daylight-saving-time-hour-boundaries branch 2 times, most recently from 10c0910 to 5c0ef3c Compare April 28, 2026 11:51
@clawsweeper

clawsweeper Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the contribution. This PR has been inactive for a while and still is not in a landable state.

Close this PR as abandoned: it contains a plausible fix for a still-relevant DST hour-slicing bug, but its head has been inactive since April 28, 2026, is currently conflict-dirty, has no real after-fix behavior proof, and retains a test-environment cleanup defect.

So I’m closing this as inactive for now. If you pick the work back up, push a rebased branch with green checks and reopen (or open a fresh PR) and it will be reviewed again.

Review details

Best possible solution:

Preserve the DST-safe next-boundary design in a fresh, rebased PR that fixes the TZ restoration, resolves current conflicts, and includes redacted real Usage-page proof across a DST boundary.

Do we have a high-confidence way to reproduce the issue?

No high-confidence executed reproduction is available in this review. Current main retains the local end-of-hour cursor logic described by the report, so the failure path is source-reproducible but not live-verified here.

Is this the best way to solve the issue?

No. The shared next-hour-boundary helper is the right general direction, but this stale branch is conflict-dirty, lacks real behavior evidence, and needs the TZ cleanup repair before it is a safe solution vehicle.

Security review:

Security review cleared: The three-file UI and test change introduces no concrete security or supply-chain concern.

AGENTS.md: found and applied where relevant.

What I checked:

  • Current-main behavior: Current main still derives a local end-of-hour instant and advances the cursor by one millisecond, so the proposed DST hang fix is not already implemented on main. (ui/src/ui/views/usage-metrics.ts:56, e04ea7916c5b)
  • Proposed fix surface: The branch changes hour slicing to next-boundary stepping and consolidates selected-hour filtering into the shared metrics helper. (ui/src/ui/views/usage-metrics.ts:56, 49e0900832e9)
  • Unresolved test defect: The existing review correctly notes that assigning an undefined original TZ value back to process.env writes the string "undefined" rather than restoring an unset environment variable, leaking invalid timezone state to later tests. (ui/src/ui/views/usage-metrics.node.test.ts:119, 49e0900832e9)
  • Idle conflicted branch: The branch head is 49e0900 from April 28, 2026; as of July 18, 2026 GitHub reports the PR as mergeable=false with mergeableState=dirty. The contributor has not supplied real behavior proof despite the June 13, 2026 proof-request label. (49e0900832e9)

Likely related people:

  • steipete: Related DST Usage work in fix: keep usage day buckets correct across DST #103097 indicates current ownership context for the overlapping Control UI time-zone behavior, though it does not establish ownership of this exact hour-slicing helper. (role: adjacent DST Usage contributor; confidence: low; files: ui/src/ui/views/usage-metrics.ts, ui/src/ui/views/usage.ts)

Codex review notes: model internal, reasoning high; reviewed against e04ea7916c5b.

@rex993
rex993 force-pushed the codex/pr-usage-daylight-saving-time-hour-boundaries branch from 5c0ef3c to bab8ccc Compare April 28, 2026 12:10
@rex993
rex993 force-pushed the codex/pr-usage-daylight-saving-time-hour-boundaries branch from bab8ccc to 49e0900 Compare April 28, 2026 12:11
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels May 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 19, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 11, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 11, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 12, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 13, 2026
@clawsweeper clawsweeper Bot added the status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. label Jun 13, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 3, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 3, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 18, 2026
@clawsweeper clawsweeper Bot removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant