test: fix flaky test_background_task_runs_and_exits near the exit tick#216
Open
CyberDefenseOperations wants to merge 1 commit into
Open
Conversation
The background-shell poll helper (_poll_output) returned the instant it saw status=='exited', but shell_task_output reads are incremental and the final output chunk can still be draining into the task buffer on the same tick the status flips to exited. Under load the first post-exit read returns empty and the helper returns acc='', failing 'quick_done' in acc. This is a harness race, not a shell bug (the incremental-read contract is correct). Keep reading until a read yields nothing new (bounded 2s) after the terminal status so the tail is captured deterministically. Verified 15/15.
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.
_poll_outputreturns the moment it seesstatus == "exited", butshell_task_outputreads are incremental and the final output chunk can still be draining into the task buffer on the same tick the status flips to exited. Under load the first post-exit read returns empty, so the helper returnsacc == ""and the test fails with'quick_done' not in ''.This is a harness race, not a shell bug — the incremental-read contract is correct; the poll helper just returned before the tail was drained. The fix keeps reading until a read yields nothing new (bounded 2s) after the terminal status, so the final output is captured deterministically. The existing
again["output"] == ""assertion still holds (the drain leaves nothing buffered). Verified 15/15 in a loop.