Honor cancellation before local worktree commits #34

Closed
opened 2026-10-27 13:34:41 +00:00 by sam · 0 comments
Owner

CommitAll discards its context and can stage and commit after task cancellation.

Confirmed still present on main: Manager.CommitAll (internal/worktree/worktree.go:387) takes _ context.Context and never reads it. Between entry and wt.Commit it performs AddWithOptions{All: true} and wt.Commit, neither of which is context-aware in go-git, so a task cancelled just before the call still mutates the index and HEAD.

Steps to Reproduce

  1. Prepare a task worktree with uncommitted changes.
  2. Create an already-cancelled context: ctx, cancel := context.WithCancel(context.Background()); cancel().
  3. Call Manager.CommitAll(ctx, dir, "msg").
  4. Observe it returns (true, nil): the index was staged and a new commit is on HEAD despite the context being cancelled before the call.
  5. In production this leaves a commit on the task branch for work the operator cancelled, which the subsequent push/PR path can then publish.

Acceptance Criteria

A pre-canceled context causes no index or HEAD mutation; cancellation is checked between non-context-aware go-git phases where possible, with regression tests.

Acceptance criteria

A pre-canceled context causes no index or HEAD mutation; cancellation is checked between non-context-aware go-git phases where possible, with regression tests.

Close reason

Fixed: CommitAll now takes a live context and checks ctx.Err() before open, worktree, staging, status and commit (worktree.go:398-430), so a pre-cancelled context mutates neither index nor HEAD. Proven red against pre-fix code: 'CommitAll() error = nil, want context canceled' for both a cancelled context and an expired deadline. task check green; fresh adversarial review zero findings.


Imported from beads archie-core-1ysw.8 · GitHub #603 · type bug · priority P3 · created 2026-08-22 · closed 2026-08-24

CommitAll discards its context and can stage and commit after task cancellation. Confirmed still present on main: `Manager.CommitAll` (internal/worktree/worktree.go:387) takes `_ context.Context` and never reads it. Between entry and `wt.Commit` it performs `AddWithOptions{All: true}` and `wt.Commit`, neither of which is context-aware in go-git, so a task cancelled just before the call still mutates the index and HEAD. ## Steps to Reproduce 1. Prepare a task worktree with uncommitted changes. 2. Create an already-cancelled context: `ctx, cancel := context.WithCancel(context.Background()); cancel()`. 3. Call `Manager.CommitAll(ctx, dir, "msg")`. 4. Observe it returns `(true, nil)`: the index was staged and a new commit is on HEAD despite the context being cancelled before the call. 5. In production this leaves a commit on the task branch for work the operator cancelled, which the subsequent push/PR path can then publish. ## Acceptance Criteria A pre-canceled context causes no index or HEAD mutation; cancellation is checked between non-context-aware go-git phases where possible, with regression tests. ### Acceptance criteria A pre-canceled context causes no index or HEAD mutation; cancellation is checked between non-context-aware go-git phases where possible, with regression tests. ### Close reason Fixed: CommitAll now takes a live context and checks ctx.Err() before open, worktree, staging, status and commit (worktree.go:398-430), so a pre-cancelled context mutates neither index nor HEAD. Proven red against pre-fix code: 'CommitAll() error = nil, want context canceled' for both a cancelled context and an expired deadline. task check green; fresh adversarial review zero findings. --- _Imported from beads `archie-core-1ysw.8` · GitHub #603 · type bug · priority P3 · created 2026-08-22 · closed 2026-08-24_
sam added the lowbug labels 2026-10-27 13:34:41 +00:00
sam self-assigned this 2026-10-27 13:34:41 +00:00
sam closed this issue 2026-10-27 13:34:41 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#34