Skip to content

Avoid allocations when sanitizing TUI user text - #38214

Merged
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/9e39cbc0d83c5791941b37a7eb4bb918c1a05f68
Aug 12, 2026
Merged

copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/9e39cbc0d83c5791941b37a7eb4bb918c1a05f68

Conversation

@copyberry

@copyberry copyberry Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Avoid allocations when sanitizing TUI user text

Why

Sanitizing user messages and pasted text always allocated a new string, even
when the input contained no terminal control characters.

What changed

  • Return a Cow<str> from sanitize_user_text so clean borrowed input remains
    borrowed.
  • Reuse owned input buffers when sanitization leaves the text intact or only
    removes content at the edges.
  • Update transcript rendering, history cells, and paste handling to consume the
    borrowed-or-owned result without unnecessary cloning.

Testing

Add sanitizer coverage for clean text, control sequences, Unicode control
characters, incomplete escape sequences, buffer reuse, and multi-fragment
output.

## Why

Sanitizing user messages and pasted text always allocated a new string, even
when the input contained no terminal control characters.

## What changed

- Return a `Cow<str>` from `sanitize_user_text` so clean borrowed input remains
  borrowed.
- Reuse owned input buffers when sanitization leaves the text intact or only
  removes content at the edges.
- Update transcript rendering, history cells, and paste handling to consume the
  borrowed-or-owned result without unnecessary cloning.

## Testing

Add sanitizer coverage for clean text, control sequences, Unicode control
characters, incomplete escape sequences, buffer reuse, and multi-fragment
output.

GitOrigin-RevId: 9e39cbc0d83c5791941b37a7eb4bb918c1a05f68
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/9e39cbc0d83c5791941b37a7eb4bb918c1a05f68 branch from 5f39876 to 91d6f48 Compare August 12, 2026 16:34
@copyberry
copyberry Bot merged commit 91d6f48 into main Aug 12, 2026
28 of 32 checks passed
@copyberry
copyberry Bot deleted the copyberry/codex-internal-to-codex-oss/9e39cbc0d83c5791941b37a7eb4bb918c1a05f68 branch August 12, 2026 16:35
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 12, 2026

This branch was previously deployed

1 inactive deployment
issue-triage — 91d6f489 Deployed Aug 12, 2026 by Ben2248 via Translate non-English issue #7747
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants