Skip to content

refactor(infra): canonicalize session usage timestamps#100687

Merged
steipete merged 3 commits into
mainfrom
codex/fix-session-usage-timestamp-canonical
Jul 6, 2026
Merged

refactor(infra): canonicalize session usage timestamps#100687
steipete merged 3 commits into
mainfrom
codex/fix-session-usage-timestamp-canonical

Conversation

@steipete

@steipete steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Malformed transcript timestamps can become NaN in session usage logs. Gateway JSON serialization then exposes that value as null, and direct parsing also skips the existing nested message-timestamp fallback.

This supersedes #99418 with a stable maintainer-owned branch after repeated contributor-branch rebases invalidated exact-head proof. It preserves @sheyanmin's authorship through a Co-authored-by trailer and changelog credit, and tightens the minimal guard merged in #99420.

Why This Change Was Made

loadSessionLogs now uses the same canonical parseTimestamp path as session usage summaries. That preserves valid ISO timestamps, falls back to numeric nested message timestamps, and normalizes truly malformed entries to epoch zero before sorting or serialization.

The regression test covers all three states in one transcript: malformed without fallback, malformed with nested fallback, and valid ISO input.

User Impact

Session usage detail logs always return finite numeric timestamps. Existing valid timestamps and nested fallback behavior remain unchanged.

Evidence

  • Blacksmith Testbox tbx_01kwv0vw0yy55xenj6evvanps7: CI=true pnpm test src/infra/session-cost-usage.test.ts — 65/65 passed.
  • Final exact-head source-blind sanitized AWS validation: run_97d2116b617e on cbx_49e34d8a40d4 (swift-shrimp) at d22f63bc08cff61d1f2cd25a32ae73b8ca32c093 — finite/order/content assertions, byte-identical repeat and restart, valid-top and nested-removal mutations, and missing-session isolation all passed. Public network, no Tailscale/hydration/ambient credentials; lease stopped.
  • Exact-head hosted run 28774705174 passed after rerunning one unrelated flaky PTY assertion; 4,713 tests passed on the first attempt.
  • Fresh AutoReview: clean, confidence 0.91.
  • git diff --check: passed.

Co-authored-by: sheyanmin <44184140+sheyanmin@users.noreply.github.com>
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Jul 6, 2026
…ge-timestamp-canonical

# Conflicts:
#	CHANGELOG.md
@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed July 6, 2026, 3:25 AM ET / 07:25 UTC.

Summary
The PR routes session usage detail-log timestamp parsing through parseTimestamp, adds regression coverage for malformed, nested-fallback, and valid timestamps, and adds a changelog entry.

PR surface: Source -6, Tests +39, Docs +1. Total +34 across 3 files.

Reproducibility: yes. at source level. Current main still returns 0 instead of the finite nested message.timestamp when the top-level log timestamp string is malformed, while the PR test covers that path directly.

Review metrics: 1 noteworthy metric.

  • Release-owned changelog edit: 1 added. The PR changes the release-generated changelog directly, which maintainers should resolve before merge.

Stored data model
Persistent data-model change detected: serialized state: src/infra/session-cost-usage.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #100687
Summary: This PR is the canonical replacement branch for the remaining shared-parser session usage timestamp fix; the predecessor branch is superseded and the merged sibling only covers the narrower NaN guard.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Remove the direct CHANGELOG.md entry while preserving the runtime and regression-test changes.

Risk before merge

  • [P1] Merging as-is keeps a direct CHANGELOG.md release-note edit that can duplicate or conflict with release-generated changelog output.

Maintainer options:

  1. Remove the release-owned changelog edit (recommended)
    Drop only the added CHANGELOG.md entry, leaving the runtime and regression-test fix unchanged.
  2. Accept the release-note conflict
    Maintainers may intentionally merge the direct changelog edit, but that opts into possible duplication with release generation.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Remove the added `CHANGELOG.md` session usage logs entry only; keep the `src/infra/session-cost-usage.ts` and `src/infra/session-cost-usage.test.ts` changes unchanged.

Next step before merge

  • [P2] A narrow automated repair can remove the release-owned changelog entry without changing the runtime or regression-test fix.

Security
Cleared: Security review cleared: the diff changes local TypeScript timestamp parsing, focused unit coverage, and changelog text, with no dependency, workflow, secret, permission, package, or code-execution surface added.

Review findings

  • [P3] Drop the direct changelog edit — CHANGELOG.md:33
Review details

Best possible solution:

Land the canonical parseTimestamp runtime/test fix after removing the direct changelog edit and keep release-note context in the PR body or squash message.

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

Yes, at source level. Current main still returns 0 instead of the finite nested message.timestamp when the top-level log timestamp string is malformed, while the PR test covers that path directly.

Is this the best way to solve the issue?

Yes for the runtime and test path: reusing parseTimestamp removes duplicate parsing and aligns detail logs with usage summaries. The direct CHANGELOG.md edit is not the best release-note path and should be removed.

Full review comments:

  • [P3] Drop the direct changelog edit — CHANGELOG.md:33
    CHANGELOG.md is release-owned by root policy, and this PR already carries the needed release-note context in its body. This prior finding still applies on the latest head: leaving the added line can duplicate or conflict with generated release notes, so remove only this changelog entry.
    Confidence: 0.91

Overall correctness: patch is correct
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add merge-risk: 🚨 other: Merging the direct CHANGELOG.md edit can conflict with OpenClaw's release-owned changelog generation.

Label justifications:

  • P2: This is a normal-priority session usage log data-shape fix with a narrow affected surface and focused regression coverage.
  • merge-risk: 🚨 other: Merging the direct CHANGELOG.md edit can conflict with OpenClaw's release-owned changelog generation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): Sufficient linked-artifact proof: the PR body cites an exact Blacksmith Testbox focused test run and a source-blind Crabbox Gateway validation run of the identical runtime/test patch.
  • proof: sufficient: Contributor real behavior proof is sufficient. Sufficient linked-artifact proof: the PR body cites an exact Blacksmith Testbox focused test run and a source-blind Crabbox Gateway validation run of the identical runtime/test patch.
Evidence reviewed

PR surface:

Source -6, Tests +39, Docs +1. Total +34 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 9 -6
Tests 1 39 0 +39
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 43 9 +34

Acceptance criteria:

  • [P1] git diff --check.
  • [P1] Verify gh pr diff 100687 --repo openclaw/openclaw no longer shows a CHANGELOG.md diff and still retains the src/infra/session-cost-usage.ts and src/infra/session-cost-usage.test.ts changes.

What I checked:

  • Root policy applied: Root AGENTS.md says CHANGELOG.md is release-only and normal PRs should not edit it, which drives the remaining review finding. (AGENTS.md:238, de30d2f5c333)
  • Current-main baseline still misses nested fallback: Current main directly parses a string top-level timestamp and only checks message.timestamp in the else if, so a malformed top-level string still prevents the nested finite timestamp fallback from being used. (src/infra/session-cost-usage.ts:2742, de30d2f5c333)
  • Shared parser has the intended fallback contract: parseTimestamp already rejects invalid top-level timestamp strings and falls back to a finite nested message.timestamp, making it the right local owner for detail-log timestamps. (src/infra/session-cost-usage.ts:862, de30d2f5c333)
  • Gateway caller exposes the value: The sessions.usage.logs Gateway method calls loadSessionLogs and responds with { logs }, so the timestamp parser controls a user-visible RPC response. (src/gateway/server-methods/usage.ts:1544, de30d2f5c333)
  • PR runtime patch matches the intended owner boundary: The PR head replaces the duplicate local timestamp branch with parseTimestamp(parsed)?.getTime() ?? 0. (src/infra/session-cost-usage.ts:2742, d22f63bc08cf)
  • PR adds focused regression coverage: The new test covers malformed without fallback, malformed with finite nested fallback, and valid ISO timestamps in one loadSessionLogs transcript. (src/infra/session-cost-usage.test.ts:2922, d22f63bc08cf)

Likely related people:

  • steipete: History shows prior session cost usage work by Peter Steinberger, and this branch is the stable replacement carrying the shared-parser fix with preserved co-authorship. (role: recent area refactor contributor and replacement branch owner; confidence: high; commits: 3ce1ee84ace4, 8cd20e220fbc, 57cea58b4105; files: src/infra/session-cost-usage.ts, src/infra/session-cost-usage.test.ts, CHANGELOG.md)
  • Takhoffman: The token usage dashboard commit introduced the backend usage-log and Gateway usage surfaces touched by this PR. (role: introduced usage-log surface; confidence: medium; commits: 8a352c8f9dfd; files: src/infra/session-cost-usage.ts, src/gateway/server-methods/usage.ts, ui/src/ui/views/usage.ts)
  • krissding: The merged sibling PR added the current-main NaN guard on the same loadSessionLogs timestamp parser path. (role: recent overlapping fix contributor; confidence: medium; commits: e183d665eea7; files: src/infra/session-cost-usage.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-06T07:18:34.134Z sha c76c591 :: needs changes before merge. :: [P3] Drop the direct changelog edit

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 6, 2026

@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: d22f63bc08

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

Comment thread CHANGELOG.md
- **Small-context compaction:** cap the effective reserve against the known model context window so small local models do not enter compaction from the first token. (#100621) Thanks @vincentkoc.
- **Plugin install diagnostics:** suppress the misleading hook-pack fallback after plugin install failures only when the hook manifest is absent, while preserving actionable malformed hook-pack errors. (#100554) Thanks @vincentkoc.
- **Config validation diagnostics:** emit each unchanged sanitized validation-warning payload once per config path, reset deduplication after a clean validation, and preserve the warning fingerprint across transient invalid reads and failed refreshes. (#100569, #25574) Thanks @vincentkoc.
- **Session usage logs:** normalize malformed transcript timestamps before sorting and Gateway serialization so invalid dates cannot surface as null usage-log times. (#99418) Thanks @sheyanmin.

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 Remove the manual changelog entry

For this normal infra fix, CHANGELOG.md should stay release-owned: AGENTS.md says normal PRs/direct fixes should carry release-note context in the PR body or commit message instead, and scripts/pr-lib/common.sh:34 makes changelog updates never required for changed files because release automation generates the file. Leaving this manual Unreleased entry can make release generation duplicate or reorder notes for #99418, so please drop it from the code change.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Jul 6, 2026
@steipete
steipete merged commit f6f3423 into main Jul 6, 2026
178 of 180 checks passed
@steipete
steipete deleted the codex/fix-session-usage-timestamp-canonical branch July 6, 2026 07:39
@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 6, 2026
Co-authored-by: sheyanmin <44184140+sheyanmin@users.noreply.github.com>
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
Co-authored-by: sheyanmin <44184140+sheyanmin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant