Skip to content

Commit 6c68b79

Browse files
committed
make it work
1 parent d829cf2 commit 6c68b79

File tree

15 files changed

+726
-29
lines changed

15 files changed

+726
-29
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,13 @@ cython_debug/
162162
# and can be added to the global gitignore or merged into this file. For a more nuclear
163163
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
164164
#.idea/
165+
input/
165166
evaluation/reports/
166167
output/
167168
# *data_collection/collect/*.sh
168169
*data_collection/collect/temp
169170
*evaluation/temp
170-
temp/
171+
temp/
172+
173+
174+
ignore.*

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.

FILE_LOCATION_DEBUG.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# File Location Debug Guide
2+
3+
## Issue Description
4+
5+
When running the SWE Factory tool, files are being created at the repository root instead of in the specified output directories, despite providing the correct `--output-dir`, `--setup-dir`, and `--results-path` parameters.
6+
7+
## Root Cause Analysis
8+
9+
After analyzing the codebase, I found that the system is correctly designed to use the specified output directories. All file writing operations use proper path construction with `pjoin()` or `os.path.join()` to ensure files are written to the correct output directories.
10+
11+
However, there are several potential causes for files appearing in the wrong location:
12+
13+
### 1. Working Directory Changes
14+
The code uses `cd` context managers in several places (like in `dump_cost` function), which temporarily change the working directory. If any file operations happen outside of these context managers while the directory is changed, they might write to the wrong location.
15+
16+
### 2. Race Conditions
17+
The system uses multiprocessing, and there might be race conditions where the working directory is changed in one process while another process is writing files.
18+
19+
### 3. Missing Absolute Paths
20+
Some file operations might not be using absolute paths, causing them to write relative to the current working directory.
21+
22+
## Changes Made
23+
24+
I've made the following improvements to ensure files are written to the correct locations:
25+
26+
### 1. Added Absolute Path Safety Checks
27+
- Modified `run_raw_task()` to ensure `task_output_dir` is absolute
28+
- Modified `do_inference()` to ensure `task_output_dir` is absolute
29+
- Modified `dump_cost()` to ensure `task_output_dir` is absolute
30+
31+
### 2. Added Debug Logging
32+
- Added logging in `AgentsManager` to track where Dockerfile, eval.sh, and status.json are written
33+
- Added logging in `TestAnalysisAgent` to track where Dockerfile and eval.sh are written
34+
35+
### 3. Created Debug Script
36+
- Created `debug_file_locations.py` to monitor file creation during execution
37+
38+
## How to Debug the Issue
39+
40+
### Step 1: Run with Debug Logging
41+
The enhanced logging will now show exactly where files are being written. Look for log messages like:
42+
```
43+
Writing Dockerfile to: /path/to/output/dir/Dockerfile
44+
Writing eval.sh to: /path/to/output/dir/eval.sh
45+
Writing status.json to: /path/to/output/dir/status.json
46+
```
47+
48+
### Step 2: Use the Debug Script
49+
Run the debug script in a separate terminal to monitor file creation:
50+
51+
```bash
52+
# In one terminal, start the debug script
53+
python debug_file_locations.py output/swe-factory-runs/kareldb-test 600 10
54+
55+
# In another terminal, run your command
56+
LITELLM_API_BASE="https://api.dev.halo.engineer/v1/ai" \
57+
OPENAI_API_KEY="${OPENAI_API_KEY?->Need a key}" \
58+
PYTHONPATH=. python app/main.py local-issue \
59+
--task-id "kareldb-connection-1" \
60+
--local-repo "/Users/[email protected]/xynova/kareldb-cp" \
61+
--issue-file "input/kareldb_test_issue.txt" \
62+
--model google/gemini-2.5-flash \
63+
--output-dir "output/swe-factory-runs/kareldb-test" \
64+
--setup-dir "output/swe-factory-runs/testbed" \
65+
--results-path "output/swe-factory-runs/results" \
66+
--conv-round-limit 3 \
67+
--num-processes 1 \
68+
--model-temperature 0.2
69+
```
70+
71+
The debug script will:
72+
- Monitor file creation every 10 seconds for 10 minutes
73+
- Log all new files created
74+
- Warn about files created outside the expected output directory
75+
- Show the current working directory at each check
76+
77+
### Step 3: Check the Logs
78+
Look for:
79+
1. **Expected behavior**: Files being written to the specified output directory
80+
2. **Unexpected behavior**: Files being written to the current working directory or repository root
81+
3. **Working directory changes**: Any unexpected changes in the current working directory
82+
83+
## Expected File Locations
84+
85+
Based on your command, files should be created in:
86+
87+
- **Task output files**: `output/swe-factory-runs/kareldb-test/kareldb-connection-1/`
88+
- `Dockerfile`
89+
- `eval.sh`
90+
- `status.json`
91+
- `cost.json`
92+
- `meta.json`
93+
- `problem_statement.txt`
94+
- `developer_patch.diff`
95+
- `info.log`
96+
- `test_analysis_agent_0/` (subdirectory with test results)
97+
98+
- **Setup directory**: `output/swe-factory-runs/testbed/`
99+
- Repository clones and working directories
100+
101+
- **Results**: `output/swe-factory-runs/results/results.json`
102+
- Aggregated results from all tasks
103+
104+
## Troubleshooting
105+
106+
If files are still being created in the wrong location:
107+
108+
1. **Check the debug logs** to see exactly where files are being written
109+
2. **Verify the output directory exists** and is writable
110+
3. **Check for any error messages** about directory creation or file writing
111+
4. **Ensure no other processes** are changing the working directory
112+
5. **Verify the command line arguments** are being parsed correctly
113+
114+
## Additional Recommendations
115+
116+
1. **Use absolute paths** in your command line arguments
117+
2. **Ensure the output directories exist** before running the command
118+
3. **Check file permissions** on the output directories
119+
4. **Monitor system resources** to ensure there are no disk space issues
120+
121+
## Code Changes Summary
122+
123+
The following files were modified to improve file location handling:
124+
125+
- `app/main.py`: Added absolute path safety checks
126+
- `app/agents/agents_manager.py`: Added debug logging for file creation
127+
- `app/agents/test_analysis_agent/test_analysis_agent.py`: Added debug logging for file creation
128+
- `debug_file_locations.py`: Created debug script for monitoring file creation
129+
- `FILE_LOCATION_DEBUG.md`: This documentation file

app/agents/agents_manager.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self,
4949
client: docker.DockerClient,
5050
start_time: datetime,
5151
max_iteration_num: int,
52-
results_path:str,
52+
results_path: str | None,
5353
disable_memory_pool:bool,
5454
disable_context_retrieval:bool,
5555
disable_run_test:bool,
@@ -79,7 +79,19 @@ def __init__(self,
7979
self.set_agent_status("context_retrieval_agent",True)
8080
self.agents_dict['test_analysis_agent'].disable_context_retrieval= disable_context_retrieval
8181
self.agents_dict['test_analysis_agent'].disable_run_test = disable_run_test
82-
self.results_file = f'{results_path}/results.json'
82+
83+
# Handle None results_path by setting a default
84+
if results_path is None:
85+
results_path = os.path.join(output_dir, "results")
86+
87+
# Ensure results_path is absolute
88+
if not os.path.isabs(results_path):
89+
results_path = os.path.abspath(results_path)
90+
91+
# Create the results directory if it doesn't exist
92+
os.makedirs(results_path, exist_ok=True)
93+
94+
self.results_file = os.path.join(results_path, 'results.json')
8395
lock_path = self.results_file + '.lock'
8496
self.lock = FileLock(lock_path, timeout=30)
8597
with self.lock:
@@ -263,15 +275,21 @@ def run_workflow(self) -> None:
263275
eval_script_content = self.agents_dict['write_eval_script_agent'].get_latest_eval_script()
264276
eval_script_skeleton_content = self.agents_dict['write_eval_script_agent'].get_latest_eval_script_skeleton()
265277
if dockerfile_content and eval_script_content:
266-
with open(os.path.join(self.output_dir, "Dockerfile"), "w") as dockerfile_f:
278+
dockerfile_path = os.path.join(self.output_dir, "Dockerfile")
279+
logger.info(f"Writing Dockerfile to: {dockerfile_path}")
280+
with open(dockerfile_path, "w") as dockerfile_f:
267281
dockerfile_f.write(dockerfile_content)
268282

269283

270-
with open(os.path.join(self.output_dir, "eval.sh"), "w") as eval_script_f:
284+
eval_script_path = os.path.join(self.output_dir, "eval.sh")
285+
logger.info(f"Writing eval.sh to: {eval_script_path}")
286+
with open(eval_script_path, "w") as eval_script_f:
271287
eval_script_f.write(eval_script_content)
272288

273289

274-
with open(os.path.join(self.output_dir, "status.json"), "w") as status_file_f:
290+
status_file_path = os.path.join(self.output_dir, "status.json")
291+
logger.info(f"Writing status.json to: {status_file_path}")
292+
with open(status_file_path, "w") as status_file_f:
275293
json.dump({"is_finish": self.workflow_finish_status}, status_file_f)
276294

277295
if self.workflow_finish_status:

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

0 commit comments

Comments
 (0)