Skip to content

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

Merged
canvrno-oai merged 7 commits into
mainfrom
codex/fix-tui-wrap-borrowed-slice-range
May 13, 2026
Merged

[codex] Fix TUI wrapping for external borrowed slices#21235
canvrno-oai merged 7 commits into
mainfrom
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
Copy link
Copy Markdown
Contributor

@fcoury-oai fcoury-oai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempt to trigger the panic but couldn't, at least on macOS.

Code looks good, approved 👍

@canvrno-oai canvrno-oai merged commit 5d7e6a2 into main May 13, 2026
27 checks passed
@canvrno-oai canvrno-oai deleted the codex/fix-tui-wrap-borrowed-slice-range branch May 13, 2026 21:19
@github-actions github-actions Bot locked and limited conversation to collaborators May 13, 2026
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.

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

2 participants