Stop preset tests from waiting on the tail poll - #4089
Merged
Conversation
The agent's output goes to files rather than pipes, so reading it polls every 200ms, and every `run_preset_agent` call waited once after the agent had already exited. Tests write the whole output up front, so `test_agent.py` spent 2.5s of its 4.3s sleeping.
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.
What
The preset agent writes its output to files rather than pipes, so reading it means polling:
_FileLineReader._POLL_SECONDS = 0.2. When there is no new data and the agent process is still alive, the reader sleeps 200ms. Tests write the whole fake-agent output up front and the process exits in ~20ms, so everyrun_preset_agentcall waited out a full poll it had nothing to wait for.Tests that trigger a resume pay it 2-3 times, which matched the timings exactly:
An autouse fixture in the presets test package sets the interval to 0.
Effect
test_agent.pygoes from 4.18s to 1.65s, 41 passed. It was the most expensive test file in the suite.What remains is genuine:
test_creates_private_cli_home_and_dstack_wrapperspawns the realdstackCLI to prove the generated workspace wrapper executes, which cannot be shown without executing it.No production code changed.
Also
Two notes in AGENTS.md on keeping the suite fast, since this was the same class of issue as the lock-retry sleeps fixed in #4088.
AI assistance: written with Claude Code.