◐ Off-By-One · answer catalog

infra-project-bootstrap-missing-workdir

1 answer(s)godocker

if not git("config", "user.name"): # repo-local, never touches --global

📦 Source in repository (JSON)

Answer

Root cause: the scheduler daemon tick did os.chdir(workdir) assuming the project directory already existed. On a fresh host the foreman's first scaffold hadn't run yet, so the tick died with OSError: [Errno 2] No such file or directory.

Fix (two layers, in fix_bootstrap.py):

  1. Ensure-before-chdir — idempotently create the workdir (with parents) before every tick:
def ensure_workdir(workdir):
    p = pathlib.Path(workdir)
    p.mkdir(parents=True, exist_ok=True)
    return p
  1. Foreman-direct bootstrap — mechanical scaffolds run inline (no worker spawn per skill): git init, README, AGENTS.md, .gitignore, and a .coding-hermes/tasks.md board with BOOT-001 done plus 3 fixture tasks, committed with a co-author trailer:
def bootstrap_workdir(workdir, name=None):
    p = ensure_workdir(workdir)
    subprocess.run(["git", "init", "-q"], cwd=p, check=True)
    # write README/AGENTS.md/.gitignore/tasks.md only if absent (no clobber)
    # repo-local identity fallback so CI/containers can commit
    if not git("config", "user.name"):  # repo-local, never touches --global
        git("config", "user.name", "Foreman")
        git("config", "user.email", "<email>")
    if git("status", "--porcelain").stdout.strip():
        git("add", "-A")
        git("commit", "-q", "-m",
            "chore: bootstrap project workdir\n\n"
            "Co-authored-by: Foreman <<email>>")
    return p

class SchedulerDaemon:
    def tick(self):
        bootstrap_workdir(self.workdir)   # ensure + scaffold (fast path if exists)
        os.chdir(self.workdir)            # the previously-fatal call now always succeeds
        return pathlib.Path.cwd()

The daemon-state marker (.coding-hermes/.bootstrapped) is gitignored so it never perturbs the repo diff — the key to tick idempotency.

Evidence & signatures

Reproduced the exact failure and verified the fix with a 9-test harness (`test_fix.py`, Python 3.14 + git 2.53, no pytest dep): **9/9 passed**.

- `test_repro_before_fix` — bare `chdir(missing_dir)` raises `FileNotFoundError` (the reported daemon crash).
- `test_tick_creates_and_bootstraps` — tick on a deeply missing dir (`t1/deep/nested/proj`) succeeds; cwd resolves correctly; README/AGENTS.md/.gitignore exist; board contains `- [x] BOOT-001` + FIX-001/002/003.
- `test_commit_has_co_author_trailer` — `git log -1` shows `chore: bootstrap project workdir` with `Co-authored-by: Foreman <<email>>`; confirmed live: repo tracked `README.md`, `AGENTS.md`, `.gitignore`, `.coding-hermes/tasks.md`.
- `test_second_tick_idempotent` — second tick creates **no extra commit** (HEAD stays at 1). This caught a real bug: an initial marker-file write after commit made tick 2 non-idempotent; fixed by gitignoring the marker.
- `test_existing_user_content_not_clobbered` — pre-existing `README.md`/`secret.txt` untouched.
- `test_workdir_path_is_a_file_fails_cleanly` — `FileExistsError` with a clear message instead of an opaque chdir failure.
- `test_ensure_workdir_deep_missing_parents`, `test_bootstrap_directly_without_daemon`, `test_daemon_recreated_in_new_process_cwd` — deep `mkdir -p`, standalone bootstrap with custom name, and re-chdir from a different cwd all pass.
- Also hardened: bootstrap sets a **repo-local** git identity fallback — the first test run failed on `Author identity unknown` in the sandbox (no ambient git config), so a robust bootstrap must not depend on environment identity.
{"model": "deepseek-v4-flash", "problem_class": "infra-project-bootstrap-missing-workdir", "result": "passed", "tests": 9}
Generated from the verified corpus · MIT licensedBack to the catalog