Skip to content

fix(micode): normalize epoch seconds vs milliseconds in time.created - #747

Merged
junhoyeo merged 1 commit into
mainfrom
fix/micode-710-time
Jun 22, 2026
Merged

fix(micode): normalize epoch seconds vs milliseconds in time.created#747
junhoyeo merged 1 commit into
mainfrom
fix/micode-710-time

Conversation

@junhoyeo

@junhoyeo junhoyeo commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Problem

crates/tokscale-core/src/sessions/micode.rs hard-assumed time.created/time.completed are epoch milliseconds (matching OpenCode). Some MiMo Code channels/builds have been observed writing epoch seconds, which made dates land ~1000x in the past (1970-era) and durations ~1000x too small (PR #710).

Fix

Added micode_timestamp_to_ms: a value at/under the 1e12 threshold is treated as seconds and scaled to ms, mirroring the existing timestamp_secs_to_ms helpers in the goose/hermes parsers. The normalized value now feeds:

  • the UnifiedMessage timestamp (the date),
  • the dedup fingerprint (created_bits/completed_bits),
  • the duration calculation (micode_duration_ms normalizes both endpoints),

so all three agree regardless of the input unit. Smallest correct change; no unrelated refactors. ClientId / commit metadata untouched (not a code issue).

Tests (would fail without the fix)

  • test_parse_micode_sqlite_normalizes_seconds_and_milliseconds: a ms-valued and a seconds-valued time.created denoting the same instant yield identical timestamp (1_700_000_000_000) and date, plus a millisecond-scale duration (Some(1234)). Without normalization the seconds input formats to 1970 and a ~1ms duration.
  • test_parse_micode_sqlite_non_object_path_field: a non-object path (bare string) no longer risks dropping the message; workspace stays None (previously untested, flagged).
  • test_parse_micode_sqlite_legacy_fallback_embedded_path_workspace: with no session table the modern JOIN query fails to prepare and the legacy fallback runs; workspace is derived from the embedded path.root (previously untested, flagged).

cargo test -p tokscale-core and cargo clippy -p tokscale-core --tests both pass clean.

Residual concern

A single real MiMo database that mixes seconds and ms across rows is not specifically tested, though each row is normalized independently so mixed units are handled.

🤖 Generated with Claude Code


Summary by cubic

Normalize MiMo Code time.created/time.completed to milliseconds to fix 1970-era dates and 1000x-short durations when some channels write epoch seconds. The normalization now powers timestamps, dedup fingerprints, and duration so they stay consistent across mixed inputs.

  • Bug Fixes
    • Added micode_timestamp_to_ms to treat values ≤ 1e12 as seconds and scale to ms.
    • Used normalized created_ms/completed_ms for UnifiedMessage timestamp, created_bits/completed_bits, and micode_duration_ms.
    • Tests cover seconds vs ms normalization, defensive parsing of non-object path, and legacy fallback deriving workspace from embedded path.root.

Written for commit d6da0cb. Summary will update on new commits.

Review in cubic

MiMo Code's `time.created`/`time.completed` were hard-assumed to be epoch
milliseconds (matching OpenCode). Some MiMo channels/builds have been
observed writing epoch *seconds*, which made dates land ~1000x in the past
(1970-era) and durations ~1000x too small.

Add `micode_timestamp_to_ms`: values at/under the 1e12 threshold are treated
as seconds and scaled to ms, mirroring `timestamp_secs_to_ms` in the
goose/hermes parsers. The normalized value feeds the UnifiedMessage
timestamp, the dedup fingerprint, and the duration calculation so all three
stay consistent regardless of the input unit.

Tests:
- a ms-valued and a seconds-valued time.created denoting the same instant
  now yield identical timestamp/date and a millisecond-scale duration.
- non-object `path` field is handled defensively (message survives, no
  embedded workspace) — previously untested.
- legacy-query fallback (no `session` table) derives the workspace from the
  embedded `path.root` — previously untested.

Confidence: high
Scope-risk: narrow
Not-tested: real MiMo databases that mix seconds and ms within one file
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tokscale Ignored Ignored Jun 22, 2026 7:25am

Request Review

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 1 file

Re-trigger cubic

@junhoyeo
junhoyeo merged commit c2156fe into main Jun 22, 2026
14 of 15 checks passed
makoMakoGo added a commit to makoMakoGo/tokscale that referenced this pull request Jun 23, 2026
ported from upstream junhoyeo#735
ported from upstream junhoyeo#737
ported from upstream junhoyeo#747
ported from upstream junhoyeo#750
ported from upstream junhoyeo#752
ported from upstream junhoyeo#760
ported from upstream junhoyeo#766
t1000040 pushed a commit to tmobi-internal/tokscale that referenced this pull request Jun 30, 2026
…unhoyeo#747)

MiMo Code's `time.created`/`time.completed` were hard-assumed to be epoch
milliseconds (matching OpenCode). Some MiMo channels/builds have been
observed writing epoch *seconds*, which made dates land ~1000x in the past
(1970-era) and durations ~1000x too small.

Add `micode_timestamp_to_ms`: values at/under the 1e12 threshold are treated
as seconds and scaled to ms, mirroring `timestamp_secs_to_ms` in the
goose/hermes parsers. The normalized value feeds the UnifiedMessage
timestamp, the dedup fingerprint, and the duration calculation so all three
stay consistent regardless of the input unit.

Tests:
- a ms-valued and a seconds-valued time.created denoting the same instant
  now yield identical timestamp/date and a millisecond-scale duration.
- non-object `path` field is handled defensively (message survives, no
  embedded workspace) — previously untested.
- legacy-query fallback (no `session` table) derives the workspace from the
  embedded `path.root` — previously untested.

Confidence: high
Scope-risk: narrow
Not-tested: real MiMo databases that mix seconds and ms within one file
@junhoyeo
junhoyeo deleted the fix/micode-710-time branch July 13, 2026 02: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.

1 participant