From 64f8b8ee0cb3e67e5edfc6842fd37496d7bee84a Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:52:47 -0800 Subject: [PATCH] Preserve send windows across transcript replacement --- .../transcript-input-content.perf.test.ts | 35 ++++- .../native-chat-incremental-assembler.ts | 6 +- .../use-native-chat-assembled-messages.ts | 13 +- .../delivery/native-chat-pending.test.ts | 2 +- .../terminal/delivery/native-chat-pending.ts | 35 ++++- .../use-native-chat-pending-delivery.test.tsx | 147 ++++++++++++++++++ .../use-native-chat-pending-delivery.ts | 13 +- .../read/native-chat-live-session-contract.ts | 2 + .../read/use-native-chat-live-session.ts | 15 +- .../transcript/native-chat-source-receipts.ts | 56 +++++-- 10 files changed, 286 insertions(+), 38 deletions(-) diff --git a/src/main/native-chat/transcript-input-content.perf.test.ts b/src/main/native-chat/transcript-input-content.perf.test.ts index d530f3e7a29..f0b1f652f12 100644 --- a/src/main/native-chat/transcript-input-content.perf.test.ts +++ b/src/main/native-chat/transcript-input-content.perf.test.ts @@ -171,9 +171,14 @@ it.each([1000, 10000])('does no glue work on %i rows preceding live legacy bound } }) -it.each([8, 80])( - 'bounds allocation work for eight identical legacy sends across %i eligible rows', - (rows) => { +it.each([ + [8, 'continue'], + [80, 'continue'], + [8, 'continue continue'], + [80, 'continue continue'] +] as const)( + 'bounds allocation work for eight identical legacy sends across %i eligible rows of %s', + (rows, text) => { const count = 8 const pending: NativeChatPendingSend[] = Array.from({ length: count }, (_, index) => ({ id: `same-${index}`, @@ -181,12 +186,17 @@ it.each([8, 80])( sentAt: 1 })) const messages = [ - ...Array.from({ length: rows }, (_, index) => user('continue', `same-row-${index}`)), + ...Array.from({ length: rows }, (_, index) => user(text, `same-row-${index}`)), { ...user('', 'reply'), role: 'assistant' as const } ] const BaseMap = globalThis.Map let writes = 0 + let lookups = 0 class CountingMap extends BaseMap { + override get(key: K): V | undefined { + lookups++ + return super.get(key) + } override set(key: K, value: V): this { writes++ return super.set(key, value) @@ -194,13 +204,26 @@ it.each([8, 80])( } vi.stubGlobal('Map', CountingMap) try { - expect(prunePendingSends(pending, messages)).toEqual([]) + const startedAt = performance.now() + const remaining = prunePendingSends(pending, messages) + const elapsedMs = performance.now() - startedAt + const allocationLookups = lookups + expect(remaining).toEqual([]) // Eight legal row alternatives per signature; each state assigns, requires or omits each send. const states = 3 ** count const witnessesPerRow = 2 ** count - 1 + count const maxAllocationWrites = count * states * (witnessesPerRow + 1) expect(writes).toBeLessThanOrEqual(maxAllocationWrites + rows + 2 ** count) - console.info('legacy allocation count', { rows, pending: count, mapWrites: writes }) + // Every candidate allocates before its next-state lookup, including candidates never written. + expect(allocationLookups).toBeLessThanOrEqual(maxAllocationWrites + rows * count + 2 ** count) + console.info('legacy allocation count', { + rows, + text, + pending: count, + mapWrites: writes, + candidateAllocationUpperBound: allocationLookups, + elapsedMs + }) } finally { vi.stubGlobal('Map', BaseMap) } diff --git a/src/renderer/src/components/native-chat/session/terminal/assembly/native-chat-incremental-assembler.ts b/src/renderer/src/components/native-chat/session/terminal/assembly/native-chat-incremental-assembler.ts index 8e62d665443..8d58565a7ff 100644 --- a/src/renderer/src/components/native-chat/session/terminal/assembly/native-chat-incremental-assembler.ts +++ b/src/renderer/src/components/native-chat/session/terminal/assembly/native-chat-incremental-assembler.ts @@ -9,6 +9,8 @@ import { compareNativeChatDisplayMessages as compareMessages } from '../../../.. import { mergeOne, sortForImageNormalization } from './native-chat-session-assembler' export type IncrementalChatAssembler = { + /** Changes whenever the published list is not an extension of its previous prefix. */ + generation: object byId: Map byTurn: Map // Last emitted sorted output; stable reference until a mutation occurs. @@ -16,7 +18,7 @@ export type IncrementalChatAssembler = { } export function createIncrementalAssembler(): IncrementalChatAssembler { - return { byId: new Map(), byTurn: new Map(), messages: [] } + return { generation: {}, byId: new Map(), byTurn: new Map(), messages: [] } } /** Reset from a windowed base using the canonical transcript-only assembly path. */ @@ -29,6 +31,7 @@ export function reset( for (const message of base) { mergeOne(assembler.byId, assembler.byTurn, message) } + assembler.generation = {} assembler.messages = [...sortForImageNormalization(Array.from(assembler.byId.values()))] return assembler.messages } @@ -56,6 +59,7 @@ export function applyAppends( return assembler.messages } + assembler.generation = {} assembler.messages = [...sortForImageNormalization(Array.from(assembler.byId.values()))] return assembler.messages } diff --git a/src/renderer/src/components/native-chat/session/terminal/assembly/use-native-chat-assembled-messages.ts b/src/renderer/src/components/native-chat/session/terminal/assembly/use-native-chat-assembled-messages.ts index 7a73061ac16..2fe5d860c93 100644 --- a/src/renderer/src/components/native-chat/session/terminal/assembly/use-native-chat-assembled-messages.ts +++ b/src/renderer/src/components/native-chat/session/terminal/assembly/use-native-chat-assembled-messages.ts @@ -19,6 +19,7 @@ type AssemblyCache = { function cloneAssembler(assembler: IncrementalChatAssembler): IncrementalChatAssembler { return { + generation: assembler.generation, byId: new Map(assembler.byId), byTurn: new Map(assembler.byTurn), messages: assembler.messages @@ -44,7 +45,11 @@ export function useNativeChatAssembledMessages(args: { sessionId: string | null baseMessages: readonly NativeChatMessage[] appended: NativeChatMessage[] -}): { assembledMessages: NativeChatMessage[]; normalizedMessages: NativeChatMessage[] } { +}): { + assembledMessages: NativeChatMessage[] + normalizedMessages: NativeChatMessage[] + sourceObservation: { messages: readonly NativeChatMessage[]; generation: object } +} { const committedCacheRef = useRef(null) const { agent, sessionId, baseMessages, appended } = args @@ -83,5 +88,9 @@ export function useNativeChatAssembledMessages(args: { () => prepareNativeChatLiveMessages(assembly.assembledMessages, agent), [agent, assembly.assembledMessages] ) - return { assembledMessages: assembly.assembledMessages, normalizedMessages } + const sourceObservation = useMemo( + () => ({ messages: assembly.assembledMessages, generation: assembly.assembler.generation }), + [assembly] + ) + return { assembledMessages: assembly.assembledMessages, normalizedMessages, sourceObservation } } diff --git a/src/renderer/src/components/native-chat/session/terminal/delivery/native-chat-pending.test.ts b/src/renderer/src/components/native-chat/session/terminal/delivery/native-chat-pending.test.ts index 116331cd870..b6309543222 100644 --- a/src/renderer/src/components/native-chat/session/terminal/delivery/native-chat-pending.test.ts +++ b/src/renderer/src/components/native-chat/session/terminal/delivery/native-chat-pending.test.ts @@ -275,7 +275,7 @@ it.each([5000, 50000])( observePendingSendCache(scope, [history[0]], session) observePendingSendCache(scope, [{ ...next, id: 'disjoint' }], session) const [entry] = appendPendingSendCache(scope, send('new-send', 'old')) - expect(entry.afterMessageId).toBe('frontier') + expect(entry.sourceBoundary?.id).toBe('frontier') } ) diff --git a/src/renderer/src/components/native-chat/session/terminal/delivery/native-chat-pending.ts b/src/renderer/src/components/native-chat/session/terminal/delivery/native-chat-pending.ts index aaebf7a72dd..9b41c6910ec 100644 --- a/src/renderer/src/components/native-chat/session/terminal/delivery/native-chat-pending.ts +++ b/src/renderer/src/components/native-chat/session/terminal/delivery/native-chat-pending.ts @@ -27,6 +27,7 @@ type PendingOwner = { pending: NativeChatPendingSend[] boundary?: NativeChatSourceBoundary sessionId?: string + search?: { generation: object; length: number; found: boolean } } const pendingSendCache = new Map() let pendingSendCounter = 0 @@ -54,7 +55,8 @@ export function writePendingSendCache( export function observePendingSendCache( scope: NativeChatPendingSendScope, messages: readonly NativeChatMessage[], - sessionId: string + sessionId: string, + generation?: object ): void { const key = pendingSendScopeKey(scope) const owner = pendingSendCache.get(key) ?? { pending: [] } @@ -63,7 +65,12 @@ export function observePendingSendCache( const message = last?.source === 'transcript' ? last : undefined if (!message) { if (owner.sessionId !== sessionId) { - setBoundedScopeCacheEntry(pendingSendCache, key, { ...owner, sessionId, boundary: undefined }) + setBoundedScopeCacheEntry(pendingSendCache, key, { + ...owner, + sessionId, + boundary: undefined, + search: undefined + }) } return } @@ -73,14 +80,28 @@ export function observePendingSendCache( previous.position?.kind === position?.kind && previous.position?.value === position?.value ) { + if ( + generation && + (owner.search?.generation !== generation || owner.search.length !== messages.length) + ) { + setBoundedScopeCacheEntry(pendingSendCache, key, { + ...owner, + search: { generation, length: messages.length, found: true } + }) + } return } let advances = !previous + const search = owner.sessionId === sessionId ? owner.search : undefined + const extension = + generation && search?.generation === generation && search.length <= messages.length if (previous) { if (position && previous.position?.kind === position.kind) { advances = position.value > previous.position.value } else { - for (let index = messages.length - 2; index >= 0; index--) { + advances = extension ? search.found : false + const start = extension ? search.length : 0 + for (let index = messages.length - 2; !advances && index >= start; index--) { if (messages[index].id === previous.id) { advances = true break @@ -88,10 +109,11 @@ export function observePendingSendCache( } } } - if (owner.sessionId !== sessionId || (message && advances)) { + if (generation || owner.sessionId !== sessionId || advances) { setBoundedScopeCacheEntry(pendingSendCache, key, { ...owner, sessionId, + search: generation ? { generation, length: messages.length, found: advances } : undefined, boundary: message && advances ? { sessionId, id: message.id, timestamp: message.timestamp, position } @@ -122,10 +144,7 @@ export function appendPendingSendCache( entry.afterEmptyTranscriptSessionId === boundary.sessionId) ? { ...entry, - sourceBoundary: boundary, - afterMessageId: boundary.id, - afterMessageTimestamp: boundary.timestamp, - afterEmptyTranscriptSessionId: undefined + sourceBoundary: boundary } : entry const next = entry.sourceAgent ? captured : assignNativeChatPendingOccurrence(existing, captured) diff --git a/src/renderer/src/components/native-chat/session/terminal/delivery/use-native-chat-pending-delivery.test.tsx b/src/renderer/src/components/native-chat/session/terminal/delivery/use-native-chat-pending-delivery.test.tsx index 77098648980..b3068d62700 100644 --- a/src/renderer/src/components/native-chat/session/terminal/delivery/use-native-chat-pending-delivery.test.tsx +++ b/src/renderer/src/components/native-chat/session/terminal/delivery/use-native-chat-pending-delivery.test.tsx @@ -5,6 +5,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { NativeChatMessage } from '../../../../../../../shared/native-chat/native-chat-types' import { useNativeChatPendingDelivery } from './use-native-chat-pending-delivery' import { clearPendingSendCacheForTests } from './native-chat-pending' +import * as pendingOwner from './native-chat-pending' +import { useNativeChatAssembledMessages } from '../assembly/use-native-chat-assembled-messages' const boundary: NativeChatMessage = { id: 'boundary', @@ -31,9 +33,114 @@ beforeEach(() => { }) afterEach(() => { cleanup() + vi.restoreAllMocks() vi.useRealTimers() }) +it.each([200, 2000])( + 'searches only the source suffix after a disjoint %i-row reconnect publication', + (size) => { + let observing = false + let reads = 0 + const originalObserve = pendingOwner.observePendingSendCache + vi.spyOn(pendingOwner, 'observePendingSendCache').mockImplementation((...input) => { + observing = true + try { + return originalObserve(...input) + } finally { + observing = false + } + }) + const initial = { ...boundary, id: 'original-frontier', timestamp: 1 } + const first = { ...boundary, id: 'append-one', timestamp: 10_000 } + const second = { ...boundary, id: 'append-two', timestamp: 10_001 } + const disjoint = Array.from({ length: size }, (_, index) => ({ + ...boundary, + timestamp: index + 100, + get id() { + if (observing) { + reads++ + } + return `disjoint-${index}` + } + })) + const empty: NativeChatMessage[] = [] + const mounted = renderHook( + ({ baseMessages, appended }) => { + const assembly = useNativeChatAssembledMessages({ + agent: 'claude', + sessionId: 'session', + baseMessages, + appended + }) + return useNativeChatPendingDelivery({ + ...args, + session: { + messages: assembly.normalizedMessages, + sourceObservation: assembly.sourceObservation, + readPhase: 'ready', + sessionId: 'session' + } + }) + }, + { initialProps: { baseMessages: [initial], appended: empty } } + ) + mounted.rerender({ baseMessages: disjoint, appended: empty }) + expect(reads).toBeLessThanOrEqual(size + 2) + reads = 0 + mounted.rerender({ baseMessages: disjoint, appended: [first] }) + expect(reads).toBeLessThanOrEqual(2) + reads = 0 + mounted.rerender({ baseMessages: disjoint, appended: [first, second] }) + expect(reads).toBeLessThanOrEqual(2) + act(() => mounted.result.current.record('waiting', undefined, false, 'claude')) + expect(mounted.result.current.pending[0].sourceBoundary?.id).toBe('original-frontier') + // A newly paged base can restore overlap; a miss never promotes an unfamiliar tail. + mounted.rerender({ baseMessages: [initial, ...disjoint], appended: [first, second] }) + act(() => mounted.result.current.record('later', undefined, false, 'claude')) + expect(mounted.result.current.pending.at(-1)?.sourceBoundary?.id).toBe('append-two') + } +) + +it('keeps a new old-host Send behind its visible window after a disjoint reconnect', () => { + vi.setSystemTime(4000) + type Session = Parameters[0]['session'] + const initial: Session = { + messages: [{ ...boundary, id: 'A', timestamp: 1000 }], + readPhase: 'ready', + sessionId: 'session' + } + const mounted = renderHook(({ session }) => useNativeChatPendingDelivery({ ...args, session }), { + initialProps: { session: initial } + }) + const old = [ + { ...userRow('repeat'), id: 'old-user', timestamp: 2000 }, + { ...boundary, id: 'B', timestamp: 3000 } + ] + mounted.rerender({ session: { ...initial, messages: old } }) + let id = '' + act(() => { + id = mounted.result.current.record('repeat', undefined, false, 'claude') + mounted.result.current.useSourceEvidence(id, false) + }) + expect(mounted.result.current.pending.map((entry) => entry.id)).toEqual([id]) + const unrelated = { ...userRow('other'), id: 'unrelated', timestamp: 4100 } + mounted.rerender({ session: { ...initial, messages: [...old, unrelated] } }) + expect(mounted.result.current.pending.map((entry) => entry.id)).toEqual([id]) + mounted.rerender({ + session: { + ...initial, + messages: [ + ...old, + unrelated, + { ...userRow('repeat'), id: 'genuine-user', timestamp: 4200 }, + { ...boundary, id: 'genuine-answer', timestamp: 4300 } + ] + } + }) + expect(mounted.result.current.pending).toEqual([]) +}) + describe('terminal Chat pending delivery', () => { it('keeps uncertain queued input pending until an authoritative session can observe its turn', () => { const initialSession: Parameters[0]['session'] = { @@ -188,6 +295,46 @@ function sourceRow(text: string, id = `source:${text}`): NativeChatMessage { } } +it.each([true, false])( + 'keeps a source=%s survivor behind its timestamp after the session changes', + (source) => { + vi.setSystemTime(4000) + type Session = Parameters[0]['session'] + const initial: Session = { + messages: [{ ...boundary, id: 'reused-boundary', timestamp: 1000 }], + readPhase: 'ready', + sessionId: 'A' + } + const mounted = renderHook( + ({ session }) => useNativeChatPendingDelivery({ ...args, agent: 'opencode', session }), + { initialProps: { session: initial } } + ) + let id = '' + act(() => { + id = mounted.result.current.record('repeat', undefined, false, 'opencode') + mounted.result.current.useSourceEvidence(id, source) + }) + const old = [ + { ...sourceRow('repeat', 'old-user'), timestamp: 500 }, + { ...boundary, id: 'reused-boundary', timestamp: 600 } + ] + mounted.rerender({ session: { ...initial, sessionId: 'B', messages: old } }) + expect(mounted.result.current.pending.map((entry) => entry.id)).toEqual([id]) + mounted.rerender({ + session: { + ...initial, + sessionId: 'B', + messages: [ + ...old, + { ...sourceRow('repeat', 'new-user'), timestamp: 4100 }, + { ...boundary, id: 'new-answer', timestamp: 4200 } + ] + } + }) + expect(mounted.result.current.pending).toEqual([]) + } +) + it('assigns identical legacy occurrences at the real capability fallback and never double-charges a spent row', () => { const first = mountOwned() let one = '', diff --git a/src/renderer/src/components/native-chat/session/terminal/delivery/use-native-chat-pending-delivery.ts b/src/renderer/src/components/native-chat/session/terminal/delivery/use-native-chat-pending-delivery.ts index ce9dae41730..5dbb3e32fcf 100644 --- a/src/renderer/src/components/native-chat/session/terminal/delivery/use-native-chat-pending-delivery.ts +++ b/src/renderer/src/components/native-chat/session/terminal/delivery/use-native-chat-pending-delivery.ts @@ -20,7 +20,7 @@ import { writePendingSendCache } from './native-chat-pending' import type { NativeChatDeliveryNotice } from '../../../messages/rows/NativeChatMessageRow' -import type { ReadState } from '../read/native-chat-live-session-contract' +import type { NativeChatLiveSession, ReadState } from '../read/native-chat-live-session-contract' /** Wait for transcript evidence after lost write acknowledgment; mobile uses the same hold. */ export const NATIVE_CHAT_UNCONFIRMED_SEND_HOLD_MS = 20_000 @@ -38,12 +38,14 @@ export function useNativeChatPendingDelivery(args: { messages: NativeChatMessage[] readPhase?: ReadState['phase'] sessionId?: string | null + sourceObservation?: NativeChatLiveSession['sourceObservation'] } }) { const t = useTranslate() const languageRevision = useUiLanguageRevision() const { paneKey, agent, composerRef, workingEpoch } = args const { messages } = args.session + const sourceObservation = args.session.sourceObservation const sessionId = args.session.sessionId ?? null // Without a sessionId, ready is an unread placeholder. const readEmptySessionId = @@ -72,12 +74,17 @@ export function useNativeChatPendingDelivery(args: { ) useEffect(() => { if (args.session.readPhase === 'ready' && sessionId) { - observePendingSendCache(scope, messages, sessionId) + observePendingSendCache( + scope, + sourceObservation?.messages ?? messages, + sessionId, + sourceObservation?.generation + ) } save((entries) => prunePendingSends(releaseEmptyTranscriptClaims(entries, sessionId), messages, sessionId ?? '') ) - }, [messages, save, sessionId, scope, args.session.readPhase]) + }, [messages, sourceObservation, save, sessionId, scope, args.session.readPhase]) const record = useCallback( (text: string, imagePaths?: string[], recovery = false, sourceAgent?: AgentType) => { const sentAt = Date.now() diff --git a/src/renderer/src/components/native-chat/session/terminal/read/native-chat-live-session-contract.ts b/src/renderer/src/components/native-chat/session/terminal/read/native-chat-live-session-contract.ts index 6613b47c50c..ba8995ec758 100644 --- a/src/renderer/src/components/native-chat/session/terminal/read/native-chat-live-session-contract.ts +++ b/src/renderer/src/components/native-chat/session/terminal/read/native-chat-live-session-contract.ts @@ -19,6 +19,8 @@ export function isNativeChatTranscriptUnsettled(phase: ReadState['phase']): bool } export type NativeChatLiveSession = NativeChatSession & { + /** Canonical source publication paired with its append/reset provenance, before display folding. */ + sourceObservation?: { messages: readonly NativeChatMessage[]; generation: object } /** Latest provider turn boundary, used to settle orphaned running tool rows. */ transcriptLifecycle?: NativeChatTurnLifecycle /** Hook-reported human wait not yet ended by the transcript; absent on hookless lanes. */ diff --git a/src/renderer/src/components/native-chat/session/terminal/read/use-native-chat-live-session.ts b/src/renderer/src/components/native-chat/session/terminal/read/use-native-chat-live-session.ts index 4af7c08cf96..3a6759f46d8 100644 --- a/src/renderer/src/components/native-chat/session/terminal/read/use-native-chat-live-session.ts +++ b/src/renderer/src/components/native-chat/session/terminal/read/use-native-chat-live-session.ts @@ -287,12 +287,13 @@ export function useNativeChatLiveSession( // Keep status-only hook updates from rerunning the assembler. const baseMessages = read.phase === 'ready' ? read.messages : EMPTY_MESSAGES - const { assembledMessages, normalizedMessages } = useNativeChatAssembledMessages({ - agent, - sessionId, - baseMessages, - appended - }) + const { assembledMessages, normalizedMessages, sourceObservation } = + useNativeChatAssembledMessages({ + agent, + sessionId, + baseMessages, + appended + }) return useMemo(() => { const session = mergeNativeChatLiveSession({ @@ -310,6 +311,7 @@ export function useNativeChatLiveSession( }) return { ...session, + sourceObservation, hasMore, loadingEarlier, olderHistoryGeneration, @@ -319,6 +321,7 @@ export function useNativeChatLiveSession( } }, [ normalizedMessages, + sourceObservation, assembledMessages, read, sessionId, diff --git a/src/shared/native-chat/transcript/native-chat-source-receipts.ts b/src/shared/native-chat/transcript/native-chat-source-receipts.ts index a890cdecd32..5aa5a4250a6 100644 --- a/src/shared/native-chat/transcript/native-chat-source-receipts.ts +++ b/src/shared/native-chat/transcript/native-chat-source-receipts.ts @@ -65,21 +65,55 @@ export function nativeChatReceiptWindow( ): (row: NativeChatReceiptRow) => boolean { const boundary = entry.sourceBoundary const sameSession = boundary?.sessionId === sessionId - const boundaryId = boundary && !sameSession ? undefined : entry.afterMessageId - const boundaryIndex = sameSession - ? snapshot.boundaries.get(boundary.id) - : boundaryId - ? snapshot.boundaries.get(boundaryId) - : undefined - return ({ message, index }) => { - const position = nativeChatSourcePosition(message) - if (sameSession && boundary.position && position?.kind === boundary.position.kind) { - return position.value > boundary.position.value + const original = receiptWindowAfter( + boundary && !sameSession ? { ...entry, afterMessageId: null } : entry, + snapshot, + sessionId, + glue + ) + if (!sameSession) { + return original + } + const frontier = receiptWindowAfter( + { + ...entry, + afterMessageId: boundary.id, + afterMessageTimestamp: boundary.timestamp, + matchingAfterTimestamp: undefined, + afterEmptyTranscriptSessionId: undefined + }, + snapshot, + sessionId, + glue + ) + return (row) => { + const position = nativeChatSourcePosition(row.message) + if (boundary.position && position?.kind === boundary.position.kind) { + return ( + position.value > boundary.position.value && + (boundary.id === entry.afterMessageId || original(row)) + ) } + if (!original(row)) { + return false + } + return frontier(row) + } +} + +function receiptWindowAfter( + entry: NativeChatPendingSend, + snapshot: NativeChatReceiptSnapshot, + sessionId: string, + glue: boolean +): (row: NativeChatReceiptRow) => boolean { + const boundaryId = entry.afterMessageId + const boundaryIndex = boundaryId ? snapshot.boundaries.get(boundaryId) : undefined + return ({ message, index }) => { if (boundaryIndex !== undefined) { return index > boundaryIndex } - if (!boundary && boundaryId === undefined && !glue) { + if (boundaryId === undefined && !glue) { return true } if (