Skip to content

Fix code mode yield startup race#14959

Merged
aibrahim-oai merged 1 commit intomainfrom
codex/code-mode-yield-startup-race
Mar 17, 2026
Merged

Fix code mode yield startup race#14959
aibrahim-oai merged 1 commit intomainfrom
codex/code-mode-yield-startup-race

Conversation

@aibrahim-oai
Copy link
Copy Markdown
Collaborator

What is flaky

code_mode_yield_timeout_works_for_busy_loop in codex-rs/core/tests/suite/code_mode.rs intermittently failed on loaded CI runners.

Why it was flaky

The initial yield_time_ms budget started when the worker was created, not when user code actually started running.

  • Worker startup includes thread scheduling, context creation, and runtime setup.
  • On a busy runner, that startup latency could consume most or all of the configured 100 ms yield budget.
  • The test expected the busy loop to emit output before the initial yield, but the timer could already have expired before the first user statement executed.

That made the test sensitive to runner startup jitter rather than to the actual code-mode yield behavior.

How this PR fixes it

  • Have the worker send a started message once the runtime is initialized and execution is about to begin.
  • Store the intended initial yield budget on the session.
  • Schedule the initial yield timer only after the started message arrives.

Why this fix fixes the flakiness

yield_time_ms now measures execution time instead of worker boot time. Startup jitter can no longer steal the timeout budget, so the test outcome depends on the code-mode runner semantics rather than on CI machine load at worker creation.

Start the initial yield timer only after the worker reports that code execution has started, so worker startup jitter on loaded CI runners does not consume the yield budget before user code runs.

Co-authored-by: Codex <noreply@openai.com>
@aibrahim-oai aibrahim-oai requested a review from pakrym-oai March 17, 2026 17:20
@aibrahim-oai aibrahim-oai merged commit 0d531c0 into main Mar 17, 2026
33 checks passed
@aibrahim-oai aibrahim-oai deleted the codex/code-mode-yield-startup-race branch March 17, 2026 18:09
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants