Ended a turn whose task panicked, instead of hanging. - #2
Open
moedash wants to merge 1 commit into
Open
Conversation
The spawn site owns turn lifecycle, as its comment says, but a panic in the task unwound past both the finish hook and the waiter notification. A client waiting on the turn's terminal event then waited for one that never came, and codex stayed alive holding the thread's writer lock, which blocked every later resume of that thread. Verified by restoring a panic that used to happen here and resuming a thread with a dangling tool call: the turn now reports turn.failed and the process exits.
3 tasks
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.
What changed?
A panic in a turn task no longer escapes the spawn site in
codex-rs/core/src/tasks/mod.rs. The task future runs undercatch_unwind, and a panic becomes aFataltask error, soon_task_finishedemits the turn's terminal event like it does for any other failure.Why?
That spawn site owns turn lifecycle, as its own comment says: "Finish uniformly from the spawn site so all tasks share the same lifecycle." A panic was the one path that escaped it, unwinding past both
on_task_finishedanddone.notify_waiters().The result is worse than a crash. A client waiting on the turn waits for a terminal event that never arrives, and the process stays alive holding the thread's writer lock, so every later resume of that thread fails with
already has an active writer.codex exechangs rather than exiting, because its wait loop only ends on an event or a closed stream.This is the general guard. It is not hypothetical: it happened, and the specific panic that triggered it is fixed separately.
How did you test it?
describe_panichas a unit test for the payload shapes it can read.End to end: put the old panic back, resumed a thread with a dangling tool call, and watched it log
turn task panicked, emit{"type":"turn.failed",...}, and exit. The same command hung indefinitely before this change.