Skip to content

fix(artifacts): order companion slots by byte compare - #12404

Closed
aniruddhaadak80 wants to merge 1 commit into
kirodotdev:mainfrom
aniruddhaadak80:fix/artifacts-companion-byte-compare
Closed

aniruddhaadak80 wants to merge 1 commit into
kirodotdev:mainfrom
aniruddhaadak80:fix/artifacts-companion-byte-compare

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

Problem / Motivation

pickBoundSlot in ArtifactDetailPage and the split-view picker in SessionGridView ordered machine ISO-8601 last_activity_ts values with localeCompare. The collator is host-locale sensitive and slower, and it disagrees with the library page's own byte-order compare, so two views could pick different companion sessions for one artifact slug, and sub-second-distinct stamps could misorder.

Why it matters

Wrong companion session opens on artifact race or History-resume cases. The i18n catalog explicitly blesses byte order for machine timestamps and flags bare localeCompare as a finding.

What changed (motivation, approach, change)

Added compareIsoTsDesc to the src/i18n/format.ts seam (newest-first byte compare, empty as oldest) and routed both pickers through it, mirroring the ArtifactsPage updated_at precedent. No visual change; ordering only.

Tests

  • New compareIsoTsDesc block in src/i18n/format.test.ts: microsecond ordering, missing-stamp handling, locale invariance under tr.
  • vitest run src/i18n/format.test.ts: 59 passed.
  • vitest run src/test/ArtifactDetailPage.companionChat.test.tsx: 28 passed.
  • tsc --noEmit clean; eslint clean on all four files.

Manual verification

N/A - unit coverage sufficient; no UI layout change (no screenshots).

Related Issues

None - self-identified defect during frontend i18n review.

Pattern harvest

Rule candidate: review-prompt
Pattern: localeCompare used on machine ISO timestamps instead of byte order

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

N/A - placeholder wording pending OSPO; no CLA text invented.

pickBoundSlot and the split-view picker ordered machine ISO-8601 stamps with localeCompare, which is host-dependent and drops microsecond precision. Route both through a new compareIsoTsDesc seam helper matching the library page.
@aniruddhaadak80
aniruddhaadak80 requested review from a team and hoang-phan98 September 21, 2026 01:18
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ⚠️ review incomplete

Reviewed 8749bdbcb26e89ffd43c0a98fc7b78176eb0aab4 via the fork AI-review pipeline; updated in place on each push.

No completed Opus verdict for this commit; see the Fork Opus 4.8 Review job logs.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ⚠️ could not complete

The design review did not produce a verdict for 8749bdbcb26e89ffd43c0a98fc7b78176eb0aab4 (the review step failed). See the Fork Design Review job logs. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ⚠️ could not complete

The first-principles review did not produce a verdict for 8749bdbcb26e89ffd43c0a98fc7b78176eb0aab4 (the review step failed). See the Fork First Principles Review job logs. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed 8749bdbcb26e89ffd43c0a98fc7b78176eb0aab4 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 8749bdb

@bolichen97

Copy link
Copy Markdown
Contributor

Closing as a duplicate of PR #10950

Thanks for finding this. Sorting last_activity_ts with localeCompare is a real problem, and main still does it. PR #10950 (opened 2026-09-15) fixes the same two sites. The two PRs conflict in both source files, so only one of them can land.

Overlap

  • The same two sites: pickBoundSlot (website/src/pages/ArtifactDetailPage.tsx:66) and the PlaceholderPane picker tie-break (website/src/components/SessionGridView.tsx:254). Both PRs remove the same (b.last_activity_ts || '').localeCompare(a.last_activity_ts || '') line at each one.
  • Both replace it with a shared newest-first comparator. Here that is compareIsoTsDesc (website/src/i18n/format.ts:601). In PR fix(dashboard): order session recency by instant, not timestamp text #10950 it is byRecentActivity in a new website/src/utils/slotRecency.ts.

Why PR #10950 is the one to keep
Byte order gives chronological order only when every stamp has the same format, and this field does not. The docstring at format.ts:596 says "the stamps share one backend format", but main says otherwise:

  • src/kiro_crew/dashboard/slot_projection.py:175 passes the raw transcript ts through unchanged (message.get("ts")).
  • src/kiro_crew/history.py:1047 says "Timestamps in one transcript are not guaranteed to share one format". Legacy rows are naive.
  • monotonic_transcript_ts (history.py:1132) turns a naive clock into the host's local offset. Stamps can therefore carry different offsets, for example from two hosts or across a DST change.

I ran both comparators in node:

  • 09:00+08:00 (01:00Z) vs 02:30+00:00 (02:30Z): compareIsoTsDesc picks the older 01:00Z slot. byRecentActivity picks 02:30Z.
  • 'not a timestamp': byte order ranks it newest. byRecentActivity ranks it last.

PR #10950 compares instants and adds back the sub-millisecond digits that Date truncates. That covers the microsecond and missing-stamp cases your tests check. It also matches components/commandPalette/slotRecency.ts (merged in PR #12620), which already orders this field by instant. And it adds component tests in SessionGridViewCoverage.test.tsx and ArtifactDetailPage.companionChat.test.tsx.

Harvest: nothing to port. After PR #10950 lands, nothing would call compareIsoTsDesc, which also makes its three tests in format.test.ts dead. The tr locale test has nothing to check against a numeric compare, since that cannot vary by locale. The rule from your pattern harvest (no bare localeCompare on machine timestamps) is already in website/docs/i18n-catalog.md.

If this is wrong, for example if you know an input that byte order orders correctly and instant order does not, reply here and we will reopen.

From a full open-PR audit against origin/main c66f95b (2026-09-25); findings were checked by independent reviewers reading the code. Reply here if this is wrong.

@bolichen97 bolichen97 closed this Sep 25, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants