Skip to content

[codex] Fix TUI wrapping for external borrowed slices#21235

Open
canvrno-oai wants to merge 3 commits intomainfrom
codex/fix-tui-wrap-borrowed-slice-range
Open

[codex] Fix TUI wrapping for external borrowed slices#21235
canvrno-oai wants to merge 3 commits intomainfrom
codex/fix-tui-wrap-borrowed-slice-range

Conversation

@canvrno-oai
Copy link
Copy Markdown
Contributor

Fixes #20587, reported by @noeljackson.

This prevents the TUI wrapping code from panicking when textwrap returns a borrowed slice that does not point into the original source text. The fix follows the direction proposed by @misrtjakub in the issue comment: validate the borrowed slice pointer range first, and fall back to the existing owned-line mapper when the slice is external.

  • Guards borrowed wrapped slices before converting pointer offsets into byte ranges.
  • Reuses the existing owned-line range recovery path for external borrowed slices.
  • Adds coverage for rejecting borrowed slices outside the source text.

End-user testing steps:

  • Start Codex in TUI mode under a PTY wrapper that can inject stdin after startup.
  • Inject \x1b[200~test message\x1b[201~\r after the TUI is ready.
  • Confirm Codex does not panic and the pasted text is handled normally.

Local validation:

  • cargo test -p codex-tui wrapping::tests::
  • cargo test -p codex-tui -- --skip status::tests::status_permissions_full_disk_managed_with_network_is_danger_full_access --skip status::tests::status_permissions_full_disk_managed_without_network_is_external_sandbox

@canvrno-oai canvrno-oai marked this pull request as ready for review May 5, 2026 22:25
@canvrno-oai
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@canvrno-oai canvrno-oai requested a review from fcoury-oai May 5, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI panics in wrapping.rs:52 (byte index near u64::MAX) on bracketed-paste injection over stdin

1 participant