perf: skip stale replay concat for large pty chunks (#3915)
This commit is contained in:
@@ -26,7 +26,12 @@ import {
|
||||
import { getBranchConflictKind, getDefaultBaseRef } from '../git/repo'
|
||||
import type { OrchestrationDb } from './orchestration/db'
|
||||
import type { MessagePriority, MessageRow, MessageType } from './orchestration/types'
|
||||
import { appendNormalizedToTailBuffer, buildPreview, OrcaRuntimeService } from './orca-runtime'
|
||||
import {
|
||||
appendNormalizedToTailBuffer,
|
||||
appendRecentPtyOutput,
|
||||
buildPreview,
|
||||
OrcaRuntimeService
|
||||
} from './orca-runtime'
|
||||
import {
|
||||
registerSshFilesystemProvider,
|
||||
unregisterSshFilesystemProvider
|
||||
@@ -3964,6 +3969,16 @@ describe('OrcaRuntimeService', () => {
|
||||
expect(mapCallCount).toBe(0)
|
||||
})
|
||||
|
||||
it('keeps recent PTY replay output capped without needing previous data for large chunks', () => {
|
||||
const previous = 'old-output'.repeat(1000)
|
||||
const data = 'new-output'.repeat(1000)
|
||||
const expected = `${previous}${data}`.slice(-4096)
|
||||
|
||||
expect(appendRecentPtyOutput(previous, 'tail')).toBe(`${previous}tail`.slice(-4096))
|
||||
expect(appendRecentPtyOutput(previous, data)).toBe(expected)
|
||||
expect(appendRecentPtyOutput(undefined, data)).toBe(data.slice(-4096))
|
||||
})
|
||||
|
||||
it('bounds retained partial terminal output before preview reads', async () => {
|
||||
const runtime = new OrcaRuntimeService(store)
|
||||
|
||||
|
||||
@@ -2257,7 +2257,7 @@ export class OrcaRuntimeService {
|
||||
this.ptyOutputSequenceById.set(ptyId, outputSequence)
|
||||
this.recentPtyOutputById.set(
|
||||
ptyId,
|
||||
`${this.recentPtyOutputById.get(ptyId) ?? ''}${data}`.slice(-RECENT_PTY_OUTPUT_LIMIT)
|
||||
appendRecentPtyOutput(this.recentPtyOutputById.get(ptyId), data)
|
||||
)
|
||||
// Agent detection runs on raw data before leaf processing, since the
|
||||
// tail buffer logic normalizes away the OSC sequences we need.
|
||||
@@ -12665,6 +12665,13 @@ function withTimeoutResult<T>(
|
||||
})
|
||||
}
|
||||
|
||||
export function appendRecentPtyOutput(previous: string | undefined, data: string): string {
|
||||
if (data.length >= RECENT_PTY_OUTPUT_LIMIT) {
|
||||
return data.slice(-RECENT_PTY_OUTPUT_LIMIT)
|
||||
}
|
||||
return `${previous ?? ''}${data}`.slice(-RECENT_PTY_OUTPUT_LIMIT)
|
||||
}
|
||||
|
||||
export function buildPreview(lines: string[], partialLine: string): string {
|
||||
const previewLines: string[] = []
|
||||
const collectVisibleLine = (line: string): void => {
|
||||
|
||||
Reference in New Issue
Block a user