Commit d80eed8d8 for llama.cpp

commit d80eed8d8ea0d67238ffe0900bc61e8c7e89e804
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date:   Sun Dec 6 11:01:09 2026 +0100

    ui: keep a new chat's first message on screen; expand the chat form only by hand (#33796)

    * ui: keep a new chat's first message on screen as it lands

    Sending the first message of a new conversation glided the page to its
    bottom before the message had rendered, so the moment a tall message
    appeared the page was already sweeping it off the top of the screen:
    the layout jumped and the message the user just wrote was cut off.
    A one-line message never made the page scrollable, which is why only
    taller ones showed it.

    A send that starts a new conversation now holds the viewport while the
    message lands, and the hold releases itself once the message has
    settled. A message that leaves the page unscrollable leaves the reader
    at its bottom: the reply streaming in under it eases the viewport down
    as before. A tall one leaves the reader at the top of a page that
    already scrolls: that place is theirs, the reply streams in below it
    out of sight, and following returns the moment they scroll to it.

    Assisted-by: Llama Chat (ggml-org/Qwen4-35B-A3B-GGUF:Q8_0 + MTP:Q8_0)

    * ui: expand the chat form only by hand

    The form expanded on its own once the message being written had several
    lines or a markdown block in its finished lines, growing the card
    mid-typing without the reader asking for it. It now expands only when
    the reader clicks the toggle — or for a message put back after a failed
    send, which keeps its explicit expand path. shouldExpandChatForm,
    CHAT_FORM_EXPAND_MIN_LINES and the markdown structure detector they
    alone used are removed with it.

    Assisted-by: Llama Chat (ggml-org/Qwen4-35B-A3B-GGUF:Q8_0 + MTP:Q8_0)

    * ui: hold a new chat's first message until it is on the page

    The landing hold let go once the page had not grown for 16 ms, so the
    early layout changes of a new chat (the form moving, the navigation)
    could release it before the first message existed, and the message was
    swept off the top again. The hold now waits until the reply's row shows
    up in that conversation, then lets go once the page stops growing; a
    timer remains only as a fallback.

    A tall first message now keeps the reader at its top with reduced
    motion too, scrolling to the bottom ends a pending hold, and the
    landing is tied to the conversation it was sent into, so a failed send
    or a switch to another chat no longer keeps that chat from opening at
    its bottom. A message put back after a failed send expands the form
    only when it spans more than one line.

    Assisted-by: Claude (Opus 5.5 Medium)

diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
index d8b23aa69..3db6dd1cb 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
@@ -419,10 +419,7 @@
 	$effect(() => {
 		void textHeight;

-		const content = inputRef?.getContentDOM();
-		const lineHeight = content ? parseFloat(getComputedStyle(content).lineHeight) : 0;
-		const lines = content && lineHeight ? content.offsetHeight / lineHeight : 0;
-		const fitsOneLine = lines < CHAT_FORM_SINGLE_ROW_MAX_TEXT_LINES;
+		const fitsOneLine = textLines() < CHAT_FORM_SINGLE_ROW_MAX_TEXT_LINES;
 		const length = value.length;

 		// an emptied form tries the one row again; one that wraps while empty keeps the two rows
@@ -491,9 +488,19 @@
 		micUnavailableReason = microphoneUnavailableReason();
 	});

-	/** Expands for the message as it stands, e.g. one put back after a send failed. */
+	/** Lines the text takes up as laid out now. */
+	function textLines(): number {
+		const content = inputRef?.getContentDOM();
+		const lineHeight = content ? parseFloat(getComputedStyle(content).lineHeight) : 0;
+
+		return content && lineHeight ? content.offsetHeight / lineHeight : 0;
+	}
+
+	/** Expands for a message put back after a send failed, unless it fits one line. */
 	export function expandForMessage() {
-		expansion.handleInput();
+		if (value.includes('\n') || textLines() >= CHAT_FORM_SINGLE_ROW_MAX_TEXT_LINES) {
+			expansion.expandForMessage();
+		}
 	}

 	export function focus() {
@@ -947,7 +954,7 @@
 			data-single-row={isSingleRow || undefined}
 			data-slot="input-area"
 		>
-			<!-- a single row has no room for it: a message expands once it has a second line -->
+			<!-- a single row has no room for it: a message that fits one row stays in it -->
 			{#if expandable && !isSingleRow}
 				<ActionIcon
 					class={expandToggleClass}
@@ -993,7 +1000,6 @@
 					expanded={isExpanded}
 					onInput={() => {
 						voice.handleUserInput();
-						expansion.handleInput();
 						pickers.handleInput();
 						onValueChange?.(value);
 					}}
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/chat-form-expand.ts b/ui/apps/chat/src/lib/components/app/chat/ChatForm/chat-form-expand.ts
index e761ce58e..99278319f 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/chat-form-expand.ts
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/chat-form-expand.ts
@@ -1,6 +1,3 @@
-import { hasMarkdownStructure } from '#lib/components/app/content/MarkdownEditor/markdown-structure.ts';
-import { CHAT_FORM_EXPAND_MIN_LINES } from '#lib/constants/index.ts';
-
 /** The collapsed card's `rounded-4xl` on a phone. */
 const COLLAPSED_CARD_RADIUS = '2rem';

@@ -9,19 +6,6 @@ export type SheetBox = { height: number; left: number; right: number; top: numbe
 export type SheetRects = { actionsTop: number; card: SheetBox; padTop: number };
 export type SheetFrame = { actions: Keyframe; card: Keyframe };

-/**
- * Should a message expand the chat form on its own? Once it has several lines, or a
- * markdown block in its finished lines: the line still being typed does not count, as
- * a lone `-`, `#` or `1.` already parses as a block.
- */
-export function shouldExpandChatForm(text: string): boolean {
-	const finishedLines = text.slice(0, text.lastIndexOf('\n') + 1);
-
-	return (
-		text.split('\n').length >= CHAT_FORM_EXPAND_MIN_LINES || hasMarkdownStructure(finishedLines)
-	);
-}
-
 /** The laid-out phone sheet as it is: full screen, square. */
 export const SHEET_AT_REST: SheetFrame = {
 	actions: { top: '0px' },
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte
index 9b45755b3..45ef92a82 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte
@@ -26,6 +26,7 @@
 		CHAT_FORM_MOVE_TO_BOTTOM_OUT_MS,
 		ROUTES
 	} from '#lib/constants/index.ts';
+	import { MessageRole } from '#lib/enums/index.ts';
 	import { useChatScreenActiveModel } from '#lib/hooks/use-chat-screen-active-model.svelte.ts';
 	import { useChatScreenDragAndDrop } from '#lib/hooks/use-chat-screen-drag-and-drop.svelte.ts';
 	import { useChatScreenFileUpload } from '#lib/hooks/use-chat-screen-file-upload.svelte.ts';
@@ -148,16 +149,32 @@
 			return false;
 		}

-		// Sending re-arms following: the message glides to the top of the screen
-		// and the reply streams in under it.
-		stick.glideToBottom();
+		// Sending glides to the bottom; a new conversation's first message lands at the top instead
+		const sendLanding = conversationsStore.activeConversation ? null : { id: null };

-		await chatStore.sendMessage(message, result?.extras);
+		if (sendLanding) {
+			landing = sendLanding;
+			stick.holdForLanding();
+		} else {
+			stick.glideToBottom();
+		}
+
+		try {
+			await chatStore.sendMessage(message, result?.extras);
+		} finally {
+			// the send ended without its message landing (it failed or was aborted)
+			if (sendLanding && landing === sendLanding) {
+				landing = null;
+				stick.releaseLanding();
+			}
+		}

 		return true;
 	}

 	let lastScrolledConversationId: string | null = null;
+	/** The new conversation a send is landing in; its id is set once it shows up. */
+	let landing: { id: string | null } | null = null;

 	// Every navigation lands anew: this screen outlives its routes, so coming
 	// back to the conversation it last landed on (via the new-chat screen)
@@ -167,6 +184,8 @@
 	onNavigate((navigation) => {
 		lastScrolledConversationId = null;

+		if (landing?.id && navigation.to?.params?.id !== landing.id) landing = null;
+
 		if (navigation.to?.params?.id) disableScrollHandling();
 	});

@@ -174,14 +193,30 @@
 	// The resize observer keeps it there while the list settles (lazy rows,
 	// syntax highlighting, images) without polling for a stable height.
 	async function handleMessagesReady(messageCount: number) {
-		if (messageCount === 0) return;
-
 		const id = conversationsStore.activeConversation?.id ?? null;

-		if (!id || id === lastScrolledConversationId) return;
+		// the conversation a send creates is the first one to show up after it
+		if (landing && !landing.id) landing.id = id;
+
+		const isLanding = !!id && landing?.id === id;
+
+		// the reply's row comes after the first message: that message is on the page
+		if (
+			isLanding &&
+			conversationsStore.activeMessages.some((m) => m.role === MessageRole.ASSISTANT)
+		) {
+			landing = null;
+			stick.releaseLanding();
+		}
+
+		if (messageCount === 0 || !id || id === lastScrolledConversationId) return;

 		lastScrolledConversationId = id;
 		await tick();
+
+		// the first message stays at the top, where the page put it
+		if (isLanding) return;
+
 		stick.scrollToBottom();
 	}

diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-structure.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-structure.ts
deleted file mode 100644
index b23dcd26a..000000000
--- a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-structure.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { markdownLanguage } from '@codemirror/lang-markdown';
-
-/**
- * Does `source` hold any markdown block other than plain paragraphs (a heading,
- * list, quote, code block, table, rule, ...)? Inline markup inside a paragraph
- * does not count.
- */
-export function hasMarkdownStructure(source: string): boolean {
-	const tree = markdownLanguage.parser.parse(source);
-
-	for (let node = tree.topNode.firstChild; node; node = node.nextSibling) {
-		if (node.name !== 'Paragraph') return true;
-	}
-
-	return false;
-}
diff --git a/ui/apps/chat/src/lib/constants/chat-form.constants.ts b/ui/apps/chat/src/lib/constants/chat-form.constants.ts
index 99a35e900..6ba945f47 100644
--- a/ui/apps/chat/src/lib/constants/chat-form.constants.ts
+++ b/ui/apps/chat/src/lib/constants/chat-form.constants.ts
@@ -25,8 +25,6 @@ export const CHAT_FORM_PICKER_WIDTH_CLASS =
  */
 export const CHAT_FORM_PATH_PICKER_WIDTH_CLASS = 'w-[min(36rem,var(--bits-popover-anchor-width))]';
 export const NEW_CHAT_DRAFT_KEY = '__new_chat__';
-/** Lines of text from which the main chat form expands into its large editor. */
-export const CHAT_FORM_EXPAND_MIN_LINES = 4;
 /** Below this text height (a line and change) the main chat form keeps to one row. */
 export const CHAT_FORM_SINGLE_ROW_MAX_TEXT_LINES = 1.5;

diff --git a/ui/apps/chat/src/lib/hooks/use-chat-form-expansion.svelte.ts b/ui/apps/chat/src/lib/hooks/use-chat-form-expansion.svelte.ts
index 718f9c0a3..e6f0a43d9 100644
--- a/ui/apps/chat/src/lib/hooks/use-chat-form-expansion.svelte.ts
+++ b/ui/apps/chat/src/lib/hooks/use-chat-form-expansion.svelte.ts
@@ -8,8 +8,7 @@ import {
 	type SheetFrame,
 	sheetFrameAt,
 	type SheetRects,
-	shiftSheetRects,
-	shouldExpandChatForm
+	shiftSheetRects
 } from '#lib/components/app/chat/ChatForm/chat-form-expand.ts';
 import { CHAT_FORM_EASE_OUT, CHAT_FORM_SHEET_MS, UI_DATA_ATTRS } from '#lib/constants/index.ts';
 import { deviceStore, uiStore } from '#lib/stores/index.ts';
@@ -26,14 +25,12 @@ export interface UseChatFormExpansionOptions extends CollapsedHeightHoldOptions
 }

 /**
- * The chat form's expanded editor: entered by hand, or on a desktop once the message being
- * written asks for it (see shouldExpandChatForm), kept while it has text, left once it is
- * cleared or sent. Collapsing by hand holds until then too. On a phone it is a full-screen
- * sheet that slides from and back to the card (see sheetFrameAt).
+ * The chat form's expanded editor: entered by hand, or for a message put back after a
+ * failed send, left once it is cleared or sent. On a phone it is a full-screen sheet
+ * that slides from and back to the card (see sheetFrameAt).
  */
 export function useChatFormExpansion(options: UseChatFormExpansionOptions) {
 	let isExpanded = $state(false);
-	let isCollapsedByUser = false;
 	let hadText = false;
 	let wasExpanded = false;
 	let isSheetMoving = $state(false);
@@ -75,24 +72,22 @@ export function useChatFormExpansion(options: UseChatFormExpansionOptions) {
 		untrack(reset);
 	});

-	/** Straight back to the small form, without the sheet's slide, free to expand again. */
+	/** Straight back to the small form, without the sheet's slide. */
 	function reset() {
-		isCollapsedByUser = false;
-
 		if (isSheetMoving) clearSheetAnimations();

 		isExpanded = false;
 	}

 	/**
-	 * Expands for what the user writes or pastes, not for a draft restored on opening a
-	 * chat. A phone only expands by hand: the sheet switching in mid-typing moves the text
-	 * under the keyboard.
+	 * Expands for the message as it stands, e.g. one put back after a send failed:
+	 * what the user writes never expands the form on its own. A phone keeps the small
+	 * form: the sheet switching in under the keyboard moves the text.
 	 */
-	function handleInput() {
-		if (!options.isEnabled() || isExpanded || isCollapsedByUser || deviceStore.isMobile) return;
+	function expandForMessage() {
+		if (!options.isEnabled() || isExpanded || isSheetMoving || deviceStore.isMobile) return;

-		isExpanded = shouldExpandChatForm(options.getValue() ?? '');
+		isExpanded = true;
 	}

 	$effect(() => {
@@ -286,9 +281,6 @@ export function useChatFormExpansion(options: UseChatFormExpansionOptions) {
 	function toggle() {
 		if (isSheetMoving) return;

-		// collapsing an empty form leaves the next message free to expand it again
-		isCollapsedByUser = isExpanded && !!(options.getValue() ?? '').trim();
-
 		if (isExpanded && animatesSheet()) {
 			void collapseSheet();

@@ -302,7 +294,7 @@ export function useChatFormExpansion(options: UseChatFormExpansionOptions) {
 	}

 	return {
-		handleInput,
+		expandForMessage,
 		get isBlurHeld() {
 			return isBlurHeld;
 		},
diff --git a/ui/apps/chat/src/lib/hooks/use-stick-to-bottom.svelte.ts b/ui/apps/chat/src/lib/hooks/use-stick-to-bottom.svelte.ts
index 1ae4f6920..95bb18c8a 100644
--- a/ui/apps/chat/src/lib/hooks/use-stick-to-bottom.svelte.ts
+++ b/ui/apps/chat/src/lib/hooks/use-stick-to-bottom.svelte.ts
@@ -48,6 +48,10 @@ const GLIDE_MAX_FRAME_MS = 34;
 const GLIDE_SETTLED_MS = 150;
 /** Close enough to the bottom for a glide to stop. */
 const GLIDE_DONE_PX = 0.5;
+/** A landing hold that `releaseLanding` never ends lets go after this long anyway. */
+const LANDING_RELEASE_MAX_MS = 5000;
+/** After `releaseLanding`, the page counts as settled once it has not grown for this long. */
+const LANDING_RELEASE_FRAME_MS = 16;
 const GLIDE_CANCEL_EVENTS = ['wheel', 'touchstart', 'keydown'] as const;
 const GLIDE_SCROLL_KEYS: readonly string[] = [
 	' ',
@@ -90,6 +94,13 @@ export class StickToBottom {
 	private glideFrame: number | null = null;
 	private glideSettleUntil = 0;
 	private graceTimer: ReturnType<typeof setTimeout> | undefined;
+	/** The page height the landing is waiting for to stop changing. */
+	private landingHeight = 0;
+	/** Set while a new conversation's first message lands at the top of the page. */
+	private landingHold = false;
+	/** The first message is on the page: the hold lets go once the page stops growing. */
+	private landingSettling = false;
+	private landingReleaseTimer: ReturnType<typeof setTimeout> | undefined;
 	private lastScrollHeight = 0;
 	private lastScrollTop = 0;
 	private markPressed = (): void => {
@@ -141,6 +152,7 @@ export class StickToBottom {

 	detach(): void {
 		this.stopGlide();
+		this.clearLanding();
 		this.glideSettleUntil = 0;
 		clearTimeout(this.settleTimer);
 		this.observer?.disconnect();
@@ -151,6 +163,44 @@ export class StickToBottom {
 		this.container = undefined;
 	}

+	/**
+	 * Ends the landing hold. A tall first message keeps the reader at its top; a short one
+	 * leaves them at the bottom, where the reply is followed.
+	 */
+	followLanding(): void {
+		const el = this.container;
+
+		if (!el) return;
+
+		this.clearLanding();
+		this.measure();
+
+		// a tall message: the reply growing below must not drag the reader
+		if (this.distanceFromBottom(el) > FAR_FROM_BOTTOM_PX) {
+			this.stick = false;
+			this.syncAnchor();
+
+			return;
+		}
+
+		if (
+			!this.enabled ||
+			typeof requestAnimationFrame === 'undefined' ||
+			window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
+		) {
+			return;
+		}
+
+		this.stick = true;
+		this.glideSettleUntil = performance.now() + GLIDE_SETTLE_MS;
+		// once the window is over the pin anchors again, without waiting for a scroll
+		clearTimeout(this.settleTimer);
+		this.settleTimer = setTimeout(() => this.syncAnchor(), GLIDE_SETTLE_MS + 1);
+
+		// content that grew during the hold gets no further resize, so glide to it now
+		if (this.distanceFromBottom(el) > GLIDE_DONE_PX) this.startGlide();
+	}
+
 	/**
 	 * Also follows `element`'s size changes, even right after a press: the grace keeps
 	 * a block the reader expands from dragging the viewport, but the chat form
@@ -185,6 +235,7 @@ export class StickToBottom {
 		if (!el) return;

 		this.stick = true;
+		this.clearLanding();
 		this.pressedAt = -Infinity;

 		if (
@@ -211,12 +262,48 @@ export class StickToBottom {
 		this.measure();
 	}

+	/**
+	 * Holds the viewport for a send that starts a new conversation: its first message lands at
+	 * the top of the page. Call `releaseLanding` once that message is on the page.
+	 */
+	holdForLanding(): void {
+		const el = this.container;
+
+		if (!el) return;
+
+		this.landingHold = true;
+		this.landingSettling = false;
+		this.stopGlide();
+		this.glideSettleUntil = 0;
+		clearTimeout(this.settleTimer);
+		// the send that led here outranks the press that led here
+		this.stick = true;
+		this.pressedAt = -Infinity;
+		this.atBottom = true;
+		this.farFromBottom = false;
+		this.syncAnchor();
+		// a fallback only: the hold waits for `releaseLanding`
+		this.armLandingRelease(LANDING_RELEASE_MAX_MS);
+	}
+
+	/** The first message is on the page: lets go of the hold once the page stops growing. */
+	releaseLanding(): void {
+		const el = this.container;
+
+		if (!el || !this.landingHold) return;
+
+		this.landingSettling = true;
+		this.landingHeight = el.scrollHeight;
+		this.armLandingRelease(LANDING_RELEASE_FRAME_MS);
+	}
+
 	scrollToBottom(behavior: ScrollBehavior = 'auto'): void {
 		const el = this.container;

 		if (!el) return;

 		el.scrollTo({ behavior, top: el.scrollHeight });
+		this.clearLanding();
 		this.stick = true;
 		this.atBottom = true;
 		this.farFromBottom = false;
@@ -231,6 +318,17 @@ export class StickToBottom {
 		untrack(() => this.syncAnchor());
 	}

+	private armLandingRelease(ms: number): void {
+		clearTimeout(this.landingReleaseTimer);
+		this.landingReleaseTimer = setTimeout(() => this.followLanding(), ms);
+	}
+
+	private clearLanding(): void {
+		clearTimeout(this.landingReleaseTimer);
+		this.landingHold = false;
+		this.landingSettling = false;
+	}
+
 	/**
 	 * The document scroller's clientHeight is iOS's smaller viewport: Safari's with its
 	 * toolbar shown, the installed app's without the status bar. The page scrolls on past it
@@ -246,6 +344,16 @@ export class StickToBottom {

 		if (!el) return;

+		// a first message landing is not followed; once released, wait for the page to settle
+		if (this.landingHold) {
+			if (this.landingSettling && el.scrollHeight !== this.landingHeight) {
+				this.landingHeight = el.scrollHeight;
+				this.armLandingRelease(LANDING_RELEASE_FRAME_MS);
+			}
+
+			return;
+		}
+
 		// a running glide reads the new bottom on its next frame
 		if (this.glideFrame !== null) return;

@@ -394,7 +502,9 @@ export class StickToBottom {
 	 */
 	private syncAnchor(): void {
 		const pressedRecently = performance.now() - this.pressedAt < INTERACTION_GRACE_MS;
-		const gliding = this.glideFrame !== null || performance.now() < this.glideSettleUntil;
+		// the hold keeps the pin from dragging the viewport down to the landing message
+		const gliding =
+			this.landingHold || this.glideFrame !== null || performance.now() < this.glideSettleUntil;

 		this.container?.toggleAttribute(
 			STICK_ATTRIBUTE,
diff --git a/ui/apps/chat/tests/client/chat-form-expansion.svelte.test.ts b/ui/apps/chat/tests/client/chat-form-expansion.svelte.test.ts
index e8be20671..e6785088a 100644
--- a/ui/apps/chat/tests/client/chat-form-expansion.svelte.test.ts
+++ b/ui/apps/chat/tests/client/chat-form-expansion.svelte.test.ts
@@ -1,5 +1,6 @@
 // Guards when the main chat form expands into its large editor and collapses back:
-// on its own once a message asks for it, by hand, and back once it is cleared.
+// only by hand (or for a message put back after a failed send), never on its own while
+// the message is written, and back once it is cleared.

 import ChatFormTestWrapper from './components/ChatFormTestWrapper.svelte';
 import { EditorView } from '@codemirror/view';
@@ -64,32 +65,33 @@ describe('ChatForm expansion', () => {
 		}
 	});

-	it('expands on a finished markdown line or a fourth line', async () => {
+	it('stays small for a finished markdown line or a fourth line', async () => {
 		const { isExpanded, write } = await renderForm();

 		await write('# Title\n');
-		expect(isExpanded()).toBe(true);
-
-		await write('');
 		expect(isExpanded()).toBe(false);

 		await write('one\ntwo\nthree\nfour');
-		expect(isExpanded()).toBe(true);
+		expect(isExpanded()).toBe(false);
 	});

 	it('stays expanded while the message has text', async () => {
-		const { isExpanded, write } = await renderForm();
+		const { isExpanded, toggle, write } = await renderForm();

+		await toggle();
 		await write('one\ntwo\nthree\nfour');
 		await write('one');

 		expect(isExpanded()).toBe(true);
 	});

-	it('keeps a collapse by hand until the message is cleared', async () => {
+	it('keeps a collapse by hand while the message is written', async () => {
 		const { isExpanded, toggle, write } = await renderForm();

 		await write('# Title\n');
+		await toggle();
+		expect(isExpanded()).toBe(true);
+
 		await toggle();
 		await tick();
 		expect(isExpanded()).toBe(false);
@@ -98,17 +100,16 @@ describe('ChatForm expansion', () => {
 		expect(isExpanded()).toBe(false);

 		await write('');
-		await write('# Title\n');
-		expect(isExpanded()).toBe(true);
+		expect(isExpanded()).toBe(false);
 	});

-	it('leaves a restored draft in the small form until it is written in', async () => {
+	it('leaves a restored draft in the small form', async () => {
 		const { isExpanded, write } = await renderForm('# Title\n\n- item\n');

 		expect(isExpanded()).toBe(false);

 		await write('# Title\n\n- item\n- another\n');
-		expect(isExpanded()).toBe(true);
+		expect(isExpanded()).toBe(false);
 	});

 	it('expands a message put back after a failed send', async () => {
@@ -122,6 +123,15 @@ describe('ChatForm expansion', () => {
 		expect(isExpanded()).toBe(true);
 	});

+	it('keeps a one-line message put back after a failed send small', async () => {
+		const { component, isExpanded } = await renderForm('hi');
+
+		component.expandForMessage();
+		await tick();
+
+		expect(isExpanded()).toBe(false);
+	});
+
 	it('expands on a phone only by hand', async () => {
 		await page.viewport(PHONE.width, PHONE.height);

@@ -135,9 +145,10 @@ describe('ChatForm expansion', () => {
 	});

 	it('starts collapsed in another conversation', async () => {
-		const { isExpanded, write } = await renderForm();
+		const { isExpanded, toggle, write } = await renderForm();

 		await write('# Title\n');
+		await toggle();
 		expect(isExpanded()).toBe(true);

 		conversationsStore.activeConversation = { id: 'other' } as DatabaseConversation;
diff --git a/ui/apps/chat/tests/client/stick-to-bottom.svelte.test.ts b/ui/apps/chat/tests/client/stick-to-bottom.svelte.test.ts
index d229bba0f..76cb2aa93 100644
--- a/ui/apps/chat/tests/client/stick-to-bottom.svelte.test.ts
+++ b/ui/apps/chat/tests/client/stick-to-bottom.svelte.test.ts
@@ -186,4 +186,142 @@ describe('StickToBottom', () => {

 		expect(distanceFromBottom(container)).toBeLessThanOrEqual(1);
 	});
+
+	// A new conversation's first message lands at the top: the hold keeps it there until
+	// releaseLanding, then a tall message keeps the reader at its top and a short one follows.
+	it("holds the viewport while a new conversation's first message lands", async () => {
+		const { container, content, stick } = setup();
+
+		// back to the top, where a new conversation's page starts
+		container.scrollTop = 0;
+		stick.handleScroll();
+
+		stick.holdForLanding();
+		content.style.height = '1400px';
+		await resizeObserved();
+		await frame();
+
+		// the message's own appearance did not drag the viewport down
+		expect(container.scrollTop).toBe(0);
+	});
+
+	it('keeps a tall first message in place while the reply streams in below it', async () => {
+		const { container, content, stick } = setup();
+
+		container.scrollTop = 0;
+		stick.handleScroll();
+
+		stick.holdForLanding();
+		content.style.height = '900px';
+		await resizeObserved();
+		stick.releaseLanding();
+		await new Promise((resolve) => setTimeout(resolve, 120));
+
+		// the reply streams in under the message, out of sight
+		content.style.height = '1400px';
+		await resizeObserved();
+		await frame();
+
+		// the reader's place is theirs: the viewport did not move
+		expect(container.scrollTop).toBe(0);
+	});
+
+	it('follows the reply down when the landing leaves the reader at the bottom', async () => {
+		// a page the first message leaves unscrollable: the reader sits at its bottom
+		const container = document.createElement('div');
+		const content = document.createElement('div');
+
+		container.style.cssText = 'height: 600px; overflow-y: auto;';
+		content.style.height = '100px';
+		container.append(content);
+		document.body.append(container);
+
+		const stick = createStickToBottom();
+
+		stick.attach(container, content);
+		cleanup.push(() => {
+			stick.detach();
+			container.remove();
+		});
+
+		stick.holdForLanding();
+		// a one-line message lands: the page still does not scroll
+		content.style.height = '300px';
+		await resizeObserved();
+		stick.releaseLanding();
+		await new Promise((resolve) => setTimeout(resolve, 120));
+
+		// the reply streams in and the page grows past the screen
+		content.style.height = '700px';
+		await resizeObserved();
+
+		await settled(container);
+
+		expect(distanceFromBottom(container)).toBeLessThanOrEqual(1);
+	});
+
+	it('keeps holding through an early layout change until the message is released', async () => {
+		const { container, content, stick } = setup();
+
+		container.scrollTop = 0;
+		stick.handleScroll();
+		stick.holdForLanding();
+
+		// the new-chat screen changes layout, then the message takes a while to arrive
+		content.style.height = '150px';
+		await resizeObserved();
+		await new Promise((resolve) => setTimeout(resolve, 120));
+
+		content.style.height = '900px';
+		await resizeObserved();
+		stick.releaseLanding();
+		await new Promise((resolve) => setTimeout(resolve, 120));
+
+		content.style.height = '1400px';
+		await resizeObserved();
+		await frame();
+
+		expect(container.scrollTop).toBe(0);
+	});
+
+	it('keeps a tall first message in place with reduced motion', async () => {
+		const matchMedia = window.matchMedia;
+
+		window.matchMedia = ((query: string) =>
+			({ matches: query.includes('reduce') }) as MediaQueryList) as typeof window.matchMedia;
+		cleanup.push(() => (window.matchMedia = matchMedia));
+
+		const { container, content, stick } = setup();
+
+		container.scrollTop = 0;
+		stick.handleScroll();
+		stick.holdForLanding();
+		content.style.height = '900px';
+		await resizeObserved();
+		stick.releaseLanding();
+		await new Promise((resolve) => setTimeout(resolve, 120));
+
+		content.style.height = '1400px';
+		await resizeObserved();
+		await frame();
+
+		expect(container.scrollTop).toBe(0);
+	});
+
+	it('releases the hold when a send glides to the bottom instead', async () => {
+		const { container, content, stick } = setup();
+
+		container.scrollTop = 0;
+		stick.handleScroll();
+		stick.holdForLanding();
+
+		// a later send in an existing conversation glides, hold notwithstanding
+		stick.glideToBottom();
+		content.style.height = '1400px';
+		await resizeObserved();
+
+		await settled(container);
+
+		expect(distanceFromBottom(container)).toBeLessThanOrEqual(1);
+	});
 });
diff --git a/ui/apps/chat/tests/unit/chat-form-expand.test.ts b/ui/apps/chat/tests/unit/chat-form-expand.test.ts
index db5a0361e..f202c0f31 100644
--- a/ui/apps/chat/tests/unit/chat-form-expand.test.ts
+++ b/ui/apps/chat/tests/unit/chat-form-expand.test.ts
@@ -2,33 +2,10 @@ import {
 	SHEET_AT_REST,
 	sheetFrameAt,
 	type SheetRects,
-	shiftSheetRects,
-	shouldExpandChatForm
+	shiftSheetRects
 } from '#lib/components/app/chat/ChatForm/chat-form-expand.ts';
 import { describe, expect, it } from 'vitest';

-describe('shouldExpandChatForm', () => {
-	it('ignores markdown markers on the line still being typed', () => {
-		for (const text of ['*', '*really*', '-', '-5 degrees', '#', '#hashtag', '> ', '1.', '2024.']) {
-			expect(shouldExpandChatForm(text), text).toBe(false);
-		}
-
-		expect(shouldExpandChatForm('# Title')).toBe(false);
-		expect(shouldExpandChatForm('plain text\n- item')).toBe(false);
-	});
-
-	it('expands on a markdown block in a finished line', () => {
-		expect(shouldExpandChatForm('# Title\n')).toBe(true);
-		expect(shouldExpandChatForm('- item\nmore')).toBe(true);
-		expect(shouldExpandChatForm('```js\nconst a = 1;')).toBe(true);
-	});
-
-	it('expands on several lines of plain text', () => {
-		expect(shouldExpandChatForm('one\ntwo\nthree')).toBe(false);
-		expect(shouldExpandChatForm('one\ntwo\nthree\nfour')).toBe(true);
-	});
-});
-
 describe('sheetFrameAt', () => {
 	// a phone screen, and the card floating above its bottom edge
 	const sheet: SheetRects = {
diff --git a/ui/apps/chat/tests/unit/markdown-structure.test.ts b/ui/apps/chat/tests/unit/markdown-structure.test.ts
deleted file mode 100644
index 868bd5112..000000000
--- a/ui/apps/chat/tests/unit/markdown-structure.test.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { hasMarkdownStructure } from '#lib/components/app/content/MarkdownEditor/markdown-structure.ts';
-import { describe, expect, it } from 'vitest';
-
-describe('hasMarkdownStructure', () => {
-	it('is false for plain paragraphs, inline markup included', () => {
-		expect(hasMarkdownStructure('')).toBe(false);
-		expect(hasMarkdownStructure('hello world')).toBe(false);
-		expect(hasMarkdownStructure('one\n\ntwo')).toBe(false);
-		expect(hasMarkdownStructure('some **bold**, `code` and [a](file:///tmp/a.md)')).toBe(false);
-		expect(hasMarkdownStructure('/model is broken')).toBe(false);
-	});
-
-	it('is true for any other block', () => {
-		expect(hasMarkdownStructure('# Title')).toBe(true);
-		expect(hasMarkdownStructure('text\n\n- item')).toBe(true);
-		expect(hasMarkdownStructure('1. first')).toBe(true);
-		expect(hasMarkdownStructure('> quote')).toBe(true);
-		expect(hasMarkdownStructure('```js\nconst a = 1;\n```')).toBe(true);
-		expect(hasMarkdownStructure('| a | b |\n| - | - |\n| 1 | 2 |')).toBe(true);
-		expect(hasMarkdownStructure('---')).toBe(true);
-	});
-});