Files
PaperClipAI/server
OscarandClaude Opus 5.5 c8f363ef47 fix: treat an empty .git directory as no repository in the workspace source proof (#21409)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Before each heartbeat run, Paperclip proves the Git source of the
task workspace (`readWorkspaceGitSourceRoots`)
> - A workspace can contain an empty `.git` directory that is not a
repository. The Codex sandbox creates it as a mount point to protect
`.git` in a non-repository workspace (openai/codex#33813,
openai/codex#32872). When the run stops early (task reassignment,
cancel, quota failure), the empty directory stays
> - The proof treats the empty `.git` as a broken repository and throws
`workspace_git_source_unproven`. Every later run on that task fails at
setup, and the task cannot recover without manual cleanup
> - The proof already treats a `.git` that holds only `info/exclude` as
"no repository". An empty `.git` holds even less Git state
> - This pull request treats an empty `.git` directory as "no
repository" in the same way
> - The benefit is that interrupted runs no longer block all later runs
on the same task

## Linked Issues or Issue Description

Refs #20805

This change answers question B in the triage comment on #20805 for the
empty-placeholder case. We saw the failure on a self-hosted instance
many times on one day. Each time, the trigger was a task reassignment
while a `codex_local` run was active on that task. Inside one minute of
the reassignment, an empty `.git` directory appeared in the task's
isolated workspace. All later runs on the task failed at setup with
`workspace_git_source_unproven`. After `rmdir` of only the empty `.git`,
the next run passed setup. The concurrent-write case and the capacity
limits in #20805 are separate and this PR does not change them.

Related Codex issues (the source of the empty directory):
openai/codex#33813, openai/codex#32872, openai/codex#33450.

## What Changed

- `readWorkspaceGitSourceRoots` returns `null` (no repository) when the
`.git` marker is a real, empty directory. It still rejects symlinks and
every non-empty partial Git state.
- The existing ignore-only test now also covers an empty `.git`, both
directly and through ancestor lookup.

## Verification

- `pnpm vitest run
server/src/services/workspace-git-source-roots.test.ts`
- Manual: on an instance that showed the failure, removing the empty
`.git` made the next run pass setup. With this change, the proof returns
"no repository" for that state, so the removal is not necessary.

## Risks

- Low risk. An empty directory cannot hold objects, refs or a `gitdir`
pointer, so no Git source can hide behind it.
- `readNestedWorkspaceGitSourceRoots` keeps its current behavior: a
nested `.git` that is not a repository still fails that scan, the same
as the existing ignore-only case.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and
code execution.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass (the changed test file: 20
passed; the new assertion fails without the fix)
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes (no
documentation describes this check)
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 04:11:51 -08:00
..