Skip to content

Commit e37e29a

Browse files
committed
fixes
1 parent 243cc1a commit e37e29a

File tree

5 files changed

+143
-0
lines changed

5 files changed

+143
-0
lines changed

DOCKER_LOGGING_FIX.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Docker Logging Configuration Fix
2+
3+
## Issue Description
4+
5+
The Docker containers created by the SWE Factory tool were using a logging configuration that disabled container logs:
6+
7+
```json
8+
"ContainerIDFile": "",
9+
"LogConfig": {
10+
"Type": "none",
11+
"Config": {}
12+
}
13+
```
14+
15+
This configuration meant:
16+
- No container logs were being captured
17+
- `docker logs <container>` would not work
18+
- Debugging container issues was difficult
19+
- The tool couldn't capture container output for analysis
20+
21+
## Root Cause
22+
23+
The issue was in the container creation code in two files:
24+
1. `app/agents/test_analysis_agent/docker_utils.py` - `build_container()` function
25+
2. `evaluation/docker_build.py` - `build_container()` and `build_setup_container()` functions
26+
27+
These functions were creating containers without explicit logging configuration, causing Docker to use default settings that might be set to `"none"` in some environments.
28+
29+
## Solution Applied
30+
31+
I've updated all container creation calls to include proper logging configuration:
32+
33+
### Before:
34+
```python
35+
container = client.containers.create(
36+
image=test_image_name,
37+
name=test_container_name,
38+
user="root",
39+
detach=True,
40+
command="tail -f /dev/null",
41+
nano_cpus=None,
42+
platform="linux/x86_64",
43+
)
44+
```
45+
46+
### After:
47+
```python
48+
container = client.containers.create(
49+
image=test_image_name,
50+
name=test_container_name,
51+
user="root",
52+
detach=True,
53+
command="tail -f /dev/null",
54+
nano_cpus=None,
55+
platform="linux/x86_64",
56+
log_config={
57+
"Type": "json-file",
58+
"Config": {
59+
"max-size": "10m",
60+
"max-file": "3"
61+
}
62+
}
63+
)
64+
```
65+
66+
## Benefits of the Fix
67+
68+
1. **Container Logs Available**: You can now use `docker logs <container>` to view container output
69+
2. **Better Debugging**: Container issues can be diagnosed more easily
70+
3. **Log Rotation**: Logs are automatically rotated when they reach 10MB
71+
4. **Storage Management**: Only 3 log files are kept per container
72+
5. **Tool Functionality**: The SWE Factory tool can now capture and analyze container output
73+
74+
## Files Modified
75+
76+
1. `app/agents/test_analysis_agent/docker_utils.py` - Line 330-340
77+
2. `evaluation/docker_build.py` - Lines 590-600 and 650-660
78+
79+
## Testing the Fix
80+
81+
After applying this fix, you should be able to:
82+
83+
1. Run the SWE Factory tool as usual
84+
2. Use `docker logs <container_name>` to view container logs
85+
3. See container output in the tool's log files
86+
4. Debug container issues more effectively
87+
88+
## Recommended Docker Configuration
89+
90+
For optimal performance, ensure your Docker daemon is configured with:
91+
92+
```json
93+
{
94+
"log-driver": "json-file",
95+
"log-opts": {
96+
"max-size": "10m",
97+
"max-file": "3"
98+
}
99+
}
100+
```
101+
102+
This ensures consistent logging behavior across all containers, even those created without explicit logging configuration.

app/agents/test_analysis_agent/docker_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ def build_container(client,test_image_name,test_container_name,instance_id,run_t
339339
command="tail -f /dev/null",
340340
nano_cpus=None,
341341
platform="linux/x86_64",
342+
log_config={
343+
"Type": "json-file",
344+
"Config": {
345+
"max-size": "10m",
346+
"max-file": "3"
347+
}
348+
}
342349
)
343350

344351

app/globals.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@
5353
disable_context_retrieval: bool = False
5454

5555
disable_run_test: bool = False
56+
57+
# whether to only organize output without running tasks
58+
organize_output_only: bool = False

app/main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def main(args, subparser_dest_attr_name: str = "command"):
7777
globals.output_dir = args.output_dir
7878
if globals.output_dir is not None:
7979
globals.output_dir = abspath(globals.output_dir)
80+
else:
81+
# Set a default output directory if none is provided
82+
globals.output_dir = abspath("output/swe-factory-runs/default")
8083
num_processes: int = int(args.num_processes)
8184
# set whether brief or verbose log
8285
print_stdout: bool = not args.no_print
@@ -100,6 +103,11 @@ def main(args, subparser_dest_attr_name: str = "command"):
100103

101104
globals.context_generation_limit = args.output_fix_limit
102105
globals.setup_dir = args.setup_dir
106+
if globals.setup_dir is not None:
107+
globals.setup_dir = abspath(globals.setup_dir)
108+
else:
109+
# Set a default setup directory if none is provided
110+
globals.setup_dir = abspath("output/swe-factory-runs/testbed")
103111

104112
globals.organize_output_only = args.organize_output_only
105113
globals.results_path = args.results_path
@@ -657,6 +665,11 @@ def run_raw_task(
657665

658666
start_time_s = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
659667
# task_output_dir = pjoin(globals.output_dir, f"{task_id}_{start_time_s}")
668+
669+
# Ensure globals.output_dir is set
670+
if not globals.output_dir:
671+
globals.output_dir = abspath("output/swe-factory-runs/default")
672+
660673
task_output_dir = pjoin(globals.output_dir, f"{task_id}")
661674

662675
# Ensure task_output_dir is absolute
@@ -721,6 +734,10 @@ def do_inference(
721734
if hasattr(python_task, 'repo_cache_path'):
722735
repo_cache_path = python_task.repo_cache_path
723736
else:
737+
# Ensure globals.setup_dir is set
738+
if not globals.setup_dir:
739+
globals.setup_dir = abspath("output/swe-factory-runs/testbed")
740+
724741
# Create a working directory in the testbed to avoid deleting the original repo
725742
working_dir = pjoin(globals.setup_dir, f"{python_task.project_path.split('/')[-1]}_working")
726743
repo_cache_path = python_task.project_path

evaluation/docker_build.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,13 @@ def build_container(
603603
command="tail -f /dev/null",
604604
nano_cpus=nano_cpus,
605605
platform=test_spec.platform,
606+
log_config={
607+
"Type": "json-file",
608+
"Config": {
609+
"max-size": "10m",
610+
"max-file": "3"
611+
}
612+
}
606613
)
607614

608615
logger.info(f"Container for {test_spec.instance_id} created: {container.id}")
@@ -659,6 +666,13 @@ def build_setup_container(
659666
command="tail -f /dev/null",
660667
# nano_cpus=nano_cpus,
661668
platform=test_spec.platform,
669+
log_config={
670+
"Type": "json-file",
671+
"Config": {
672+
"max-size": "10m",
673+
"max-file": "3"
674+
}
675+
}
662676
)
663677

664678
logger.info(f"Container for {test_spec.instance_id} created: {container.id}")

0 commit comments

Comments
 (0)