Skip to content

Fix: Debounce baseline saves to reduce I/O and improve git operation detection#2

Merged
khaledesmail merged 6 commits intomainfrom
fix/git-pull-ignore-from-ai-detection
Feb 8, 2026
Merged

Fix: Debounce baseline saves to reduce I/O and improve git operation detection#2
khaledesmail merged 6 commits intomainfrom
fix/git-pull-ignore-from-ai-detection

Conversation

@khaledesmail
Copy link
Contributor

@khaledesmail khaledesmail commented Feb 7, 2026

Description

Fix: Debounce baseline saves to reduce I/O and improve git operation detection

  • Add debounced saving for persisted baselines (1 second delay) to reduce
    unnecessary disk I/O during rapid file changes
  • Improve git operation detection by checking FETCH_HEAD and MERGE_HEAD
    file modification times to detect recent pull/merge/checkout operations
  • Remove unnecessary debug logging and comments for cleaner code
  • Re-enable logging in BaseTracker for production debugging

This prevents false AI detection when git operations trigger text change
events as VS Code reloads files, and reduces disk I/O from excessive
baseline saving.

Related Issue

Fixes #(issue number)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Style/UI update
  • Code refactoring
  • Performance improvement
  • Test update

Testing

  • I tested this in VS Code Extension Development Host
  • I ran npm test and all tests pass
  • I ran npm run lint and fixed all issues
  • I tested with multiple AI tools (if applicable)
  • I tested on multiple platforms (if applicable)

Test Instructions

Screenshots

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally
  • Any dependent changes have been merged and published
  • I have updated the CHANGELOG.md file

Additional Notes

When performing git operations like pull, merge, checkout, or rebase,
files are updated on disk but should not be flagged as AI-generated code.

Changes:
- Add `isGitOperation` flag to track git-originated changes
- Add `recentTextChanges` map for deduplication logic
- When file is tracked AND has no diff vs HEAD, detect as git operation
- Skip AI detection for git operations (only update baseline)
- Process external changes to open files (with deduplication to prevent double counting)

Fixes issues where:
1. Git pull triggered false AI detection leading to automatic version bump
2. Git checkout/merge on open files were missed entirely
3. AI agents modifying open files externally were missed

The fix handles all cases:
- Git operations (pull, merge, checkout, rebase, commit) → Skip AI
- AI agents modifying files (with uncommitted changes) → Detect AI
- New untracked files → Detect AI
- Non-git repos → Use baseline tracking
The workflow was automatically bumping the patch version on every push to main,
which was causing unintended version increases even for non-release changes like bug fixes.

This removes the automatic version bumping. Future releases will need to be done manually.
…detection

- Add debounced saving for persisted baselines (1 second delay) to reduce
  unnecessary disk I/O during rapid file changes
- Improve git operation detection by checking FETCH_HEAD and MERGE_HEAD
  file modification times to detect recent pull/merge/checkout operations
- Remove unnecessary debug logging and comments for cleaner code
- Re-enable logging in BaseTracker for production debugging

This prevents false AI detection when git operations trigger text change
events as VS Code reloads files, and reduces disk I/O from excessive
baseline saving.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first pull request! We're excited to review your contribution.

Please ensure:

  • Tests pass (npm test)
  • Linter passes (npm run lint)
  • You've updated documentation if needed
  • You've added tests for new features

A maintainer will review your PR as soon as possible.

- Fix BaseTracker test to expect logging output (logging is now enabled)
- Add proper timeout handling for git operation detection tests
- Fix execSync mock to handle encoding parameter correctly
- Add debounce wait periods for tests that call file change handler multiple times

All tests now pass (1396 passed, 18 skipped).
The test was failing because exactly 1 hour (3600000ms) could become
59 minutes during test execution due to timing. Added 1 minute buffer
(3660000ms total) to ensure the status always shows 'hour'.
@khaledesmail khaledesmail merged commit 690b922 into main Feb 8, 2026
7 checks passed
@khaledesmail khaledesmail deleted the fix/git-pull-ignore-from-ai-detection branch February 8, 2026 19:18
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