Repository navigation
Fix REPL source measurement cache collisions - #1217
Conversation
The published @bomb.sh/tty 0.9.0 engine keys its text-measurement cache by hash alone, so two texts sharing a hash share one width (#1216). Setup now compiles the pinned tty/Clay source with a readable cache patch and the pinned WASI SDK, and publishes the verified runtime to the ignored packages/cli/generated/tty. CLI modules import it directly, and the external dependency and its lock entries are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds the public collision regression (batched, sequential, key-storage reset, oversized-after-resize and a full frame), a nested reading that recovers, cuts and aligns exactly at three profiles, and a cold-reopen journey over a settled history holding the colliding pair. Preparation tests cover refusal before replacement, held tools and writes, and the preflight; the driver reproduces the runtime twice. The npm, JSR and host-binary distributions carry the runtime, declarations and notice without producer inputs, and the release specification records the prepared route. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR #1217: Fix REPL source measurement cache collisions42 files, +2035 / -54 Scope🔴 PR has 2089 lines changed. Split into focused PRs. 🟡 2089 lines changed. PRs under 400 receive more thorough review. 🟡 42 files changed. Are all changes related? 🟡 Changes span 8 directories. 🟡 PR mixes config and source changes. Structural🟡 Type declarations with no consumers: ScanResult.
🟡 3 console statements. Oxlint structural signals:
Slop
Oxlint slop signals:
Static AnalysisOxlint: 51 diagnostics across 12 files (11 rules) no-shadow (17): packages/cli/src/repl/renderer.ts, packages/cli/src/repl/layout.ts, packages/cli/src/repl/fitting.ts CorrectnessNo extraneous code patterns detected. |
Clay copied a text key when it began creating a cache entry, before the word-capacity check. A refused entry stayed unlinked, so every later lookup copied its key again, and a 1.1 MB frame wrote 281 KB past the key arena into the packed input before the capacity error (#1216). A key is now copied only when its entry is published, and a copy that would not fit borrows the call's wire bytes and resets the cache after presenting. The regression proves the packed input is unchanged, the capacity refusal stands and a replacement engine measures 57/91. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Why
Opening a readable retained REPL session could refuse a source row as too wide. A second synthetic case showed silent source-tail loss. Both came from tty’s Clay text cache treating a matching 32-bit hash as text identity. Fixes #1216.
What changes
Before: measuring one text could return a different text’s width, within one batch or across calls. A synthesized 316×40 production frame reproduced the reported refusal exactly.
After: cache lookup compares the actual text and measurement inputs. The existing fitter and drawing engine receive the correct widths, preserving complete source, grapheme cuts, nesting and status reservations.
How it works
The CLI uses a source-derived local repair of tty 0.9.0 and its pinned Clay engine. The cache owns retained key bytes and copies them only when an entry is published. Every copy checks remaining storage. A key that would exceed the arena borrows the current call’s immutable wire bytes; the cache clears those borrowed keys after presentation. Capacity refusals preserve packed input and current-layout references. The public tty API and the existing two-engine renderer remain intact.
Setup verifies pinned source, compiler, patch and output identities, then publishes a complete 21-file runtime/declaration/notice directory through staged replacement. Builds and checks consume prepared output. The CLI’s imports, npm/JSR output and compiled notice asset use that same graph. The external tty runtime dependency is removed.
Review guide
Start with the cache patch and recipe in
packages/cli/vendor/tty/, thenscripts/lib/prepare-tty.tsand its preflight/staged-write integration. Inspect the cache equality and key lifetime together, including oversized layouts after resize.Review the public collision and exact-wrapping regressions, passive cold-history journey, preparation failure/cancellation tests and actual distribution consumers. Check correctness, necessity and UI cost, including existing fit-store and engine reuse.
What must stay true
How to verify it
Signed head:
963561422491395b3570f0aca5b3167b9fefbb20, followingc0d216f2a96edbb369eaefdd483f1db9513fb64eand preparation commit92c7d148adff94c68a88e2f0a761e09c79dbd697, on baseccd70ca3421df8ee725036a97697204a62344566.Passing focused evidence covers:
deno task verify:clean. Clean verification passed preparation, offline builds, release compilation, resolution and three-runtime interference with tracked files, dependency layout, locks and cache content preserved.Planner correction review, committed
verify:clean, the fresh synthetic cold-history regression and required CI PASS at this head. CI run 2576 completed with 61 successful jobs and one skipped job, including the successfulgreenaggregate. Current Main-health evidence also passes.The same independent Fable reviewer returned substantive PASS and closed the capacity finding, but its 1,605-character summary exceeded the recorded 1,500-character schema. The original reply and rejection remain unchanged. A one-time no-call reconciliation proposal is awaiting direct human approval; the PR stays in draft until that review gate is resolved.
Scope
The engine-cache correction, its prepared delivery route and focused regression/distribution evidence. Retained history, disclosure, provider behavior, runtime flags and unrelated dependencies keep their existing contracts.
New abstractions
The tty producer and recipe supply the concrete prepared runtime consumed by the CLI. Directory staging publishes that multi-file runtime without exposing partial output. They reuse existing preparation/process ownership patterns and add no public API or general registry.
Dependencies and generated changes
The runtime remains tty 0.9.0 with a pinned source repair. WASI SDK 27.0 is a checksum-pinned preparation tool. Generated runtime bytes are ignored; maintained inputs, patches and notices are tracked. Import changes are mechanical. The owning release specification describes the prepared path and notice assets.
Risks and limitations
Reproducibility was executed on macOS arm64. Other pinned compiler hosts must produce the same expected output or refuse. Linux setup and the exhaustive Deno/Node/Bun suites passed in CI for this head. The cache adds bounded key storage per engine and retains existing engine and fit-store reuse.
Scope confirmation