Skip to content

fix(git-history): prune orphaned commit vectors on HEAD rewinds#59

Merged
m1rl0k merged 10 commits into
Context-Engine-AI:testfrom
voarsh2:prune-orphaned-commits
Dec 18, 2025
Merged

fix(git-history): prune orphaned commit vectors on HEAD rewinds#59
m1rl0k merged 10 commits into
Context-Engine-AI:testfrom
voarsh2:prune-orphaned-commits

Conversation

@voarsh2

@voarsh2 voarsh2 commented Dec 13, 2025

Copy link
Copy Markdown
Contributor

Summary

Prunes orphaned git commit vectors in Qdrant when a non–fast-forward move of HEAD is detected (e.g., reset or force-push). Upload clients emit snapshot manifests on such events, points are tagged with a per-run identifier, and older commit metadata not in the latest snapshot is removed. Optional cleanup of local git_history_*.json manifests is included.

Problem

After a git reset or force-push, previous commit vectors can remain indexed even though those commits are no longer reachable. This creates stale search results and inconsistent commit timelines.

Solution

  • Detect non–fast-forward transitions using git merge-base --is-ancestor and automatically switch to mode=snapshot for the next upload.
  • Tag ingested commit points with metadata.git_history_run_id and metadata.git_history_mode.
  • On snapshot ingest, prune older git_message points for the same repo whose git_history_run_id does not match the latest run.
  • Add optional cleanup for .remote-git/git_history_*.json manifests:
    • Delete the current manifest after ingest.
    • Cap retained manifest files per directory by mtime.

Key Changes

  • scripts/remote_upload_client.py
    • Detect non–fast-forward changes and set manifest mode to snapshot or delta.
    • Include head, prev_head, base_head in git_history.json.
    • Add upload_git_history_only(...) for cases with no file changes but updated history.
  • scripts/standalone_upload_client.py
    • Mirrors the same detection and snapshot/delta behavior.
  • scripts/ingest_history.py
    • Tag points with git_history_run_id and git_history_mode.
    • _prune_old_commit_points(...) deletes older git_message vectors on snapshot ingest (guarded by env).
    • _cleanup_manifest_files(...) deletes current manifest and enforces a max file retention, if configured.
  • .env.example / docker-compose.yml
    • New environment variables to control pruning and manifest cleanup.
  • tests/test_git_history_prune.py
    • Unit tests verifying:
      • Pruning is skipped on delta.
      • Pruning obeys GIT_HISTORY_PRUNE.
      • Correct filter construction.
      • Delete errors are swallowed.
  • vscode-extension/context-engine-uploader/package.json
    • Version bump: 0.1.36.

Configuration

Variable Default (compose) Example (.env.example) Description
GIT_HISTORY_PRUNE 1 1 Enable pruning on snapshot ingest for the repo’s older git_message points.
GIT_HISTORY_DELETE_MANIFEST 0 1 Delete git_history_*.json manifest(s) after successful ingest.
GIT_HISTORY_MANIFEST_MAX_FILES 0 50 Cap retained manifest files per .remote-git dir by mtime (0 disables).
REMOTE_UPLOAD_GIT_FORCE n/a 0 Force full snapshot manifests instead of incremental deltas.

Detect non-fast-forward HEAD moves in upload clients and emit snapshot git-history manifests (mode=snapshot). Tag commit points with git_history_run_id and, on snapshot ingests, delete older git_message points for the same repo that are not part of the latest run to avoid orphaned commit metadata after reset/force-push.

Also add optional cleanup for .remote-git/git_history_*.json manifests via env (GIT_HISTORY_DELETE_MANIFEST / GIT_HISTORY_MANIFEST_MAX_FILES) and document the
new knobs in .env.example.
@Context-Engine-AI Context-Engine-AI deleted a comment from augmentcode Bot Dec 16, 2025
Relaxes the type hint for the `model` parameter in the `_ingest_from_manifest` function.

This change allows the function to accept a wider range of model types,
promoting flexibility and avoiding potential type-related issues.
… ops

When the watch loop detects no filesystem changes, still collect git history and upload a git-history-only delta bundle when HEAD/ref movement is detected.
This ensures commit/undo operations emit git_history manifests so watcher can ingest and prune snapshot rewrites.
@voarsh2

voarsh2 commented Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

Confirmed working, orphaned commits are pruned. Need to write a pytest and bump extension version

@voarsh2 voarsh2 marked this pull request as ready for review December 18, 2025 06:13
@m1rl0k m1rl0k merged commit b963976 into Context-Engine-AI:test Dec 18, 2025
1 check passed
@voarsh2 voarsh2 deleted the prune-orphaned-commits branch December 18, 2025 14:05
m1rl0k added a commit that referenced this pull request Mar 1, 2026
fix(git-history): prune orphaned commit vectors on HEAD rewinds
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.

3 participants