Skip to content

fix: platform git children never start git auto-maintenance (#4001) - #4007

Merged
obasilakis merged 3 commits into
devfrom
feature/4001-fetch-no-auto-maintenance
Oct 29, 2026
Merged

obasilakis merged 3 commits into
devfrom
feature/4001-fetch-no-auto-maintenance

Conversation

@obasilakis

Copy link
Copy Markdown
Contributor

Summary

  • Every git child the agent server spawns now runs with -c maintenance.auto=false. Before this, a repo-local maintenance.auto=true made a bounded platform fetch/pull/commit/merge/rebase start maintenance run --auto → gc → repack. The child's timeout killed that repack partway through and left objects/maintenance.lock behind. Git never expires that lock, so auto-maintenance stayed off for the repo with no warning.
  • A stale objects/maintenance.lock (older than 1 h) is now removed on every cycle, using the same age rule as gc.pid and index.lock.

Changes

  • docker/base-image/agent_server/utils/registered_run.py: new constant GIT_NO_AUTO_MAINTENANCE, inserted after git in the command the child runs. Return values and exceptions still carry the caller's original argv, because _with_stash reads the verb from exc.cmd[1].
  • docker/base-image/agent_server/routers/git.py:
    • The 7 raw subprocess.run / _git call sites (sync, pull and reset endpoints) prepend the constant.
    • _reap_stale_git_litter also handles objects/maintenance.lock.
  • tests/unit/test_ent708_settings_json_guard.py: its AST guard now skips the starred option at the start of the argv when it reads the git verb.
  • Docs: git-sync-health.md flow, requirements/github.md.

The issue proposed --no-auto-maintenance on fetches. That flag exists only for fetch/pull, and commit/merge/rebase fail the same way. Verified with GIT_TRACE: a repo with local maintenance.auto=true starts maintenance run --auto on commit, and with -c maintenance.auto=false it starts nothing.

Test Plan

  • cd tests && pytest unit/test_4001_no_auto_maintenance.py -v: 8 tests against real repos with GIT_TRACE, plus a control test showing the fixture really does start maintenance.
  • Mutation checks: removing the seam splice, the raw pull/commit flags, the _git flag or the lock cleanup each turns a test red.
  • All 57 agent-server unit test files that touch git, run_registered or auto-sync pass (1,556 tests).
  • /cso --diff: no findings at the gate.

Merge note: #4006 (#4000) also touches routers/git.py, git-sync-health.md, requirements/github.md and the top of tests/registry.json. Whichever PR lands second needs a rebase; the conflicts should be trivial (both add new lines).

Fixes #4001

🤖 Generated with Claude Code

@AndriiPasternak31 AndriiPasternak31 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at c8ed19cfb830d7a92b510119340cdc0f55bc1b9a.

Splicing -c maintenance.auto=false in at the run_registered seam is the right fix, and it covers more than the --no-auto-maintenance the issue proposed. Keeping the caller's argv on results and exceptions keeps _with_stash's exc.cmd[1] working. I checked it against real repos with a repo-local maintenance.auto=true and gc.auto=1. A plain git fetch origin starts maintenance run --auto. Through run_registered, neither fetch origin nor pull --rebase origin main starts anything. The PR's own tests pass at this head (test_4001_no_auto_maintenance.py, test_ent708_settings_json_guard.py, test_1595_git_maintenance.py: 121 passed).

Against #4001: the status poll's 30 s fetch (routers/git.py:1927) and the auto-sync and pull cycles' 120 s fetches all go through run_registered, so all of them are covered. The operator endpoints' raw fetches prepend the flag. The optional maintenance.lock hardening is done with the same 1 h age gate as gc.pid/index.lock, not "no git process running". That is a reasonable substitute. Extending the fix to commit/merge/rebase goes beyond the issue, but the body justifies it and I agree with it. Two things block.

Blocking

  1. Three git rebase --abort children still start auto-maintenance. docker/base-image/agent_server/routers/git.py:2243, :2619 and :2685 are raw subprocess.run(["git", "rebase", "--abort"], timeout=10) calls, and they are not flagged. rebase --abort runs maintenance run --auto just like a completed rebase. I reproduced this on git 2.50: after a conflicting rebase in a repo with local maintenance.auto=true and gc.auto=1, GIT_TRACE=1 git rebase --abort shows maintenance run --auto, and with -c maintenance.auto=false it starts nothing. I did not re-run this on the base image's git.

    • Scenario: a repo-local re-enable is in place, and an operator runs POST /api/git/sync with pull_first, or a pull with stash_reapply or the default strategy, and the pull --rebase conflicts. The abort child then starts gc → repack, and the request blocks on it. At 10 s, subprocess.run kills git rebase only, not its process group. The maintenance grandchild is left running, unregistered, holding objects/maintenance.lock. That is the failure this PR closes everywhere else.
    • This contradicts the requirement line the PR adds ("Platform git children run with -c maintenance.auto=false"), and _AUTO_MAINTENANCE_VERBS already lists rebase.
    • test_operator_endpoints_flag_every_maintenance_capable_call cannot see these sites. _Recorder answers rc 0 for every call, so pull --rebase never fails and the abort branches never run.
    • Fix: prepend *GIT_NO_AUTO_MAINTENANCE at the three sites, and make the recorder fail the first pull so the abort branches are driven.
  2. Both red checks are caused by this PR. tests/unit/test_4001_no_auto_maintenance.py:31-46 copies the guarded eviction from test_1595_git_maintenance.py but not its _STUBBED_MODULE_NAMES list and autouse _restore_sys_modules fixture.

    • Lint: python tests/lint_sys_modules.py at this head reports this file going from 0 to 2 violations (:38 bare sys.modules.pop, :45 bare sys.modules[...] =) and fails. On the merge base 0f689db8 it passes ("no new violations").
    • Regression diff: its only new failure is test_lint_sys_modules::test_committed_baseline_matches_current_repo_state. It fails at this head and passes at the merge base.
    • Once merged, the sys.modules lint is red on every PR cut from dev, and that unit test fails on dev itself.
    • Fix: add the restore fixture the way test_1595_git_maintenance.py does. Don't regenerate the baseline.

Non-blocking

  1. At this head, _reap_stale_git_litter runs only from the auto-sync cycle (routers/git.py:1381) and the pull cycle (:1273). An agent with both flags off never gets a stale objects/maintenance.lock removed until it restarts, and self-pushing agents are exactly the agents in #4000/#4002. The body's "removed on every cycle" becomes true once #4006 lands, because its every-tick maintenance pass calls the reap. Worth saying so in the flow doc entry.

Pairing with #4006. I merged the two branches locally. The only conflicts are textual, in tests/registry.json and docs/memory/requirements/github.md. They are the same whichever lands first and resolve by keeping both sides. routers/git.py merges cleanly. On the combined tree, both PRs' tests pass (188), and so do the git, sync and canary suites (1547 passed, 4 skipped). The two halves agree: #4006's new children (repack, reflog expire, prune) go through run_registered, so they carry the flag, and maintenance.auto doesn't affect an explicit repack/prune/gc. The platform's own maintenance therefore keeps working in either merge order. With both merged, the maintenance.lock reap also runs on every tick for agents with auto-sync off.

# Pull with rebase (from upstream branch, not working branch)
pull_result = subprocess.run(
["git", "pull", "--rebase", "origin", pull_branch],
["git", *GIT_NO_AUTO_MAINTENANCE, "pull", "--rebase", "origin", pull_branch],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This pull --rebase is flagged, but its failure branch at :2243 runs git rebase --abort raw with a 10 s timeout, and rebase --abort starts maintenance run --auto too. I reproduced this with a repo-local maintenance.auto=true. The same pair appears at :2610/:2619 and :2676/:2685. Prepending *GIT_NO_AUTO_MAINTENANCE to the three aborts closes it. The recorder in the test answers rc 0, so it never reaches these branches.

):
for _mod in list(sys.modules):
if _mod == "agent_server" or _mod.startswith("agent_server."):
sys.modules.pop(_mod, None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This bare sys.modules.pop and the bare assignment at :45 are what turn lint (sys.modules pollution check) red. The new failure in regression diff, test_lint_sys_modules::test_committed_baseline_matches_current_repo_state, has the same cause. test_1595_git_maintenance.py pairs this same eviction with _STUBBED_MODULE_NAMES and an autouse _restore_sys_modules fixture. Copying that clears both checks without touching the baseline.

fetch, pull, commit, merge and rebase each run `git maintenance run
--auto` when a repo-local config re-enables it, and wait for it. A
bounded platform child (the 30 s status-poll fetch, the auto-sync
commit, the pull-cycle merge) then dies at its timeout mid-repack and
strands objects/maintenance.lock, which git never expires: with --auto
a stale lock disables auto-maintenance for that repo, silently.

- run_registered splices GIT_NO_AUTO_MAINTENANCE
  (`-c maintenance.auto=false`) after `git` for every git child.
  Results and exceptions keep the caller's argv (_with_stash names the
  timed-out verb from exc.cmd[1]).
- The raw subprocess.run fetch/pull/commit sites in the sync, pull and
  reset endpoints, and the _git helper, prepend the same constant.
- _reap_stale_git_litter removes objects/maintenance.lock older than
  1 h, the same age gate as gc.pid and index.lock.

The issue proposed --no-auto-maintenance on fetches; that flag exists
for fetch/pull only, and commit/merge/rebase share the failure.

Mutation checks: removing the seam splice, the raw pull/commit flags,
the _git flag or the lock reap each turns a test in
test_4001_no_auto_maintenance.py red.

Fixes #4001

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@obasilakis
obasilakis force-pushed the feature/4001-fetch-no-auto-maintenance branch from c8ed19c to 21f591d Compare October 28, 2026 11:11
…ules in the #4001 test (#4001)

Review of #4007:
- The three raw `subprocess.run(["git", "rebase", "--abort"])` recovery
  calls in the sync and pull endpoints now prepend
  GIT_NO_AUTO_MAINTENANCE. `rebase --abort` starts `maintenance run
  --auto` like a completed rebase, and its 10 s timeout kills only the
  direct child, leaving the maintenance grandchild holding
  objects/maintenance.lock.
- The test recorder now fails every `pull` and reports the repo behind
  origin, so all three abort branches run. Un-flagging any one of them
  turns test_operator_endpoints_flag_every_maintenance_capable_call red.
- test_4001_no_auto_maintenance.py gains the `_STUBBED_MODULE_NAMES` +
  autouse `_restore_sys_modules` pair test_1595_git_maintenance.py uses,
  so tests/lint_sys_modules.py passes against the committed baseline.
- Flow doc: the maintenance.lock reap runs from the every-tick
  maintenance pass (#4000), so agents with auto-sync off are covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@obasilakis

Copy link
Copy Markdown
Contributor Author

Thanks. I agreed with all three points, and they're addressed in d8af18148.

  1. Raw rebase --abort: the three recovery calls in the sync and pull endpoints now prepend GIT_NO_AUTO_MAINTENANCE. I also checked stash push/stash pop with GIT_TRACE against a repo-local maintenance.auto=true. They start no maintenance, so they stay as they are.
    • The test recorder now fails every pull and reports the repo as behind origin, so all three abort branches run.
    • I removed the flag from each abort site one at a time, and each removal turns test_operator_endpoints_flag_every_maintenance_capable_call red.
  2. sys.modules: test_4001_no_auto_maintenance.py now has the _STUBBED_MODULE_NAMES plus autouse _restore_sys_modules pair from test_1595_git_maintenance.py. tests/lint_sys_modules.py reports OK: 132 violation(s) … no new violations, and test_lint_sys_modules.py passes. The baseline is unchanged.
  3. Lock reap coverage: fix: run git maintenance and git-health stats on every auto-sync tick (#4000) #4006 has landed, so _reap_stale_git_litter now runs from _run_git_maintenance_once on every tick. The flow doc says so.

The branch is rebased on current dev. Related suites pass: 235 tests (#4001, #4000 every-tick, ent708, ent703, 1595, the pull branch, the sys.modules lint, and the reset guardrails).

@github-actions

Copy link
Copy Markdown

⚠️ Live-instance suite skipped — merge conflict against dev.

Resolve by merging dev locally and pushing the result; the next nightly re-tests.

@github-actions

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

@AndriiPasternak31 AndriiPasternak31 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed at d8af18148dce7d83969342949d7b55471a7fad4e.

All three points are addressed. The rebase onto dev (21f591db3) changed only docs and tests/registry.json. routers/git.py, registered_run.py and both test files are line-for-line the change I reviewed at c8ed19cf.

  1. rebase --abort. Fixed. routers/git.py:2300, :2676 and :2742 prepend *GIT_NO_AUTO_MAINTENANCE. The recorder now fails every pull and reports the repo behind origin, so all three abort branches run, and the test requires rebase among the recorded verbs. I un-flagged each abort site, and each of the six other raw fetch/pull/commit sites, one at a time. Every one of the nine turns test_operator_endpoints_flag_every_maintenance_capable_call red. Against a real repo with local maintenance.auto=true, a raw git rebase --abort after a conflicting rebase traces maintenance run --auto. With -c maintenance.auto=false it traces nothing. stash push/stash pop trace nothing either, so leaving them raw is right. An AST scan of agent_server finds no fetch/pull/commit/merge/rebase child left that is neither routed through run_registered nor flagged.
  2. sys.modules. Fixed. python tests/lint_sys_modules.py reports OK: 132 violation(s) … no new violations, with no findings in test_4001_no_auto_maintenance.py, and the baseline is untouched.
  3. Reap coverage. Fixed. _run_git_maintenance_once reaps first (routers/git.py:1570) and runs on every tick with auto-sync on or off, and the flow doc now says so.

Tests at this head: the PR's suites and the related ones (#4001, #4000 every-tick, ent708, ent703, 1595, pull branch, sys.modules lint, reset guardrails) pass, 235 passed. Every unit test file that touches the git router, run_registered or auto-sync also passes: 1498 passed, 1 skipped, 0 failed. I did not re-run anything on the base image's git.

Before merge: the branch conflicts with dev again, in tests/registry.json only. Keep both sides. One nit: the body still says "7 raw call sites". It is 10 now (9 raw plus _git).

@obasilakis
obasilakis merged commit af193c8 into dev Oct 29, 2026
25 checks passed
@obasilakis
obasilakis deleted the feature/4001-fetch-no-auto-maintenance branch October 29, 2026 10:19
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.

2 participants