Skip to content

fix(command-palette): rank recents past an empty last_activity_ts - #11318

Closed
leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/palette-recency-empty-activity-sentinel
Closed

leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/palette-recency-empty-activity-sentinel

Conversation

@leonlaiyc

@leonlaiyc leonlaiyc commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Open the Command Palette (⌘K / Ctrl+K) right after sending a prompt and the
session you are working in is at the bottom of the Current group, under
sessions nobody has touched for weeks, with no timestamp on its row.

recencyEpoch in the recents provider is documented as a ladder — "last
activity, else last msg, else created" — but it is written with ??:

const t = slot.last_activity_ts ?? slot.last_ts ?? slot.created
if (!t) return 0

The backend spells "no activity yet" as the empty string, not as an absent
key. SlotProjection.to_dict initialises last_activity_ts = ""
(src/kiro_crew/dashboard/slot_projection.py:155) and assigns it only when its
reverse walk finds an assistant / tool_call / tool_result row that is not a
system notice (:160-166). The key is then shipped unconditionally
(:284), so every projected slot carries the field, and ?? — which only
falls through on null/undefined — stops on the first rung for all of them.
Neither last_ts nor created is ever read; if (!t) return 0 then catches the
"" and the slot scores 0.

Three call sites read that same expression, and all three are wrong in the same way:

Site Consequence when last_activity_ts is ""
recentsProvider.ts:160 recencyEpoch slot scores 0 and sorts last in the Current group
recentsProvider.ts:308 row timestamp fmtRelativeTime("") → toDate returns null → the row renders no time at all
CommandPalette.tsx:358 liveFingerprint the activity term is pinned to "", so the open palette stops revalidating as that session's rows arrive

Which sessions carry "" is not a one-frame race:

  • a session whose transcript holds only the user's own prompt — the one being
    worked in right now, or a queued prompt that has not started;
  • a session whose agent only ever wrote system notices (the walk skips
    them), e.g. one that failed on its first turn. That state is permanent, not
    transient;
  • every empty "+ New Session…" slot, where last_ts is "" too and created
    is the only instant it has — which is exactly the value prepareCurrentSlots
    documents itself as using ("keep at most ONE empty-new slot, the most
    recent
    "). Under ?? every such slot scores 0, the comparator returns 0 for
    every pair, and a stable sort hands back whichever one happened to arrive
    first.

Why it matters

The Current group is a quick-switcher: its whole job is to put the session you
were last in at the top, so ⌘K + Enter resumes it. A session ranks 0 precisely
while it is most active — between the user's prompt and the agent's first row —
so the ranking inverts at the one moment the switcher is used most, and the row
also loses the relative time a reader would use to spot it manually.

The bug is invisible to the existing tests because they omit last_activity_ts
entirely, and on an absent key ?? and || agree. Only the "" the wire
actually sends separates the two readings.

What changed (motivation → approach → change)

Symptom: the palette's Current group ranks a just-prompted session last and
renders it without a timestamp. Root cause: a nullish-coalescing ladder over a
wire field whose producer's "absent" sentinel is "", which makes every rung
below the first dead code. Change: read the ladder with || at all three sites,
so "" falls through exactly as an absent key already did.

pages/chat/sessionOrder.ts already reads these same wire rows correctly —
slotActivityTs is last_turn_ts || last_ts || created — so the sidebar and the
palette now agree about what "no activity yet" means instead of disagreeing.
That is the whole change: no field is added, no ranking key is swapped, and a
slot that genuinely has no instant at all still scores 0 and still sorts last.

Not in scope, deliberately: which field the palette ranks on
(last_activity_ts vs the sidebar's settled last_turn_ts) is a product
question about churn while an agent works, and this PR does not touch it.
#10950 is a separate defect in separate files (SessionGridView.tsx,
ArtifactDetailPage.tsx) — comparing instants as text — with no file, hunk or
root-cause overlap with this one.

Tests

website/src/components/commandPalette/providers/recentsProvider.test.ts, three
cases, each seeding the "" the producer actually sends:

  1. ranks an empty-string slot on its last_ts, not below every other row —
    a session last active two days ago vs one prompted today whose only row is
    that prompt (last_activity_ts: '', real last_ts). Red-before the order is
    ['stale', 'live']; after, ['live', 'stale'].
  2. falls through to created when the slot has no timestamps at all — three
    empty-new slots with last_activity_ts: '', last_ts: '' and different
    created. Red-before the survivor is 'a' (input order, every score 0);
    after it is 'b', the most recently created — the row prepareCurrentSlots
    documents itself as keeping.
  3. timestamps a row whose last_activity_ts is the empty-string sentinel —
    two rows describing the same instant reached two ways: one with the backend's
    filled last_activity_ts, one with "" plus that instant in last_ts. The
    assertion is that the two rows carry the same timestamp, which keeps it
    free of the app language and of how long ago the instant is when the suite
    runs. Red-before the second is undefined.

Red-before at this branch's base (f4cbf1021), production hunks reverted:
3 failed | 32 passed, failing exactly as quoted above. Green-after:
122 passed across recentsProvider.test.ts,
recentsProvider.cov80.test.tsx and CommandPalette.test.tsx. Wider run over
src/apps/command-bar, src/components/commandPalette, CommandPalette.test.tsx,
QuickSearchSurface.test.tsx, switchSlotCallsiteClassification.test.ts,
paletteNavLeaveGuard.test.tsx, MemoI18nSubscriptionRatchet.test.ts and
useWebSocket.thinkingStatusChurn.test.ts: 607 passed, 1 failed.

That one failure is settingsRegistry.test.ts's byte-for-byte check of
src/kiro_crew/docs/settings-registry.generated.json. It is a line-ending
artifact of this Windows checkout — the file is CRLF on disk while
generateAgentRegistryJson emits LF — and it is unreachable from this diff: the
test imports scripts/settingsExtract, subNavParams and settingsRegistry.gen
and has no import path to either changed module. Not this branch's regression,
and not repaired here.

tsc -p tsconfig.app.json clean; eslint clean on all three changed files.

Manual verification

The unit tests assert both observables at the provider boundary — the ordered
slot list and the row's timestamp field — so the fix itself is covered without
a rendered frame. What they cannot show is the frame a user actually sees, which
is what the UX review asked for, so the Current group was also captured from the
running component (below).

Capture path, so the frame can be reproduced or disbelieved: an isolated Vite
entry mounts the real CommandPalette (open, unscoped, empty query — the
quick-switcher view) over the real useRecentsProvider, inside the app's own
Redux store seeded through the real sseSlots action. Nothing about the
provider, the ordering or the row rendering is stubbed; the fixtures are the slot
payload and the backend. The payload is the wire shape
slot_projection.to_dict emits — the just-prompted session carries
last_activity_ts: '' next to a real last_ts, every other slot carries a
filled last_activity_ts — and the three history-group fetches are refused, so
the Current group is the only group rendered. App language pinned to en for
legibility, since every branch of fmtRelativeTime resolves against the app
language rather than the browser locale.

Screenshots / video

Command Palette, Current group, at this PR's head:

Command Palette Current group: "Refactor the export pipeline" ranked first with an 11:55 PM timestamp and a pulsing "Thinking…" status, above three sessions last active Mon, Fri and Aug 26

Refactor the export pipeline is the just-prompted session — the one whose
transcript holds only the user's own prompt, so the wire hands it
last_activity_ts: ''. It ranks first among the sessions, above three slots
last active Monday, Friday and Aug 26, and it carries a time label (11:55 PM)
and its live Thinking… status. Before this change that same row scored 0, sorted
below all three, and rendered with no time at all — which is the red-before
the first and third tests in the Tests section pin (['stale', 'live'], and a
timestamp of undefined).

11:55 PM is the relative-time label: fmtRelativeTime is Telegram-style,
so its today branch renders the clock time, and its older branches render the
weekday (Mon, Fri) and then the date (Aug 26) — all three forms are visible
in the frame.

Two disclosures about the hosting, since neither is the shape the template
prescribes and both are visible to a reviewer:

  • It is not a user-attachments URL. gh pr edit --attach is present
    (gh 2.100.0) but refuses: attaching files requires write access to the repository, and gh api repos/kirodotdev/KiroCrew --jq .permissions reports
    push: false. GitHub gates the user-attachments upload on write access to the
    target repo, so no gh version lets a fork contributor produce one of those
    URLs. A maintainer re-attaching this file, or dragging it into this box, would.
  • It is not committed to this branch. .gitignore says review evidence is
    never committed, and the diff is unchanged from the reviewed head
    22ed0475c0348b1f783fc6ade2c1febc835b921c — no push accompanies this edit. The
    file lives on the fork's existing evidence branch and the link is pinned to the
    immutable commit 8da0e9a that added it, not to the branch tip, so what is
    linked here cannot change under review.

Related Issues

None — found by comparing the palette's recency ladder against
pages/chat/sessionOrder.ts's ladder over the same wire rows, then reading
slot_projection.to_dict to see which of the two matched the producer.

Pattern harvest

Rule candidate: semgrep
Pattern: ?? used to fall back over a wire field whose producer's "absent"
sentinel is the empty string — every rung below the first is then dead code.

This generalizes past this file in a checkable way, because the producer side is
where the fact lives: a Python projection that initialises a key to "" and
ships it unconditionally can never be read with ?? on the consumer side. The
narrow, low-false-positive shape is a chained a ?? b where a is a field this
repo's own dashboard projections emit as a string default — slot_projection
alone does it for last_activity_ts, last_ts, last_turn_ts, served_model
and last_message. The sibling to watch on the same wire is
dashboardSlice.ts:803 slot.surface ?? slot.mode ?? '', which degenerates
identically; it has no observable today only because to_dict sets both
surface and mode from the same slot.mode, so the dead rung is unreachable
rather than correct.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|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

🤖 Generated with Claude Code

`recencyEpoch` is documented as a ladder -- last activity, else last message,
else created -- but reads it with `??`. The backend spells "no activity yet"
as the EMPTY STRING: `SlotProjection.to_dict` initialises
`last_activity_ts = ""` and assigns it only when its reverse walk finds an
`assistant`/`tool_call`/`tool_result` row that is not a system notice, then
ships the key unconditionally. `??` only falls through on null/undefined, so
for every projected slot the ladder stopped on its first rung and neither
fallback was ever read.

A session whose transcript holds only the user's own prompt therefore scored 0
and sorted below sessions untouched for weeks -- at the one moment the
quick-switcher is used most -- and its row rendered with no relative time,
because `fmtRelativeTime("")` resolves to undefined. Every empty "+ New
Session..." slot scored 0 too, so the surviving row was the first one in the
array rather than the most recently created one the function documents.

Read the ladder with `||` at the three sites that share the expression, so ""
falls through exactly as an absent key already did. `slotActivityTs` in
`pages/chat/sessionOrder` reads the same wire rows with `||`; the sidebar and
the palette now agree on what "no activity yet" means. Which field the palette
ranks on is unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@leonlaiyc
leonlaiyc requested review from a team and smeyffret September 16, 2026 14:53
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) 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 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of 22ed0475c0348b1f783fc6ade2c1febc835b921c 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

Nothing to check.

[DESIGN-REVIEWED] 22ed047

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] 22ed047

@github-actions

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 22ed047

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of 22ed0475c0348b1f783fc6ade2c1febc835b921c 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: PASS

The palette still ranks on last_activity_ts while the sidebar ranks on last_turn_ts — confirm that declared divergence is wanted before merge.

Verified against base: slot_projection.py:155 initialises last_activity_ts = "" and line 284 ships it unconditionally, so ?? never reaches a fallback rung; the doc comment at recentsProvider.ts:158 already pins the ladder ("last activity, else last msg, else created"), which this fix restores. Grepped last_activity_ts ??|last_ts ??|last_turn_ts ?? across website/src: exactly 3 hits, all three fixed here — zero unfixed siblings of this producer's fields (other ?? timestamp reads are over different producers with no "" sentinel shown). sessionOrder.ts:48 confirms the || reading is the repo's settled convention for these wire rows. No pins deleted; tests only added.

What this change ships

Inventory (4 items) — 4 justified

Intent: make the Command Palette's Current group rank a just-prompted session first instead of last — a FIX.

  1. A just-prompted session now sorts at the top of the Current group, not the bottom — justified
  2. Rows whose only activity is the user's own prompt now show a relative timestamp — justified
  3. An open palette now revalidates as a just-prompted session's rows arrive — justified
  4. Among duplicate empty "+ New Session…" slots, the most recently created one now survives — justified

[FIRST-PRINCIPLES-REVIEWED] 22ed047

@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — 🔴 BLOCK

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

UX-Verdict: BLOCK

cannot evaluate: missing a screenshot of the fixed palette — the PR's entire on-screen delta (row order, new timestamp) is shown nowhere.

Evidence gaps

  • The Current group's corrected state — a just-prompted session ranked first with its relative-time label (the author's stated delta: "a relative-time label appearing on a row that had none", from timestamp: … fmtRelativeTime(s.last_activity_ts || s.last_ts)) — appears in no attachment (image list empty). Close with one ⌘K palette screenshot showing a just-prompted session sorted above stale ones with its timestamp rendered.

[UX-REVIEWED] 22ed047

@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 16, 2026
leonlaiyc added a commit to leonlaiyc/KiroCrew that referenced this pull request Sep 16, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 23, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Closing: superseded by PR #12620 (604e6ac), which is already on main

Thanks for the careful diagnosis. PR #12620 (merged 2026-09-23, squash 604e6ac) fixed the same root cause: the wire sends "" to mean "nothing yet", so the ?? ladder stops on its first rung. That PR added website/src/components/commandPalette/slotRecency.ts, and all three of this PR's sites now go through it:

This PR (22ed047) origin/main
recentsProvider.ts:170 recencyEpoch || ladder recentsProvider.ts:169 slotRecency(slot).epoch. slotRecency.ts:18 treats "" as missing, and :36-40 falls back to created
recentsProvider.ts:320 row timestamp recentsProvider.ts:314 fmtRelativeTime(slotRecency(s).timestamp), which also falls back to created
CommandPalette.tsx:363 liveFingerprint CommandPalette.tsx:369 ${slotRecency(s).timestamp ?? ''}
test "ranks an empty-string slot on its last_ts" recentsProvider.test.ts:176-188, almost word for word

Main also fixes the case this PR declared out of scope. slotRecency.ts:29-33 takes the later of last_activity_ts and last_ts, so an older activity row no longer beats a newer prompt. The rule is written down in docs/system-specs/modules/command-bar.md:117. This is also why the || hunks can't just be rebased. Both production files conflict, and a first-non-empty ladder would undo the later-of-two rule.

One thing main doesn't have, though it isn't enough to keep this PR open: two of your tests have no literal counterpart there.

  • "falls through to created when the slot has no timestamps at all" (recentsProvider.test.ts:186). Reviewers changed slotRecency.ts:39 to epoch: 0, which drops the created fallback from the sort. This was the only test that failed.
  • "timestamps a row whose last_activity_ts is the empty-string sentinel" (:369). Main's hook-level test uses an absent key, not "".

Both tests pass against main without changes. If you'd like them in, a small test-only PR against main would be welcome.

If this PR still does something I've missed, please reply here or reopen it.

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) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants