Skip to content

fix(bots): accept shlex-quoted shell wrappers so Look around can save Codex suggestions - #48660

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-48624
Nov 25, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-48624

Conversation

@nwparker

@nwparker nwparker commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When a Codex bot runs Look around and wants to save a suggestion like orca bot suggest --title 'Follow up', Codex hands Orca the command wrapped in /bin/zsh -lc ... with extra quoting. Orca only knew one style of that quoting, so it couldn't see the real command and refused it. Now Orca reads the quoting Codex actually uses, then checks the real command the same way as before.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

What Changed

  • Before: Any Codex Look around command with a quoted multi-word value (orca bot suggest --title 'Follow up' --why '...' --ask '...', gh pr list --search 'a b') stayed wrapped as /bin/zsh -lc ..., so the read-only policy saw /bin/zsh and refused it. Suggestions were never saved.
  • After: Those commands are unwrapped to the script and pass the same read-only checks as an unwrapped command. Anything that still isn't a plain read (; rm x, $(id), backticks, !) is refused as before.
  • Mechanism: Codex builds the approval text with shlex_join(["/bin/zsh", "-lc", script]) (codex-rs/app-server/src/bespoke_event_handling.rs). shlex double-quotes a script that contains a ', or splits it into '...' and "..." runs. SHELL_WRAPPER in src/main/bots/bot-look-around-shell-syntax.ts now accepts the wrapped word as a sequence of literal runs: 'single', "double" with no $, ` or ! and only the \" and \\ escapes, and \'. unwrapShell decodes those runs to the script. Adjacent single-quoted runs ('a''b') are not accepted, because zsh's RC_QUOTES reads '' as a literal '. That would make the decoded text differ from what zsh runs.

Why

The approval text is the only thing Orca sees, and it is produced by shlex, not by Orca's earlier '\''-only assumption. Decoding just the literal subset of shlex output keeps the policy strict: any form that could expand or run something in bash, zsh (with or without RC_QUOTES) or dash stays wrapped and is refused. The other options were less safe. Loosening the read-only allow-list would let more commands through, and a general shell parser could get expansions wrong.

Linked Issue

Fixes #48624

Visual Proof

N/A. This changes how the main-process approval policy parses a command string. There is no UI change, and the evidence is the parser output below (before: refused, after: unwrapped and allowed).

Testing

  • Repro: replayed the issue's command /bin/zsh -lc 'orca bot suggest --title '"'"'Follow up'"'"' ...' and the double-quoted shlex form against unwrapShell and the Look around policy. On main it stays wrapped and is refused as "/bin/zsh" isn't a read. On this branch it unwraps to orca bot suggest --title 'Follow up' ... and is allowed.
  • Added 17 cases to src/main/bots/bot-look-around-policy.test.ts. They cover double-quoted and split-run shlex output, chained ${ORCA_CLI_COMMAND:-orca} calls with \", and \\ and ! runs. Refusals cover ; rm x, $(id), backticks, \" and ! inside double quotes, unbalanced runs, and the RC_QUOTES 'a'';rm y;' bypass. The new allow cases fail on main.
  • Probe (not committed): shlex 1.3.0 joins of generated scripts decoded exactly (74,388 unwrapped, 0 misdecodes). Accepted random words decoded identically under bash, zsh -f, zsh -f -o rc_quotes and dash.
  • vitest run src/main/bots/bot-look-around-policy.test.ts: 158 passed. oxlint, oxfmt, anti-slop, code-quality native plugins, ast-grep and the changed-code quality gate are clean on both files.
  • Platforms: macOS. The code path is POSIX-shell only (shell === 'bash'). PowerShell handling is unchanged.

Performance

None, because unwrapShell runs once per Look around command approval in the main process. That path is not hot: it doesn't run per render, per keystroke, on terminal output or on a poll. It adds no I/O or subprocesses. Micro-benchmark, old vs new regex plus decode:

  • typical /bin/zsh -lc 'git status': 0.07 µs vs 0.16 µs per call
  • issue command (86 chars): 0.02 µs vs 0.39 µs per call
  • adversarial 30–100 KB inputs (thousands of alternating runs, long \\ chains, 100 KB unterminated quote): worst case 0.26 ms. No catastrophic backtracking, because each alternative starts on a different character. The 100 KB unterminated case is faster than the old regex (77 µs vs 192 µs).

Risk

Level: Low. The riskiest part is the policy boundary: a decoding mismatch could let a non-read through. Mitigations: only literal runs are accepted, the decoded script still goes through every existing check, and decoding was cross-checked against four shells. A plain revert restores the old behavior, where Codex suggestions are refused again.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Reported by @Hello-Pig

… Codex suggestions

Codex sends a command approval as shlex_join(["/bin/zsh", "-lc", script]).
shlex double-quotes a script that contains a single quote, or splits it
into '...' and "..." runs, so every Look around command with a quoted
value (orca bot suggest --title 'Follow up' ...) stayed wrapped and was
refused.

Read the wrapped word as literal runs: '...', "..." with no $, ` or !
and only shlex's \" and \\ escapes, and \'. Adjacent single-quoted runs
stay wrapped because zsh's RC_QUOTES reads '' as a quote. The decoded
script then goes through the same read-only checks as before.

Fixes #48624
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

unwrapShell now decodes wrapped commands composed of adjacent single-quoted, restricted double-quoted, and escaped-single-quote runs. The policy tests cover valid read commands and commands that remain denied, including commands with rm or command substitution.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 6ebbd

This change lets Look around save suggestions with multi-word quoted arguments while keeping shell expansion and chaining refused. No concrete merge-blocking risk was found in the reviewed parser or its policy path.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Look around can now save Codex suggestions because shlex-quoted shell wrappers are accepted. It matches the raw summary, which describes unwrapShell accepting Codex sh…
Linked Issues check Passed [#48624] requires a Codex-backed Look around run to save a suggestion with spaces under the existing read-only policy. The reported repro uses a zsh-wrapped command with double-quoted apostrophes (`'"…
Out of Scope Changes check Passed The whole-PR change (merge base 7f2a281 to head 6ebbdc6) touches the shell-wrapper parsing in bot-look-around-shell-syntax.ts and its policy tests. Both directly implement the #48624 objective of un…
Description check Passed The description follows the repository template closely. It has an ELI5, a detailed What Changed section with before and after behavior and mechanism, a Why section that explains the chosen approach a…
Full details: Title check

Explanation

The title names the main change: Look around can now save Codex suggestions because shlex-quoted shell wrappers are accepted. It matches the raw summary, which describes unwrapShell accepting Codex shell-wrapper commands made of adjacent literal quoted runs, and the policy test additions. The title uses the fix(bots) convention and is specific, so it passes.

Full details: Linked Issues check

Explanation

[#48624] requires a Codex-backed Look around run to save a suggestion with spaces under the existing read-only policy. The reported repro uses a zsh-wrapped command with double-quoted apostrophes ('"'"'). At head, SHELL_WRAPPER in src/main/bots/bot-look-around-shell-syntax.ts accepts adjacent single-quoted runs, double-quoted runs without $, backtick, or !, and \' escapes. unwrapShell decodes those runs with LITERAL_RUN, so the wrapped orca bot suggest ... command reaches the existing read-only checks. The previous '\'' form is still decoded. Adjacent single-quoted runs ('a''b') are rejected, which keeps the decoded text aligned with zsh's RC_QUOTES reading. The PR also reports 17 added policy test cases in src/main/bots/bot-look-around-policy.test.ts. I did not re-run those tests. I did not re-read the Rust shlex_join source in codex-rs, so the match between the Codex output and the accepted grammar rests on the reported probe and the issue's repro.

Full details: Out of Scope Changes check

Explanation

The whole-PR change (merge base 7f2a281 to head 6ebbdc6) touches the shell-wrapper parsing in bot-look-around-shell-syntax.ts and its policy tests. Both directly implement the #48624 objective of unwrapping Codex-quoted commands. The change does not loosen the read-only allow-list, and PowerShell handling is unchanged. The related issues #46064, #48395, and #48411 are not targeted, and the PR does not claim to address them. The PR description's agent-skill checkbox is non-code and does not affect the diff.

Full details: Description check

Explanation

The description follows the repository template closely. It has an ELI5, a detailed What Changed section with before and after behavior and mechanism, a Why section that explains the chosen approach and the alternatives rejected, a linked issue (Fixes #48624), and a Visual Proof section marked N/A with a reason. The Testing section lists the reproduction steps, the 17 added test cases, the cross-shell probe, the vitest result, and the platform tested (macOS). The Performance section gives a one-line justification with measurements. The Risk section states the level (Low), names the riskiest part, and explains the revert path. The Agent skill upstream boundary box is checked. Minor gaps: the AI Disclosure section is blank, the Testing checkboxes are not ticked, and the Checklist is not reflected in the body. None of these is critical. The description is mostly complete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 804ae879-e24d-41df-a6bb-ab70abf17eca
Commits

Reviewing files that changed from the base of the PR and between 4843fe1 and 6ebbdc6.

Files selected for processing: 2

  • src/main/bots/bot-look-around-policy.test.ts
  • src/main/bots/bot-look-around-shell-syntax.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@nwparker
nwparker merged commit ea36e65 into main Nov 25, 2026
54 of 55 checks passed
@nwparker
nwparker deleted the bugbash/issue-48624 branch November 25, 2026 03:02
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.

[Bug]: Codex Look around cannot save suggestions with quoted arguments

1 participant