Repository navigation
fix(git-sync): bound agent .git bloat — maintenance repack + ignore conventions + size observability (#1596, PR-1) - #1597
Conversation
…nventions, size observability (#1596, PR-1) Git-sync auto-commit snapshots the whole workspace every 15-min heartbeat and NEVER ran git maintenance, so data-churn + `git gc --auto`'s never-consolidating packs grew one agent's `.git` to 44GB / 2,267 packs and the fleet to ~110GB. This is the non-destructive first slice (the safe trio); an opt-in history-squash policy for existing bloat is a deferred follow-up. Maintenance (agent side, docker/base-image/agent_server/routers/git.py): - after a successful push, `_maybe_run_git_maintenance` runs a consolidating `git repack -adl` + `git gc --prune=now` once packs cross GIT_MAINTENANCE_PACK_THRESHOLD (default 20). Self-throttling, best-effort, never fails the sync. Non-destructive — does NOT rewrite reachable history. Ignore conventions (git_service._GITIGNORE_PATTERNS): - add node_modules/, .venv/, venv/, __pycache__/, *.pyc/*.pyo, .pytest_cache/, .mypy_cache/, .ruff_cache/, .ipynb_checkpoints/, *.sqlite/*.sqlite3/*.db so churny non-source files stop being auto-committed (merged into agents on sync, which also untracks already-committed matches; agents can negate per-repo). Observability (.git size curve): - agent measures `.git` size (du -sb) into sync-state.json.git_dir_bytes and returns it via GET /api/git/status. - new agent_sync_state.git_dir_bytes column (dual migration: SQLite agent_sync_state_git_dir_bytes + Alembic 0019); SyncHealthService persists it; surfaced on GET /api/agents/sync-health, /fleet/sync-audit, and the per-agent sync-state endpoint. Tests: test_1596_git_sync_observability.py — git_dir_bytes round-trips + partial-update-preserves; default .gitignore includes the bulk-data set and keeps the credential/content safety rules. Schema + Alembic parity green. Deferred follow-ups (documented): opt-in history squash/rotation (destructive, needs owner consent) + a warn-on-large-file guardrail. Note: the agent-side maintenance + size measurement need a base-image rebuild to reach existing agents; the DB/backend surfacing works immediately. Related to #1596 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…erns The regression-diff CI job flagged test_doc_and_constant_in_sync: PR-1 added 13 bulk-data/cache/dep/index patterns to _GITIGNORE_PATTERNS (git_service.py) but the mirrored .gitignore block in TRINITY_COMPATIBLE_AGENT_GUIDE.md was not updated. Add the matching entries so the doc-drift guard passes. Related to #1596 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Resolve by running |
500a9dd to
c515b02
Compare
|
Heads-up: I force-pushed this branch back to the non-destructive PR-1 scope and dropped the destructive history-compaction commits I'd added. Reason: the parallel investigation in #1595 / #1505 identified the true root cause — git maintenance can never complete inside agent containers (detached So rewriting history was the wrong fix (and unsafe — a long rebase would be SIGKILLed mid-operation by the same sweeper). The load-bearing change (sweeper SIGTERM-then-SIGKILL + git-maintenance allowlist + stale-lock cleanup) belongs in #1595. This PR stays scoped to the two prongs that stand on their own — ignore conventions + observability — plus the non-destructive repack (whose large-repo reliability depends on #1595). |
vybe
left a comment
There was a problem hiding this comment.
Validated via /validate-pr: non-destructive self-throttling repack (pack-count gated, in-process child so the #817 sweeper doesn't apply), git_dir_bytes observability wired agent→sync-state→dashboard/audit, dual-track migration correct (SQLite agent_sync_state_git_dir_bytes + Alembic 0019 revising 0018), schema.py/tables.py/architecture.md synced, named regression tests. Security scan clean; CI green. Heads-up applied at merge time: #1550 must re-chain its 0019/0020 Alembic revisions onto this one. ✅
…nto 0019 (#1597) dev's #1597 landed 0019_agent_sync_state_git_dir_bytes (also revising 0018), colliding with this branch's 0019/0020. Re-chained: pull_claim_lease -> 0020 (down: 0019_agent_sync_state_git_dir_bytes), redelivery_count -> 0021. SQLite MIGRATIONS list keeps both tracks (git_dir_bytes entry first, matching dev apply order). Doc references updated. Co-Authored-By: Claude Fable 5 <[email protected]>
Problem (P1 — disk exhaustion)
Git-sync auto-commit (
agent_server/routers/git.py::_run_auto_sync_once) doesgit add -A→ commit → push every 15-min heartbeat. Under skills that write churny data files,.gitgrew unboundedly: one agent's.gitreached 44 GB / 2,267 packs / 4.26M objects; the fleet hit ~110 GB and the host 90%.Further investigation (credit: parallel work on #1595 / #1505) found the true root cause is not reachable history retention — it's that git maintenance can never complete inside agent containers: git's detached
gc --autoreparents to PID 1, the #817 orphan sweeper SIGKILLs it (a bare SIGKILL, so it leaves stale.lock/gc.pidlitter), and every subsequent gc then aborts on the stale lock — permanently disabling maintenance for that repo. ~97% of the bloat is unreachable garbage, not committed history (a plain non-destructivegit gc --prune=nowtook one agent 44 GB → 1.6 GB,fsckclean, HEAD unchanged).Consequence for this PR:
This PR — the non-destructive prongs that stand on their own
1. Maintenance repack (agent side)
After a successful push,
_maybe_run_git_maintenancerunsgit repack -adl+git gc --prune=nowonce the pack count crossesGIT_MAINTENANCE_PACK_THRESHOLD(default 20). Self-throttling, best-effort, non-destructive. Note: its reliability on large repos depends on the #1595 sweeper fix (an in-container git process is currently sweep-exposed) — it fully self-heals small/medium repos now and all repos once #1595 lands.2. Ignore conventions
git_service._GITIGNORE_PATTERNSnow also excludesnode_modules/,.venv/,venv/,__pycache__/,*.pyc/*.pyo,.pytest_cache/,.mypy_cache/,.ruff_cache/,.ipynb_checkpoints/,*.sqlite/*.sqlite3/*.db. Merged into each agent on sync (also untracks already-committed matches). Datasets/indexes belong indata_paths(#1169).3. Observability
.gitsize (du -sb) intosync-state.json.git_dir_bytes, returned viaGET /api/git/status.agent_sync_state.git_dir_bytescolumn (dual migration: SQLite + Alembic0019);SyncHealthServicepersists it; surfaced onGET /api/agents/sync-health,GET /api/fleet/sync-audit, and the per-agent sync-state endpoint.Acceptance criteria
.gitignoreexcludes data/cache/venv/index/deps..gitsize in sync health + fleet audit.Tests
tests/unit/test_1596_git_sync_observability.py—git_dir_bytesround-trips + a partial (failed) update preserves the last size; the default.gitignoreincludes the bulk-data set and keeps the pre-existing credential/content/safety rules. Schema + Alembic parity green.Deploy note
Agent-side maintenance +
.git-size measurement land on a base-image rebuild + agent recreate. The DB/backend surfacing works immediately. Full de-bloat of the existing 44 GB agents comes from #1595 (fix the sweeper sogc --prune=nowcan run to completion); this PR bounds future growth and gives operators the size curve.Related to #1596 · root cause #1595 · #1505
🤖 Generated with Claude Code