Skip to content

fix(dashboard): order session recency by instant, not timestamp text - #10950

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/slot-recency-instant-compare
Oct 4, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/slot-recency-instant-compare

Conversation

@leonlaiyc

@leonlaiyc leonlaiyc commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Order the split-session picker and artifact companion choice by actual last-activity instants across timestamp formats and offsets.

Two dashboard surfaces decide "most recently active" by comparing last_activity_ts as text:

(b.last_activity_ts || '').localeCompare(a.last_activity_ts || '')

last_activity_ts is the raw transcript ts, forwarded verbatim — slot_projection.py:166 reads message.get("ts") and passes the string straight through. The backend states those rows do not share one format: current builds stamp offset-aware values via history.monotonic_transcript_ts, while transcripts written by older builds still hold naive datetime.now().isoformat() rows. history.transcript_sort_key:972 exists on the Python side for exactly this, and its docstring names the failure — compared as strings they order by their text.

Two aware stamps written under different offsets are enough to break it: 09:00:00+08:00 is 01:00Z and 02:30:00+00:00 is 02:30Z, so the more recent session carries the smaller string.

What a user sees:

  • Session picker (SessionGridView) lists the staler session above the live one.
  • Artifact companion chat (ArtifactDetailPage.pickBoundSlot) returns the stale session as "the most recently active", so opening an artifact's chat resumes the wrong conversation. "New chat" depends on that same tie-break, so when it picks the archived slot the button looks inert.

Why it matters

Both surfaces exist to answer one question — which session should I open? — and answer it with the wrong one. The picker case is a mis-sorted list the user can work around by reading titles. The companion-chat case is silent: the page resumes an older conversation and nothing says it picked the wrong one, so context gets appended to an archived session.

The two formats coexist on purpose (old transcripts are not rewritten), so this is not a migration that ages out. A single host crossing a DST boundary is enough to produce the mixed-offset pair.

Not a goal

  • No change to needs-input/running priorities or session binding/ownership.
  • No backend timestamp schema migration or inference of a legacy writer's timezone.
  • No broader recents-provider migration.

What changed (motivation → approach → change)

Both current consumers still compare last_activity_ts text. Replay the original PR's instant comparator in their current owners, using toDate and restoring the fractional millisecond remainder that JavaScript Date truncates. The original two commits are consolidated into one logical fix; the session spec records both the precision and naive-timestamp limitation. The existing command-palette recency selector has broader fallback semantics and millisecond precision, so it cannot replace this comparator without changing these consumers' contract.

Backwards compatibility

Compatible: the same session fields, picker priorities and artifact binding rules remain. Only erroneous mixed-offset/format ordering and sub-millisecond ties change. Naive timestamps remain an approximation in the viewer's zone.

Removes nothing: no session, field, public API, supported path or capability is removed.

Tests

90 tests passed across slotRecency.test.ts, SessionGridViewCoverage.test.tsx and ArtifactDetailPage.companionChat.test.tsx. They exercise mixed offsets, timestamp precision, invalid/missing values, picker priorities and artifact companion resolution. Focused ESLint passed. npm run build passed (TypeScript and Vite); docs lint and the added-line brand gate passed.

Manual verification

Captured the production picker in Chromium using two offset-aware timestamps whose text and instant order disagree. The visible list changes from Earlier / Later to Later / Earlier. No runtime page errors occurred. Component tests cover the artifact resolver with the same kind of pair.

Screenshots / video

Scripted Playwright renders the production PlaceholderPane with the same deterministic fixtures on both heads. Both sessions are idle, unbound and have equal priority. Text sorting puts 09:00+08:00 first, although 02:30+00:00 is the later instant. This branch lists the later session first. The heading and timestamp explanation are capture context; the picker itself is the production component loaded directly from current main or this branch.

Before: older session first under textual timestamp ordering
After: later instant first in the session picker

Related Issues

Closes #16516

Pattern harvest

Rule candidate: review-prompt
Pattern: compare timestamp instants rather than timestamp text, and preserve the producer's precision when Date truncation could turn distinct records into ties.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

@leonlaiyc
leonlaiyc requested review from a team and hoang-phan98 September 15, 2026 02:17
@github-actions github-actions Bot added the fork Pull request from a fork (external contributor) label Sep 15, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 15, 2026
@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of d89a469e11135f89c543d48b30b2a8fca9743c05 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Before merging, check that opening an artifact's companion chat resumes the newer of two sessions stamped with different timezone offsets. No screenshot shows that path.

[UX-REVIEWED] d89a469

Description read

[DESCRIPTION-READ] 0fcb8e85c3e83577a5e0f0810898337b138101bf7c1a33ac1c47465f82f25ff8

That sha256 names everything this verdict read: the PR description, plus the 5 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of d89a469e11135f89c543d48b30b2a8fca9743c05 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that the rendered picker list stays stable across rerenders: the comparator now parses each timestamp, regexes it, and returns fractional values on every comparison.

[DESIGN-REVIEWED] d89a469

Description read

[DESCRIPTION-READ] 9c384f51ff6ab020166d4d22e38ae4aef29fa373f56f000971f7f8b8a6af9901

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🟡 CONCERNS

Premise-level review of d89a469e11135f89c543d48b30b2a8fca9743c05 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

This adds a second slotRecency module that turns a slot's timestamp into an epoch, and it leaves one more text comparison of the same value in the same file unfixed.

Not justified as shipped

  • Item 4 — duplicate of website/src/components/commandPalette/slotRecency.ts: there are now two modules named slotRecency that both turn last_activity_ts into an epoch. One reads sub-millisecond digits and the other (timestampEpoch, new Date(timestamp).getTime()) does not. The two will drift apart.
    Subtraction: move the subMillis parse into the existing module's timestampEpoch and export it. Then delete website/src/utils/slotRecency.ts and keep only a two-line comparator at the two call sites.
    Clears when: one module parses slot timestamps for every recency consumer.
  • Item 1 — symptom-level, 1 unfixed sibling: the cause is the backend passing on the raw transcript ts, and the description defers that cause ("No backend timestamp schema migration"). Searching last_activity_ts in non-test website/src code still finds one text comparison: ArtifactDetailPage.tsx:1371, artifact.updated_at > boundSlotResolved.last_activity_ts. The two mixed-offset stamps that break the picker also make this freshness nudge misfire.
    Clears when: line 1371 compares instants, or the description says this sibling is deliberately left.

What this change ships

Inventory (6 items) — 4 justified

Intent: open the session that was truly active most recently, whatever the timestamp format or offset — a FIX.

  1. The split-session picker orders idle sessions by real instant — symptom-level, 1 unfixed sibling
  2. The artifact companion chat resumes the session that was active most recently — justified
  3. Sessions apart by less than a millisecond (one microsecond) no longer tie — justified
  4. A new exported slotActivityMs / byRecentActivity utility — duplicate of commandPalette/slotRecency.ts
  5. A session.md spec paragraph on recency and the naive-timestamp limit — justified
  6. Committed before/after screenshots under temp-screenshots/ — justified

[FIRST-PRINCIPLES-REVIEWED] d89a469

Description read

[DESCRIPTION-READ] 8ec7e531d5b3cd64a8c2d6e6598cc1e0d0e7525cd23ff057b62de3350800703a

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] d89a469

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] d89a469

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 15, 2026
@dwu96 dwu96 added the needs-pr-triage PR scanner: awaiting automated triage label Sep 22, 2026
@NicholasRBowers NicholasRBowers added drive-to-green PR claimed by drive-to-green pipeline and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 22, 2026
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been inactive for 7+ days with failing CI. I've assessed the blockers and they appear resolvable — I'll push fixes directly to this branch as a co-author.

Assessment: Every AI review lane is PASS with no blocking findings (GPT 5.6, Opus 4.8, Design Review, First Principles Review, UX Review), the branch is MERGEABLE, and both the new slotRecency util and its 113-line test suite are green on Linux. Neither remaining red is your code:

  • Frontend Lint & Type Check is base drift, already fixed upstream. The single failing sub-check is the repo-wide manifest-sync hard-zero: dev-fleet.description drifted from dev_fleet/app.json. I checked current main — apps.devFleet.manifest.description in en.json now matches the manifest, so a rebase clears it with no edit on your side. That gate scans the whole repo rather than the diff, which is why a PR touching six frontend files went red on an app manifest.
  • Backend Tests (Windows) (3) and the macOS shards were cancelled, not failed. All of them end in The operation was canceled from the 2026-09-15 run, with no assertion failure anywhere in the logs — Windows shard 3 was 6,700+ cases into a passing run when it was killed. A fresh macOS matrix is already queued against this head; the rebase push re-runs the rest.

I'll also post dispositions for the advisory Watch items Design Review and First Principles Review left (the recencyEpoch fold in recentsProvider.ts:159, the backend slot_projection normalized-instant follow-up, and whether ArtifactDetailPage.tsx's best-effort text compare still accepts its miss under this PR's mixed-format premise). Those are written answers, not scope — the instant-based comparison and the util's public shape stay as you designed them.

If you'd prefer I don't touch this PR, add the pr-no-autofix label.

`last_activity_ts` is forwarded verbatim from the transcript row that
produced it -- slot_projection reads `message.get("ts")` and passes the
string straight through -- and the backend states those rows do not
share one format: current builds stamp offset-aware values via
`monotonic_transcript_ts`, while transcripts from older builds still
hold naive `datetime.now().isoformat()` rows. `transcript_sort_key`
exists on the Python side for exactly this, and its docstring names the
failure: compared as STRINGS they order by their text.

Two frontend sites compared that text and so could rank a later session
first. Two aware stamps written under different offsets are enough:
`09:00:00+08:00` is 01:00Z and `02:30:00+00:00` is 02:30Z, so the more
recent session carries the smaller string.

- SessionGridView's picker listed the staler session above the live one.
- ArtifactDetailPage's `pickBoundSlot` returned the stale session as
  "the most recently active", so opening an artifact's companion chat
  resumed the wrong conversation -- and "New chat" depends on that same
  tie-break, where picking the archived slot makes the button look inert.

Both now resolve the stamp to an instant first, which is also how the
backend reads it: an offset-bearing value is absolute, a naive one is
local, i.e. the zone of the writer that produced it.

Resolving to an instant is not by itself enough, because `Date` keeps
three fractional digits and TRUNCATES the rest. `monotonic_transcript_ts`
stamps a row as `previous + 1 microsecond` whenever the host clock has
not advanced between two writes -- on Windows, whose system clock
advances in ~15.6 ms steps, that is the ordinary case -- so a session
that wrote twice inside one tick is one MICROSECOND ahead of a session
that wrote once in it. A plain `getTime()` reads both as the same
instant, the comparator returns 0, and `Array.prototype.sort` being
stable then answers "most recently active" with whatever order the slots
happened to arrive in. `slotActivityMs` therefore adds back the fraction
of a millisecond the parse dropped; truncation is what makes that safe,
since the remainder is always the part `Date` discarded rather than a
value it rounded past.

`recencyEpoch` in the command palette's recents provider already
resolved this field to an instant by hand; it is left as it is, since
folding it in would also change how it treats a numeric stamp, which
nothing here shows is needed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

Deterministic picker evidence: production PlaceholderPane, identical fixtures and source selected directly from main or the feature head. The visible order reverses to choose the later instant. Captured with scripted Playwright on 2026-10-03; no page errors. Source head in the record is the feature head before this evidence-only amend.

[
  {
    "mode": "before",
    "source": "origin/main",
    "order": [
      "Earlier: 01:00 UTC",
      "Later: 02:30 UTC"
    ],
    "errors": []
  },
  {
    "mode": "after",
    "source": "17a7c33f842d7b74f76df74a202442674abfb451",
    "order": [
      "Later: 02:30 UTC",
      "Earlier: 01:00 UTC"
    ],
    "errors": []
  }
]

@leonlaiyc
leonlaiyc force-pushed the fix/slot-recency-instant-compare branch from 17a7c33 to d89a469 Compare October 3, 2026 14:20
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

Sharing the command-palette parser would change the two repaired consumers' current contract: its selector includes broader timestamp fallbacks and intentionally has millisecond precision. This comparator preserves the transcript's fractional precision and existing missing/invalid-value ordering. Consolidating every recency consumer is outside this repair's frozen goal; the controller explicitly keeps this concern advisory unless escalated to BLOCK. The focused consumer and helper tests validate the bounded repair.

@leonlaiyc

Copy link
Copy Markdown
Contributor Author

ArtifactDetailPage's freshness nudge comparison is deliberately left outside this PR. It decides whether to offer refreshed context, whereas this goal repairs session selection and picker ordering. It does not participate in byRecentActivity or pickBoundSlot. The controller explicitly excludes this sibling from this repair cycle unless the review upgrades it to BLOCK; this verdict is CONCERNS. No additional source scope is absorbed.

@leonlaiyc

Copy link
Copy Markdown
Contributor Author

Review dispositions for current head d89a469e11135f89c543d48b30b2a8fca9743c05 — the two PASS verification observations.

  • UX, artifact companion selection: the existing ArtifactDetailPage.companionChat.test.tsx case picks the most recent by INSTANT, not by timestamp text exercises the production component with 09:00+08:00 and 02:30+00:00, which sort oppositely as text and instants, and asserts selection of the later session. The rendered picker evidence is already posted; artifact selection is covered by that component regression. A manual full-app companion-chat check remains a maintainer verification observation, not evidence claimed by the picker screenshots.
  • Design, stability across rerenders: byRecentActivity derives its result solely from the two immutable timestamp values and the existing date parser. It does not mutate slots or consult the current clock. Repeating a comparison with the same inputs therefore preserves the ordering, including fractional milliseconds; needs-input/running priority remains ahead of it. The focused helper/component coverage and production-picker capture are recorded in the description. No cache or shared-parser refactor is added for this PASS observation.

The two First Principles CONCERNS already have individual current-head dispositions above; these comments do not reopen or widen that repair.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Oct 4, 2026

@iamwhatever iamwhatever 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.

Reviewed: session recency in SessionGridView and the artifact companion chat now sorts by parsed instant (new slotRecency util) instead of comparing timestamp text, which mis-ordered mixed offsets and precisions. The util is unit-tested for offsets, fractional seconds and unparsable values, and both call sites have render tests. Spec note added. CI green.

@iamwhatever
iamwhatever merged commit 3b14d05 into kirodotdev:main Oct 4, 2026
109 of 110 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 4, 2026
@mbriones98 mbriones98 removed the drive-to-green PR claimed by drive-to-green pipeline label Oct 13, 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.

dashboard session recency compares timestamp text instead of instants

5 participants