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.
This commit is contained in:
Neil
2026-10-18 00:35:30 -07:00
committed by GitHub
parent dcfbec0377
commit ed3ee7e08a
2 changed files with 9 additions and 9 deletions
@@ -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)
}
}
+3 -3
View File
@@ -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)}`
}