Wait for a run to complete and return its output.
If the run is already in a terminal state (success, error, interrupted), the output is returned immediately. Otherwise the server waits up to 30 seconds for the background task to finish.
Sessions are managed manually (not via Depends) to avoid holding a pool connection during the long wait, which would starve background tasks.