Skip to content

[AGE-4279] fix(frontend): open a chat at its latest message - #6664

Open
ardaerzin wants to merge 1 commit into
release/v0.115.4from
fix/age-4279-open-chat-at-latest
Open

[AGE-4279] fix(frontend): open a chat at its latest message#6664
ardaerzin wants to merge 1 commit into
release/v0.115.4from
fix/age-4279-open-chat-at-latest

Conversation

@ardaerzin

Copy link
Copy Markdown
Contributor

Closes #6623.

Opening an existing chat on /m showed the first message of the conversation, not the latest, so any long chat had to be scrolled from the top every time it was opened.

Why it happened

useTranscriptAutoScroll pins the transcript in a useLayoutEffect keyed on turn-array identity. That measures the height at layout time, but a transcript keeps growing afterwards: a code fence finishes highlighting, an image loads, a tool card lays itself out. web/mobile had no ResizeObserver anywhere, so nothing followed that growth — the pin stayed at what had been the bottom of a much shorter document, which on a long chat is the very top.

It only reproduces on a cold open, where the session has no cached messages and every turn arrives in one commit. With a warm localStorage cache the turns land in a later commit and re-fire the pin after layout, which hides it entirely. That is why it reads as "on mobile or desktop" in the report: a second device is a cold open by definition.

The EE transcript is unaffected — its SC-3 ResizeObserver in useTranscriptScroll already re-pins on post-layout growth. This change makes /m do the same thing.

Before / after

Cold open (cleared localStorage) of a 10-turn chat, sampled every 4s:

viewport before after
390x844 top=0 of max 6480 top=6375 = bottom
1440x900 top=0 of max 3997 top=3892 = bottom

At 390x844 the pre-fix transcript happened to correct itself after ~20s, when a background poll changed the turns array and re-fired the pin. At 1440x900 nothing rescued it — it stayed on the first message for the whole sample. Since /m now serves large viewports, that is the more reliable case, not a secondary one.

Not regressed

A reader parked mid-transcript is not pulled to the bottom: the observer no-ops while nearBottomRef is false. Verified at both viewports (parked at 900 and at 1500, held across samples). The zero-height guard keeps a pane hidden behind the config split from being read as the reader moving.

Verified in a real browser against the local EE stack, not only in tests.

The transcript pin measures at layout time, but a transcript keeps growing
after that — a code fence finishes highlighting, an image loads, a tool card
lays itself out. On a cold open (no cached messages for the session) every
turn arrives in a single commit, so the pin lands on a fraction of the final
height and a long chat opens at its first message instead of its latest one.

Follow that growth with a ResizeObserver while the reader is at the bottom,
and ignore a zero-height measurement, which is a pane hidden behind the
config split rather than the reader moving.

Measured on a 10-turn chat, cold open with cleared localStorage:

  390x844    before: top=0 of max 6480    after: top=6375 (bottom)
  1440x900   before: top=0 of max 3997    after: top=3892 (bottom)

A reader parked mid-transcript is not moved. The EE transcript already does
this through the SC-3 observer in useTranscriptScroll, so it needs no change.
@linear-code

linear-code Bot commented Sep 8, 2026

Copy link
Copy Markdown

AGE-4279

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agenta-documentation Ready Ready Preview Sep 8, 2026 4:10pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved chat transcript auto-scrolling when the pane is hidden or resized.
    • Preserved the near-bottom position while content loads and the transcript expands.
    • Ensured the transcript correctly returns to the bottom when it becomes visible.

Walkthrough

The transcript auto-scroll hook now ignores hidden-pane measurements and observes transcript resizing. It restores the bottom position while the reader remains near the latest message.

Changes

Transcript auto-scroll

Layer / File(s) Summary
Hidden pane and resize handling
web/mobile/src/features/chat/useTranscriptAutoScroll.ts
The hook ignores zero-height transcript measurements. A ResizeObserver re-pins the transcript to the bottom while the reader remains near the bottom and content resizes. The observer disconnects during cleanup.

Priority: ➖ Normal — Schedule the mobile chat auto-scroll fix because it keeps existing conversations opening at the latest message after content finishes loading.

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to a87cc

Mobile chat reopening is improved for post-layout transcript growth, but a status line added after setup may still leave readers above the newest content. Addressing late-added status nodes would complete the latest-message behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the frontend fix that opens chats at the latest message. It matches the primary change.
Description check ✅ Passed The description directly explains the opening-scroll defect, its cause, the fix, and regression behavior.
Linked Issues check ✅ Passed The change addresses issue #6623 by observing post-layout transcript growth, re-pinning near-bottom readers, and ignoring zero-height hidden panes. This supports opening existing chats at the latest m…
Out of Scope Changes check ✅ Passed The changes are limited to transcript auto-scroll behavior required for issue #6623. No unrelated code changes are identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/age-4279-open-chat-at-latest

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: 38b39ffb-fb3c-47e3-b9a9-9aa629d0202a

📥 Commits

Reviewing files that changed from the base of the PR and between 0c85a59 and a87cc82.

📒 Files selected for processing (1)
  • web/mobile/src/features/chat/useTranscriptAutoScroll.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment on lines +52 to +55
// The pin above measures at layout time, but a transcript keeps growing after that — a fence
// finishes highlighting, an image loads, a tool card lays itself out. Without this the opening
// pin lands on a fraction of the final height and a long chat reads as starting at the top.
// Follow the growth while the reader is at the bottom; the moment they scroll up this no-ops.

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Keep the new comment to one short line.

The added comment spans Line 52 through Line 55 and violates the repository rule.

As per coding guidelines, comments must be at most one short line.

Source: Coding guidelines

el.scrollTop = el.scrollHeight
})
observer.observe(el)
for (const child of Array.from(el.children)) observer.observe(child)

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 10 'useTranscriptAutoScroll|TurnStatusLine|return null|working=|waitingForInput=' web/mobile/src

Repository: Agenta-AI/agenta

Length of output: 50372


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- useTranscriptAutoScroll.ts ---'
cat -n web/mobile/src/features/chat/useTranscriptAutoScroll.ts | sed -n '1,120p'

printf '%s\n' '--- ChatScreen.tsx ---'
cat -n web/mobile/src/features/chat/ChatScreen.tsx | sed -n '185,225p'

printf '%s\n' '--- LiveConversation.tsx ---'
cat -n web/mobile/src/features/chat/LiveConversation.tsx | sed -n '485,500p;630,648p'

printf '%s\n' '--- TurnStatusLine.tsx ---'
cat -n web/mobile/src/features/chat/TurnStatusLine.tsx | sed -n '1,50p'

Repository: Agenta-AI/agenta

Length of output: 9310


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- scroll container and ContentRail definitions ---'
rg -n -C 8 'function ScreenScaffold|const ScreenScaffold|export.*ScreenScaffold|function ContentRail|const ContentRail|export.*ContentRail|overflow-(auto|y)' web/mobile/src/features web/mobile/src/components web/mobile/src 2>/dev/null | head -n 240

Repository: Agenta-AI/agenta

Length of output: 24518


🏁 Script executed:

#!/bin/bash
set -euo pipefail
cat -n web/mobile/src/features/chat/useTranscriptAutoScroll.ts | sed -n '1,120p'
cat -n web/mobile/src/features/chat/TurnStatusLine.tsx | sed -n '11,42p'
cat -n web/mobile/src/features/chat/ChatScreen.tsx | sed -n '203,225p'
cat -n web/mobile/src/features/chat/LiveConversation.tsx | sed -n '630,648p'

Repository: Agenta-AI/agenta

Length of output: 6840


Observe late-added status nodes. TurnStatusLine can mount after content changes, but the hook observes only the initial children, so its growth can leave a near-bottom reader above the latest content. Observe child-list changes or keep a stable status node.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Preview URL https://gateway-pr-6664.up.railway.app/w
Project agenta-oss-clone-spike
Image tag pr-6664-5418253
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-09-08T16:23:10.809Z

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.

1 participant