Skip to content

fix(members): commit the roster display order per membership, not per refetch - #9537

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
LuisBrel:fix/members-roster-stable-order
Sep 8, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
LuisBrel:fix/members-roster-stable-order

Conversation

@LuisBrel

@LuisBrel LuisBrel commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

On the Crew Members page the roster re-sorted itself while the user was pointing at
it. The list now lives in the React Query cache and refetches on every server
refresh frame, on window focus and on staleness, but orderedMembers still sorted
by last_active_ts on each render. A refetch landing between aiming at a row and
clicking it moved the active member to row 1 and shifted every row below, so the
click opened a different member's durable pinned thread.

Why it matters

Opening the wrong member's durable thread is a trust-level failure for this page,
and the trigger needs no unusual conditions -- an active crew and a user browsing
the roster is enough. The comment that documented the guarantee was DELETED by
the same migration: af52805f7 (#6616) added the two lines saying the list was
sorted once from the roster snapshot because live re-sorting mid-session would
move rows under the cursor, and f3d739546 (#9442) removed exactly those lines
while keeping the per-render sort they described. Base therefore carried the
behaviour with no warning left in the file.

What changed (motivation -> approach -> change)

Symptom: rows move under the cursor and the click lands on the wrong member.
Root cause: the sort key advances with member activity, and the sort re-runs on
every refetch, so ordering is a function of refetch timing rather than of the
roster.

The change makes the display order a function of MEMBERSHIP instead of of time.
The committed order is held in a ref: it re-sorts from scratch only when the set
of member names changes (add / remove / rename), and otherwise maps the committed
name order over the fresh rows. Row CONTENT stays live -- star, last-message
preview and presence all still update from every refetch -- while positions hold.

Rejected alternative: freezing the query (longer staleTime, or refetch off).
That would fix the movement by making the roster stale, losing the live presence
and preview the refetch exists to deliver. Ordering and content have different
requirements here, so only ordering is pinned.

Tests

a refresh-frame refetch never reorders the roster; a membership change re-sorts it
in website/src/pages/members/MembersPage.test.tsx locks both halves: after a
refetch that advances a lower row's last_active_ts and changes its preview text,
the new content is on screen while the order is unchanged; then a new member
appears and the roster re-sorts by recency.

The test is mutation-proven: with the previous per-render sort restored it fails
with expected [ 'beta', 'alpha' ] to deeply equal [ 'alpha', 'beta' ] -- the
row swap that causes the misroute.

Manual verification

N/A -- the defect is a timing race between a background refetch and a click, which
the test reproduces deterministically by invalidating the query mid-assertion; a
manual attempt would be less reliable than the test, not more.

Screenshots / video

Why no screenshot: there is no visual delta to capture. No styling, layout,
markup or component changes -- the roster renders the same rows, with the same
classes, in the same positions at first paint. What changes is purely temporal:
whether a BACKGROUND REFETCH is allowed to reorder those rows afterwards. A still
of before and after is byte-identical, and a recording would have to reproduce a
refetch landing inside a click, which is exactly what the regression test does
deterministically (and it is mutation-proven: with the old sort restored it fails
on the row swap).

Disclosed rather than omitted: I also could not produce a recording locally even
had one been meaningful -- npm ci in this environment fails E401 against the
configured package registry, so the dev server cannot build a complete bundle. If
a maintainer wants a capture anyway, say so and I will get one from a working
environment.

Related Issues

Fixes #9524

Pattern harvest

Rule candidate: review-prompt
Pattern: a comment asserting an invariant ("sorted once from the snapshot") that a
later migration silently invalidated -- when data moves from a one-shot fetch to a
live cache, every derived value whose comment claims stability needs re-deriving,
because nothing fails when the claim stops being true.

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

Correction (post-merge). An earlier revision of this description said the
comment above the sort still promised that, which implied it was present in base.
It was not, and the First Principles lane was right to grep for it: the comment was
added in af52805f7 (#6616) and removed by f3d739546 (#9442). The paragraph above
now cites both commits instead of quoting base. The fix itself rests on #9524 and
the mutation-proven test, neither of which depended on that quote.

… refetch

The Crew Members roster moved into the React Query cache, which refetches on
every server refresh frame, on window focus and on staleness. `orderedMembers`
kept sorting by `last_active_ts` on each render, so a refetch landing between
the user aiming at a row and clicking it moved the active member to row 1,
shifted every row below, and the click opened a different member's durable
pinned thread -- the misroute the page's exact-name keying exists to prevent.
The comment above the sort still claimed the order was taken once from a
snapshot; that stopped being true when the data became live.

The display order is now committed per MEMBERSHIP in a ref: it re-sorts from
scratch only when the set of member names changes (add / remove / rename), and
otherwise maps the committed order over the fresh rows, so star, last-message
preview and presence keep updating live while positions hold.

Refs kirodotdev#9524
@LuisBrel
LuisBrel requested review from a team and CrysisDeu September 8, 2026 20:40
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — ✅ PASS

UX-level review of 0f48e72bba915961300df9195fd634d465e293e1 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

Removes the self-reordering roster (rows jumping under the cursor) with zero visual or copy delta — no new user-visible control, so no evidence gap.

[UX-REVIEWED] 0f48e72

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of 0f48e72bba915961300df9195fd634d465e293e1 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

Real, user-visible misroute fixed at its cause — the moving sort key — while keeping row content live; proportionate, well-tested, alternative honestly weighed.

[DESIGN-REVIEWED] 0f48e72

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 0f48e72

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

Premise-level review of 0f48e72bba915961300df9195fd634d465e293e1 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.

All evidence is in. The fix itself is well-derived (linked issue, mutation-proven test, and the mechanism is verifiable in base: useWebSocket.ts:68 invalidates the roster's parent key on every refresh frame while MembersPage.tsx:463-470 re-sorts per render). Two genuine concerns survive: an unfixed sibling in the same file, and a description quote that doesn't exist in the base tree.

First-Principles-Verdict: CONCERNS

The identical live-activity re-sort still moves click targets one panel over (drivingSessions), and the description quotes a base comment that does not exist.

What this change ships

Intent: stop background refetches from reordering the Crew Members roster so a click can't land on the wrong member's durable thread — a FIX.

Inventory (4 items)
  1. Roster rows no longer shift position when a background refetch lands — justified
  2. A member add/remove/rename now re-sorts the whole roster by recency at once — justified
  3. Recency ranking goes stale while the page stays open; a newly active member stays put until membership changes or remount — justified
  4. A regression test pins order-hold on refetch and re-sort on membership change — justified

Watch

  • Point patch with 1 counted unfixed sibling: drivingSessions (MembersPage.tsx:504-509) sorts by lastActivityEpoch over live WS liveSlots and renders as navigate() buttons (MembersPage.tsx:1490-1492) — the same "activity-keyed sort over live data moves click targets" cause, in the same file (grepped lastActivityEpoch|last_active_ts across *.tsx).
    Clears when: that list holds order too, or a comment records why live reordering is intended there.
  • The description asserts "The comment above the sort still promised the order was taken once from a snapshot ('live re-sorting mid-session would move rows under the cursor')" — no such comment exists in base; MembersPage.tsx:460-462 only covers the default-open (grepped under the cursor|sorted once|mid-session, zero hits in members code). The fix stands on Crew Members roster re-sorts under the cursor on every refetch after the React Query migration #9524 and the test, but this quoted pin is invented.
    Clears when: the description drops the quote or points at the commit where that comment lived.

[FIRST-PRINCIPLES-REVIEWED] 0f48e72

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] 0f48e72

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 8, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) September 8, 2026 22:03

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

Tier 1 auto-approve: fix (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean, security checklist all-NO, AI reviewers green. Category: roster display order now committed per membership instead of per refetch, so a refresh-frame last_active_ts bump no longer re-sorts rows under the cursor mid-click; row content still updates live. CodeQL is not applicable on this fork PR (default-setup emits no check-run); SAST coverage is Semgrep only, latest run success with 0 annotations.

@iamwhatever
iamwhatever merged commit f40d319 into kirodotdev:main Sep 8, 2026
75 of 76 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 8, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
… refetch (kirodotdev#9537)

The Crew Members roster moved into the React Query cache, which refetches on
every server refresh frame, on window focus and on staleness. `orderedMembers`
kept sorting by `last_active_ts` on each render, so a refetch landing between
the user aiming at a row and clicking it moved the active member to row 1,
shifted every row below, and the click opened a different member's durable
pinned thread -- the misroute the page's exact-name keying exists to prevent.
The comment above the sort still claimed the order was taken once from a
snapshot; that stopped being true when the data became live.

The display order is now committed per MEMBERSHIP in a ref: it re-sorts from
scratch only when the set of member names changes (add / remove / rename), and
otherwise maps the committed order over the fresh rows, so star, last-message
preview and presence keep updating live while positions hold.

Refs kirodotdev#9524

Co-authored-by: LuisBrel <193017400+LuisBrel@users.noreply.github.com>
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.

Crew Members roster re-sorts under the cursor on every refetch after the React Query migration

2 participants