Skip to content

Commit uncommitted work before every agent turn, so a reset or clean can't destroy it (#321) - #1687

Merged
currentbits merged 1 commit into
mainfrom
coder/auto-wip-commit-before-every-agent-turn--a2f349
Oct 19, 2026
Merged

currentbits merged 1 commit into
mainfrom
coder/auto-wip-commit-before-every-agent-turn--a2f349

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Every agent turn in a worktree now starts by committing any uncommitted work: hand edits made between turns, or leftovers from a stopped or failed turn. Before this, only a successful turn was checkpointed, so that work went into the next run uncommitted, and one git reset --hard, checkout -- or clean -fd from the agent destroyed it for good. Part of #321.

Changes

  • Before a provider is dispatched, the runner commits a coder-checkpoint: turn N snapshot of the dirty worktree. It is an ordinary checkpoint, so it appears in the checkpoint list and can be restored from the UI.
  • No snapshot while the worktree is mid merge, rebase, cherry-pick or revert. add -A + commit there would seal conflict markers into a merge commit and break the conflict-resolve flow.
  • The snapshot runs after the thread is marked active, so the await opens no double-send window. It also runs after the project's setup step settles, so a half-written install is not committed.

Verification

  • New runner test: an agent runs git reset --hard and git clean -fd, and the hand edit and the untracked file both survive in the snapshot. It fails without the runner hook (checked by reverting it).
  • New unit test: a worktree with MERGE_HEAD gets no snapshot; once that is cleared it does.
  • electron/test/checkpoints.test.js: 19/19 pass.
  • Full npm run test:electron in a CI-like env: 4946 pass, 3 fail. The 3 failures (PDF extraction, PTY terminal, QR banner) come from pdfjs-dist, @lydell/node-pty and qrcode-generator missing from the local node_modules clone, not from this change. CI is the real check for those.

Notes for reviewers

  • One existing test changed. "Failed turn does not checkpoint" used to edit a file before the failing run, and the new pre-turn snapshot now commits that on purpose. The failing agent now writes the file itself, which keeps what the test is checking.
  • Pre-turn snapshots count toward turn N, so N drifts further from the real number of turns (restore's safety commit already does this).
  • The snapshot's message-id trailer points at this turn's prompt. Restoring it keeps the prompt and drops the reply, which matches the files at that moment.
  • Left out: snapshotting before each git-changing command within a turn, the issue's second half. That needs a change in each provider's guardrail hook (codex, cursor, grok, kimi, muse, opencode). Until then, an agent can still wipe its own edits from earlier in the same turn.

🤖 Generated with Claude Code

Solenta-Message-Id: c28300b2-c858-4bac-8e55-d069d73507ca
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T08:10:58.115300Z 6ebabeb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@currentbits
currentbits enabled auto-merge (squash) October 19, 2026 08:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ebabeb5db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +361 to +364
if (MID_OPERATION_MARKERS.some((m) => fs.existsSync(path.join(dir, m)))) {
return null;
}
return await maybeCreateCheckpoint(store, threadId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve unmerged-index conflicts before checkpointing

When a worktree has conflicts without one of these operation markers—for example, after a conflicted git stash pop or git apply --3way—this check falls through to maybeCreateCheckpoint, whose git add -A marks every conflict resolved and commits the conflict-marker contents. Starting the next turn therefore destroys the unmerged index and breaks the user's conflict-resolution workflow. Check for unmerged index entries (such as via git ls-files -u) in addition to these marker files before creating the snapshot.

Useful? React with 👍 / 👎.

@currentbits
currentbits merged commit 1e16d6d into main Oct 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant