Repository navigation
Description
Summary
The Windows forced-delete checker can assign a -Force parameter from a read-only Get-ChildItem call to a separate, non-forced Remove-Item call inside an if/elseif block. With approval_policy = "never", this false positive rejects the whole PowerShell script with only blocked by policy.
This report provides an independently observed rejection, a reduced regression-test shape, and version-specific source analysis. Related reports: #43732 and #51791. It does not request disabling forced-delete safeguards.
Environment
- Component: Windows Codex desktop app, bundled Codex app-server/shell execution.
- The executable used by the running app reports
codex-cli 0.153.4(not a different CLI found on PATH). - Windows x64, OS version
10.0.26300.0; PowerShell7.6.5. - Effective session settings:
sandbox_mode = "danger-full-access"andapproval_policy = "never". - Subscription/model: not included; the reported condition is in local command classification.
- Latest stable checked:
0.163.0, published 2026-10-15. Its classifier file is byte-for-byte identical to 0.153.4. 0.163.0 was inspected in source only, not run.
Observed behavior
An explicitly requested cleanup of an empty, agent-created directory was rejected before process creation. The deletion used only -LiteralPath, with no -Force or -Recurse. The script first checked that the directory was not a reparse point and that it contained no entries, including hidden entries.
The tool error ended with:
exec_command failed: CreateProcess { message: "Rejected(... rejected: blocked by policy)" }
A later read-only check confirmed that the directory remained. The exact original script was parsed as data with PowerShell's Parser.ParseInput: zero parse errors; both Remove-Item AST nodes had only LiteralPath; the sole Force parameter belonged to Get-ChildItem.
The user rules file had no deny rule. A static codex execpolicy check against that file returned {"matchedRules": []}. That rules-only check does not evaluate the complete runtime heuristic path.
Reduced reproduction / proposed regression test
Use a disposable empty directory and the Windows PowerShell shell with the settings above. This is a sanitized, reduced form of the observed conditional; the reduced case has not been executed:
# $folder refers to an already-created disposable empty directory.
if (@(Get-ChildItem -LiteralPath $folder -Force).Count -eq 0) {
Remove-Item -LiteralPath $folder
}The observed original had this conditional body inline, with no semicolon between the listing expression and the deletion:
elseif (@(Get-ChildItem -LiteralPath $folder -Force).Count -eq 0) { Remove-Item -LiteralPath $folder; 'Deleted empty directory.' }This fragment is context, not a standalone script.
Source analysis
In the 0.163.0 Windows checker, has_force_delete_cmdlet:
- Separates command segments only on
; | &\n\r\t. - Treats braces and parentheses as soft punctuation, not command boundaries.
- Returns true when any deletion atom and any
-forceatom occur in one segment.
Therefore, the listing in the condition and the deletion in the block can be grouped together. A read-only Python reproduction of this source algorithm against the exact original command found a matching segment containing both atoms. This is a static algorithm reproduction, not a run of the compiled Rust classifier.
The policy fallback maps a dangerous match plus AskForApproval::Never to Decision::Forbidden. The rejection formatter reports Windows Other matches as only blocked by policy.
The runtime logs did not expose the winning classifier predicate. The observed error, actual parameter ownership, and source-level match support this diagnosis, but a compiled end-to-end regression test is still needed.
Expected behavior
- Preserve PowerShell command/parameter ownership across conditional expressions and script blocks: a listing's
-Forcemust not make a separate deletion forced. - Keep genuine
Remove-Item -Forcesafeguards intact. - Add regression coverage for this conditional shape and newline variants, including real forced-delete positive controls.
- Include the matched safety condition in the rejection message.
No protection, execution policy, or permissions were changed. No alternative deletion method was used. Private paths, credentials, raw logs, and session identifiers are omitted.
Activity
Alex770 commentedon Nov 5, 2026
Reproduced on Windows with the running bundled executable reporting
codex-cli 0.166.0-alpha.6. The desktop updater reports version 26.1029.61003 / build 24614 / prod as up to date.Effective execution settings:
approval_policy=Never,sandbox_policy=DangerFullAccess; Full Access is selected in the UI.Three non-destructive runtime tests were executed through the normal shell tool, using an already-created disposable fixture and
Remove-Item -WhatIf:if (Test-Path fixture.txt) { Get-Item fixture.txt -Force<newline>Remove-Item fixture.txt -WhatIf }: rejected before process creation withblocked by policy.if (Test-Path fixture.txt) { Remove-Item fixture.txt -Force -WhatIf }: rejected as expected by the existing dangerous-command heuristic.if (Test-Path fixture.txt) { Get-Item fixture.txt<newline>Remove-Item fixture.txt -WhatIf }: allowed; PowerShell printed the WhatIf operation.No file was deleted by these tests. No approval rule, safety check, sandbox boundary, or running executable was changed. The contrast between cases 1 and 3 establishes an executable reduced reproduction of the read-only Force parameter being associated with a separate ordinary deletion. An implementation fix still needs regression coverage preserving case 2 and conservative handling of dynamic/continued PowerShell syntax.