Skip to content

fix: Add safeguards against losing unpushed work on main #85

Closed

Description

@admarble

Problem

Work can be lost when commits are made directly on main and then overwritten by sync operations. This was discovered when issue #78's implementation was lost:

19:44 - commit: fix(skills): make sub-agent usage mandatory  # Made on main
19:46 - reset: moving to origin/main                          # 2 min later - WIPED

The commit existed only locally and was never pushed. When git reset --hard origin/main was run to sync, the work was lost. The issue was closed manually, assuming the work was done.

Root Causes

  1. Work done directly on main - bypassed worktree isolation
  2. No warning before destructive reset - git reset --hard ran without checking for unpushed commits
  3. No verification on issue close - issues can be closed without merged PRs

Proposed Safeguards

1. Pre-reset hook (HIGH PRIORITY)

Add to pre-tool.sh - block git reset --hard if there are unpushed commits on main:

if [[ "$TOOL_INPUT" =~ "reset --hard" ]] || [[ "$TOOL_INPUT" =~ "reset.*origin" ]]; then
    # Check for unpushed commits on main
    unpushed=$(git log origin/main..HEAD --oneline 2>/dev/null | wc -l | xargs)
    if [[ "$unpushed" -gt 0 ]]; then
        echo "HOOK_BLOCKED: $unpushed unpushed commit(s) on main would be lost"
        echo "Push first: git push origin main"
        echo "Or stash: git stash"
        exit 1
    fi
fi

2. Force worktree for issue work (MEDIUM PRIORITY)

Update /exec skill to REQUIRE worktree creation:

  • Check if working from main at start of exec
  • If on main, create worktree before any implementation
  • Block implementation directly on main

3. Issue close verification (LOW PRIORITY)

Add sequant verify-closed command or post-close hook:

  • For each closed issue, verify a merged PR or commit exists in main
  • Alert if issue closed without evidence of merged work

Acceptance Criteria

  • git reset --hard origin/main is blocked when unpushed commits exist on main
  • Warning message shows number of commits that would be lost
  • Hook log records blocked reset attempts
  • /exec skill refuses to implement on main without worktree
  • Documentation updated with worktree workflow requirements

Immediate Recovery

The lost #78 commit can be recovered from reflog:

git cherry-pick 259bfde

This should be done to restore the sub-agent mandatory language to skills.


Related

Activity

  1. added
    bug
    enhancement
    on Jan 14, 2026
  2. added a commit that references this issue on Jan 16, 2026
  3. admarble commented on Jan 16, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete

    Issue: #85 - Add safeguards against losing unpushed work on main
    Status: READY_FOR_MERGE

    AC Coverage

    AC Status Implementation
    AC-1 ✅ MET git reset --hard blocked when unpushed commits on main
    AC-2 ✅ MET Warning shows: "X unpushed commit(s) on main would be lost"
    AC-3 ✅ MET Blocked attempts logged to /tmp/claude-hook.log
    AC-4 ✅ MET /exec skill now checks for main branch before implementation
    AC-5 ✅ MET Safety Safeguards section added to worktree-isolation.md

    Files Changed

    • .claude/hooks/pre-tool.sh - Hard reset protection hook
    • templates/hooks/pre-tool.sh - Same for new installations
    • .claude/skills/exec/SKILL.md - Main branch safeguard
    • docs/concepts/worktree-isolation.md - Safety documentation

    Quality Metrics

    • Tests: 363/363 passed
    • Build: TypeScript compiles successfully
    • Type safety: No any types introduced
    • Scope: 110 lines added across 4 files

    Iterations

    Phase Iterations Status
    Spec 1/1 Complete
    Exec 1/1 Complete
    Test N/A Backend only (no UI)
    QA 1/2 Complete

    PR: #98


    Ready for human review and merge.

  4. added a commit that references this issue on Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions