Skip to content

Install Git Pre-Commit Hooks for Copilot Agent #121

Closed

Description

@josecelano

Parent Epic: #112 - Refactor and Improve E2E Test Execution
Depends On: #120 - Configure GitHub Copilot Agent Environment (Issue 1-4)

Overview

Install Git pre-commit hooks in the Copilot agent's environment to enforce pre-commit checks deterministically. This ensures the agent cannot commit code without running linting checks, even if the agent forgets or ignores the instruction in .github/copilot-instructions.md.

Problem

Previous attempts to instruct the Copilot agent to run pre-commit checks via .github/copilot-instructions.md were not reliable. The agent sometimes:

  • Forgot to run checks before committing
  • Ignored the instructions
  • Committed code that failed linting

Solution: Use Git hooks to enforce checks mechanistically, not instructionally.

Objectives

  • Create symlink from .git/hooks/pre-commit to ./scripts/pre-commit.sh
  • Install hook in Copilot setup workflow
  • Verify hook works correctly (blocks bad commits)
  • Document the hook installation process

Implementation Approach

Use Symlink (NOT Wrapper Script):

ln -sf ../../scripts/pre-commit.sh .git/hooks/pre-commit

Why Symlink:

  • ✅ Simple - no wrapper script needed
  • ✅ Always up-to-date - changes to script are immediately reflected
  • ✅ Single source of truth - ./scripts/pre-commit.sh
  • ✅ Easy to verify - readlink .git/hooks/pre-commit

Workflow Integration

Add to .github/workflows/copilot-setup-steps.yml:

- name: Install Git pre-commit hooks
  run: |
    # Create symlink to enforce pre-commit checks
    ln -sf ../../scripts/pre-commit.sh .git/hooks/pre-commit
    chmod +x .git/hooks/pre-commit
    
    # Verify hook is installed
    if [ -L .git/hooks/pre-commit ]; then
      echo "✅ Pre-commit hook installed successfully"
      readlink .git/hooks/pre-commit
    else
      echo "❌ Failed to install pre-commit hook"
      exit 1
    fi

Acceptance Criteria

  • Pre-commit checks pass
  • Hook installation added to Copilot setup workflow
  • Hook successfully blocks commits that fail checks
  • Hook is verified during workflow execution
  • Documentation updated

Time Estimate

2-3 hours

Related Documentation

Activity

  1. added 2 commits that reference this issue on Nov 3, 2025
  2. added a commit that references this issue on Nov 6, 2025
  3. added a commit that references this issue on Nov 6, 2025
  4. josecelano commented on Nov 6, 2025

    @josecelano
    MemberAuthor

    This is not working. The pre-commit checks script takes longer than Copilot waits for a bash command, and it continues; then it realises the commit was not done, tries again, and so on until we reach the whole agent timeout for a task.

    Image

    I think there is a way to increase timeouts. I will try to find that in the Copilot agent docs.

    In my machine pre-commit checks take ~6 minutes:

    real    5m44,649s
    user    10m45,778s
    sys     3m18,677s
    
  5. josecelano commented on Nov 6, 2025

    @josecelano
    MemberAuthor

    Update: Root Cause Identified

    I've identified the root cause of the infinite loop issue with GitHub Copilot agent and pre-commit checks.

    The Problem:
    GitHub Copilot coding agent has a hardcoded ~5-6 minute timeout for command execution during the coding phase. When our pre-commit script (which takes ~6 minutes) exceeds this timeout, Copilot assumes the commit failed and retries, creating an infinite loop.

    Discussion:
    https://github.com/orgs/community/discussions/178998

    Key Findings:

    • The timeout-minutes setting in .github/workflows/copilot-setup-steps.yml only applies to the setup phase
    • There is currently NO way to configure command execution timeout during Copilot's coding workflow
    • This is known but undocumented behavior (not a bug)

    Temporary Solution:
    We will implement an environment variable-based approach to skip E2E tests when Copilot agent is running, while keeping the full pre-commit verification for local development.

  6. added 2 commits that reference this issue on Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions