Repository: harbor-framework/harbor
Issue: 🚨 CRITICAL: Docker Compose project name validation bug breaks Oracle on custom_docker_compose tasks
Root cause: Validation Gap

# 🚨 CRITICAL: Harbor Docker Compose Project Name Validation Bug

**Priority:** 🔴 HIGHEST - Infrastructure Regression  
**Impact:** Oracle solutions fail on tasks using `custom_docker_compose = true`  
**Status:** Blocks CI validation of Harbor tasks

## Summary

Harbor generates trial IDs that start with underscores (e.g., `__TBCYUP6`), which Docker Compose rejects as invalid project names. This causes Oracle runs to fail with `RuntimeError` even when the task solution is correct.

## Error Details

```
RuntimeError: Docker compose command failed for environment . 
Command: docker compose -p __tbcyup6 -f <path>/docker-compose.yaml up -d. 
Return code: 1. 
Stdout: invalid project name "__tbcyup6": must consist only of lowercase alphanumeric characters, hyphens, and underscores as well as start with a letter or number
```

**Location:** `harbor/environments/docker/docker.py`, line 166 (in `_run_docker_compose_command`)

## Root Cause

Docker Compose project names must:
- Start with a letter or number (not underscore)
- Contain only lowercase alphanumeric characters, hyphens, and underscores

Harbor's trial ID generation can produce IDs starting with `__`, which violates this constraint.

## Impact

- **Oracle solutions fail** on tasks with `custom_docker_compose = true`
- **CI incorrectly flags tasks as "unsolvable"** when they're actually correct
- **False negatives** in task validation pipeline
- **Blocks task development** for Harbor tasks using custom docker-compose

## Affected Task Example

- Task: `reproducible-build-path-order`
- Oracle solution: ✅ Correct (passes when Docker Compose works)
- Oracle runs: ❌ Fail due to invalid project name
- CI result: ❌ Incorrectly flagged as "unsolvable"

## Workaround (Temporary)

Sanitize project names before passing to `docker compose`:

```python
# In harbor/environments/docker/docker.py, _run_docker_compose_command method
# Before: project_name = trial_id.lower()
# After:
project_name = trial_id.lower()
# Ensure project name starts with alphanumeric character
if project_name.startswith('_'):
    project_name = 'tb' + project_name.lstrip('_')
# Or use a more robust sanitization:
import re
project_name = re.sub(r'^[^a-z0-9]+', 'tb', project_name.lower())
project_name = re.sub(r'[^a-z0-9_-]', '', project_name)
```

## Expected Behavior

1. Harbor should sanitize trial IDs before using them as Docker Compose project names
2. Project names should always start with a letter or number
3. Oracle runs should succeed when task solutions are correct

## Reproduction Steps

1. Create a Harbor task with `custom_docker_compose = true` in `task.toml`
2. Run: `harbor run --path <task-path> -a oracle --n-attempts 3`
3. Observe: Some runs fail with `RuntimeError` due to invalid project name
4. Check trial IDs: They may start with `__` (double underscore)

## Files Involved

- `harbor/environments/docker/docker.py` - `_run_docker_compose_command` method
- Trial ID generation logic (wherever trial IDs are created)

## Test Case

```python
# Test that project names are valid for Docker Compose
def test_docker_compose_project_name_sanitization():
    trial_ids = ["__TBCYUP6", "normal-id", "_single", "123abc"]
    for trial_id in trial_ids:
        project_name = sanitize_for_docker_compose(trial_id)
        assert re.match(r'^[a-z0-9][a-z0-9_-]*$', project_name), \
            f"Invalid project name: {project_name}"
        assert not project_name.startswith('_'), \
            f"Project name cannot start with underscore: {project_name}"
```

## Additional Context

- This is a **regression** - tasks that previously worked are now failing
- The task infrastructure is correct - Oracle solutions work when Docker Compose succeeds
- This bug creates false negatives in CI, making it appear tasks are unsolvable when they're actually correct

## Action Required

1. **Immediate:** Add sanitization logic to ensure Docker Compose project names are valid
2. **Verify:** Oracle runs should pass consistently on tasks with `custom_docker_compose = true`
3. **Test:** Run Oracle on `reproducible-build-path-order` - should pass 100% after fix

---

**Repository:** https://github.com/laude-institute/harbor  
**Related Issue:** Blocks validation of Harbor tasks in CI



shoot i think this is happening bc of #140 

this is fixed now