[Performance] Skip unchanged CodeGraph auto-sync before copying the checkout and index
Problem
AutoSyncScheduler scans every ready CodeGraph on each interval (10 minutes by default) and calls CodeGraphService.sync(). PR #1518 builds a sibling candidate so the last-good index remains safe, but every admitted refresh still closes the old index, copies the entire checkout (including .git and .codegraph), fetches, indexes, promotes, writes status/audit records, and sends callbacks. A repository with no remote change pays this cost on every scan. Without effective reflinks, the copy uses I/O and temporary disk space proportional to the whole checkout and index; queries also pause briefly during copy and promotion.
Proposed behavior
For automatic sync of a ready asset with a committed last-good index, perform a bounded, read-only version probe before status admission or filesystem work. For Git, resolve the configured branch's exact refs/heads/<branch> through the fetcher's validation and credential path, then compare the full remote commit SHA with the canonical checkout's full HEAD. If they match, return a distinct unchanged result: keep ready, and skip the worker, SQLite close/checkpoint, directory copy, reindex, build callback, audit entry, and last_sync_at update. Store probe time/result separately if observability needs it.
If the remote differs, retain #1518's candidate build and atomic admission. A timeout, network error, deleted branch, or missing local version must never be treated as equality. Keep the last-good index queryable when the remote probe fails and report a retryable diagnostic for the next scan. An explicit /sync should still be able to force a rebuild at the same commit. Fetchers without a reliable version probe may retain the existing full-refresh behavior.
GitSourceFetcher.headCommit() currently stores only 12 SHA characters, so comparing commit_hash directly with a full remote SHA is unsound. Read the canonical checkout's full HEAD or migrate to a full persisted SHA. The probe-to-admission race still needs the existing store CAS: a concurrent manual sync or delete must not start duplicate work. A remote advance after an equality probe can be picked up at the next interval.
Acceptance criteria
- A local bare Git remote and indexed checkout prove that two unchanged automatic scans probe the remote but perform zero candidate copies, index closes/checkpoints, status transitions, build callbacks, or reindex calls; queries continue to serve the last-good index.
- A new commit and a force-pushed branch each trigger one candidate refresh, update the stored commit/stats, and preserve #1518's rollback behavior on failure.
- Probe timeout/network failure or a missing remote ref leaves an existing last-good index queryable and records a retryable diagnostic. Missing/corrupt local
HEADor index is never classified asunchangedand follows the existing recovery/error path. Manual/syncstill forces rebuilding an unchanged commit. - Report before/after elapsed time, copied bytes (or copy count), and peak extra disk for an unchanged scan of a representative large checkout, including the filesystem used.
For changed revisions, reducing .git copy cost is a separate optimization. Any local clone or object-sharing strategy must leave the promoted candidate independent of .previous, which is removed after promotion; --shared/alternates alone would not be safe.
Related: #1518 review P2-8. #1516 covers last-good correctness rather than unchanged-scan cost.
Source: TencentCloud/TencentDB-Agent-Memory