Delete the hidden renderer skip grammar
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -175,9 +175,6 @@ closed by the slice-3 `initiallyHidden` spawn flag (races section).
|
||||
|
||||
- Visible or unmarked PTY (chunk was delivered).
|
||||
- Renderer delivery interest registered (chunk was delivered to a sidecar).
|
||||
- Codex startup window active — the renderer never marks the PTY hidden while
|
||||
the window runs (`pty-connection.ts:2259-2261`), so the gate predicate is
|
||||
structurally false; the live xterm answers startup probes.
|
||||
- Remote-runtime (`remote:`) PTYs — never markable
|
||||
(`isHiddenDeliveryGateManagedPty`), bytes never transit local main.
|
||||
- Remote view subscriber attached (mobile/web/remote desktop owns replies).
|
||||
@@ -210,13 +207,12 @@ point per chunk); where the race costs anything it costs a missing reply.
|
||||
That is acceptable for state queries (DSR/CPR/DECRPM — TUIs re-probe or
|
||||
tolerate silence, as they did for every hidden pane before this phase). The
|
||||
one blocking-on-no-reply sequence, ConPTY DA1, only fires at spawn. A visible
|
||||
pane or an active codex startup window answers it from the renderer xterm.
|
||||
A PTY spawned hidden **without** the startup window previously had no
|
||||
answerer until the renderer's hidden mark landed in main (one IPC hop after
|
||||
spawn). Slice 3 closes that window with the `initiallyHidden` spawn-record
|
||||
flag: the renderer declares hidden-at-spawn on `pty:spawn` (never while the
|
||||
codex startup window would run, and never for remote-runtime transports),
|
||||
and main marks the PTY hidden before the first byte — pre-spawn for
|
||||
pane answers it from the renderer xterm. A PTY spawned hidden previously had
|
||||
no answerer until the renderer's hidden mark landed in main (one IPC hop
|
||||
after spawn). Slice 3 closes that window with the `initiallyHidden`
|
||||
spawn-record flag: the renderer declares hidden-at-spawn on `pty:spawn`
|
||||
(never for remote-runtime transports), and main marks the PTY hidden before
|
||||
the first byte — pre-spawn for
|
||||
daemon-host sessions whose id is minted up front, immediately after
|
||||
`provider.spawn` resolves otherwise — so the gate and responder own queries
|
||||
from byte one. The pane's first visibility sync then re-marks or unmarks
|
||||
@@ -293,15 +289,20 @@ otherwise untouched in this phase.
|
||||
|
||||
## What Phase 6 (delete skip grammar + startup window) requires from this design
|
||||
|
||||
Phase 6 is shipped: the renderer hidden-skip eligibility grammar and the 10s
|
||||
codex startup renderer-query window are deleted. Kill-switch-off hidden panes
|
||||
fall back to the pre-grammar path — hidden bytes ride the bounded background
|
||||
scheduler queue; overflow latches the model-snapshot restore — and never run
|
||||
a per-chunk content scan.
|
||||
|
||||
Accepted and shipped in slice 3 (except where noted):
|
||||
|
||||
- **Mark-before-first-byte** (shipped): panes spawned without a visible view
|
||||
are hidden-marked at spawn via the `initiallyHidden` flag on `pty:spawn`
|
||||
(spawn-record flag, not a renderer round trip) so startup queries —
|
||||
including ConPTY's blocking DA1 — are main-owned from byte zero. Codex
|
||||
startup probes stay renderer-answered while the 10s window exists: the
|
||||
renderer never sets the flag for codex startups; once Phase 6 deletes the
|
||||
window, dropping that exclusion makes codex spawns main-owned too.
|
||||
including ConPTY's blocking DA1 — are main-owned from byte zero. Phase 6
|
||||
removed the codex exclusion with the window: codex spawns are main-owned
|
||||
from byte zero too, the responder answering their startup probes.
|
||||
- **Attributes before spawn** (shipped): the renderer pushes composed view
|
||||
attributes once at app start (right after settings load, before terminal
|
||||
reconnect/spawn), so spawn-time view-attribute queries no longer fall into
|
||||
|
||||
@@ -2219,7 +2219,6 @@ export function registerPtyHandlers(
|
||||
// §races) — the renderer knows at spawn time that no visible view
|
||||
// will consume this PTY's bytes, so main marks it hidden BEFORE the
|
||||
// first byte and the gate + model responder own spawn-time queries.
|
||||
// The renderer never sets this while the codex startup window runs.
|
||||
initiallyHidden?: boolean
|
||||
// Why: closes the SIGKILL race documented in INVESTIGATION.md by
|
||||
// letting main patch + sync-flush the (worktreeId, tabId, leafId →
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { shouldSkipHiddenRendererOutput } from './hidden-renderer-skip-eligibility'
|
||||
|
||||
describe('shouldSkipHiddenRendererOutput', () => {
|
||||
it('skips hidden plain ASCII output when a snapshot restore is available', () => {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data: 'line one\r\nline two\tok\n'
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('skips hidden width-stable Latin output when a snapshot restore is available', () => {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data: 'café déjà vu São Tomé Żubrówka Ḃḃ\r\n'
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps visible or non-restorable output on the live renderer path', () => {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: true,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data: 'visible\r\n'
|
||||
})
|
||||
).toBe(false)
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: false,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data: 'hidden\r\n'
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('skips complete hidden title OSC chunks when a snapshot restore is available', () => {
|
||||
for (const data of ['\x1b]0;window title\x07', '\x1b]1;icon title\x07', '\x1b]2;both\x1b\\']) {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data
|
||||
})
|
||||
).toBe(true)
|
||||
}
|
||||
})
|
||||
|
||||
it('skips hidden title OSC mixed with otherwise restorable plain output', () => {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data: 'line before\r\n\x1b]0;next title\x07line after\r\n'
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps hidden synchronized redraw chunks live without the model restore gate', () => {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: true,
|
||||
data: '\x1b[?2026h\x1b[1;1H\x1b[2J\x1b[32mready\x1b[0m\x1b[?25l\x1b[?2026l\n'
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('skips model-restorable synchronized rich chunks when model restore is allowed', () => {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: true,
|
||||
allowSynchronizedModelRestore: true,
|
||||
data: '\x1b[?2026h\x1b[?1049h\x1b[2J\x1b[H╭ rich 😀 ╮\r\n\x1b[?25l\x1b[?2026l'
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('skips synchronized model output with PTY-mapped CRCRLF newlines', () => {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: true,
|
||||
allowSynchronizedModelRestore: true,
|
||||
data: '\x1b[?2026h\x1b[2J\x1b[H╭ rich 😀 ╮\r\r\n\x1b[?2026l'
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps query and incomplete synchronized chunks live even with model restore allowed', () => {
|
||||
for (const data of [
|
||||
'\x1b[?2026h\x1b[6n',
|
||||
'\x1b[?2026h\x1b[c',
|
||||
'\x1b[?2026h\x1b[?25',
|
||||
'\x1b[?2026h\x9b6n'
|
||||
]) {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: true,
|
||||
allowSynchronizedModelRestore: true,
|
||||
data
|
||||
})
|
||||
).toBe(false)
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps startup query windows live', () => {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: true,
|
||||
synchronizedOutputActive: false,
|
||||
data: 'plain\r\n'
|
||||
})
|
||||
).toBe(false)
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: true,
|
||||
synchronizedOutputActive: false,
|
||||
data: '\x1b]0;title\x07'
|
||||
})
|
||||
).toBe(false)
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: true,
|
||||
synchronizedOutputActive: true,
|
||||
allowSynchronizedModelRestore: true,
|
||||
data: '\x1b[?2026h\x1b[2J\x1b[Hmodel-restorable\r\n\x1b[?2026l'
|
||||
})
|
||||
).toBe(false)
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data: '\x1b[?1;2c'
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps query and incomplete control chunks live', () => {
|
||||
for (const data of ['\x1b[6n', '\x1b[c', '\x1b[?25', '\x1b[?1049h']) {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data
|
||||
})
|
||||
).toBe(false)
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps non-title OSC and incomplete title OSC chunks live', () => {
|
||||
for (const data of ['\x1b]52;c;clipboard\x07', '\x1b]9;notify\x07', '\x1b]0;partial-title']) {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data
|
||||
})
|
||||
).toBe(false)
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps rewrite and wide or combining unicode chunks live', () => {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data: 'progress 10%\rprogress 20%'
|
||||
})
|
||||
).toBe(false)
|
||||
for (const data of ['emoji 😀\r\n', '漢字 table\r\n', 'combining e\u0301\r\n']) {
|
||||
expect(
|
||||
shouldSkipHiddenRendererOutput({
|
||||
foreground: false,
|
||||
canRestoreHiddenOutput: true,
|
||||
startupRendererQueryWindowActive: false,
|
||||
synchronizedOutputActive: false,
|
||||
data
|
||||
})
|
||||
).toBe(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1,188 +0,0 @@
|
||||
export type HiddenRendererSkipEligibility = {
|
||||
foreground: boolean
|
||||
canRestoreHiddenOutput: boolean
|
||||
startupRendererQueryWindowActive: boolean
|
||||
synchronizedOutputActive: boolean
|
||||
allowSynchronizedModelRestore?: boolean
|
||||
data: string
|
||||
}
|
||||
|
||||
function isAllowedPlainHiddenOutputCodePoint(codePoint: number): boolean {
|
||||
if (codePoint === 0x09 || codePoint === 0x0a) {
|
||||
return true
|
||||
}
|
||||
if (codePoint >= 0x20 && codePoint <= 0x7e) {
|
||||
return true
|
||||
}
|
||||
// Why: hidden restore can safely replay ordinary single-cell Latin text from
|
||||
// headless state, while wide/combining/table glyph classes stay live.
|
||||
return (
|
||||
(codePoint >= 0x00a0 && codePoint <= 0x024f) || (codePoint >= 0x1e00 && codePoint <= 0x1eff)
|
||||
)
|
||||
}
|
||||
|
||||
function findTitleOscEnd(data: string, startIndex: number): number | null {
|
||||
const command = data.charCodeAt(startIndex + 2)
|
||||
if (
|
||||
data.charCodeAt(startIndex) !== 0x1b ||
|
||||
data.charCodeAt(startIndex + 1) !== 0x5d ||
|
||||
(command !== 0x30 && command !== 0x31 && command !== 0x32) ||
|
||||
data.charCodeAt(startIndex + 3) !== 0x3b
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
for (let index = startIndex + 4; index < data.length; index++) {
|
||||
const code = data.charCodeAt(index)
|
||||
if (code === 0x07) {
|
||||
return index + 1
|
||||
}
|
||||
if (code === 0x1b) {
|
||||
return data.charCodeAt(index + 1) === 0x5c ? index + 2 : null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function findSafeCsiEnd(
|
||||
data: string,
|
||||
startIndex: number,
|
||||
mode: 'plain' | 'synchronized-model' = 'plain'
|
||||
): number | null {
|
||||
if (data.charCodeAt(startIndex) !== 0x1b || data.charCodeAt(startIndex + 1) !== 0x5b) {
|
||||
return null
|
||||
}
|
||||
|
||||
for (let index = startIndex + 2; index < data.length; index++) {
|
||||
const code = data.charCodeAt(index)
|
||||
if (code < 0x40 || code > 0x7e) {
|
||||
continue
|
||||
}
|
||||
const body = data.slice(startIndex + 2, index)
|
||||
const final = data[index]
|
||||
if (isSafeHiddenRedrawCsi(body, final, mode)) {
|
||||
return index + 1
|
||||
}
|
||||
return null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function isSafeHiddenRedrawCsi(
|
||||
body: string,
|
||||
final: string,
|
||||
mode: 'plain' | 'synchronized-model'
|
||||
): boolean {
|
||||
if (/[^0-9;?]/.test(body)) {
|
||||
return false
|
||||
}
|
||||
if (final === 'h' || final === 'l') {
|
||||
return body === '?2026' || body === '?25' || (mode === 'synchronized-model' && body === '?1049')
|
||||
}
|
||||
return (
|
||||
final === 'm' ||
|
||||
final === 'H' ||
|
||||
final === 'f' ||
|
||||
final === 'A' ||
|
||||
final === 'B' ||
|
||||
final === 'C' ||
|
||||
final === 'D' ||
|
||||
final === 'G' ||
|
||||
final === 'J' ||
|
||||
final === 'K'
|
||||
)
|
||||
}
|
||||
|
||||
function containsOnlyRestorableHiddenOutput(data: string): boolean {
|
||||
for (let index = 0; index < data.length; ) {
|
||||
const code = data.charCodeAt(index)
|
||||
if (code === 0x1b) {
|
||||
const nextIndex = findTitleOscEnd(data, index) ?? findSafeCsiEnd(data, index)
|
||||
if (nextIndex === null) {
|
||||
return false
|
||||
}
|
||||
index = nextIndex
|
||||
continue
|
||||
}
|
||||
if (code === 0x0d) {
|
||||
if (data.charCodeAt(index + 1) !== 0x0a) {
|
||||
return false
|
||||
}
|
||||
index += 1
|
||||
continue
|
||||
}
|
||||
const codePoint = data.codePointAt(index)
|
||||
if (typeof codePoint !== 'number' || !isAllowedPlainHiddenOutputCodePoint(codePoint)) {
|
||||
return false
|
||||
}
|
||||
index += codePoint > 0xffff ? 2 : 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function containsOnlyModelRestorableSynchronizedOutput(data: string): boolean {
|
||||
for (let index = 0; index < data.length; ) {
|
||||
const code = data.charCodeAt(index)
|
||||
if (code === 0x1b) {
|
||||
const nextIndex =
|
||||
findTitleOscEnd(data, index) ?? findSafeCsiEnd(data, index, 'synchronized-model')
|
||||
if (nextIndex === null) {
|
||||
return false
|
||||
}
|
||||
index = nextIndex
|
||||
continue
|
||||
}
|
||||
if (code === 0x0d) {
|
||||
let newlineIndex = index + 1
|
||||
// Why: real PTYs can map an app-written CRLF into CRCRLF. Treat only
|
||||
// CR runs that immediately end in LF as newlines, not cursor rewrites.
|
||||
while (data.charCodeAt(newlineIndex) === 0x0d) {
|
||||
newlineIndex += 1
|
||||
}
|
||||
if (data.charCodeAt(newlineIndex) !== 0x0a) {
|
||||
return false
|
||||
}
|
||||
index = newlineIndex + 1
|
||||
continue
|
||||
}
|
||||
const codePoint = data.codePointAt(index)
|
||||
if (
|
||||
typeof codePoint !== 'number' ||
|
||||
codePoint < 0x09 ||
|
||||
codePoint === 0x7f ||
|
||||
(codePoint >= 0x80 && codePoint <= 0x9f)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
if (codePoint < 0x20 && codePoint !== 0x09 && codePoint !== 0x0a) {
|
||||
return false
|
||||
}
|
||||
index += codePoint > 0xffff ? 2 : 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export function shouldSkipHiddenRendererOutput({
|
||||
foreground,
|
||||
canRestoreHiddenOutput,
|
||||
startupRendererQueryWindowActive,
|
||||
synchronizedOutputActive,
|
||||
allowSynchronizedModelRestore = false,
|
||||
data
|
||||
}: HiddenRendererSkipEligibility): boolean {
|
||||
if (
|
||||
foreground ||
|
||||
!canRestoreHiddenOutput ||
|
||||
startupRendererQueryWindowActive ||
|
||||
data.length === 0
|
||||
) {
|
||||
return false
|
||||
}
|
||||
if (synchronizedOutputActive) {
|
||||
if (!allowSynchronizedModelRestore) {
|
||||
return false
|
||||
}
|
||||
return containsOnlyModelRestorableSynchronizedOutput(data)
|
||||
}
|
||||
return containsOnlyRestorableHiddenOutput(data)
|
||||
}
|
||||
@@ -8,6 +8,11 @@
|
||||
* as a delivery-interest signal, so it is only used while the hidden-delivery
|
||||
* gate is OFF — gated parked PTYs answer from the main tracker's
|
||||
* '2031-subscribe' fact instead (parked-terminal-byte-watcher.ts).
|
||||
*
|
||||
* Survives Phase 6 (skip-grammar deletion): mounted switch-off hidden panes
|
||||
* answer 2031 from xterm once the background queue drains, but a PARKED tab
|
||||
* has no xterm in any switch-off mode, and the '2031-subscribe' fact is only
|
||||
* consumed while the gate is ON — this sidecar stays the only answerer here.
|
||||
*/
|
||||
import {
|
||||
mode2031SequenceFor,
|
||||
|
||||
@@ -2958,59 +2958,11 @@ describe('connectPanePty', () => {
|
||||
expect(transport.sendInput).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('restores safe hidden terminal-control bytes from the main snapshot', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: {
|
||||
current: ((data: string, meta?: { seq?: number; rawLength?: number }) => void) | null
|
||||
} = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
const getMainBufferSnapshot = window.api.pty.getMainBufferSnapshot as unknown as ReturnType<
|
||||
typeof vi.fn
|
||||
>
|
||||
getMainBufferSnapshot.mockResolvedValue({
|
||||
data: 'control snapshot\r\n',
|
||||
cols: 100,
|
||||
rows: 30,
|
||||
seq: 64
|
||||
})
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
|
||||
connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
const controlOutput = '\x1b[2J\x1b[Hhello\r\n'
|
||||
capturedDataCallback.current?.(controlOutput, {
|
||||
seq: controlOutput.length,
|
||||
rawLength: controlOutput.length
|
||||
})
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(controlOutput, expect.any(Function))
|
||||
|
||||
;(deps.isVisibleRef as { current: boolean }).current = true
|
||||
capturedDataCallback.current?.('visible\r\n', {
|
||||
seq: controlOutput.length + 'visible\r\n'.length,
|
||||
rawLength: 'visible\r\n'.length
|
||||
})
|
||||
await flushAsyncTicks(20)
|
||||
|
||||
expect(getMainBufferSnapshot).toHaveBeenCalledWith('pty-id', { scrollbackRows: 5000 })
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
expect.stringContaining('control snapshot'),
|
||||
expect.any(Function)
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps visually rich hidden PTY bytes on the live xterm path', async () => {
|
||||
// Why: Phase 6 deleted the hidden-skip eligibility grammar. With the kill
|
||||
// switch off, EVERY hidden chunk — plain, control-heavy, rich glyphs,
|
||||
// synchronized frames, embedded queries — rides the bounded background
|
||||
// scheduler queue and parses in xterm; nothing is content-scanned per chunk.
|
||||
it('queues hidden PTY bytes on the background scheduler without per-chunk scanning', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
@@ -3032,57 +2984,32 @@ describe('connectPanePty', () => {
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const hiddenTuiChunk = '\x1b[2J\x1b[H╭ table 😀 ╮\r\n'
|
||||
capturedDataCallback.current?.(hiddenTuiChunk)
|
||||
const hiddenChunks = [
|
||||
'plain hidden text\r\n',
|
||||
'\x1b[2J\x1b[Hcontrol redraw\r\n',
|
||||
'\x1b[2J\x1b[H╭ table 😀 ╮\r\n',
|
||||
'\x1b[?2026h| Sam Syntax | 😀 |\r\n\x1b[?2026l',
|
||||
'\x1b[?2026h\x1b[6n'
|
||||
]
|
||||
for (const chunk of hiddenChunks) {
|
||||
capturedDataCallback.current?.(chunk)
|
||||
}
|
||||
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(hiddenTuiChunk)
|
||||
// Background path defers writes; nothing is written synchronously.
|
||||
expect(pane.terminal.write).not.toHaveBeenCalled()
|
||||
vi.advanceTimersByTime(50)
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(hiddenTuiChunk)
|
||||
// The drain may coalesce queued chunks into one write — assert content.
|
||||
const written = pane.terminal.write.mock.calls.map((call) => String(call[0])).join('')
|
||||
for (const chunk of hiddenChunks) {
|
||||
expect(written).toContain(chunk)
|
||||
}
|
||||
// No model restore is latched for bounded hidden output.
|
||||
expect(window.api.pty.getMainBufferSnapshot).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('skips every chunk of a rich hidden synchronized frame for model-backed restore', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
|
||||
connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const startChunk = '\x1b[?2026h\x1b[2J\x1b[Hsafe heading\r\n'
|
||||
const richChunk = '| Sam Syntax | 😀 |\r\n'
|
||||
const tailChunk = 'LONG_TABLE_SCROLL_RESTORE_marker\r\n\x1b[?2026l'
|
||||
|
||||
capturedDataCallback.current?.(startChunk)
|
||||
capturedDataCallback.current?.(richChunk)
|
||||
capturedDataCallback.current?.(tailChunk)
|
||||
|
||||
vi.advanceTimersByTime(50)
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(expect.stringContaining(startChunk))
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(expect.stringContaining(richChunk))
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(expect.stringContaining(tailChunk))
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
describe('hidden-delivery gate', () => {
|
||||
function enableMainAuthority(): void {
|
||||
mockStoreState.settings = {
|
||||
@@ -3142,6 +3069,11 @@ describe('connectPanePty', () => {
|
||||
dataCallback('hidden output\r\n', { seq: 16, rawLength: 16 })
|
||||
expect(setHiddenRendererPty).toHaveBeenCalledWith('pty-id', true)
|
||||
|
||||
// Why: with the skip grammar gone, gated drops latch the restore via
|
||||
// main's out-of-band marker, not a renderer-side content scan.
|
||||
const { _dispatchPtyModelRestoreNeededForTest } = await import('./pty-model-restore-channel')
|
||||
_dispatchPtyModelRestoreNeededForTest({ id: 'pty-id', reason: 'hidden-drop', markerSeq: 64 })
|
||||
|
||||
// Reveal rides the visible-resume backlog recovery hook.
|
||||
;(deps.isVisibleRef as { current: boolean }).current = true
|
||||
const { requestTerminalBacklogRecovery } =
|
||||
@@ -3179,56 +3111,33 @@ describe('connectPanePty', () => {
|
||||
expect(setHiddenRendererPty).toHaveBeenLastCalledWith('pty-id', true)
|
||||
})
|
||||
|
||||
it('never marks hidden while the codex startup renderer-query window is active', async () => {
|
||||
it('marks hidden codex panes immediately — no startup renderer-query window remains', async () => {
|
||||
enableMainAuthority()
|
||||
// Why: only fake the clock — the default fake set would also replace
|
||||
// the suite's synchronous requestAnimationFrame mock and the deferred
|
||||
// connect frame would never run.
|
||||
vi.useFakeTimers({ toFake: ['Date', 'setTimeout', 'clearTimeout'] })
|
||||
try {
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false },
|
||||
startup: { command: 'codex' }
|
||||
})
|
||||
const { transport, dataCallback } = await connectHiddenPane(deps)
|
||||
const setHiddenRendererPty = getSetHiddenRendererPtyMock()
|
||||
const transportOptions = createdTransportOptions.at(-1) as {
|
||||
onPtySpawn?: (ptyId: string) => void
|
||||
}
|
||||
transportOptions.onPtySpawn?.('pty-id')
|
||||
const factsHandler = await import('./terminal-side-effect-facts-handler')
|
||||
|
||||
dataCallback('startup probe output\r\n')
|
||||
expect(setHiddenRendererPty).not.toHaveBeenCalledWith('pty-id', true)
|
||||
|
||||
// Why: the fact is the sole 2031 responder for gate-managed PTYs —
|
||||
// even during the startup window (the xterm-side CSI reply is
|
||||
// suppressed by the lifecycle for these panes), so a fact racing the
|
||||
// hidden mark can never produce zero or two replies.
|
||||
factsHandler._dispatchTerminalSideEffectBatchForTest({
|
||||
ptyId: 'pty-id',
|
||||
seq: 8,
|
||||
facts: [{ kind: '2031-subscribe' }]
|
||||
})
|
||||
expect(transport.sendInput).toHaveBeenCalledTimes(1)
|
||||
expect(transport.sendInput).toHaveBeenCalledWith('\x1b[?997;1n')
|
||||
|
||||
// Why: after the 10s window lapses, hidden output gates normally.
|
||||
vi.advanceTimersByTime(10_001)
|
||||
dataCallback('post window output\r\n')
|
||||
expect(setHiddenRendererPty).toHaveBeenLastCalledWith('pty-id', true)
|
||||
|
||||
// Gated now — a new subscribe fact still gets exactly one reply.
|
||||
factsHandler._dispatchTerminalSideEffectBatchForTest({
|
||||
ptyId: 'pty-id',
|
||||
seq: 16,
|
||||
facts: [{ kind: '2031-subscribe' }]
|
||||
})
|
||||
expect(transport.sendInput).toHaveBeenCalledTimes(2)
|
||||
expect(transport.sendInput).toHaveBeenLastCalledWith('\x1b[?997;1n')
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false },
|
||||
startup: { command: 'codex' }
|
||||
})
|
||||
const { transport, dataCallback } = await connectHiddenPane(deps)
|
||||
const setHiddenRendererPty = getSetHiddenRendererPtyMock()
|
||||
const transportOptions = createdTransportOptions.at(-1) as {
|
||||
onPtySpawn?: (ptyId: string) => void
|
||||
}
|
||||
transportOptions.onPtySpawn?.('pty-id')
|
||||
const factsHandler = await import('./terminal-side-effect-facts-handler')
|
||||
|
||||
// Why: Phase 6 deleted the 10s codex window — codex startups gate like
|
||||
// any hidden pane and the main responder answers their startup probes.
|
||||
dataCallback('startup probe output\r\n')
|
||||
expect(setHiddenRendererPty).toHaveBeenCalledWith('pty-id', true)
|
||||
|
||||
// The fact stays the sole 2031 responder for gate-managed PTYs.
|
||||
factsHandler._dispatchTerminalSideEffectBatchForTest({
|
||||
ptyId: 'pty-id',
|
||||
seq: 8,
|
||||
facts: [{ kind: '2031-subscribe' }]
|
||||
})
|
||||
expect(transport.sendInput).toHaveBeenCalledTimes(1)
|
||||
expect(transport.sendInput).toHaveBeenCalledWith('\x1b[?997;1n')
|
||||
})
|
||||
|
||||
it('latches model restore from the out-of-band marker and restores on reveal', async () => {
|
||||
@@ -3338,12 +3247,12 @@ describe('connectPanePty', () => {
|
||||
expect(bindingWithPredicate.isHiddenDeliveryGateManagedPty()).toBe(true)
|
||||
})
|
||||
|
||||
it('declares hidden-at-spawn on connect for hidden non-codex panes', async () => {
|
||||
it('declares hidden-at-spawn on connect for hidden panes', async () => {
|
||||
enableMainAuthority()
|
||||
const deps = createDeps({ isVisibleRef: { current: false } })
|
||||
const { transport } = await connectHiddenPane(deps)
|
||||
// Why: waiting for the first dataCallback sync left a spawn-time query
|
||||
// window where neither side replied (the non-codex DA1 loss). The flag
|
||||
// window where neither side replied (the spawn-time DA1 loss). The flag
|
||||
// lets main mark the PTY hidden before its first byte.
|
||||
expect(transport.connect).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ initiallyHidden: true })
|
||||
@@ -3357,16 +3266,21 @@ describe('connectPanePty', () => {
|
||||
expect(transport.connect.mock.calls[0]![0]).not.toHaveProperty('initiallyHidden')
|
||||
})
|
||||
|
||||
it('never declares hidden-at-spawn while the codex startup window is active', async () => {
|
||||
it('declares hidden-at-spawn for hidden codex panes too', async () => {
|
||||
enableMainAuthority()
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false },
|
||||
startup: { command: 'codex' }
|
||||
})
|
||||
const { transport } = await connectHiddenPane(deps)
|
||||
// Codex startup probes need live renderer delivery for the 10s window;
|
||||
// a spawn-time hidden mark would gate them (codex spawns keep delivery).
|
||||
expect(transport.connect.mock.calls[0]![0]).not.toHaveProperty('initiallyHidden')
|
||||
// Why: the 10s codex startup window is deleted — codex spawns are
|
||||
// main-owned from byte zero, with the model responder answering their
|
||||
// startup probes (including ConPTY's blocking DA1; the main-side pin is
|
||||
// pty.test.ts 'answers DA1 from the model on the first chunk of a
|
||||
// hidden-at-spawn PTY').
|
||||
expect(transport.connect).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ initiallyHidden: true })
|
||||
)
|
||||
})
|
||||
|
||||
it('does not gate or fact-reply when the hidden-delivery kill switch is off', async () => {
|
||||
@@ -3675,292 +3589,6 @@ describe('connectPanePty', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('skips split hidden synchronized output frames for model-backed restore', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: {
|
||||
current: ((data: string, meta?: { seq?: number; rawLength?: number }) => void) | null
|
||||
} = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
const getMainBufferSnapshot = window.api.pty.getMainBufferSnapshot as unknown as ReturnType<
|
||||
typeof vi.fn
|
||||
>
|
||||
getMainBufferSnapshot.mockResolvedValue({
|
||||
data: 'snapshot table\r\nLONG_TABLE_SCROLL_RESTORE_marker\r\n',
|
||||
cols: 100,
|
||||
rows: 30,
|
||||
seq: 80
|
||||
})
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
|
||||
connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
const startChunk = '\x1b[?2026h'
|
||||
const plainRowChunk = '| Sam Syntax | Compiler | Online |\r\n'
|
||||
const endChunk = 'LONG_TABLE_SCROLL_RESTORE_marker\r\n\x1b[?2026l'
|
||||
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
capturedDataCallback.current?.(startChunk, {
|
||||
seq: startChunk.length,
|
||||
rawLength: startChunk.length
|
||||
})
|
||||
capturedDataCallback.current?.(plainRowChunk, {
|
||||
seq: startChunk.length + plainRowChunk.length,
|
||||
rawLength: plainRowChunk.length
|
||||
})
|
||||
capturedDataCallback.current?.(endChunk, {
|
||||
seq: startChunk.length + plainRowChunk.length + endChunk.length,
|
||||
rawLength: endChunk.length
|
||||
})
|
||||
|
||||
vi.advanceTimersByTime(50)
|
||||
expect(getMainBufferSnapshot).not.toHaveBeenCalled()
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(expect.stringContaining(startChunk))
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(expect.stringContaining(plainRowChunk))
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(expect.stringContaining(endChunk))
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('detects split hidden synchronized starts before skipping later payload', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
|
||||
connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
const splitStartHead = '\x1b[?20'
|
||||
const splitStartTail = '26h\x1b[2J\x1b[H'
|
||||
const payload = 'split synchronized payload\r\n\x1b[?2026l'
|
||||
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
capturedDataCallback.current?.(splitStartHead)
|
||||
capturedDataCallback.current?.(splitStartTail)
|
||||
capturedDataCallback.current?.(payload)
|
||||
|
||||
vi.advanceTimersByTime(50)
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(expect.stringContaining(splitStartHead))
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(expect.stringContaining(splitStartTail))
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(expect.stringContaining(payload))
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('clears hidden synchronized state when the end marker arrives while visible', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const isVisibleRef = { current: false }
|
||||
const deps = createDeps({ isVisibleRef })
|
||||
|
||||
connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
const hiddenSyncQueryChunk = '\x1b[?2026h\x1b[6n'
|
||||
const foregroundEndChunk = 'done\x1b[?2026l'
|
||||
const hiddenWideGlyphChunk = '│ 漢字 ║ 🚀 │\r\n'
|
||||
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
capturedDataCallback.current?.(hiddenSyncQueryChunk)
|
||||
isVisibleRef.current = true
|
||||
capturedDataCallback.current?.(foregroundEndChunk)
|
||||
isVisibleRef.current = false
|
||||
capturedDataCallback.current?.(hiddenWideGlyphChunk)
|
||||
|
||||
vi.advanceTimersByTime(50)
|
||||
// Why: the synchronized frame ended while visible, so the wide-glyph
|
||||
// hidden output must be judged by the strict plain rules and stay live.
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
expect.stringContaining(hiddenWideGlyphChunk)
|
||||
)
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('does not inherit hidden synchronized state across PTY restarts', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
|
||||
connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
const hiddenSyncQueryChunk = '\x1b[?2026h\x1b[6n'
|
||||
const hiddenWideGlyphChunk = '│ 漢字 ║ 🚀 │\r\n'
|
||||
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
capturedDataCallback.current?.(hiddenSyncQueryChunk)
|
||||
;(transport.attach as unknown as (opts: { existingPtyId: string }) => void)({
|
||||
existingPtyId: 'pty-id-2'
|
||||
})
|
||||
capturedDataCallback.current?.(hiddenWideGlyphChunk)
|
||||
|
||||
vi.advanceTimersByTime(50)
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
expect.stringContaining(hiddenWideGlyphChunk)
|
||||
)
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps hidden synchronized terminal queries on the live xterm path', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
|
||||
connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
const queryChunk = '\x1b[?2026h\x1b[6n'
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
capturedDataCallback.current?.(queryChunk)
|
||||
vi.advanceTimersByTime(50)
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(expect.stringContaining(queryChunk))
|
||||
expect(window.api.pty.getMainBufferSnapshot).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('restores default hidden rich synchronized output from the headless model', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: {
|
||||
current: ((data: string, meta?: { seq?: number; rawLength?: number }) => void) | null
|
||||
} = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
const getMainBufferSnapshot = window.api.pty.getMainBufferSnapshot as unknown as ReturnType<
|
||||
typeof vi.fn
|
||||
>
|
||||
const richHiddenFrame = [
|
||||
'\x1b[?2026h',
|
||||
'\x1b[?1049h',
|
||||
'\x1b[2J\x1b[H',
|
||||
'\x1b[?25l',
|
||||
'\x1b[2;36m╭────────────────────────────╮\x1b[0m\r\n',
|
||||
'\x1b[2;36m│ model-backed rich 😀 ███░ │\x1b[0m\r\n',
|
||||
'\x1b[2;36m╰────────────────────────────╯\x1b[0m',
|
||||
'\x1b[6;4H\x1b[?25h',
|
||||
'\x1b[?2026l'
|
||||
].join('')
|
||||
const visibleTrigger = 'visible-trigger\r\n'
|
||||
getMainBufferSnapshot.mockResolvedValue({
|
||||
data: richHiddenFrame,
|
||||
cols: 96,
|
||||
rows: 18,
|
||||
seq: richHiddenFrame.length + visibleTrigger.length,
|
||||
source: 'headless'
|
||||
})
|
||||
|
||||
const pane = createPane(1)
|
||||
const refresh = vi.fn()
|
||||
const terminal = pane.terminal as typeof pane.terminal & {
|
||||
_core?: { refresh: typeof refresh }
|
||||
}
|
||||
terminal._core = { refresh }
|
||||
terminal.write = vi.fn((_data: string, callback?: () => void) => {
|
||||
callback?.()
|
||||
})
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
const disposable = connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.(richHiddenFrame, {
|
||||
seq: richHiddenFrame.length,
|
||||
rawLength: richHiddenFrame.length
|
||||
})
|
||||
await flushAsyncTicks(2)
|
||||
|
||||
expect(pane.terminal.write).not.toHaveBeenCalled()
|
||||
expect(getMainBufferSnapshot).not.toHaveBeenCalled()
|
||||
|
||||
;(deps.isVisibleRef as { current: boolean }).current = true
|
||||
capturedDataCallback.current?.(visibleTrigger, {
|
||||
seq: richHiddenFrame.length + visibleTrigger.length,
|
||||
rawLength: visibleTrigger.length
|
||||
})
|
||||
await flushAsyncTicks(20)
|
||||
|
||||
expect(getMainBufferSnapshot).toHaveBeenCalledWith('pty-id', { scrollbackRows: 5000 })
|
||||
expect(pane.terminal.resize).toHaveBeenCalledWith(96, 18)
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(richHiddenFrame, expect.any(Function))
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(visibleTrigger, expect.any(Function))
|
||||
expect(refresh).toHaveBeenCalledWith(0, 39, true)
|
||||
disposable.dispose()
|
||||
})
|
||||
|
||||
it('queues visible split-pane PTY bytes when the pane is not active', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport()
|
||||
@@ -4060,115 +3688,6 @@ describe('connectPanePty', () => {
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith('backgrounded document output\r\n')
|
||||
})
|
||||
|
||||
it('keeps hidden Codex telemetry startup output parsing briefly', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const binding = connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
createDeps({
|
||||
isVisibleRef: { current: false },
|
||||
startup: {
|
||||
command: 'wrapped-agent',
|
||||
telemetry: {
|
||||
agent_kind: 'codex',
|
||||
launch_source: 'tab_bar_quick_launch',
|
||||
request_kind: 'new'
|
||||
}
|
||||
}
|
||||
}) as never
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
|
||||
capturedDataCallback.current?.('\x1b]11;?\x1b\\startup frame\r\n')
|
||||
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
'\x1b]11;?\x1b\\startup frame\r\n',
|
||||
expect.any(Function)
|
||||
)
|
||||
|
||||
binding.dispose()
|
||||
})
|
||||
|
||||
it('keeps hidden bare Codex startup commands parsing briefly', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const binding = connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
createDeps({
|
||||
isVisibleRef: { current: false },
|
||||
startup: { command: 'codex' }
|
||||
}) as never
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
|
||||
capturedDataCallback.current?.('\x1b]11;?\x1b\\startup frame\r\n')
|
||||
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
'\x1b]11;?\x1b\\startup frame\r\n',
|
||||
expect.any(Function)
|
||||
)
|
||||
|
||||
binding.dispose()
|
||||
})
|
||||
|
||||
it('skips arbitrary hidden startup output parsing', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const binding = connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
createDeps({
|
||||
isVisibleRef: { current: false },
|
||||
startup: { command: 'printf noisy startup' }
|
||||
}) as never
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
|
||||
capturedDataCallback.current?.('hidden startup output\r\n')
|
||||
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(
|
||||
'hidden startup output\r\n',
|
||||
expect.any(Function)
|
||||
)
|
||||
|
||||
binding.dispose()
|
||||
})
|
||||
|
||||
it('writes mode 2031 through hidden xterm instead of side-channel answering it', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
@@ -4206,157 +3725,21 @@ describe('connectPanePty', () => {
|
||||
binding.dispose()
|
||||
})
|
||||
|
||||
it('restores plain hidden output from the main snapshot when the pane returns', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: {
|
||||
current: ((data: string, meta?: { seq?: number; rawLength?: number }) => void) | null
|
||||
} = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
const getMainBufferSnapshot = window.api.pty.getMainBufferSnapshot as unknown as ReturnType<
|
||||
typeof vi.fn
|
||||
>
|
||||
const hidden = 'small-hidden-output\r\n'
|
||||
const live = 'visible-after-hidden\r\n'
|
||||
getMainBufferSnapshot.mockResolvedValue({
|
||||
data: `snapshot-with-${hidden}`,
|
||||
cols: 100,
|
||||
rows: 30,
|
||||
seq: hidden.length + live.length
|
||||
})
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
const disposable = connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.(hidden, { seq: hidden.length, rawLength: hidden.length })
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(hidden, expect.any(Function))
|
||||
|
||||
;(deps.isVisibleRef as { current: boolean }).current = true
|
||||
capturedDataCallback.current?.(live, {
|
||||
seq: hidden.length + live.length,
|
||||
rawLength: live.length
|
||||
})
|
||||
await flushAsyncTicks(20)
|
||||
|
||||
expect(getMainBufferSnapshot).toHaveBeenCalledWith('pty-id', { scrollbackRows: 5000 })
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(hidden)
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(live, expect.any(Function))
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
expect.stringContaining(`snapshot-with-${hidden}`),
|
||||
expect.any(Function)
|
||||
)
|
||||
disposable.dispose()
|
||||
})
|
||||
|
||||
it('restores hidden Latin text from the main snapshot when the pane returns', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: {
|
||||
current: ((data: string, meta?: { seq?: number; rawLength?: number }) => void) | null
|
||||
} = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
const getMainBufferSnapshot = window.api.pty.getMainBufferSnapshot as unknown as ReturnType<
|
||||
typeof vi.fn
|
||||
>
|
||||
const hidden = 'café déjà vu São Tomé Żubrówka\r\n'
|
||||
const live = 'visible-after-hidden\r\n'
|
||||
getMainBufferSnapshot.mockResolvedValue({
|
||||
data: `snapshot-with-${hidden}`,
|
||||
cols: 100,
|
||||
rows: 30,
|
||||
seq: hidden.length + live.length
|
||||
})
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
const disposable = connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.(hidden, { seq: hidden.length, rawLength: hidden.length })
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(hidden, expect.any(Function))
|
||||
|
||||
;(deps.isVisibleRef as { current: boolean }).current = true
|
||||
capturedDataCallback.current?.(live, {
|
||||
seq: hidden.length + live.length,
|
||||
rawLength: live.length
|
||||
})
|
||||
await flushAsyncTicks(20)
|
||||
|
||||
expect(getMainBufferSnapshot).toHaveBeenCalledWith('pty-id', { scrollbackRows: 5000 })
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(hidden)
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(live, expect.any(Function))
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
expect.stringContaining(`snapshot-with-${hidden}`),
|
||||
expect.any(Function)
|
||||
)
|
||||
disposable.dispose()
|
||||
})
|
||||
|
||||
it('skips hidden title OSC renderer writes while keeping pane title handling wired', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
const capturedDataCallback: {
|
||||
current: ((data: string, meta?: { seq?: number; rawLength?: number }) => void) | null
|
||||
} = { current: null }
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
})
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
const disposable = connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
const hiddenTitle = '\x1b]0;hidden title\x07'
|
||||
capturedDataCallback.current?.(hiddenTitle, {
|
||||
seq: hiddenTitle.length,
|
||||
rawLength: hiddenTitle.length
|
||||
})
|
||||
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(hiddenTitle, expect.any(Function))
|
||||
const titleHandler = createdTransportOptions[0]?.onTitleChange as
|
||||
| ((title: string, rawTitle: string) => void)
|
||||
| undefined
|
||||
if (!titleHandler) {
|
||||
throw new Error('Expected onTitleChange to be registered')
|
||||
}
|
||||
titleHandler('hidden title', 'hidden title')
|
||||
expect(deps.setRuntimePaneTitle).toHaveBeenCalledWith('tab-1', pane.id, 'hidden title')
|
||||
disposable.dispose()
|
||||
})
|
||||
|
||||
it('restores plain hidden remote runtime output from its serialized snapshot', async () => {
|
||||
it('restores overflowed hidden remote runtime output from its serialized snapshot', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('remote:env-1@@terminal-1')
|
||||
const capturedDataCallback: {
|
||||
current: ((data: string, meta?: { seq?: number; rawLength?: number }) => void) | null
|
||||
} = { current: null }
|
||||
// Why: with the skip grammar gone, the model restore for remote-runtime
|
||||
// PTYs is latched by background-queue overflow, not per-chunk scanning.
|
||||
const hidden = 'x'.repeat(2 * 1024 * 1024 + 1)
|
||||
const live = 'visible remote output\r\n'
|
||||
transport.serializeBuffer = vi.fn().mockResolvedValue({
|
||||
data: 'remote snapshot with hidden remote output\r\n',
|
||||
cols: 120,
|
||||
rows: 40,
|
||||
seq: 40,
|
||||
seq: hidden.length + live.length,
|
||||
source: 'headless'
|
||||
})
|
||||
transport.connect.mockImplementation(async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
@@ -4374,14 +3757,12 @@ describe('connectPanePty', () => {
|
||||
const disposable = connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
const hidden = 'hidden remote output\r\n'
|
||||
const live = 'visible remote output\r\n'
|
||||
capturedDataCallback.current?.(hidden, { seq: hidden.length, rawLength: hidden.length })
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(hidden, expect.any(Function))
|
||||
|
||||
;(deps.isVisibleRef as { current: boolean }).current = true
|
||||
capturedDataCallback.current?.(live, {
|
||||
seq: 40 + live.length,
|
||||
seq: hidden.length + live.length,
|
||||
rawLength: live.length
|
||||
})
|
||||
await flushAsyncTicks(20)
|
||||
@@ -4430,7 +3811,9 @@ describe('connectPanePty', () => {
|
||||
disposable = connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
const hidden = 'hidden inactive output\r\n'
|
||||
// Why: overflowing the background queue is what latches the model
|
||||
// restore now — the per-chunk skip grammar is gone.
|
||||
const hidden = 'x'.repeat(2 * 1024 * 1024 + 1)
|
||||
const live = 'visible inactive output\r\n'
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
capturedDataCallback.current?.(hidden, { seq: hidden.length, rawLength: hidden.length })
|
||||
@@ -4494,7 +3877,8 @@ describe('connectPanePty', () => {
|
||||
disposable = connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
const hidden = 'hidden inactive output\r\n'
|
||||
// Why: overflow latches the model restore (no skip grammar remains).
|
||||
const hidden = 'x'.repeat(2 * 1024 * 1024 + 1)
|
||||
const live = 'visible inactive output\r\n'
|
||||
expect(capturedDataCallback.current).not.toBeNull()
|
||||
capturedDataCallback.current?.(hidden, { seq: hidden.length, rawLength: hidden.length })
|
||||
@@ -4518,7 +3902,7 @@ describe('connectPanePty', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('retries null remote snapshots for skipped plain hidden runtime output', async () => {
|
||||
it('retries null remote snapshots for overflowed hidden runtime output', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('remote:env-1@@terminal-1')
|
||||
const capturedDataCallback: {
|
||||
@@ -4543,7 +3927,8 @@ describe('connectPanePty', () => {
|
||||
const disposable = connectPanePty(pane as never, manager as never, deps as never)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
const hidden = 'hidden remote output\r\n'
|
||||
// Why: overflow latches the model restore (no skip grammar remains).
|
||||
const hidden = 'x'.repeat(2 * 1024 * 1024 + 1)
|
||||
const firstLive = 'first visible output\r\n'
|
||||
capturedDataCallback.current?.(hidden, { seq: hidden.length, rawLength: hidden.length })
|
||||
|
||||
@@ -4575,6 +3960,9 @@ describe('connectPanePty', () => {
|
||||
disposable.dispose()
|
||||
})
|
||||
|
||||
// Why: pins the entire switch-off hidden fallback chain — hidden bytes ride
|
||||
// the background queue, the 2MB lossy cap drops the backlog and latches the
|
||||
// restore, and reveal repaints from the model snapshot.
|
||||
it('restores hidden backlog overflow from the main terminal snapshot on foreground output', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
const transport = createMockTransport('pty-id')
|
||||
|
||||
@@ -33,8 +33,7 @@ import {
|
||||
import { getSystemPrefersDark } from '@/lib/terminal-theme'
|
||||
import {
|
||||
mode2031SequenceFor,
|
||||
resolveTerminalColorSchemeMode,
|
||||
scanMode2031Sequences
|
||||
resolveTerminalColorSchemeMode
|
||||
} from '../../../../shared/terminal-color-scheme-protocol'
|
||||
import { warnTerminalLifecycleAnomaly } from './terminal-lifecycle-diagnostics'
|
||||
import { registerPtySerializer, registerPtyTitleSource } from './pty-buffer-serializer'
|
||||
@@ -92,7 +91,6 @@ import {
|
||||
normalizeAgentProviderSession
|
||||
} from '../../../../shared/agent-session-resume'
|
||||
import { isWslUncPath } from '../../../../shared/wsl-paths'
|
||||
import { shouldSkipHiddenRendererOutput } from './hidden-renderer-skip-eligibility'
|
||||
import {
|
||||
AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS,
|
||||
AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS,
|
||||
@@ -115,10 +113,7 @@ const HIDDEN_OUTPUT_RESTORE_SCROLLBACK_ROWS = 5000
|
||||
const HIDDEN_OUTPUT_RESTORE_PENDING_CHARS = 512 * 1024
|
||||
const HIDDEN_OUTPUT_RESTORE_DEFERRED_RETRY_MS = 50
|
||||
const HIDDEN_OUTPUT_RESTORE_DEFERRED_RETRY_MAX = 3
|
||||
const HIDDEN_STARTUP_RENDERER_QUERY_WINDOW_MS = 10_000
|
||||
const STARTUP_COMMAND_EXTENSION_RE = /\.(?:exe|cmd|bat|ps1)$/i
|
||||
const TERMINAL_RENDERER_RISK_SCAN_TAIL_CHARS = 256
|
||||
const SYNCHRONIZED_OUTPUT_SCAN_TAIL_CHARS = 16
|
||||
const CURSOR_SHOW_SEQUENCE = '\x1b[?25h'
|
||||
const CURSOR_HIDE_SEQUENCE = '\x1b[?25l'
|
||||
const REATTACH_IDLE_AGENT_CURSOR_RESET_DELAY_MS = 250
|
||||
@@ -162,14 +157,11 @@ type E2eTerminalHiddenSnapshotOverride = {
|
||||
|
||||
const e2eTerminalHiddenSnapshotOverrides = new Map<string, E2eTerminalHiddenSnapshotOverride>()
|
||||
|
||||
// Why: the per-chunk hidden-skip grammar is deleted (Phase 6) — hidden bytes
|
||||
// either never reach the renderer (delivery gate) or ride the background
|
||||
// scheduler queue. Only the mode-2031 fact-reply counter still has a producer.
|
||||
type E2eTerminalPtyOutputDebugSnapshot = {
|
||||
hiddenRendererSkipCount: number
|
||||
hiddenRendererSkippedChars: number
|
||||
hiddenRendererMode2031ReplyCount: number
|
||||
hiddenRendererLiveSynchronizedChars: number
|
||||
hiddenRendererLiveNonSynchronizedChars: number
|
||||
hiddenRendererStartupWindowChars: number
|
||||
hiddenRendererSplitBoundaryChars: number
|
||||
}
|
||||
|
||||
type E2eTerminalPtyOutputDebugApi = {
|
||||
@@ -182,23 +174,11 @@ type E2eTerminalPtyOutputDebugWindow = Window & {
|
||||
}
|
||||
|
||||
const e2eTerminalPtyOutputDebugState: E2eTerminalPtyOutputDebugSnapshot = {
|
||||
hiddenRendererSkipCount: 0,
|
||||
hiddenRendererSkippedChars: 0,
|
||||
hiddenRendererMode2031ReplyCount: 0,
|
||||
hiddenRendererLiveSynchronizedChars: 0,
|
||||
hiddenRendererLiveNonSynchronizedChars: 0,
|
||||
hiddenRendererStartupWindowChars: 0,
|
||||
hiddenRendererSplitBoundaryChars: 0
|
||||
hiddenRendererMode2031ReplyCount: 0
|
||||
}
|
||||
|
||||
function resetE2eTerminalPtyOutputDebug(): void {
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererSkipCount = 0
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererSkippedChars = 0
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererMode2031ReplyCount = 0
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererLiveSynchronizedChars = 0
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererLiveNonSynchronizedChars = 0
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererStartupWindowChars = 0
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererSplitBoundaryChars = 0
|
||||
}
|
||||
|
||||
function exposeE2eTerminalPtyOutputDebug(): void {
|
||||
@@ -212,34 +192,6 @@ function exposeE2eTerminalPtyOutputDebug(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function recordHiddenRendererSkip(chars: number): void {
|
||||
if (!e2eConfig.exposeStore) {
|
||||
return
|
||||
}
|
||||
exposeE2eTerminalPtyOutputDebug()
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererSkipCount += 1
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererSkippedChars += chars
|
||||
}
|
||||
|
||||
function recordHiddenRendererLiveOutput(
|
||||
chars: number,
|
||||
reason: 'synchronized' | 'non-synchronized' | 'startup-window' | 'split-boundary'
|
||||
): void {
|
||||
if (!e2eConfig.exposeStore) {
|
||||
return
|
||||
}
|
||||
exposeE2eTerminalPtyOutputDebug()
|
||||
if (reason === 'synchronized') {
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererLiveSynchronizedChars += chars
|
||||
} else if (reason === 'non-synchronized') {
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererLiveNonSynchronizedChars += chars
|
||||
} else if (reason === 'startup-window') {
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererStartupWindowChars += chars
|
||||
} else {
|
||||
e2eTerminalPtyOutputDebugState.hiddenRendererSplitBoundaryChars += chars
|
||||
}
|
||||
}
|
||||
|
||||
function recordHiddenMode2031Reply(): void {
|
||||
if (!e2eConfig.exposeStore) {
|
||||
return
|
||||
@@ -319,33 +271,6 @@ function readE2eHiddenSnapshotOverride(ptyId: string): Promise<PtyBufferSnapshot
|
||||
})
|
||||
}
|
||||
|
||||
function firstStartupCommandToken(command: string): string {
|
||||
const trimmed = command.trim()
|
||||
const quote = trimmed[0]
|
||||
if ((quote === '"' || quote === "'") && trimmed.length > 1) {
|
||||
const end = trimmed.indexOf(quote, 1)
|
||||
if (end > 1) {
|
||||
return trimmed.slice(1, end)
|
||||
}
|
||||
}
|
||||
return trimmed.split(/\s+/)[0] ?? ''
|
||||
}
|
||||
|
||||
function isCodexStartupCommand(command: string): boolean {
|
||||
const executable = firstStartupCommandToken(command)
|
||||
.split(/[\\/]/)
|
||||
.pop()
|
||||
?.toLowerCase()
|
||||
.replace(STARTUP_COMMAND_EXTENSION_RE, '')
|
||||
return executable === 'codex' || executable?.startsWith('codex-') === true
|
||||
}
|
||||
|
||||
function shouldKeepHiddenStartupRendererQueriesLive(
|
||||
startup: PtyConnectionDeps['startup']
|
||||
): boolean {
|
||||
return startup?.telemetry?.agent_kind === 'codex' || isCodexStartupCommand(startup?.command ?? '')
|
||||
}
|
||||
|
||||
let codexRestartNoticePresenceSource: Record<
|
||||
string,
|
||||
{ previousAccountLabel: string; nextAccountLabel: string }
|
||||
@@ -579,23 +504,6 @@ function shouldSynchronizedOutputRemainActive(data: string, wasActive: boolean):
|
||||
return lastStartIndex > lastEndIndex
|
||||
}
|
||||
|
||||
function updateSynchronizedOutputScanTail(data: string): string {
|
||||
return data.slice(-SYNCHRONIZED_OUTPUT_SCAN_TAIL_CHARS)
|
||||
}
|
||||
|
||||
function containsSequenceAcrossBoundary(tail: string, data: string, sequence: string): boolean {
|
||||
const maxPrefixLength = Math.min(sequence.length - 1, tail.length, data.length)
|
||||
for (let prefixLength = 1; prefixLength <= maxPrefixLength; prefixLength++) {
|
||||
if (
|
||||
tail.endsWith(sequence.slice(0, prefixLength)) &&
|
||||
data.startsWith(sequence.slice(prefixLength))
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function containsCursorPositionSequence(data: string): boolean {
|
||||
let offset = data.indexOf('\x1b[')
|
||||
while (offset !== -1) {
|
||||
@@ -644,10 +552,9 @@ export function connectPanePty(
|
||||
let terminalBellNotificationTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let pendingTerminalBellNotification = false
|
||||
let reattachIdleAgentCursorResetTimer: ReturnType<typeof setTimeout> | null = null
|
||||
// Why: DEC 2026 tracking survives only for the FOREGROUND native-Windows
|
||||
// repaint protection — hidden chunks are no longer classified per chunk.
|
||||
let synchronizedForegroundOutputActive = false
|
||||
let synchronizedHiddenOutputActive = false
|
||||
let synchronizedHiddenOutputScanTail = ''
|
||||
let synchronizedHiddenOutputPtyId: string | null = null
|
||||
// Why: hidden-delivery gate sync is wired up alongside the deferred PTY
|
||||
// output plumbing inside the connect frame; lifecycle hooks (visibility
|
||||
// flips, exit, dispose) run before/after it exists, so start with no-ops.
|
||||
@@ -2169,10 +2076,6 @@ export function connectPanePty(
|
||||
}
|
||||
let foregroundImmediateBudgetChars = 0
|
||||
let foregroundImmediateBudgetWindowStart = 0
|
||||
let hiddenMode2031ScanTail = ''
|
||||
const hiddenStartupRendererQueryUntil = shouldKeepHiddenStartupRendererQueriesLive(paneStartup)
|
||||
? Date.now() + HIDDEN_STARTUP_RENDERER_QUERY_WINDOW_MS
|
||||
: 0
|
||||
|
||||
function canUseMainBufferSnapshot(ptyId: string | null): ptyId is string {
|
||||
return Boolean(ptyId) && !isRemoteRuntimePtyId(ptyId)
|
||||
@@ -2205,29 +2108,19 @@ export function connectPanePty(
|
||||
return transport.serializeBuffer(opts)
|
||||
}
|
||||
|
||||
function isHiddenStartupRendererQueryWindowActive(): boolean {
|
||||
return (
|
||||
paneStartup !== null &&
|
||||
Date.now() < hiddenStartupRendererQueryUntil &&
|
||||
!shouldWritePtyOutputForeground(deps.isVisibleRef.current)
|
||||
)
|
||||
}
|
||||
|
||||
// Why: hidden/parked panes used to mark hidden only at the first
|
||||
// dataCallback sync, leaving a spawn-time window where neither side
|
||||
// answered queries (the non-codex DA1 loss). Declaring hidden on the
|
||||
// spawn IPC lets main mark the PTY before its first byte. Codex startups
|
||||
// are excluded — their startup window needs live renderer delivery, and
|
||||
// the window predicate is checked at connect time (same tick the flag is
|
||||
// sent), so the two decisions cannot disagree. Remote-runtime PTYs are
|
||||
// never gate-markable (no local main transit).
|
||||
// answered queries (the spawn-time DA1 loss). Declaring hidden on the
|
||||
// spawn IPC lets main mark the PTY before its first byte — including
|
||||
// codex spawns: the model responder answers their startup probes from
|
||||
// byte zero now that the 10s renderer query window is gone.
|
||||
// Remote-runtime PTYs are never gate-markable (no local main transit).
|
||||
function shouldDeclareHiddenAtSpawn(): boolean {
|
||||
return (
|
||||
hiddenDeliveryGateActive &&
|
||||
!runtimeEnvironmentId &&
|
||||
!disposed &&
|
||||
!shouldWritePtyOutputForeground(deps.isVisibleRef.current) &&
|
||||
!isHiddenStartupRendererQueryWindowActive()
|
||||
!shouldWritePtyOutputForeground(deps.isVisibleRef.current)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2251,12 +2144,8 @@ export function connectPanePty(
|
||||
if (disposed) {
|
||||
return
|
||||
}
|
||||
// Why: dropped bytes invalidate every cross-chunk carry — a DEC 2026
|
||||
// classification or partial OSC-9999 prefix spanning the gap would
|
||||
// corrupt the next live chunk.
|
||||
synchronizedHiddenOutputActive = false
|
||||
synchronizedHiddenOutputScanTail = ''
|
||||
hiddenMode2031ScanTail = ''
|
||||
// Why: dropped bytes invalidate every cross-chunk carry — a partial
|
||||
// OSC-9999 prefix spanning the gap would corrupt the next live chunk.
|
||||
transport.resetCrossChunkParserState?.()
|
||||
// Why: parity with the hidden skip path — a marker landing while a
|
||||
// restore is in flight means the in-flight snapshot may predate the
|
||||
@@ -2301,12 +2190,7 @@ export function connectPanePty(
|
||||
if (!isHiddenDeliveryGateManagedPty(ptyId) || !canUseHiddenOutputSnapshot(ptyId)) {
|
||||
return
|
||||
}
|
||||
const shouldHide =
|
||||
!disposed &&
|
||||
!shouldWritePtyOutputForeground(deps.isVisibleRef.current) &&
|
||||
// Why: codex startup probes need the live xterm to answer renderer
|
||||
// queries for 10s — never gate delivery while the window is active.
|
||||
!isHiddenStartupRendererQueryWindowActive()
|
||||
const shouldHide = !disposed && !shouldWritePtyOutputForeground(deps.isVisibleRef.current)
|
||||
const isFirstSyncForPty = hiddenDeliverySyncedPtyId !== ptyId
|
||||
hiddenDeliverySyncedPtyId = ptyId
|
||||
if (shouldHide) {
|
||||
@@ -2333,26 +2217,6 @@ export function connectPanePty(
|
||||
modelRestoreSubscribedPtyId = null
|
||||
}
|
||||
|
||||
function respondToSkippedMode2031Subscribe(data: string): void {
|
||||
// Why: gate-managed PTYs answer 2031 from main's '2031-subscribe' fact
|
||||
// (sole responder); scanning skipped chunks here too would answer the
|
||||
// same subscribe twice.
|
||||
if (isHiddenDeliveryGateManagedPty(transport.getPtyId())) {
|
||||
return
|
||||
}
|
||||
const scan = scanMode2031Sequences(hiddenMode2031ScanTail, data)
|
||||
hiddenMode2031ScanTail = scan.tail
|
||||
if (!scan.subscribe) {
|
||||
return
|
||||
}
|
||||
const settings = useAppStore.getState().settings
|
||||
const mode = resolveTerminalColorSchemeMode(settings, getSystemPrefersDark())
|
||||
// Why: hidden snapshot-backed panes skip xterm.write for PTY bytes. Answer
|
||||
// mode 2031 out-of-band so TUIs still render the snapshot with the same
|
||||
// theme-dependent styling they would have used in a visible pane.
|
||||
transport.sendInput(mode2031SequenceFor(mode))
|
||||
recordHiddenMode2031Reply()
|
||||
}
|
||||
function beforeTerminalOutputWrite(): void {
|
||||
recordTerminalOutput(pane.terminal)
|
||||
}
|
||||
@@ -2453,10 +2317,6 @@ export function connectPanePty(
|
||||
if (foreground) {
|
||||
resetHiddenOutputRestoreIfPtyChanged()
|
||||
}
|
||||
const parseHiddenStartupOutput =
|
||||
!foreground &&
|
||||
canUseHiddenOutputSnapshot(transport.getPtyId()) &&
|
||||
isHiddenStartupRendererQueryWindowActive()
|
||||
const synchronizedOutputStarted =
|
||||
shouldProtectNativeWindowsSynchronizedOutput &&
|
||||
foreground &&
|
||||
@@ -2478,17 +2338,16 @@ export function connectPanePty(
|
||||
const nativeWindowsCursorRestore =
|
||||
shouldProtectNativeWindowsSynchronizedOutput && foreground && containsCursorRestore(data)
|
||||
synchronizedForegroundOutputActive = nextSynchronizedForegroundOutputActive
|
||||
if (hiddenMode2031ScanTail) {
|
||||
respondToSkippedMode2031Subscribe(data)
|
||||
}
|
||||
writeTerminalOutput(pane.terminal, data, {
|
||||
foreground: foreground || parseHiddenStartupOutput,
|
||||
foreground,
|
||||
beforeWrite: beforeTerminalOutputWrite,
|
||||
// Why: hidden bytes ride the bounded background queue; on overflow the
|
||||
// scheduler swaps the backlog for this restore latch and the reveal
|
||||
// repaints from the model snapshot (the pre-grammar fallback).
|
||||
onBackgroundBacklogDropped: markHiddenOutputRestoreNeeded,
|
||||
latencySensitive:
|
||||
!foreground || parseHiddenStartupOutput ? true : isLatencySensitiveForegroundOutput(data),
|
||||
latencySensitive: !foreground ? true : isLatencySensitiveForegroundOutput(data),
|
||||
forceForegroundRefresh:
|
||||
(foreground || parseHiddenStartupOutput) &&
|
||||
foreground &&
|
||||
(synchronizedForegroundOutput ||
|
||||
nativeWindowsCursorRestore ||
|
||||
shouldForceForegroundRenderRefresh(data)),
|
||||
@@ -2524,15 +2383,6 @@ export function connectPanePty(
|
||||
}
|
||||
}
|
||||
|
||||
function skipHiddenRendererOutput(data: string): void {
|
||||
respondToSkippedMode2031Subscribe(data)
|
||||
markHiddenOutputRestoreNeeded()
|
||||
if (hiddenOutputRestoreInFlight) {
|
||||
hiddenOutputRestoreFreshSnapshotNeeded = true
|
||||
}
|
||||
recordHiddenRendererSkip(data.length)
|
||||
}
|
||||
|
||||
function queueLiveChunkDuringRestore(data: string, meta?: PtyDataMeta): void {
|
||||
if (!data) {
|
||||
return
|
||||
@@ -3019,8 +2869,7 @@ export function connectPanePty(
|
||||
// output the user is watching. Throttle only when the pane or whole
|
||||
// Electron document is hidden.
|
||||
const foreground = shouldWritePtyOutputForeground(deps.isVisibleRef.current)
|
||||
// Why: latch the hidden-delivery gate from the byte path too — covers
|
||||
// the startup-query-window expiring without a visibility event and a
|
||||
// Why: latch the hidden-delivery gate from the byte path too — covers a
|
||||
// PTY id arriving after the initial sync. No-op when state is current.
|
||||
if (!foreground) {
|
||||
syncHiddenRendererPtyDelivery()
|
||||
@@ -3048,58 +2897,7 @@ export function connectPanePty(
|
||||
meta = reconciliation.meta
|
||||
const restoreAppliesToCurrentPty =
|
||||
hiddenOutputRestorePtyId !== null && transport.getPtyId() === hiddenOutputRestorePtyId
|
||||
const dataPtyId = transport.getPtyId()
|
||||
if (synchronizedHiddenOutputPtyId !== dataPtyId) {
|
||||
// Why: DEC 2026 state is per PTY stream; a restarted/reattached PTY
|
||||
// must not inherit synchronized classification from the old shell.
|
||||
synchronizedHiddenOutputPtyId = dataPtyId
|
||||
synchronizedHiddenOutputActive = false
|
||||
synchronizedHiddenOutputScanTail = ''
|
||||
}
|
||||
const hiddenSynchronizedScanData = synchronizedHiddenOutputScanTail + data
|
||||
const synchronizedOutputStarted = containsSynchronizedOutputStart(hiddenSynchronizedScanData)
|
||||
const synchronizedOutputEnded = containsSynchronizedOutputEnd(hiddenSynchronizedScanData)
|
||||
// Why: if a DEC 2026 marker spans chunks, xterm may already hold the
|
||||
// first bytes of that escape. Complete that boundary live, then skip.
|
||||
const splitSynchronizedBoundary =
|
||||
!foreground &&
|
||||
(containsSequenceAcrossBoundary(
|
||||
synchronizedHiddenOutputScanTail,
|
||||
data,
|
||||
SYNCHRONIZED_OUTPUT_START_SEQUENCE
|
||||
) ||
|
||||
containsSequenceAcrossBoundary(
|
||||
synchronizedHiddenOutputScanTail,
|
||||
data,
|
||||
SYNCHRONIZED_OUTPUT_END_SEQUENCE
|
||||
))
|
||||
const synchronizedHiddenOutput =
|
||||
!foreground &&
|
||||
(synchronizedHiddenOutputActive || synchronizedOutputStarted || synchronizedOutputEnded)
|
||||
const hiddenStartupRendererQueryWindowActive = isHiddenStartupRendererQueryWindowActive()
|
||||
const shouldSkipHiddenOutput = shouldSkipHiddenRendererOutput({
|
||||
foreground,
|
||||
canRestoreHiddenOutput: canUseHiddenOutputSnapshot(transport.getPtyId()),
|
||||
startupRendererQueryWindowActive: hiddenStartupRendererQueryWindowActive,
|
||||
synchronizedOutputActive: synchronizedHiddenOutput,
|
||||
allowSynchronizedModelRestore: true,
|
||||
data
|
||||
})
|
||||
if (shouldSkipHiddenOutput && !splitSynchronizedBoundary) {
|
||||
skipHiddenRendererOutput(data)
|
||||
} else if (synchronizedHiddenOutput) {
|
||||
if (!foreground) {
|
||||
recordHiddenRendererLiveOutput(
|
||||
data.length,
|
||||
splitSynchronizedBoundary
|
||||
? 'split-boundary'
|
||||
: hiddenStartupRendererQueryWindowActive
|
||||
? 'startup-window'
|
||||
: 'synchronized'
|
||||
)
|
||||
}
|
||||
writePtyOutputToXterm(data, foreground)
|
||||
} else if (
|
||||
if (
|
||||
(hiddenOutputRestoreNeeded || hiddenOutputRestoreInFlight) &&
|
||||
restoreAppliesToCurrentPty
|
||||
) {
|
||||
@@ -3110,33 +2908,16 @@ export function connectPanePty(
|
||||
hiddenOutputRestoreNeeded = true
|
||||
hiddenOutputRestoreFreshSnapshotNeeded = true
|
||||
}
|
||||
// Why: hidden chunks with a restore already latched are dropped here —
|
||||
// the model snapshot fetched on reveal covers their bytes.
|
||||
} else {
|
||||
if (!foreground) {
|
||||
recordHiddenRendererLiveOutput(
|
||||
data.length,
|
||||
hiddenStartupRendererQueryWindowActive ? 'startup-window' : 'non-synchronized'
|
||||
)
|
||||
}
|
||||
// Why: gate-managed hidden panes normally receive no bytes (main
|
||||
// drops after model ingestion). Any hidden chunk that still arrives
|
||||
// (kill switch off, interest-held delivery) rides the bounded
|
||||
// background scheduler queue; overflow latches the model restore.
|
||||
// There is no per-chunk content grammar anymore.
|
||||
writePtyOutputToXterm(data, foreground)
|
||||
}
|
||||
if (!foreground) {
|
||||
synchronizedHiddenOutputActive = shouldSynchronizedOutputRemainActive(
|
||||
hiddenSynchronizedScanData,
|
||||
synchronizedHiddenOutputActive
|
||||
)
|
||||
synchronizedHiddenOutputScanTail = updateSynchronizedOutputScanTail(
|
||||
hiddenSynchronizedScanData
|
||||
)
|
||||
} else {
|
||||
// Why: a DEC 2026 end consumed while visible must still clear hidden
|
||||
// synchronized state, or later hidden plain output is misclassified
|
||||
// under the permissive synchronized model grammar.
|
||||
synchronizedHiddenOutputActive = shouldSynchronizedOutputRemainActive(
|
||||
hiddenSynchronizedScanData,
|
||||
synchronizedHiddenOutputActive
|
||||
)
|
||||
synchronizedHiddenOutputScanTail = ''
|
||||
}
|
||||
|
||||
schedulePendingStartupCommandDelivery()
|
||||
}
|
||||
|
||||
@@ -317,8 +317,7 @@ export type PtyTransport = {
|
||||
/** Hidden-at-spawn declaration (terminal-query-authority.md): no visible
|
||||
* view will consume this PTY's bytes, so main marks it hidden BEFORE the
|
||||
* first byte and the gate + model responder own spawn-time queries.
|
||||
* Never set while the codex startup window would run, and ignored by
|
||||
* remote-runtime transports (their PTYs are not gate-markable). */
|
||||
* Ignored by remote-runtime transports (not gate-markable). */
|
||||
initiallyHidden?: boolean
|
||||
callbacks: {
|
||||
onConnect?: () => void
|
||||
|
||||
@@ -54,9 +54,10 @@ type HiddenPressureDeps<TMeasurement, TDebug, TScheduler, TMainPressure, TAckGat
|
||||
writeInteractivePromptScript: (scriptPath: string, runId: string) => void
|
||||
}
|
||||
|
||||
// Why: the renderer hidden-skip counters are gone with the skip grammar —
|
||||
// withheld hidden output is observed via main's delivery-drop counters only.
|
||||
type HiddenPressureDebug = {
|
||||
hiddenRendererSkipCount: number
|
||||
hiddenRendererSkippedChars: number
|
||||
hiddenRendererMode2031ReplyCount: number
|
||||
}
|
||||
|
||||
type HiddenPressureMeasurement = {
|
||||
@@ -185,11 +186,11 @@ export async function runHiddenRealPtyPressureScenario<
|
||||
ackGate
|
||||
)
|
||||
|
||||
// New hidden-delivery contract (all pressure modes): bytes never reach the
|
||||
// renderer, so hidden skips may legitimately be zero — at most a pre-latch
|
||||
// trickle below one pane's output — and main's renderer-delivery pressure
|
||||
// must stay clearly below the old 2 MB backpressure target.
|
||||
expect(debug?.hiddenRendererSkippedChars ?? 0).toBeLessThan(pressureOutputChars)
|
||||
// Hidden-delivery contract (all pressure modes): bytes never reach the
|
||||
// renderer — main's drop counter is the withheld-output signal (the
|
||||
// renderer skip counters were deleted with the skip grammar) — and main's
|
||||
// renderer-delivery pressure must stay clearly below the old 2 MB
|
||||
// backpressure target.
|
||||
expect(mainPressure?.hiddenDeliveryDroppedChars ?? 0).toBeGreaterThanOrEqual(
|
||||
pressureOutputChars
|
||||
)
|
||||
@@ -214,7 +215,7 @@ export async function runHiddenRealPtyPressureScenario<
|
||||
type: `opencode-hidden-real-pty-restore${annotationSuffix ?? ''}`,
|
||||
description: `panes=${hiddenPanes.length + 1} restore=${restoreLatencyMs.toFixed(
|
||||
1
|
||||
)}ms hiddenSkippedChars=${debug?.hiddenRendererSkippedChars ?? 0} hiddenDeliveryDroppedChars=${
|
||||
)}ms hiddenDeliveryDroppedChars=${
|
||||
mainPressure?.hiddenDeliveryDroppedChars ?? 0
|
||||
} mainPeakInFlightChars=${mainPressure?.peakRendererInFlightChars ?? 0} heldAckChars=${
|
||||
ackGate?.heldAckChars ?? 0
|
||||
@@ -236,8 +237,7 @@ export async function runHiddenRealPtyPressureScenario<
|
||||
|
||||
// Why: replaces the old waitForMainPtyPressureBacklog premise — the Phase-4
|
||||
// gate drops hidden bytes in main, so renderer-delivery pressure never builds;
|
||||
// readiness is the gate reporting one pane's worth of dropped output. The 30s
|
||||
// timeout covers the rich-model 11s startup-window delay.
|
||||
// readiness is the gate reporting one pane's worth of dropped output.
|
||||
async function waitForMainHiddenDeliveryDrops<TMainPressure extends HiddenPressureMainSnapshot>(
|
||||
orcaPage: Page,
|
||||
deps: { readMainPtyPressureDebug: (page: Page) => Promise<TMainPressure | null> },
|
||||
|
||||
@@ -26,7 +26,9 @@ type RevisitPressureMeasurement = {
|
||||
maxTimerDriftMs: number
|
||||
}
|
||||
|
||||
type RevisitPressureDebug = { hiddenRendererSkipCount: number; hiddenRendererSkippedChars: number }
|
||||
// Why: the renderer hidden-skip counters were deleted with the skip grammar;
|
||||
// only the mode-2031 fact-reply counter still exists renderer-side.
|
||||
type RevisitPressureDebug = { hiddenRendererMode2031ReplyCount: number }
|
||||
|
||||
type RevisitPressureSchedulerSnapshot = {
|
||||
peakQueuedChars: number
|
||||
@@ -180,7 +182,6 @@ export async function runRendererBackpressureRevisitScenario<
|
||||
|
||||
expectPressureStayedBounded({
|
||||
ackGate,
|
||||
hiddenDebug,
|
||||
mainRendererPressureTargetChars,
|
||||
maxMedianKeyLatencyMs,
|
||||
maxRendererSchedulerQueuedChars,
|
||||
@@ -273,7 +274,6 @@ async function waitForMarkerLatency(
|
||||
|
||||
function expectPressureStayedBounded<TMeasurement extends RevisitPressureMeasurement>({
|
||||
ackGate,
|
||||
hiddenDebug,
|
||||
mainRendererPressureTargetChars,
|
||||
maxMedianKeyLatencyMs,
|
||||
maxRendererSchedulerQueuedChars,
|
||||
@@ -285,7 +285,6 @@ function expectPressureStayedBounded<TMeasurement extends RevisitPressureMeasure
|
||||
duringPressure
|
||||
}: {
|
||||
ackGate: RevisitPressureAckGate | null
|
||||
hiddenDebug: RevisitPressureDebug | null
|
||||
mainRendererPressureTargetChars: number
|
||||
maxMedianKeyLatencyMs: number
|
||||
maxRendererSchedulerQueuedChars: number
|
||||
@@ -306,8 +305,6 @@ function expectPressureStayedBounded<TMeasurement extends RevisitPressureMeasure
|
||||
expect(scheduler?.peakQueuedChars ?? Number.POSITIVE_INFINITY).toBeLessThanOrEqual(
|
||||
maxRendererSchedulerQueuedChars
|
||||
)
|
||||
expect(hiddenDebug?.hiddenRendererSkipCount ?? 0).toBe(0)
|
||||
expect(hiddenDebug?.hiddenRendererSkippedChars ?? 0).toBe(0)
|
||||
expect(measurement.medianLatencyMs).toBeLessThan(maxMedianKeyLatencyMs)
|
||||
expect(measurement.worstLatencyMs).toBeLessThan(maxWorstKeyLatencyMs)
|
||||
expect(measurement.maxTimerDriftMs).toBeLessThan(maxTimerDriftMs)
|
||||
|
||||
@@ -58,14 +58,11 @@ type SyntheticOpenCodeWindow = Window & {
|
||||
}
|
||||
}
|
||||
|
||||
// Why: the renderer hidden-skip grammar is deleted — hidden bytes are dropped
|
||||
// in main (gate) or ride the background queue. Only the mode-2031 fact-reply
|
||||
// counter still has a renderer-side producer.
|
||||
type TerminalPtyOutputDebugSnapshot = {
|
||||
hiddenRendererSkipCount: number
|
||||
hiddenRendererSkippedChars: number
|
||||
hiddenRendererMode2031ReplyCount: number
|
||||
hiddenRendererLiveSynchronizedChars: number
|
||||
hiddenRendererLiveNonSynchronizedChars: number
|
||||
hiddenRendererStartupWindowChars: number
|
||||
hiddenRendererSplitBoundaryChars: number
|
||||
}
|
||||
|
||||
type TerminalOutputSchedulerDebugSnapshot = {
|
||||
@@ -120,7 +117,6 @@ const DEFAULT_PRESSURE_BACKGROUND_PANES = 17
|
||||
const DEFAULT_PRESSURE_OUTPUT_CHARS = 768 * 1024
|
||||
const DEFAULT_HIDDEN_PRESSURE_PANES = 17
|
||||
const HIDDEN_PRESSURE_START_DELAY_MS = 1200
|
||||
const RICH_MODEL_HIDDEN_PRESSURE_START_DELAY_MS = 11_000
|
||||
const DEFAULT_FRAME_COUNT = 180
|
||||
const DEFAULT_FRAME_INTERVAL_MS = 6
|
||||
const TIMER_SAMPLE_MS = 16
|
||||
@@ -427,11 +423,7 @@ function annotateTypingMeasurement(
|
||||
mainPressure: MainPtyPressureDebugSnapshot | null = null,
|
||||
ackGate: TerminalPtyAckGateSnapshot | null = null
|
||||
): void {
|
||||
const hiddenSkipSummary = debug
|
||||
? ` hiddenSkips=${debug.hiddenRendererSkipCount} hiddenSkippedChars=${debug.hiddenRendererSkippedChars} mode2031Replies=${debug.hiddenRendererMode2031ReplyCount}` +
|
||||
` hiddenLiveSyncChars=${debug.hiddenRendererLiveSynchronizedChars} hiddenLiveNonSyncChars=${debug.hiddenRendererLiveNonSynchronizedChars}` +
|
||||
` hiddenStartupWindowChars=${debug.hiddenRendererStartupWindowChars} hiddenSplitBoundaryChars=${debug.hiddenRendererSplitBoundaryChars}`
|
||||
: ''
|
||||
const mode2031Summary = debug ? ` mode2031Replies=${debug.hiddenRendererMode2031ReplyCount}` : ''
|
||||
const schedulerSummary = scheduler
|
||||
? ` deferredForegroundEnqueue=${scheduler.deferredForegroundEnqueueCount} deferredForegroundWrite=${scheduler.deferredForegroundWriteCount} scheduledDrains=${scheduler.scheduledDrainCount} rendererQueuedTerminals=${scheduler.queuedTerminalCount} rendererQueuedChars=${scheduler.queuedChars} rendererPeakQueuedTerminals=${scheduler.peakQueuedTerminalCount} rendererPeakQueuedChars=${scheduler.peakQueuedChars} rendererPeakQueuedCharsByTerminal=${scheduler.peakQueuedCharsByTerminal} rendererDroppedBacklogs=${scheduler.droppedBacklogCount}`
|
||||
: ''
|
||||
@@ -449,7 +441,7 @@ function annotateTypingMeasurement(
|
||||
1
|
||||
)}ms maxTimerDrift=${measurement.maxTimerDriftMs.toFixed(1)}ms samples=${measurement.latencies
|
||||
.map((value) => value.toFixed(1))
|
||||
.join(',')}${hiddenSkipSummary}${schedulerSummary}${mainPressureSummary}${ackGateSummary}`
|
||||
.join(',')}${mode2031Summary}${schedulerSummary}${mainPressureSummary}${ackGateSummary}`
|
||||
})
|
||||
}
|
||||
|
||||
@@ -508,9 +500,6 @@ async function measureCrossWorkspaceTypingDuringHiddenLoad({
|
||||
scheduler,
|
||||
mainPressure
|
||||
)
|
||||
if ((debug?.hiddenRendererSkipCount ?? 0) > 0) {
|
||||
expect(debug?.hiddenRendererSkippedChars ?? 0).toBeGreaterThan(0)
|
||||
}
|
||||
expect(scheduler?.rendererDroppedBacklogs ?? 0).toBe(0)
|
||||
expect(measurement.medianLatencyMs).toBeLessThan(MAX_MEDIAN_KEY_LATENCY_MS)
|
||||
expect(measurement.worstLatencyMs).toBeLessThan(MAX_WORST_KEY_LATENCY_MS)
|
||||
@@ -776,12 +765,9 @@ test.describe('Artificial OpenCode terminal load', () => {
|
||||
hiddenPaneCount,
|
||||
pressureOutputChars: PRESSURE_OUTPUT_CHARS,
|
||||
pressureOutputMode,
|
||||
// Why: Codex/OpenCode startup queries intentionally stay live for 10s.
|
||||
// This benchmark measures steady-state model restore after that guard.
|
||||
pressureStartDelayMs:
|
||||
pressureOutputMode === 'rich-model'
|
||||
? RICH_MODEL_HIDDEN_PRESSURE_START_DELAY_MS
|
||||
: HIDDEN_PRESSURE_START_DELAY_MS,
|
||||
// Why: the 10s codex startup renderer-query window is deleted — every
|
||||
// pressure mode measures steady-state model restore with one delay.
|
||||
pressureStartDelayMs: HIDDEN_PRESSURE_START_DELAY_MS,
|
||||
testInfo,
|
||||
deps: terminalLoadScenarioDeps
|
||||
})
|
||||
@@ -792,18 +778,21 @@ test.describe('Artificial OpenCode terminal load', () => {
|
||||
mode?: HiddenPressureOutputMode
|
||||
}[] = [
|
||||
{ title: 'keeps typing responsive while hidden real PTYs are ACK-backpressured' },
|
||||
// Why: "withholds renderer delivery" — hidden bytes are dropped in main by
|
||||
// the delivery gate; the renderer no longer skip-scans chunks (Phase 6).
|
||||
{
|
||||
title: 'skips renderer writes for plain hidden PTY output while preserving restore',
|
||||
title: 'withholds renderer delivery for plain hidden PTY output while preserving restore',
|
||||
suffix: '-plain',
|
||||
mode: 'plain'
|
||||
},
|
||||
{
|
||||
title: 'skips renderer writes for Latin hidden PTY output while preserving restore',
|
||||
title: 'withholds renderer delivery for Latin hidden PTY output while preserving restore',
|
||||
suffix: '-latin',
|
||||
mode: 'latin'
|
||||
},
|
||||
{
|
||||
title: 'skips renderer writes for title-only hidden PTY output while preserving restore',
|
||||
title:
|
||||
'withholds renderer delivery for title-only hidden PTY output while preserving restore',
|
||||
suffix: '-title',
|
||||
mode: 'title'
|
||||
},
|
||||
|
||||
@@ -22,11 +22,11 @@ type HiddenTuiWindow = Window & {
|
||||
__terminalPtyDataInjection?: {
|
||||
inject: (paneKey: string, data: string, meta?: { seq?: number; rawLength?: number }) => boolean
|
||||
}
|
||||
// Why: only the mode-2031 fact-reply counter survives Phase 6 — the
|
||||
// hidden-skip counters were deleted with the renderer skip grammar.
|
||||
__terminalPtyOutputDebug?: {
|
||||
reset: () => void
|
||||
snapshot: () => {
|
||||
hiddenRendererSkipCount: number
|
||||
hiddenRendererSkippedChars: number
|
||||
hiddenRendererMode2031ReplyCount: number
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,17 +37,6 @@ type TerminalRenderDiagnostics = {
|
||||
}[]
|
||||
}
|
||||
|
||||
type LongTableDebugWindow = Window & {
|
||||
__terminalPtyOutputDebug?: {
|
||||
reset: () => void
|
||||
snapshot: () => {
|
||||
hiddenRendererSkipCount: number
|
||||
hiddenRendererSkippedChars: number
|
||||
hiddenRendererMode2031ReplyCount: number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const EMOJI_TABLE_FIXTURE = readFileSync(
|
||||
path.join(__dirname, 'fixtures', 'terminal-emoji-table.md'),
|
||||
'utf8'
|
||||
@@ -579,7 +568,6 @@ test.describe('Terminal long table scroll restore repro', () => {
|
||||
window.__store
|
||||
?.getState()
|
||||
.markFeatureTipsSeen(['orca-cli', 'cmd-j-palette', 'voice-dictation'])
|
||||
;(window as LongTableDebugWindow).__terminalPtyOutputDebug?.reset()
|
||||
})
|
||||
const firstWorktreeId = await waitForActiveWorktree(orcaPage)
|
||||
const secondWorktreeId = (await getAllWorktreeIds(orcaPage)).find(
|
||||
@@ -617,12 +605,6 @@ test.describe('Terminal long table scroll restore repro', () => {
|
||||
await scrollActiveTerminalLikeUser(orcaPage)
|
||||
await closeFeatureTips(orcaPage)
|
||||
const diagnostics = await readTerminalRenderDiagnostics(orcaPage)
|
||||
const hiddenDebug = await orcaPage.evaluate(() =>
|
||||
(window as LongTableDebugWindow).__terminalPtyOutputDebug?.snapshot()
|
||||
)
|
||||
if ((hiddenDebug?.hiddenRendererSkipCount ?? 0) > 0) {
|
||||
expect(hiddenDebug?.hiddenRendererSkippedChars).toBeGreaterThan(1024)
|
||||
}
|
||||
const restoredPane = diagnostics.allPaneStates.find((paneState) => paneState.hasMarker)
|
||||
expect(restoredPane).toBeDefined()
|
||||
expect(diagnostics.cursorHidden).toBe(false)
|
||||
@@ -647,7 +629,6 @@ test.describe('Terminal long table scroll restore repro', () => {
|
||||
window.__store
|
||||
?.getState()
|
||||
.markFeatureTipsSeen(['orca-cli', 'cmd-j-palette', 'voice-dictation'])
|
||||
;(window as LongTableDebugWindow).__terminalPtyOutputDebug?.reset()
|
||||
})
|
||||
const firstWorktreeId = await waitForActiveWorktree(orcaPage)
|
||||
const secondWorktreeId = (await getAllWorktreeIds(orcaPage)).find(
|
||||
@@ -687,12 +668,6 @@ test.describe('Terminal long table scroll restore repro', () => {
|
||||
await scrollActiveTerminalLikeUser(orcaPage)
|
||||
await closeFeatureTips(orcaPage)
|
||||
const diagnostics = await readTerminalRenderDiagnostics(orcaPage)
|
||||
const hiddenDebug = await orcaPage.evaluate(() =>
|
||||
(window as LongTableDebugWindow).__terminalPtyOutputDebug?.snapshot()
|
||||
)
|
||||
if ((hiddenDebug?.hiddenRendererSkipCount ?? 0) > 0) {
|
||||
expect(hiddenDebug?.hiddenRendererSkippedChars).toBeGreaterThan(1024)
|
||||
}
|
||||
// Why: renderer cell metrics can land one column wider in headless runs;
|
||||
// the content and screenshot assertions below cover the actual regression.
|
||||
expect(diagnostics.cols).toBeLessThanOrEqual(112)
|
||||
@@ -726,7 +701,6 @@ test.describe('Terminal long table scroll restore repro', () => {
|
||||
window.__store
|
||||
?.getState()
|
||||
.markFeatureTipsSeen(['orca-cli', 'cmd-j-palette', 'voice-dictation'])
|
||||
;(window as LongTableDebugWindow).__terminalPtyOutputDebug?.reset()
|
||||
})
|
||||
const firstWorktreeId = await waitForActiveWorktree(orcaPage)
|
||||
const secondWorktreeId = (await getAllWorktreeIds(orcaPage)).find(
|
||||
@@ -773,12 +747,6 @@ test.describe('Terminal long table scroll restore repro', () => {
|
||||
const diagnostics = await readTerminalRenderDiagnostics(orcaPage)
|
||||
const overpaint = await readTerminalRightEdgeOverpaint(orcaPage)
|
||||
const wrapDiagnostics = await readTerminalBoxTableWrapDiagnostics(orcaPage)
|
||||
const hiddenDebug = await orcaPage.evaluate(() =>
|
||||
(window as LongTableDebugWindow).__terminalPtyOutputDebug?.snapshot()
|
||||
)
|
||||
if ((hiddenDebug?.hiddenRendererSkipCount ?? 0) > 0) {
|
||||
expect(hiddenDebug?.hiddenRendererSkippedChars).toBeGreaterThan(1024)
|
||||
}
|
||||
expect(diagnostics.cols).toBeLessThan(100)
|
||||
expect(diagnostics.cursorHidden).toBe(false)
|
||||
testInfo.annotations.push({
|
||||
|
||||
@@ -169,7 +169,7 @@ type ScrollbackTabSetup = {
|
||||
}
|
||||
|
||||
// Why: each tab generates its scrollback while visible, so every xterm holds
|
||||
// the full buffer before going hidden — the hidden skip latch never gets a
|
||||
// the full buffer before going hidden — the hidden-delivery gate never gets a
|
||||
// chance to drop the output the memory comparison depends on.
|
||||
async function setUpScrollbackTabs(
|
||||
page: Page,
|
||||
|
||||
Reference in New Issue
Block a user