fix(micode): normalize epoch seconds vs milliseconds in time.created - #747
Merged
Conversation
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
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
crates/tokscale-core/src/sessions/micode.rshard-assumedtime.created/time.completedare 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 the1e12threshold is treated as seconds and scaled to ms, mirroring the existingtimestamp_secs_to_mshelpers in the goose/hermes parsers. The normalized value now feeds:UnifiedMessagetimestamp (the date),created_bits/completed_bits),micode_duration_msnormalizes 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-valuedtime.createddenoting 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-objectpath(bare string) no longer risks dropping the message; workspace staysNone(previously untested, flagged).test_parse_micode_sqlite_legacy_fallback_embedded_path_workspace: with nosessiontable the modern JOIN query fails to prepare and the legacy fallback runs; workspace is derived from the embeddedpath.root(previously untested, flagged).cargo test -p tokscale-coreandcargo clippy -p tokscale-core --testsboth 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.completedto 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.micode_timestamp_to_msto treat values ≤1e12as seconds and scale to ms.created_ms/completed_msforUnifiedMessagetimestamp,created_bits/completed_bits, andmicode_duration_ms.path, and legacy fallback deriving workspace from embeddedpath.root.Written for commit d6da0cb. Summary will update on new commits.