Skip to content

Comments

Fix js_repl in-flight tool-call waiter race#11800

Merged
fjord-oai merged 1 commit intomainfrom
fjord/js_repl_seq---4hqv5xq_6zbgq0
Feb 14, 2026
Merged

Fix js_repl in-flight tool-call waiter race#11800
fjord-oai merged 1 commit intomainfrom
fjord/js_repl_seq---4hqv5xq_6zbgq0

Conversation

@fjord-oai
Copy link
Contributor

@fjord-oai fjord-oai commented Feb 14, 2026

Summary

This PR fixes a race in js_repl tool-call draining that could leave an exec waiting indefinitely for in-flight tool calls to finish.

The fix is in:

  • /Users/fjord/code/codex-jsrepl-seq/codex-rs/core/src/tools/js_repl/mod.rs

Problem

js_repl tracks in-flight tool calls per exec and waits for them to drain on completion/timeout/cancel paths.
The previous wait logic used a check-then-wait pattern with Notify that could miss a wakeup:

  1. Observe in_flight > 0
  2. Drop lock
  3. Register wait (notified().await)

If notify_waiters() happened between (2) and (3), the waiter could sleep until another notification that never comes.

What changed

  • Updated all exec-tool-call wait loops to create an owned notification future while holding the lock:
    • use Arc<Notify>::notified_owned() instead of cloning notify and awaiting later.
  • Applied this consistently to:
    • wait_for_exec_tool_calls
    • wait_for_all_exec_tool_calls
    • wait_for_exec_tool_calls_map

This preserves existing behavior while eliminating the lost-wakeup window.

Test coverage

Added a regression test:

  • wait_for_exec_tool_calls_map_drains_inflight_calls_without_hanging

The test repeatedly races waiter/finisher tasks and asserts bounded completion to catch hangs.

Impact

  • No API changes.
  • No user-facing behavior changes intended.
  • Improves reliability of exec lifecycle boundaries when tool calls are still in flight.

git stack

@fjord-oai fjord-oai changed the base branch from fjord/js_repl_seq---4hqupa7505_e7j to main February 14, 2026 00:55
@fjord-oai fjord-oai force-pushed the fjord/js_repl_seq---4hqv5xq_6zbgq0 branch from dce304d to b269f97 Compare February 14, 2026 00:55
@fjord-oai fjord-oai changed the base branch from main to fjord/js_repl_seq---4hqupa7505_e7j February 14, 2026 00:55
Base automatically changed from fjord/js_repl_seq---4hqupa7505_e7j to main February 14, 2026 01:11
fjord-oai added a commit that referenced this pull request Feb 14, 2026
## Summary
Fixes a flaky/panicking `js_repl` image-path test by running it on a
multi-thread Tokio runtime and tightening assertions to focus on real
behavior.

## Problem
`js_repl_can_attach_image_via_view_image_tool` in  

`/Users/fjord/code/codex-jsrepl-seq/codex-rs/core/src/tools/js_repl/mod.rs`
can panic under single-thread test runtime with:

`can call blocking only when running on the multi-threaded runtime`

It also asserted a brittle user-facing text string.

## Changes
1. Updated the test runtime to:
   `#[tokio::test(flavor = "multi_thread", worker_threads = 2)]`
2. Removed the brittle `"attached local image path"` string assertion.
3. Kept the concrete side-effect assertions:
   - tool call succeeds
- image is actually injected into pending input (`InputImage` with
`data:image/png;base64,...`)

## Why this is safe
This is test-only behavior. No production runtime code paths are
changed.

## Validation
- Ran:
`cargo test -p codex-core
tools::js_repl::tests::js_repl_can_attach_image_via_view_image_tool --
--nocapture`
- Result: pass


#### [git stack](https://github.com/magus/git-stack-cli)
- 👉 `1` #11796
- ⏳ `2` #11800
- ⏳ `3` #10673
- ⏳ `4` #10670
git-stack-id: fjord/js_repl_seq---4hqv5xq_6zbgq0
git-stack-title: Fix js_repl in-flight tool-call waiter race
@fjord-oai fjord-oai force-pushed the fjord/js_repl_seq---4hqv5xq_6zbgq0 branch from b269f97 to 6e0eee0 Compare February 14, 2026 01:11
@fjord-oai fjord-oai enabled auto-merge (squash) February 14, 2026 01:12
@fjord-oai fjord-oai merged commit 0d76d02 into main Feb 14, 2026
33 checks passed
@fjord-oai fjord-oai deleted the fjord/js_repl_seq---4hqv5xq_6zbgq0 branch February 14, 2026 01:24
@github-actions github-actions bot locked and limited conversation to collaborators Feb 14, 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