Skip to content

feat: 会话 jsonl 时间戳改为上海时间 - #1363

Open
jianYanZhiX7 wants to merge 1 commit into
claude-code-best:mainfrom
jianYanZhiX7:feat/shanghai-session-timestamps
Open

jianYanZhiX7 wants to merge 1 commit into
claude-code-best:mainfrom
jianYanZhiX7:feat/shanghai-session-timestamps

Conversation

@jianYanZhiX7

@jianYanZhiX7 jianYanZhiX7 commented Sep 19, 2026

Copy link
Copy Markdown

Summary

会话 jsonl 转录在写入时将顶层 timestamp 序列化为 +08:00 偏移写法,使会话文件可直接读作本地时间,同时保持 ISO-8601 严格性(Date.parse 语义不变)。

改动

  • 新增 src/utils/shanghaiTimestamp.tstoShanghaiISOString / toShanghaiTimestamp / withShanghaiTimestamp / compareTimestamps
  • 5 个写入点接入转换:主写入队列、hydrateRemoteSession、CCR v2 前台转录与子代理转录、appendEntryToFile
  • 2 处排序改为按真实时刻比较(recoverOrphanedParallelToolResultsloadAllLogsFromSessionFile),修正 ...Z+08:00 混存时的字典序错序
  • 嵌套时间戳不改写:toolUseResult / MCP 元数据等不透明载荷保持逐字节 round-trip

变更文件

  • 新增:src/utils/shanghaiTimestamp.ts(61 行)、src/utils/__tests__/shanghaiTimestamp.test.ts(10 个用例)
  • 修改:src/utils/sessionStorage.ts(17+/9-)

Test plan

  • bun run precheck 全绿:typecheck 零错误 + biome 零修复
  • 全量 bun test:6032 pass / 10 skip / 0 fail
  • 新增 10 个用例:转换语义、非 Z / 非法值兜底、嵌套时间戳不改写、混存偏移按时刻排序

Summary by CodeRabbit

  • New Features
    • Transcript timestamps are now consistently displayed using the Shanghai timezone (+08:00).
    • Timestamped transcript entries are normalized across session storage and restored sessions.
  • Bug Fixes
    • Transcript entries with mixed timestamp formats are now ordered by their actual time rather than text formatting, improving log and tool-result ordering.
    • Existing timestamps that cannot be converted remain unchanged.

写入时将顶层 timestamp 序列化为 +08:00 偏移写法,
使会话文件可直接读作本地时间,同时保持 ISO-8601 严格性。

- 新增 src/utils/shanghaiTimestamp.ts:转换、改写与时刻比较
- 5 个写入点接入转换(主写入队列、远程水合、CCR v2 前台与子代理、追加写入)
- 2 处排序改为按真实时刻比较,修正 Z 与 +08:00 混存时的字典序错序
- 嵌套时间戳不改写,避免污染 toolUseResult 与 MCP 元数据
- 补充 shanghaiTimestamp 单元测试(10 个用例)
@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: c3e7545a-ec81-4017-bc66-2f46aa953102

📥 Commits

Reviewing files that changed from the base of the PR and between 77a7934 and 4e8daf7.

📒 Files selected for processing (3)
  • src/utils/__tests__/shanghaiTimestamp.test.ts
  • src/utils/sessionStorage.ts
  • src/utils/shanghaiTimestamp.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds Shanghai timestamp utilities and tests. Transcript hydration paths now normalize timestamps before serialization. Transcript recovery and loading now compare mixed-offset timestamps by instant.

Changes

Timestamp handling

Layer / File(s) Summary
Timestamp utility contracts and tests
src/utils/shanghaiTimestamp.ts, src/utils/__tests__/shanghaiTimestamp.test.ts
Adds timestamp conversion, entry normalization, and offset-aware comparison helpers with coverage for valid, invalid, nested, and mixed-offset values.
Transcript write normalization
src/utils/sessionStorage.ts
Applies withShanghaiTimestamp to remote session entries and CCRv2 event payloads before serialization.
Offset-aware transcript ordering
src/utils/sessionStorage.ts
Uses compareTimestamps when recovering orphaned results and loading trailing session messages.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: converting session JSONL timestamps to Shanghai time.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant