nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Auto-commit on a detached HEAD gives no warning, and agent commits carry no marker

Open addyCooks opened this issue 1 month ago • 2 comments

Description

commitFile in source/services/auto-commit.ts skips a merge, rebase, cherry-pick or revert in progress (isOperationInProgress, line 129), but not a detached HEAD. A commit made there belongs to no branch and is easy to lose at the next checkout, and the user is not told. Auto-commits also use the user's own git identity and a plain chore: update <file> message, so they cannot be found later for squashing or review.

Environment

  • OS: Windows 11 (10.0.26300)
  • Node version: 22.22.3
  • Nanocoder version: 1.31.0 (main at 9d88dda7)
  • Git: 2.55.0.windows.3
  • Provider / Model: not relevant (reproduced by calling maybeAutoCommit)

Steps to Reproduce

  1. Make a repo with two commits and turn on nanocoder.autoCommit.
  2. Run git checkout --detach HEAD~1.
  3. Let the agent edit a file.
  4. Run git status -sb, git log -1 --format=%B, and git branch --contains HEAD.

Expected Behavior

A warning that HEAD is detached (or the commit is skipped), and the commit message includes a trailer such as Nanocoder-Auto-Commit: true.

Actual Behavior

## HEAD (no branch)
tool-result note: "[auto-commit] 98b97b1 chore: update a.txt"
user sees only:   "Auto-committed a.txt (98b97b1): chore: update a.txt"
commit message:   "chore: update a.txt"
author:           T <[email protected]>   (the user's own identity)
branches containing the commit: none (only reachable from HEAD)

Suggested Fix

  • In commitFile, check git symbolic-ref -q HEAD before committing. If it fails, warn once (or skip).
  • Append a trailer to the message (line 187-188, where generateMessage and git commit -m are called) so git log --grep "Nanocoder-Auto-Commit" finds them.
  • Add tests for both.

Additional Context

  • Auto-commit came from #1512 (#1482). Related fixes: #1653, #1654.
  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

addyCooks avatar Oct 13 '26 12:10 addyCooks

AI-assisted: I’d like to work on #1747. I’ll add a fail-safe HEAD check so auto-commit skips detached HEAD before touching the index and logs a warning, plus a Nanocoder-Auto-Commit: true commit trailer. I’ll add focused regression tests for both and open a PR after they pass.

ducanhnguyen223 avatar Oct 13 '26 19:10 ducanhnguyen223

Hey @ducanhnguyen223, Assigned this one to you! Just a heads-up for next time: please wait for the assignment before opening a PR. Thanks!

addyCooks avatar Oct 17 '26 06:10 addyCooks