Skip to content

worktree-reaper: run-log filename collides for same-second runs — gate suite fails 6/6 and a second run overwrites the first run's audit log #5716

Closed

Description

@dezren39

worktree-reaper: run-log filename collides for same-second runs — the gate test suite fails 6/6 and a second run's audit log overwrites the first

Evidence (verified this run, laptop primary @ af0847d)

The reaper names its per-run decision log with second resolution plus the process id:

  • infra/worktree-reaper/bin/worktree_reaper.py:542 — ts = time.strftime("%Y%m%dT%H%M%SZ", time.gmtime(int(now)))
  • infra/worktree-reaper/bin/worktree_reaper.py:603 — log_path = os.path.join(state_dir, "runs", f"run-{ts}-{os.getpid()}.jsonl"), opened "w" at :605.

Two runs started in the same second by the same process therefore share one
log path: the second run truncates and rewrites the first run's log.

The gate suite drives the reaper in-process
(infra/worktree-reaper/tests/test_worktree_reaper.py, ReaperRun.run),
and discovers a run's decisions by diffing the runs/ directory listing
before/after. When a run's log path already exists (same second, same pid),
the diff is empty and the run returns {} decisions, so assertions die with
KeyError on the tree path.

Reproduction (laptop, current main):

  • python3 -m unittest discover -s infra/worktree-reaper/tests — FAILED in
    6 of 6 consecutive full-suite runs (1–2 errors each: test_03_reap_matrix
    KeyError at test line 234 on the patch-equivalent tree, test_04_quiet_gate
    KeyError at test line 253 on the fresh tree). Each test passes standalone.
  • Micro-repro with the suite's own harness: two runner.run() calls in the
    same second produced exactly one log file
    (run-20261105T002713Z-57087.jsonl); the first run returned its tree's
    decision, the second returned [] decisions while overwriting the file.

Why it matters

  • The suite is the only gate-logic coverage for a tool that deletes
    worktrees and branches, and it is effectively red whenever runs land in
    the same second — so nobody can trust a green/red signal from it (it is
    also not wired into any workflow, so the failure is invisible until a
    human runs it by hand).
  • In production the same naming means two invocations that share a pid in
    one second (pid reuse, wrapper re-exec) silently lose the first run's
    audit log — the only record of what the reaper deleted and why.

Acceptance criteria

  • Run-log filenames are unique per run even for same-second, same-process
    invocations (e.g. sub-second component, monotonic sequence, or exclusive
    create with a disambiguating suffix); a second run never truncates a
    previous run's log.
  • python3 -m unittest discover -s infra/worktree-reaper/tests passes 10
    consecutive full-suite runs on the laptop.
  • A regression test (or the existing gate tests run back-to-back) covers
    two runs in the same second both producing readable decision logs.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    on Nov 5, 2026
  2. developing-today commented on Nov 5, 2026

    @developing-today
    Contributor
  3. added
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    area/infraInfrastructure, deployment, and operations
    work/self-assignedAn agent grabbed this item directly, outside the queue
    on Nov 5, 2026
  4. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator-code-b
    • Session / ID: cron new-issue-creator-code-b run 2026-11-04 18:20 CST
    • Found via: filed this run
    • Task: Filed this issue after verifying on the laptop primary @ af0847d that the worktree-reaper gate suite fails 6/6 full-suite runs: the run-log name run-{ts}-{pid}.jsonl (worktree_reaper.py:542/:603) has only second resolution, so same-second in-process runs share one path — the second run truncates the first run's audit log and the test harness's directory-diff read returns no decisions (KeyError in test_03_reap_matrix / test_04_quiet_gate). Micro-repro with the suite's own harness: two runs in one second produced one log file; the second returned zero decisions.
    • Expectation: task/small-fix — guarded self-solve this run by the filer (work/self-assigned): make run-log names unique per run, add a same-second regression test, verify the suite passes repeatedly.
    • Links: evidence in the issue body; body file issue-worktree-reaper-runlog-collision.md in the goal's hidden_files.
  5. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

    • Agent: new-issue-creator-code-b
    • Session / ID: cron new-issue-creator-code-b run 2026-11-04 18:20 CST
    • Found via: filed this run; guarded self-solve (task/small-fix, no safety labels)
    • Task: Fixed in PR fix(worktree-reaper): unique run-log name per run (#5716) #5718, squash-merged as cddb887. The run log stamp now carries the microsecond fraction, the log is created exclusively ("x"), and residual clashes get a numeric suffix — a run can never truncate a previous run's audit log. New RunLogCollisionTests pins two back-to-back runs both logging.
    • Verification: laptop worktree — suite OK 10/10 consecutive runs (8 tests) vs 6/6 FAILED on unpatched main; merged main @ cddb887 re-run from the laptop primary: OK. Worktree/branch removed.
    • Links: PR fix(worktree-reaper): unique run-log name per run (#5716) #5718; body file issue-worktree-reaper-runlog-collision.md in the goal's hidden_files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/worktree-reaperinfra/worktree-reaperarea/infraInfrastructure, deployment, and operationskind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions