Repository navigation
fix: platform git children never start git auto-maintenance (#4001) - #4007
Conversation
AndriiPasternak31
left a comment
There was a problem hiding this comment.
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
-
Three
git rebase --abortchildren still start auto-maintenance.docker/base-image/agent_server/routers/git.py:2243,:2619and:2685are rawsubprocess.run(["git", "rebase", "--abort"], timeout=10)calls, and they are not flagged.rebase --abortrunsmaintenance run --autojust like a completed rebase. I reproduced this on git 2.50: after a conflicting rebase in a repo with localmaintenance.auto=trueandgc.auto=1,GIT_TRACE=1 git rebase --abortshowsmaintenance run --auto, and with-c maintenance.auto=falseit 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/syncwithpull_first, or a pull withstash_reapplyor the default strategy, and thepull --rebaseconflicts. The abort child then starts gc → repack, and the request blocks on it. At 10 s,subprocess.runkillsgit rebaseonly, not its process group. The maintenance grandchild is left running, unregistered, holdingobjects/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_VERBSalready listsrebase. test_operator_endpoints_flag_every_maintenance_capable_callcannot see these sites._Recorderanswers rc 0 for every call, sopull --rebasenever fails and the abort branches never run.- Fix: prepend
*GIT_NO_AUTO_MAINTENANCEat the three sites, and make the recorder fail the firstpullso the abort branches are driven.
- Scenario: a repo-local re-enable is in place, and an operator runs
-
Both red checks are caused by this PR.
tests/unit/test_4001_no_auto_maintenance.py:31-46copies the guarded eviction fromtest_1595_git_maintenance.pybut not its_STUBBED_MODULE_NAMESlist and autouse_restore_sys_modulesfixture.- Lint:
python tests/lint_sys_modules.pyat this head reports this file going from 0 to 2 violations (:38baresys.modules.pop,:45baresys.modules[...] =) and fails. On the merge base0f689db8it 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 ondevitself. - Fix: add the restore fixture the way
test_1595_git_maintenance.pydoes. Don't regenerate the baseline.
- Lint:
Non-blocking
- At this head,
_reap_stale_git_litterruns only from the auto-sync cycle (routers/git.py:1381) and the pull cycle (:1273). An agent with both flags off never gets a staleobjects/maintenance.lockremoved 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], |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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]>
c8ed19c to
21f591d
Compare
…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]>
|
Thanks. I agreed with all three points, and they're addressed in
The branch is rebased on current |
|
Resolve by merging |
|
Resolve by running |
AndriiPasternak31
left a comment
There was a problem hiding this comment.
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.
rebase --abort. Fixed.routers/git.py:2300,:2676and:2742prepend*GIT_NO_AUTO_MAINTENANCE. The recorder now fails everypulland reports the repo behind origin, so all three abort branches run, and the test requiresrebaseamong 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 turnstest_operator_endpoints_flag_every_maintenance_capable_callred. Against a real repo with localmaintenance.auto=true, a rawgit rebase --abortafter a conflicting rebase tracesmaintenance run --auto. With-c maintenance.auto=falseit traces nothing.stash push/stash poptrace nothing either, so leaving them raw is right. An AST scan ofagent_serverfinds no fetch/pull/commit/merge/rebase child left that is neither routed throughrun_registerednor flagged.- sys.modules. Fixed.
python tests/lint_sys_modules.pyreportsOK: 132 violation(s) … no new violations, with no findings intest_4001_no_auto_maintenance.py, and the baseline is untouched. - Reap coverage. Fixed.
_run_git_maintenance_oncereaps 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).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
-c maintenance.auto=false. Before this, a repo-localmaintenance.auto=truemade a bounded platformfetch/pull/commit/merge/rebasestartmaintenance run --auto → gc → repack. The child's timeout killed that repack partway through and leftobjects/maintenance.lockbehind. Git never expires that lock, so auto-maintenance stayed off for the repo with no warning.objects/maintenance.lock(older than 1 h) is now removed on every cycle, using the same age rule asgc.pidandindex.lock.Changes
docker/base-image/agent_server/utils/registered_run.py: new constantGIT_NO_AUTO_MAINTENANCE, inserted aftergitin the command the child runs. Return values and exceptions still carry the caller's original argv, because_with_stashreads the verb fromexc.cmd[1].docker/base-image/agent_server/routers/git.py:subprocess.run/_gitcall sites (sync, pull and reset endpoints) prepend the constant._reap_stale_git_litteralso handlesobjects/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.git-sync-health.mdflow,requirements/github.md.The issue proposed
--no-auto-maintenanceon fetches. That flag exists only forfetch/pull, andcommit/merge/rebasefail the same way. Verified withGIT_TRACE: a repo with localmaintenance.auto=truestartsmaintenance run --autooncommit, and with-c maintenance.auto=falseit starts nothing.Test Plan
cd tests && pytest unit/test_4001_no_auto_maintenance.py -v: 8 tests against real repos withGIT_TRACE, plus a control test showing the fixture really does start maintenance._gitflag or the lock cleanup each turns a test red.run_registeredor 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.mdand the top oftests/registry.json. Whichever PR lands second needs a rebase; the conflicts should be trivial (both add new lines).Fixes #4001
🤖 Generated with Claude Code