---
title: "A Git Commit Titled Checkpoint Under Our Name at 2:12 AM"
canonical: https://dxdev.com/blog/nightly-sweep-multi-session/
datePublished: 2026-09-27
---
The overnight work log for one night shows more than 50 headless `claude -p` sessions between 12:09 and 4:07 AM. Three different agent roles, a secretary, a system manager and a task manager, were handing the same "mute the pc" unit back and forth. At 2:12 one session closed without running `/close` and left its unit open. Our nightly cleanup runs into a repo like that, and until recently it had one behavior: commit everything.

## A sweep that assumed one writer

The sweep ran `git add -A` and `git commit` in every repo it found dirty. It treated the working tree as if a single writer owned it. That was fine when it was true. Now several sessions edit one repo at once, and any of them can be mid-edit when the sweep arrives.

So the sweep would find a half-written file and commit it, and the log would say we wrote it. The session that owned the file kept editing, and its next diff was against a commit it never made. Nothing crashed. The history recorded unfinished work as finished, under our name, at an hour when nobody was reviewing anything.

We left that in production longer than we should have, because the failure was quiet. A commit that says "checkpoint" looks tidy. You only notice when you try to work out why a file's history shows a state that never existed on purpose.

## Holding what a live session owns

The fix is a commit titled "checkpoint sweep holds files a live session owns instead of committing them". Before the sweep touches anything, it now checks whether a live session owns files in the repo. If one does, the sweep leaves those files alone and reports them.

A repo with no live session gets the same treatment as before. The cleanup still does its job on the idle repos, so nothing is lost there.

## Reading the same folder several times

Deciding whether a session is live means reading session transcripts, and the next commit was about that: "scan each transcript root once when seat dirs are junctions to one folder". Several seat directories are junctions pointing at a single folder, so walking each seat separately read the same transcripts several times over. The duplicate scan did not change the verdict, but it multiplied the work. Resolving the roots and scanning each real folder once fixed it.

## What the log says about "nobody is editing"

Look at how that night's log reads. Many short sessions overlap. The `OK` responses from the secretary role land between 2:47 and 3:26, a few minutes apart. Close lines show up for sessions that ended without a proper close. In that environment "nobody is editing right now" is almost never true, and a sweep that assumes it will sooner or later commit something someone is holding open.

## The rule we kept

Automation commits only work it can show has no owner. When it can't show that, it says so and leaves the files alone. A wrong commit under our name is much harder to untangle than a repo that waited until morning. If several agent sessions share a repository, check whether your nightly cleanup asks who is mid-edit before it commits.
