Skip to content

Fix logging of Docker build logs #1421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2025

Conversation

tobiasofsn
Copy link
Contributor

Log the actual build logs instead of the generator object <itertools._tee object at 0x102566100>. Note that this requires LogLevel.DEBUG.

Before:

Initializing executor, hold on...
Building Docker image jupyter-kernel...
<itertools._tee object at 0x102566100>
Starting container on 127.0.0.1:8888...
Container status: created, waiting...
Container e75fc3014e66 is running with kernel e47a7e1a-9723-4c5a-8157-fcffd14bfdae

After:

Initializing executor, hold on...
Building Docker image jupyter-kernel...
Step 1/6 : FROM python:3.12-slim
 ---> 31a416db24bd
Step 2/6 : RUN pip install jupyter_kernel_gateway requests numpy pandas
 ---> Using cache
 ---> b827be6d2dc6
Step 3/6 : RUN pip install jupyter_client notebook
 ---> Using cache
 ---> 93de55e39b1a
Step 4/6 : RUN pip install smolagents
 ---> Using cache
 ---> d7d84341b0db
Step 5/6 : EXPOSE 8888
 ---> Using cache
 ---> 63f8f9c5545c
Step 6/6 : CMD ["jupyter", "kernelgateway", "--KernelGatewayApp.ip='0.0.0.0'", "--KernelGatewayApp.port=8888", 
"--KernelGatewayApp.allow_origin='*'"]
 ---> Using cache
 ---> 5f44d4c65961
Successfully built 5f44d4c65961
Successfully tagged jupyter-kernel:latest
Starting container on 127.0.0.1:8888...
Container status: created, waiting...
Container 6e1b62d6a49e is running with kernel 5a573a4d-46b0-40a4-a52e-707e8754bb01

Test app:

from smolagents import CodeAgent, InferenceClientModel
from smolagents.monitoring import LogLevel

model = InferenceClientModel()

agent = CodeAgent(
    model=model,
    tools=[],
    executor_type="docker",
    verbosity_level=LogLevel.DEBUG
)

@albertvillanova albertvillanova requested a review from Copilot June 18, 2025 19:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes how Docker build logs are handled by converting the returned log stream generator into a readable string and trimming trailing whitespace before logging at DEBUG level.

  • Flatten the build_logs generator into a single string
  • Trim trailing whitespace and log actual build steps instead of the generator object
Comments suppressed due to low confidence (2)

src/smolagents/remote_executors.py:236

  • [nitpick] Reassigning build_logs from a generator to a string may be confusing. Consider using a new variable name (e.g., build_logs_str) to clarify the change in type.
                build_logs = "".join([x.get("stream", "") for x in build_logs])

src/smolagents/remote_executors.py:237

  • There aren't tests covering the new log formatting behavior. Adding a unit test to verify that build_logs is correctly concatenated and trimmed would help prevent regressions.
                self.logger.log(build_logs.rstrip(), level=LogLevel.DEBUG)

Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix.

@albertvillanova albertvillanova merged commit 9c323fd into huggingface:main Jun 20, 2025
3 checks passed
@tobiasofsn tobiasofsn deleted the fix-logging-docker-build branch June 20, 2025 16:53
@tobiasofsn
Copy link
Contributor Author

Thank you @albertvillanova and even better with your changes!

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.

2 participants