Turn-End Guard: Prevent premature turn completion when unified_exec processes are still running #14724
morozow
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'd like to propose a fix that prevents Codex turns from completing prematurely when background
unified_execprocesses (started viaexec_command) are still running. This is critical for workflows involving long-running commands like training scripts, build processes, or any command that takes more than a few seconds.Problem Statement
When an agent starts a long-running process through
unified_exec(e.g.,uv run train.py), the turn can end immediately after the model's response completes, even though the process is still running in the background. The agent loses the opportunity to wait for results and continue working with the output.Current behavior:
exec_commandwith a long-running commandprocess_id(indicating it's still running)ResponseEvent::Completedfireshas_pending_input()returnsfalse(no tool responses queued)Expected behavior:
Root Cause
In
codex-rs/core/src/codex.rs, the turn completion logic only checkshas_pending_input():This doesn't account for running
unified_execprocesses stored inunified_exec_manager.process_store.Proposed Solution
Add a check for running
unified_execprocesses before allowing turn completion:The
has_running_unified_exec_processesmethod checks if any process in the store:call_idprefix withturn_context.sub_id)Implementation Details
Files changed:
codex-rs/core/src/codex.rshas_running_unified_exec_processes()method; modifiedResponseEvent::Completedhandlingcodex-rs/core/src/unified_exec/mod.rsprocess_store,processes,ProcessEntry, andhas_exited()accessiblecodex-rs/core/src/unified_exec/process.rshas_exited()methodpub(crate)codex-rs/core/src/codex_tests.rscodex-rs/core/src/unified_exec/mod_tests.rsNew method signature:
Tests added:
has_running_unified_exec_processes_returns_false_when_no_processeshas_running_unified_exec_processes_detects_running_processhas_running_unified_exec_processes_ignores_completed_commandsAll tests pass.
Context: Why This Matters
I encountered this issue while working on autoresearch – an autonomous AI research platform where agents run 5-minute training experiments (
uv run train.py) and iterate on results. Without this fix, the agent's turn ends seconds after starting the training script, making autonomous experimentation impossible.This fix enables:
Request
I have a working implementation with tests ready. Since public PR access appears to be restricted, I'm requesting:
I'm happy to provide the complete diff, answer questions, or adjust the implementation based on maintainer feedback.
Beta Was this translation helpful? Give feedback.
All reactions