Skip to content

fix(sync): watcher sweep reconciles a new committed change again (#163) - #164

Merged
ViperJuice merged 1 commit into
mainfrom
t3/fix-sweep-commit-sync
Nov 22, 2026
Merged

ViperJuice merged 1 commit into
mainfrom
t3/fix-sweep-commit-sync

Conversation

@ViperJuice

@ViperJuice ViperJuice commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Cause

#155 (e42c2c4) added a staleness check to _repair_repository_drift_locked that refuses sweep drift as sweep_drift_stale when the swept commit differs from either the current HEAD or the indexed commit (mcp_server/storage/git_index_manager.py:674-678 on main):

if observed_commit is not None and observed_commit != last_indexed_commit:
    stale.append("indexed commit is …, not the swept …")

When the sweep finds a new commit at HEAD that nothing has indexed yet, the swept commit (= HEAD) differs from last_indexed_commit by definition. So the repair refused it on every sweep and never reached the branch below it (current_commit != last_indexed_commit → "not a targeted repair; running an ordinary sync"), which is exactly what the docstring says should happen when HEAD has moved. The failing test logged:

Not applying sweep drift in … : indexed commit is cc330924153a, not the swept f5540aed25f0; the next sweep recomputes it

The next sweep computed the same drift and was refused again, so the sweep stopped working as a backstop for missed commits.

Fix

Drop the swept-vs-indexed staleness condition (git_index_manager.py:670-678). A sweep that saw the current HEAD now falls through to the existing ordinary-sync branch. That sync computes its own indexed..HEAD change set through _get_changed_files and ignores the sweep's path list.

Why #155's guarantees still hold

  • Drift is never applied to a generation of another commit. The targeted repair (which applies the sweep's paths) still requires current_commit == last_indexed_commit. A swept commit that isn't the indexed one only ever reaches the ordinary sync, which doesn't use the drift paths.
  • Stale sweeps are still refused. HEAD moving after the sweep (observed_commit != current_commit) and the published generation changing (observed_index_path) are still refused as sweep_drift_stale. test_sweep_drift_from_an_older_commit_is_not_applied_after_head_moves still passes.
  • No full rebuild on an unchanged commit. The targeted-repair path is unchanged. The new test also blocks _full_index, so it proves the moved-HEAD case runs incrementally.
  • Every full rebuild logs its reason. No full-rebuild path was changed, and the ordinary sync still gets reason="watcher sweep drift (…)".
  • commit_moved refusal. Not touched.
  • A dirty tracked tree is still refused. The sweep's git status cleanliness gate is unchanged; the first half of the reconciliation test checks this.

Tests

  • New: tests/test_issue_145_rebuild_decisions.py::test_sweep_of_an_unindexed_head_commit_runs_the_incremental_sync. The index is at commit A, HEAD is at commit B, and the sweep runs. It asserts an incremental sync of exactly changed.py, no full rebuild, last_indexed_commit == B, no sweep_drift_stale, and a quiet second sweep. It fails with the fix reverted and passes with it.
  • uv run --extra dev pytest tests/test_v13_data_reconciliation.py tests/test_issue_145_rebuild_decisions.py tests/test_watcher_sweep.py tests/test_sweeper_observability.py tests/test_branch_drift_rescan.py tests/test_watcher_multi_repo.py -n 2 --no-cov: 129 passed in 67 s.
  • ruff check and black --check on the changed files: clean.

Agent gate

Added tests/test_v13_data_reconciliation.py to the agent-gate-local list in the Makefile, which make agent-gate runs. Run serially as the gate runs it: 3/3 passes, 24 tests each, in 41.8 s, 45.3 s and 27.2 s on a shared host. That cost is fine for the gate.

Fixes #163

🤖 Generated with Claude Code


Prove it works
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@ViperJuice
ViperJuice marked this pull request as ready for review November 22, 2026 02:31
#155 bound sweep drift to the commit it was computed against and refused
it as `sweep_drift_stale` when the swept commit differed from either HEAD
or the indexed commit. A commit the sweep finds at HEAD that nothing has
indexed yet differs from the indexed commit by definition, so it was
refused on every sweep and never reached the ordinary incremental sync the
repair falls through to when HEAD has moved.

Drop the swept-vs-indexed staleness condition. A sweep that saw the current
HEAD now reaches the existing "not a targeted repair" branch, which runs the
ordinary sync (indexed..HEAD change set) and never applies the sweep's path
list to the older generation. HEAD moving after the sweep, or the published
generation changing, is still refused.

Adds a regression test for the branch and puts
tests/test_v13_data_reconciliation.py in the protected agent gate.

Fixes #163

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ViperJuice
ViperJuice force-pushed the t3/fix-sweep-commit-sync branch from 9c9572e to 65ba0de Compare November 22, 2026 02:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T02:32:05.585915Z 65ba0de Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ViperJuice
ViperJuice merged commit 9f956e4 into main Nov 22, 2026
14 checks passed
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.

Regression from #155: watcher sweep no longer reconciles a new committed change

1 participant