From ed3ee7e08a744f5fdd60550d19d17032a9f60e52 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 18 Oct 2026 00:35:30 -0700 Subject: [PATCH] refactor: name the vm transcript and mobile pending-write caps for what they count (#30251) Both cap UTF-16 string length for local display and memory, never wire bytes, so _BYTES misled readers into treating them as consumer byte budgets. --- .../terminal/terminal-webview-pending-messages.ts | 12 ++++++------ src/cli/handlers/vm.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mobile/src/terminal/terminal-webview-pending-messages.ts b/mobile/src/terminal/terminal-webview-pending-messages.ts index 5aa49e2e94f..814ed1dd436 100644 --- a/mobile/src/terminal/terminal-webview-pending-messages.ts +++ b/mobile/src/terminal/terminal-webview-pending-messages.ts @@ -1,15 +1,15 @@ import type { TerminalWebViewCommand } from './terminal-webview-messages' -const MAX_PENDING_WEB_WRITE_BYTES = 1_000_000 +const MAX_PENDING_WEB_WRITE_CODE_UNITS = 1_000_000 const MAX_PENDING_WEB_WRITE_MESSAGES = 4096 export function createTerminalWebViewPendingMessages() { let pending: TerminalWebViewCommand[] = [] - let pendingWriteBytes = 0 + let pendingWriteCodeUnits = 0 let pendingWriteCount = 0 const resetCounters = () => { - pendingWriteBytes = 0 + pendingWriteCodeUnits = 0 pendingWriteCount = 0 } @@ -24,10 +24,10 @@ export function createTerminalWebViewPendingMessages() { return } - pendingWriteBytes += msg.data.length + pendingWriteCodeUnits += msg.data.length pendingWriteCount += 1 while ( - pendingWriteBytes > MAX_PENDING_WEB_WRITE_BYTES || + pendingWriteCodeUnits > MAX_PENDING_WEB_WRITE_CODE_UNITS || pendingWriteCount > MAX_PENDING_WEB_WRITE_MESSAGES ) { const dropIndex = pending.findIndex((candidate) => candidate.type === 'write') @@ -37,7 +37,7 @@ export function createTerminalWebViewPendingMessages() { } const [dropped] = pending.splice(dropIndex, 1) if (dropped?.type === 'write') { - pendingWriteBytes = Math.max(0, pendingWriteBytes - dropped.data.length) + pendingWriteCodeUnits = Math.max(0, pendingWriteCodeUnits - dropped.data.length) pendingWriteCount = Math.max(0, pendingWriteCount - 1) } } diff --git a/src/cli/handlers/vm.ts b/src/cli/handlers/vm.ts index 1bffd99f00e..7afb01fe2b5 100644 --- a/src/cli/handlers/vm.ts +++ b/src/cli/handlers/vm.ts @@ -105,16 +105,16 @@ type DoctorResult = EphemeralVmRecipeDoctorResult & { provisionTranscript?: ProvisionTranscript } -const MAX_TRANSCRIPT_STREAM_BYTES = 16_000 +const MAX_TRANSCRIPT_STREAM_CHARS = 16_000 // Why: keep both ends of a long log — the script's setup context (head) and the // failure itself (tail) — rather than only the last 500 chars. function capTranscriptStream(value: string): string { const redacted = redactEphemeralVmRecipeDiagnosticText(value) - if (redacted.length <= MAX_TRANSCRIPT_STREAM_BYTES) { + if (redacted.length <= MAX_TRANSCRIPT_STREAM_CHARS) { return redacted } - const half = Math.floor(MAX_TRANSCRIPT_STREAM_BYTES / 2) + const half = Math.floor(MAX_TRANSCRIPT_STREAM_CHARS / 2) const omitted = redacted.length - half * 2 return `${redacted.slice(0, half)}\n…[${omitted} chars omitted]…\n${redacted.slice(-half)}` }