test(session): fix shell-cancel race when trap hasn't installed yet#27408
Merged
Conversation
The "cancel persists aborted shell result when shell ignores TERM" test relied on a 50ms sleep between forking the shell and calling cancel. On a slow Linux CI runner, SIGTERM can arrive before bash has installed the `trap '' TERM` line — exercising the wrong code path (or the right one, intermittently) and flaking the test. Touch a marker file after `trap` and poll for its existence before cancelling. The poll is the hard happens-before that the 50ms sleep was hoping for.
AIALRA-0
pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
AIALRA-0
pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
avion23
pushed a commit
to avion23/opencode
that referenced
this pull request
Jun 10, 2026
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.
Summary
The `cancel persists aborted shell result when shell ignores TERM` test at `test/session/prompt.test.ts:1509` flakes on Linux CI because of a timing race:
On a slow runner, the SIGTERM can arrive before bash has parsed and installed the `trap` line, so the kill-escalation path the test is named after never gets exercised — and the resulting failure mode varies run-to-run.
Fix
Touch a marker file after trap installs, and poll for its existence before cancelling. The marker is a hard happens-before that the 50ms sleep was only approximating:
```
trap '' TERM; touch "${ready}"; sleep 30
```
POSIX guarantees the three commands run sequentially within bash, so once the marker exists the trap is installed.
Why polling beats a longer sleep
A bigger `Effect.sleep` would still be theoretically racy under CI load and would always burn its full duration. The poll typically resolves in 10–30ms (first or second tick) and is provably race-free.
Test plan