Skip to content

fix(crew-window): open a crew session at its newest message and follow new rows - #39076

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
crew/issue-radar/fix-39041-crew-window-scroll
Nov 18, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
crew/issue-radar/fix-39041-crew-window-scroll

Conversation

@kyleseaman

@kyleseaman kyleseaman commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A remote crew session opened in the crew window starts at its newest message and stays there as new messages arrive, like the local chat.

Opening a connected crew's session from the shared Sessions list puts the crew window at the FIRST message. To read the latest turn you scroll all the way down, and a reply that lands while the window is open does not move the view either. Opening the same session from the crew's own tab starts at the latest message.

Why it matters

Everyone who uses Chat on a crew hits it on every session long enough to scroll. The newest turn, which is usually why the window was opened, starts out of sight, and a live reply arrives below the fold with nothing to show it came in.

Not a goal

  • Restoring a saved reading position per crew session (the Remote Crew pane's restore is a separate surface).
  • Moving the crew window onto the local chat's virtualizer.
  • A "jump to latest" button.

What changed (motivation → approach → change)

  • Symptom: the crew window opens at the top and does not follow new rows.
  • Cause: CrewChatWindow's scroller (div.absolute.inset-0.overflow-y-auto) is handed only to useComposerDockMetrics. Nothing ever sets its scroll position. The local chat gets its bottom pin from the virtualizer behind ChatMessageList, which the crew window does not use.
  • Change (website/src/pages/chat/crew-window/CrewChatWindow.tsx): a followBottom ref, true at mount. The scroller's onScroll sets it to whether the view is within 48px of the bottom. A layout effect on the transcript rows, the running state, the pending approval and the dock height scrolls to the bottom while followBottom holds, and a ResizeObserver on the transcript content does the same when a row grows later by itself (an image or a Mermaid diagram that finishes drawing). So the window opens at the newest message, follows replies, late-growing rows and dock growth, and leaves a reader who scrolled up where they are. This is the same follow pattern ActivityViewer.tsx uses on its own lists.
  • History: git log -S for scrollTop, scrollTo, scrollHeight, scrollToBottom and useVirtualChat on the file finds nothing, so this undoes no earlier change. feat(chat): open crew sessions as a window onto the peer's own slot #16757, feat(chat): draw the crew window with the shared transcript and composer #18095 and fix(crew-window): float the composer in the local dock shape, not a glass band #23930 state no scroll placement.

Backwards compatibility

Compatible: only the window's scroll position changes; no route, prop, stored key or contract changes.

Removes nothing: the diff adds a scroll handler and a layout effect and takes nothing away.

Tests

website/src/test/CrewChatWindow.test.tsx, new transcript scroll position block (happy-dom given a 400px viewport over a measured content height):

  • opens at the newest message, not the first: the scroller sits at its full scroll height once the peer's rows land.

  • follows a new reply at the bottom, and keeps the place of a reader who scrolled up: a reply landing through the peer feed moves the view to the new bottom; after the reader scrolls up, the next reply leaves scrollTop unchanged.

  • follows asynchronous content growth without new messages unless the reader scrolled up: content growth with no new message, fired through a fake ResizeObserver, moves the view to the new bottom; a scrolled-up reader is left at 300; returning to the bottom resumes following; the observer disconnects on unmount. Fails without the observer (expected 2000 to be 2600).

The first two fail on main (expected +0 to be 2000, expected +0 to be 2600) and pass with the fix.

Proof: not provable -- frontend test (prove.py runs Python only)

Run: npx vitest run src/test/CrewChatWindow.test.tsx src/test/CrewWindowGuard.test.tsx src/test/composerHost.crewWindowTranscript.test.tsx src/test/crewWindowTranscript.test.ts src/pages/chat/crew-window/ src/pages/ChatPage.views.test.tsx → 6 files, 140 tests passed. npm run build (includes tsc -p tsconfig.app.json), eslint on the changed files and scripts/check_file_line_cap.py pass.

Manual verification

A Playwright harness (posted on this PR, not in the diff) runs the real built SPA with fixture APIs, opens a 30-row peer session in the crew window, then lands a reply through the peer feed, and prints how far the view sits from the bottom:

  • main's build: gap to bottom 1625px on open, 1658px after the reply (script exits 1).
  • this branch: gap to bottom 0px on open and after the reply.

Real-machine verification

Machine: own computer (cloud desktop), Amazon Linux 2, x86_64, 16 vCPU / 61 GB.
Before (main ade7524): DIST=<main build>/dist node capture-crew-window-scroll.mjs <out> before -> FAIL: the transcript is not at its newest message (open 1625px, after a reply 1658px from the bottom)
After (head e4da0c4): node capture-crew-window-scroll.mjs <out> after -> OK: opens at the newest message and follows a new reply
Cleanup: own computer; scratch build worktree removed.

Screenshots / video

Opening the session, before (main) and after:

Before: the crew window opens at Check 1, the first message

After: the crew window opens at Cycle 15, the newest message, just above the composer

A reply that lands while the window is open, before and after:

Before: Cycle 16 lands off screen; the view stays at the first messages

After: the view follows to Cycle 16 above the composer

Related Issues

Fixes #39041

Sibling sweep

Swept: git grep -n -l "<ChatMessageList" -- website/src
Sibling: website/src/components/ChatPane.tsx -- not affected -- uses the virtualizer's bottom pin
Sibling: website/src/pages/chat/SideChat.tsx -- not affected -- passes its scroller to the virtualizer, which owns the follow
Sibling: website/src/app-sdk/ChatEmbed.tsx -- not affected -- pins through its list's own scrollToBottom

Pattern harvest

Not generalizable: the crew window is the only ChatMessageList host that mounts its own scroller outside the virtualizer.

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

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@kyleseaman
kyleseaman requested review from a team and KiroCrewCaptain as code owners November 18, 2026 10:33
@kyleseaman
kyleseaman requested a review from CrysisDeu November 18, 2026 10:33
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of e4da0c498749e74aefa36d533a7dc9c5890d6b14 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: this is a small, local scroll-follow in the component that owns the scroller, using the same follow pattern as ActivityViewer.tsx, and screenshots are attached.

[DESIGN-REVIEWED] e4da0c4

Description read

[DESCRIPTION-READ] a7e17acbebdf15d0503709ab81a656547c3d76d1633cacf09e619f92cebc34bb

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 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of e4da0c498749e74aefa36d533a7dc9c5890d6b14 — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks. The fix is at mechanism level: the crew window's own scroller never set a scroll position, and this change makes it do so. Moving onto the virtualizer is excluded as a non-goal.

What this change ships

Inventory (6 items) — 6 justified

Intent: open a remote crew session in the crew window at its newest message and keep following new messages, as the local chat does. FIX (#39041).

  1. A crew session opened from the shared Sessions list starts at the newest message instead of the first — justified
  2. A reply that lands while the reader is at the bottom moves the view down to it — justified
  3. A reader who scrolled more than 48px up keeps their place when new rows arrive — justified
  4. The view stays at the bottom when an image or diagram finishes loading and grows its row, with no new message — justified
  5. The view stays at the bottom when the composer dock grows taller — justified
  6. The transcript's rows sit in a new inner wrapper that the content-growth watcher observes; spacing is unchanged — justified

[FIRST-PRINCIPLES-REVIEWED] e4da0c4

Description read

[DESCRIPTION-READ] 6085d7bbf7805bab8963f4881c2ed76f9948efd2e3d00e78e172eb53500bb168

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 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of e4da0c498749e74aefa36d533a7dc9c5890d6b14 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing blocks: no control is added or changed, and the four screenshots show the window opening at the newest message and following a new reply.

Notes

  • The blind reader saw that a scrolled-up reader gets no sign when a reply lands: "nothing tells me the conversation goes much further". The PR leaves out a "jump to latest" button on purpose. A follow-up could reuse the existing JumpToBottomButton in the crew window.

[UX-REVIEWED] e4da0c4

Description read

[DESCRIPTION-READ] f3b96795bc21ffd254a4ce9d2178d0bc94f6a7b32bd0a76549a095676c4071d9

That sha256 names everything this verdict read: the PR description, plus the 7 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 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed e4da0c498749e74aefa36d533a7dc9c5890d6b14 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] e4da0c4

Verdict parsed from the review's SHA-scoped output markers for commit e4da0c498749e74aefa36d533a7dc9c5890d6b14.

False positive or not applicable? A repository writer can comment:
/ai-review override fable e4da0c498749e74aefa36d533a7dc9c5890d6b14 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of e4da0c498749e74aefa36d533a7dc9c5890d6b14 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e4da0c4

False positive or not applicable? A repository writer can comment:
/ai-review override gpt e4da0c498749e74aefa36d533a7dc9c5890d6b14 false-positive: <reason, 20 to 500 characters>

@kyleseaman

Copy link
Copy Markdown
Contributor Author

Screenshot harness behind the before/after frames in the description, kept out of the diff (it duplicated capture-23928-crew-window-dock.mjs enough to trip the copy/paste gate). Run from website/ after npm run build: [DIST=<main build>/dist] node <this file> <outDir> <before|after>.

capture-crew-window-scroll.mjs
/**
 * Screenshot harness: the crew chat window opens a long transcript at its
 * newest message and follows a reply that lands while the reader is at the
 * bottom, as the local chat does.
 *
 * Runs the REAL built SPA behind the shared in-process static server with every
 * /api/** answered from fixtures (gateway-free), opens a peer row with a long
 * transcript into the crew window and shoots it, then lands one more reply
 * through the peer feed and shoots again. Each frame logs how far the view sits
 * from the bottom. The screenshots are written BEFORE the assertions, so a
 * failing run still leaves the frames to look at.
 *
 * Usage: [DIST=<dist dir>] node scripts/capture-crew-window-scroll.mjs [outDir] [prefix]
 * `DIST` points the server at another build (the pre-fix frames come from main's).
 */
import { chromium } from 'playwright'
import { mkdirSync } from 'node:fs'
import { serveDist } from './lib/serve-dist.mjs'
import { logPageProblems, stubDashboardApi, json } from './lib/stub-dashboard-api.mjs'

const OUT = process.argv[2] || '../temp-screenshots/crew-window-scroll'
const PREFIX = process.argv[3] || 'after'
mkdirSync(OUT, { recursive: true })

const PREVIEW_INSTANCE_SESSIONS = 'mc-preview-instance-sessions'
const ASTRO = {
  id: 'astro', name: 'astro', ssh_host: 'astro', remote_port: 5480, local_port: 7778,
  ttl: '20h', remote_bin: '', connection_method: 'ssh', ssm_target: '', ssm_run_as: '',
  aws_profile: '', aws_region: '', was_connected: true,
  status: { instance_id: 'astro', state: 'connected', local_port: 7778, remote_port: 5480 },
}
const SSO = { state: 'ok', seconds_remaining: 72000, expires_at: null, reason: 'valid' }
const PEER_ROW = {
  key: 'chat-9', row_identity: 'astro:chat-9', title: 'Watch the release checks',
  last_turn_ts: new Date(Date.now() - 60_000).toISOString(), running: false, pending_approval: false, agent: 'default',
}
const PEER_SLOT = { ...PEER_ROW, interrupted: false, pending_approval: false, pending_approval_info: null }
const turns = []
for (let i = 1; i <= 15; i++) {
  turns.push({ role: 'user', content: `Check ${i}: how are the release checks doing?`, ts: `u${i}` })
  turns.push({ role: 'assistant', content: `Cycle ${i}: backend shards 5 to 8 are still running and PR Readiness waits on them. Nothing has failed so far.`, ts: `a${i}` })
}
let peerMessages = turns
const LOCAL_SLOTS = [{
  key: 'chat-local', title: 'Release notes draft', messages: 2, running: false,
  agent: 'kirocrew', created: '2026-09-13T20:00:00Z', last_ts: new Date(Date.now() - 120_000).toISOString(), folder_id: '',
}]

/** How far the transcript's view sits above its bottom, in CSS px. */
const gapToBottom = page => page.evaluate(() => {
  const dock = document.querySelector('[data-testid="crew-window-dock"]')
  const el = dock.previousElementSibling
  return Math.round(el.scrollHeight - el.scrollTop - el.clientHeight)
})

async function main() {
  const { srv, base } = await serveDist(process.env.DIST || undefined)
  const { LD_LIBRARY_PATH: _mise, ...browserEnv } = process.env
  const browser = await chromium.launch({ env: browserEnv })
  const context = await browser.newContext({ viewport: { width: 1280, height: 820 }, deviceScaleFactor: 2 })
  const page = await context.newPage()
  await page.addInitScript(() => {
    // A peer feed the harness can fire, so a reply lands the way a live one does.
    window.__crewFeeds = []
    window.EventSource = class {
      constructor() { this.listeners = {}; window.__crewFeeds.push(this) }
      addEventListener(type, fn) { (this.listeners[type] ||= []).push(fn) }
      close() {}
    }
  })

  await stubDashboardApi(page, {
    folders: [], slots: LOCAL_SLOTS,
    localStorageEntries: { [PREVIEW_INSTANCE_SESSIONS]: '1' },
    extra: async (path, route) => {
      if (path === '/api/instances') { await json(route, { active: true, instances: [ASTRO], warm_set_cap: 5, sso: SSO }); return true }
      if (path === '/api/instances/astro/chat-slots') { await json(route, [PEER_ROW]); return true }
      if (path === '/api/instances/astro/capabilities') { await json(route, { instance_id: 'astro', version: '0.9.0', local_version: '0.9.0', version_match: true, agents: [], workspaces: [] }); return true }
      if (path === '/api/instances/astro/proxy/api/chat/slots') { await json(route, [PEER_SLOT]); return true }
      if (path === '/api/instances/astro/proxy/api/chat/slots/chat-9') {
        await json(route, { key: 'chat-9', title: PEER_ROW.title, running: false, messages: peerMessages }); return true
      }
      if (path === '/api/instances/astro/approval-state') { await json(route, { yolo: false }); return true }
      if (path === '/api/instances/astro/connect' || path === '/api/instances/astro/status') {
        await json(route, { ...ASTRO.status, token: 'tok' }); return true
      }
      if (path.startsWith('/api/instances/')) { await json(route, { ok: true }); return true }
      if (path === '/api/chat/slots/chat-local') {
        await json(route, { messages: [{ role: 'user', content: 'draft', ts: '2026-09-13T20:00:00Z', meta: { mid: 'l-1' } }], has_more: false, total: 1 })
        return true
      }
      return false
    },
  })
  logPageProblems(page)

  await page.goto(`${base}/chat?sid=chat-local`, { waitUntil: 'domcontentloaded' })
  await page.waitForSelector('[aria-label="Chat messages"]', { timeout: 20_000 })

  const row = page.locator('[data-session-row="astro:chat-9"]').first()
  await row.waitFor({ state: 'visible', timeout: 15_000 })
  await row.click()
  const win = page.locator('[data-testid="crew-chat-window"]')
  await win.waitFor({ state: 'visible', timeout: 15_000 })
  await win.getByText('Cycle 15:').waitFor({ state: 'attached', timeout: 15_000 })
  await page.mouse.move(900, 60)
  await page.waitForTimeout(800)

  const shot1 = `${OUT}/${PREFIX}-1-open.png`
  await page.screenshot({ path: shot1 })
  const openGap = await gapToBottom(page)
  console.log(`wrote ${shot1}; gap to bottom ${openGap}px`)

  // Scene 2: a reply lands on the peer while the window is open.
  peerMessages = [...turns, { role: 'assistant', content: 'Cycle 16: all checks passed. The PR is ready to merge.', ts: 'a16' }]
  await page.evaluate(() => {
    for (const es of window.__crewFeeds) for (const fn of es.listeners.chat_message || []) fn({ data: JSON.stringify({ slot: 'chat-9' }) })
  })
  await win.getByText('Cycle 16:').waitFor({ state: 'attached', timeout: 15_000 })
  await page.waitForTimeout(800)
  const shot2 = `${OUT}/${PREFIX}-2-new-reply.png`
  await page.screenshot({ path: shot2 })
  const replyGap = await gapToBottom(page)
  console.log(`wrote ${shot2}; gap to bottom ${replyGap}px`)

  await browser.close()
  srv.close()
  if (openGap > 48 || replyGap > 48) {
    console.error(`FAIL: the transcript is not at its newest message (open ${openGap}px, after a reply ${replyGap}px from the bottom)`)
    process.exit(1)
  }
  console.log('OK: opens at the newest message and follows a new reply')
}

main().catch(err => { console.error(err); process.exit(1) })

@kyleseaman
kyleseaman force-pushed the crew/issue-radar/fix-39041-crew-window-scroll branch from 4377840 to ff857b1 Compare November 18, 2026 10:57
@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 Nov 18, 2026
@kyleseaman
kyleseaman force-pushed the crew/issue-radar/fix-39041-crew-window-scroll branch from ff857b1 to e4da0c4 Compare November 18, 2026 11:22
@kyleseaman

kyleseaman commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: ResizeObserver on the transcript content re-pins the bottom while the reader follows it

  • span=382e37d5e4da Bottom follow misses asynchronous diagram growth

fixed in e4da0c4: a ResizeObserver on a wrapper around the transcript content re-applies scrollTop = scrollHeight while followBottom holds, so a Mermaid diagram or image that grows after the render keeps the newest text in view. A scrolled-up reader is not moved. The observer disconnects on unmount.
Test: follows asynchronous content growth without new messages unless the reader scrolled up (CrewChatWindow.test.tsx) fails without the observer (expected 2000 to be 2600) and passes with it.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 18, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier pending: being reviewed.

The PR does what it says: the crew window now opens at the newest message and follows new rows. It adds a followBottom ref, updated in onScroll with a 48px slack. A layout effect scrolls to the bottom whenever messages, running state, the approval or the dock height change, and only while followBottom is true. A ResizeObserver on a new inner content wrapper re-pins when content grows later. The scroller is always mounted, so the refs are set when the effects run, and the observer disconnects on unmount. The new wrapper keeps the old flex flex-col gap-1 layout. ChatMessageList without transcript renders as a bare fragment, so its rows lay out the same as before. No CSS or test depends on the scroller's own flex classes or its child structure. The dock padding stays on the scroller, and the dock-height dependency covers the case where padding changes the scroll height. New tests cover opening at the bottom, following a reply, keeping the place of a reader who scrolled up, and growth through the observer, including that it disconnects. The file-level afterEach calls vi.unstubAllGlobals, so the fake ResizeObserver does not leak into other tests. CI is green and no state

Tier: pending: being reviewed.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit e4da0c4987 · 120 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 18, 2026 12:21

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. This review checked head e4da0c4. The scroller and the new content wrapper always mount, so the ResizeObserver always attaches. followBottom resets for each new target because the window is keyed per session. dockH in the effect deps handles dock growth, which the observer cannot see. The composer glass layout (padding and scrollbar gutter) is unchanged. Each new test fails without its production hunk and is deterministic (no sleeps or clocks, and the stubs are restored). No AUTOSDE blocking rule applies, and nothing already on main or in another open PR duplicates this.

Done well: the fix sits on the crew window's own scroller, which no virtualizer manages, and reuses the follow pattern ActivityViewer.tsx already uses. The tests separate the observer path from the layout effect path.

Optional:

  • send() in CrewChatWindow.tsx does not set followBottom.current = true. A reader who has scrolled up and then sends does not return to the bottom, unlike the local chat with its scrollOnSend setting. This is not a regression and could be a follow-up.
  • No test covers dock growth, the running state, the approval row, or a reader within the 48px slack. One dock-growth case and one "30px above the bottom" case would pin those.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Nov 18, 2026
@KiroCrewCaptain
KiroCrewCaptain merged commit 2bff546 into main Nov 18, 2026
100 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the crew/issue-radar/fix-39041-crew-window-scroll branch November 18, 2026 12:47
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crew window opens remote sessions at the first message instead of the latest

2 participants