Fix OpenCode TUI scroll regression

Revert the May 23 terminal perf restore path and cap retained newline-free TUI redraw output while keeping completed-line terminal read pagination.
This commit is contained in:
Neil
2026-05-23 17:16:35 -07:00
committed by GitHub
parent 3233a41215
commit 82a461c66e
32 changed files with 258 additions and 1632 deletions
+35 -8
View File
@@ -3455,7 +3455,7 @@ describe('OrcaRuntimeService', () => {
expect(futureCursorRead.limited).toBe(false)
})
it('bounds preview reads by characters for long partial terminal output', async () => {
it('bounds retained partial terminal output before preview reads', async () => {
const runtime = new OrcaRuntimeService(store)
runtime.attachWindow(1)
@@ -3481,16 +3481,43 @@ describe('OrcaRuntimeService', () => {
})
const [terminal] = (await runtime.listTerminals()).terminals
const longPartialLine = `${'x'.repeat(40_000)}tail-marker`
runtime.onPtyData('pty-1', longPartialLine, 100)
runtime.onPtyData(
'pty-1',
`${Array.from({ length: 2000 }, (_, index) => `line-${index}`).join('\n')}\n`,
99
)
runtime.onPtyData('pty-1', `${'x'.repeat(40_000)}tail-marker-0`, 100)
type RetainedTailState = {
tailBuffer: string[]
tailPartialLine: string
tailTruncated: boolean
}
const cappedPartialState = (
runtime as unknown as {
ptysById: Map<string, RetainedTailState>
}
).ptysById.get('pty-1')
const retainedLineBuffer = cappedPartialState?.tailBuffer
for (let index = 1; index < 5; index += 1) {
runtime.onPtyData('pty-1', `${'x'.repeat(40_000)}tail-marker-${index}`, 100 + index)
}
const retained = (
runtime as unknown as {
ptysById: Map<string, RetainedTailState>
}
).ptysById.get('pty-1')
expect(retained?.tailBuffer).toBe(retainedLineBuffer)
expect(retained?.tailPartialLine).toHaveLength(4000)
expect(retained?.tailPartialLine.endsWith('tail-marker-4')).toBe(true)
expect(retained?.tailTruncated).toBe(true)
const preview = await runtime.readTerminal(terminal.handle)
expect(preview.tail).toHaveLength(1)
expect(preview.tail[0]).toHaveLength(32 * 1024)
expect(preview.tail[0].endsWith('tail-marker')).toBe(true)
expect(preview.limited).toBe(true)
expect(preview.tail).toHaveLength(120)
expect(preview.tail.at(-1)).toHaveLength(4000)
expect(preview.tail.at(-1)?.endsWith('tail-marker-4')).toBe(true)
expect(preview.truncated).toBe(true)
expect(preview.nextCursor).toBe('0')
expect(preview.nextCursor).toBe('2000')
})
it('delivers pending orchestration messages to an already-idle agent', async () => {
+23 -8
View File
@@ -11822,6 +11822,7 @@ export class OrcaRuntimeService {
const MAX_TAIL_LINES = 2000
const MAX_TAIL_CHARS = 256 * 1024
const MAX_TAIL_PARTIAL_CHARS = 4000
const DEFAULT_TERMINAL_READ_LIMIT = 120
const MAX_TERMINAL_READ_LIMIT = 2000
const MAX_TERMINAL_PREVIEW_CHARS = 32 * 1024
@@ -11931,26 +11932,40 @@ function appendToTailBuffer(
}
}
const pieces = `${previousPartialLine}${normalizedChunk}`.split('\n')
// Why: fullscreen TUIs often emit long, newline-free redraw streams. Keep the
// larger line transcript for pagination, but keep partial-line work bounded.
const previousPartialWasCapped = previousPartialLine.length > MAX_TAIL_PARTIAL_CHARS
const boundedPreviousPartialLine = previousPartialLine.slice(-MAX_TAIL_PARTIAL_CHARS)
const pieces = `${boundedPreviousPartialLine}${normalizedChunk}`.split('\n')
const nextPartialLine = (pieces.pop() ?? '').replace(/[ \t]+$/g, '')
const retainedPartialLine = nextPartialLine.slice(-MAX_TAIL_PARTIAL_CHARS)
const newCompleteLines = pieces.length
const nextLines = [...previousLines, ...pieces.map((line) => line.replace(/[ \t]+$/g, ''))]
let truncated = false
let nextLines =
newCompleteLines > 0
? [...previousLines, ...pieces.map((line) => line.replace(/[ \t]+$/g, ''))]
: previousLines
let truncated = previousPartialWasCapped || nextPartialLine.length > MAX_TAIL_PARTIAL_CHARS
while (nextLines.length > MAX_TAIL_LINES) {
nextLines.shift()
truncated = true
}
let totalChars = nextLines.reduce((sum, line) => sum + line.length, 0) + nextPartialLine.length
while (nextLines.length > 0 && totalChars > MAX_TAIL_CHARS) {
totalChars -= nextLines.shift()!.length
truncated = true
if (newCompleteLines > 0 || retainedPartialLine.length > previousPartialLine.length) {
if (nextLines === previousLines) {
nextLines = [...previousLines]
}
let totalChars =
nextLines.reduce((sum, line) => sum + line.length, 0) + retainedPartialLine.length
while (nextLines.length > 0 && totalChars > MAX_TAIL_CHARS) {
totalChars -= nextLines.shift()!.length
truncated = true
}
}
return {
lines: nextLines,
partialLine: nextPartialLine.slice(-MAX_TAIL_CHARS),
partialLine: retainedPartialLine,
truncated,
newCompleteLines
}