Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion plugins/codex/scripts/session-lifecycle-hook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ export const SESSION_ID_ENV = "CODEX_COMPANION_SESSION_ID";
const PLUGIN_DATA_ENV = "CLAUDE_PLUGIN_DATA";

function readHookInput() {
const raw = fs.readFileSync(0, "utf8").trim();
let raw;
try {
raw = fs.readFileSync(0, "utf8").trim();
} catch (e) {
if (e.code === "EAGAIN") {
return {};
}
Comment on lines +27 to +29
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve session event data when stdin returns EAGAIN

Handling EAGAIN by returning {} causes this lifecycle hook to proceed as if no event data was provided, even though a non-blocking read may succeed moments later. In SessionEnd, that can lose session_id/cwd context and skip targeted cleanup (cleanupSessionJobs) or cleanup the wrong scope. The read path should retry on EAGAIN rather than converting it to empty input.

Useful? React with πŸ‘Β / πŸ‘Ž.

throw e;
}
if (!raw) {
return {};
}
Expand Down
10 changes: 9 additions & 1 deletion plugins/codex/scripts/stop-review-gate-hook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ const ROOT_DIR = path.resolve(SCRIPT_DIR, "..");
const STOP_REVIEW_TASK_MARKER = "Run a stop-gate review of the previous Claude turn.";

function readHookInput() {
const raw = fs.readFileSync(0, "utf8").trim();
let raw;
try {
raw = fs.readFileSync(0, "utf8").trim();
} catch (e) {
if (e.code === "EAGAIN") {
return {};
}
Comment on lines +26 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Retry EAGAIN instead of treating hook payload as empty

EAGAIN on a non-blocking pipe means data is not ready yet, not that stdin is empty. Returning {} here drops the hook event payload when the writer is slightly delayed, so this script can run the stop-review decision with missing session_id, cwd, and last_assistant_message and make an allow/block decision on the wrong context. This should retry reads (or temporarily use blocking I/O) and only map true empty/EOF input to {}.

Useful? React with πŸ‘Β / πŸ‘Ž.

throw e;
}
if (!raw) {
return {};
}
Expand Down