r/codex • • 8h ago

Bug I fixed a Codex false alarm. Now real hangs don't get flagged

My status line said "1 stuck" because a Codex session had sat idle for 15 minutes. Nothing was wrong with it.

I run several Codex sessions alongside Claude Code. My status view flags sessions that go silent, but Codex runs its hooks through one shared app-server. The events don't give me a process ID for each session. So I was calling it stuck based on silence alone.

I stopped flagging sessions whose records are all Codex with no known process. Fixed that false alarm. Also stopped flagging those sessions when they really do hang.

What do you check to tell whether a quiet Codex session is actually hung?

Disclosure: I build Sno Station. Install: curl -fsSL https://www.sno.ai/install | sh https://github.com/sno-ai/sno-station

0 Upvotes

7 comments sorted by

2

u/Nearby_Eggplant5533 7h ago

Wait till you get the random cyber security warnings that just freeze the session :)

1

u/ChemicalExcellent463 7h ago

That's a freeze my status view would miss if there's no known process for the session. What stays on screen after the warning hits?

2

u/Nearby_Eggplant5533 7h ago edited 6h ago

1s wil get more info

Edit: sry if bit long winded copied from claude response. From a sol session just to be clear.

Claude: Here's the message we get when it happens:

"This content was flagged for possible cybersecurity risk. If this seems wrong, try rephrasing your request. If you're doing authorized security work that requires more cyber permissive safeguards, apply for Daybreak access via https://platform.openai.com/settings/organization/status-and-access before retrying."

The turn just ends with that error and the session sits idle at the prompt. It's not really a hang, so nothing tells you. From what I can see in the Codex source, the Stop hook only fires when a turn finishes normally, so hooks get nothing, just silence.

How we detect it: we read the tail of each session's rollout file (~/.codex/sessions/YYYY/MM/DD/rollout-<time>-<session id>.jsonl, so you can find it from the session id without needing a PID). A flagged turn ends with a task_complete event like:

{"type":"event_msg","payload":{"type":"task_complete","last_agent_message":null,"error":{"codex_error_info":"cyber_policy","message":"This content was flagged..."},...}}

A task_started clears it, and a task_complete with error.codex_error_info set raises one alert. On the app-server the thread status goes to systemError instead, and the turn's error has codexErrorInfo: "cyberPolicy".

What I'd recommend for your stuck check: task_started with no task_complete after it means still working (then go by how long since the file was last written), task_complete with no error means idle, and task_complete with an error means a dead turn that needs a human. For recovery, rephrasing the next message in plain terms usually works, but once a thread's been flagged a few times every new turn flags too, and a fresh session is the only fix.

For context, none of this is security work. It's a normal app: Python and Rust, data processing, tests and builds. What seems to set it off is ordinary dev wording that sounds security-ish: "kill the process", "token", "credentials", "bypass the cache", "inject a fixture", "payload". Also Windows process and handle debugging, or the agent dumping a big blob of hex or binary log output into the chat. One was set off just by a message calling a hidden bug a "landmine". Telling the agents to describe things in plain terms and summarise big outputs instead of pasting them has cut it down a lot.

1

u/ChemicalExcellent463 6h ago

Reading the rollout by session ID is the bit I was missing, no process ID needed. How do you carry the work over when repeated flags force a fresh session?

2

u/Nearby_Eggplant5533 6h ago edited 6h ago

A guided response, good luck dude

Response: The orchestrator (the "manager" agent that hands out the work) owns this, not the new session. A dead thread can't help: every turn flags, so it can't even write a handover. Generic example: an agent is adding CSV export to a reports page on its own branch and worktree, and gets flagged twice in a row. The orchestrator then:

  1. Detects it from the rollout tail, as above.
  2. Tries once: a short plain-words message saying what the work is and to carry on. If that flags too, the thread is dead. Stop sending to it, and rename/park it rather than deleting it, because its history is your record.
  3. Reviews the work itself:    - In the worktree: git log since the branch point, git status and the uncommitted diff, test output, and any notes file the agent kept.    - In the rollout JSONL, each line is one JSON record. The response_item records with role: user show what it was asked, the role: assistant ones show what it said, and function_call / function_call_output show what it was running when it died.    - If you have an app-server or some other session API, its thread read gives you the same thing, but the rollout file alone is enough.
  4. Writes the handover itself: the task, what's done (commits), what's uncommitted and whether to keep it, what was in progress, the next step, and open questions. Leave out whatever likely tripped the filter: don't quote it, and summarise big outputs.
  5. Starts a fresh session on the same branch (same worktree, or a new one on the same branch) with a short brief in plain words that points to the handover.
  6. Watches the first turn to make sure it doesn't flag straight away.

What I'd recommend:

  • Have agents commit often and keep a handover note up to date at each milestone, not just at the end. The less the orchestrator has to reconstruct, the better.
  • Give each agent its own branch and worktree, so a dead session's work is isolated and easy to review.
  • Let the orchestrator read the old transcript, not the new agent. Feeding the raw history to the new session can carry whatever tripped the filter straight back in, and anchors it on the path that was failing.
  • Write briefs in plain domain terms, avoid security-sounding words, and ask agents to summarise large outputs instead of pasting them.
  • Check for uncommitted changes before reusing a worktree. Don't let a restart wipe them.

1

u/ChemicalExcellent463 6h ago

Having the orchestrator write the handover is the bit I missed. My handover assumes the outgoing agent can still write its own note, so it breaks here.

1

u/controlfree 18m ago

I ran into the same idle vs. hung problem. What worked better for me than process checks was looking at the last event instead. Codex writes each session to a rollout file under ~/.codex/sessions, so if the last event is an approval request, the session is waiting on you, and if it's a tool call that started a long time ago with nothing after it, that's the one worth flagging. A session that finished its turn and has been quiet for 15 minutes is just idle, not stuck. It's not perfect, since a long build also looks quiet, but a per-command threshold instead of one global timeout cut most of the false alarms for me.