Fix output explosion OOM: add tool-prevention, timeout, and output caps#3
Open
rodboev wants to merge 2 commits into
Open
Fix output explosion OOM: add tool-prevention, timeout, and output caps#3rodboev wants to merge 2 commits into
rodboev wants to merge 2 commits into
Conversation
Codex CLI runs in full-auto mode and autonomously reads files, searches code, and streams JSON for every tool call. When reviewing multi-file projects, this produced 64MB+ of output that crashed the peer-reviewer agent with OOM. Changes: - Add "Do not use any tools" suffix to every codex exec prompt - Wrap all codex exec calls with timeout 120 and head -c 500000 - Add content-inclusion pattern (paste file contents vs referencing paths) - Add temp file approach (mktemp) for large prompts - Remove permissionMode: bypassPermissions (too permissive) - Add new tool permissions: mktemp, rm, timeout, head, git diff/show/log - Add output explosion section to common-mistakes.md - Add Rule 5: Output Protection to discussion-protocol.md - Improve hook scripts to try env vars before stdin JSON parsing - Add output protection to commands/codex-peer-review.md
The upstream hooks.json fires on SessionStart, every UserPromptSubmit, every Stop, and three PreToolUse matchers (ExitPlanMode, Task, Write). This causes 5+ hook subprocess invocations per turn in busy sessions, measurably slowing down conversations. Keep only the two hooks that earn their overhead: - UserPromptSubmit: keyword-gated, only outputs when prompt contains plan/design/review/architecture keywords (silent otherwise) - PreToolUse(ExitPlanMode): fires only when about to present a plan Removed hooks: - SessionStart: unconditional reminder every session - Stop: fires on every response completion - PreToolUse(Task): fires on every subagent dispatch - PreToolUse(Write): fires on every file write
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two critical issues with the codex-peer-review plugin:
codex execruns in full-auto mode and autonomously reads files, searches code, and streams JSON. For multi-file reviews, this produced 64MB+ of output that crashed the peer-reviewer agent.This PR backports defensive patterns proven in the
gemini-peer-reviewfork (by stephenbrandon), adapted for Codex CLI semantics, and reduces hooks to a minimal keyword-gated set.Root Cause — OOM
When
codex execreceives a prompt that references file paths, it autonomously:--jsonflag)teeFor a real-world test (8 shell scripts + a 430-line GUIDE.md), this produced a 64MB output file that OOM'd the peer-reviewer agent.
Root Cause — Hook Overhead
Each hook spawns a bash subprocess, reads stdin/env, runs grep, and outputs text injected into context. With 6 hooks firing across SessionStart + UserPromptSubmit + Stop + 3x PreToolUse, busy sessions trigger dozens of hook invocations per conversation turn.
Changes
Commit 1: Output Protection
All
codex execinvocations:codex execcalls wrapped withtimeout 120(prevents infinite tool loops)head -c 500000(caps at 500KB)Content Inclusion Pattern:
mktemp) for large multi-file promptsAgent Definition (
agents/codex-peer-reviewer.md):permissionMode: bypassPermissions(overly permissive)mktemp,rm,timeout,head,git diff/show/logDocumentation:
common-mistakes.mddiscussion-protocol.mdSKILL.mdHook Scripts:
user-prompt-check.sh,task-peer-review-check.sh,write-peer-review-check.sh: Try env vars first, fall back to stdin JSON parsingCommit 2: Hook Reduction
Reduced from 6 hooks to 2 — keeping only the ones that earn their overhead:
Testing
/codex-peer-reviewcommand locallyChecklist