Skip to content

fix(ffi): drain stdout/stderr pumps before Wait terminal event#705

Closed
G4614 wants to merge 1 commit into
boxlite-ai:mainfrom
G4614:fix/ffi-exec-drain-race
Closed

fix(ffi): drain stdout/stderr pumps before Wait terminal event#705
G4614 wants to merge 1 commit into
boxlite-ai:mainfrom
G4614:fix/ffi-exec-drain-race

Conversation

@G4614

@G4614 G4614 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Re-opened replacement for the previously-closed PR (force-push made the old head commit unreachable; new commit on the same branch).

Bug

Go SDK's box.Exec occasionally returned with stdout chunks still in flight — the user's callback got OnExit (or the wait gRPC reply) before the matching OnStdout/OnStderr chunks landed on the queue. From the caller's perspective the exec had finished but its stdout was silently truncated.

Fix

Make exit_pump the sole owner of terminal-event dispatch. Both execution_wait and register_exit fan into it; exit_pump awaits all stream pump receivers before pushing the terminal event. Queue order becomes Stdout/Stderr* -> Exit -> Wait* — all from the same task.

Test plan

Pin: test_p0_6_exec_stdout_race (scripts/test/e2e/cases/, from #678).

Pre-fix Post-fix
test_p0_6_exec_stdout_race (stdout loss rate over 10 short execs) ~70% loss 0% loss

Replaces an earlier split-out attempt that stacked on #682's reorg (now abandoned). Branch rebuilt against current main with a single commit.

🤖 Generated with Claude Code

The Go SDK's box.Exec would occasionally return with stdout chunks
still in flight — the user's callback got OnExit (or the wait gRPC
reply) before the matching OnStdout/OnStderr chunks landed on the
queue. From the caller's perspective, the exec had finished but its
stdout was silently truncated.

Root cause: execution_wait spawned an independent terminal task that
pushed the Wait event as soon as wait_on_clone returned — with no
drain barrier — so the wait reply could land in the event queue
ahead of still-flushing stream pumps.

Fix: make exit_pump the sole owner of terminal-event dispatch. Both
execution_wait and register_exit fan into it; exit_pump awaits all
stream pump receivers before pushing the terminal event. Queue order
becomes Stdout/Stderr* -> Exit -> Wait*, all from the same task.

Pin: test_p0_6_exec_stdout_race in boxlite-ai#678's e2e suite goes from ~70%
stdout-loss to 0%.

Replaces an earlier split-out attempt that stacked on boxlite-ai#682's reorg
(now abandoned). Branch rebuilt against current main.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8912d51b-8ce6-4f9f-8dd9-973df7cbdd59

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@G4614

G4614 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Closed — this was opened as a placeholder after #685 got auto-closed by a force-push. But the FFI drain-race fix is already tracked at #563 (same content, older PR). Continuing this work on #705 would have been a duplicate. The fix/ffi-exec-drain-race branch will be deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant