Repository navigation
Description
Summary
SyncHealthService polls every git-sync-enabled agent once a minute via db.list_git_enabled_agents() (src/backend/services/sync_health_service.py:91). That accessor (src/backend/db/schedules.py:3103) selects from agent_git_config filtered only on sync_enabled == 1 — it does not join agent_ownership and does not exclude deleted_at IS NOT NULL.
Soft delete preserves agent_git_config rows by design, so the poller keeps calling agents whose container was removed — indefinitely. Each attempt raises httpx.ConnectError, which is exactly the exception class that increments the transport circuit breaker.
Context
The sibling accessor was already hardened for this. list_all_enabled_schedules() (src/backend/db/schedules.py:437) carries a docstring stating it filters agent_ownership.deleted_at "otherwise the scheduler fires" for soft-deleted agents. The git-sync poller was simply missed by that pass.
Observed on a dev instance after an agent was soft-deleted at 11:42:52 (container removed):
Error getting git status for <name>: All connection attempts failed # once a minute, forever
11:45:14 Circuit OPENED for agent <name> after 3 failures
12:18:19 Circuit DORMANT for agent <name> after 10 consecutive open-probe failures — switching to 3600s cooldown
12:18:19 [CB] circuit_breaker_dormant operator-queue entry emitted for <name>
Three consequences, all real:
- The breaker for a deleted agent is driven to
DORMANT, which then poisons any future agent created under the same name — see the companion issue bug(lifecycle): stale transport circuit-breaker Redis key survives agent delete/recreate — a fresh healthy agent fast-fails as "unhealthy" #1560. The arithmetic corroborates the poller as the driver: withCIRCUIT_FAILURE_THRESHOLD = 3and cooldowns of 30 + 60 + 120 + 240 + 300×6 s ≈ 36 min against a 60s poll interval,11:42 + ~36 min = 12:18, matching theDORMANTlog to the minute. - A bogus operator-queue alert (
circuit_breaker_dormant) is raised naming an agent that no longer exists, and it sits unresolved in the Operations queue. - Unbounded error churn — one failed HTTP call per deleted agent per minute, forever, plus the operator-queue sync loop retrying delivery of that alert every 5s once any container reappears under the name.
fleet_audit_service.py:28 consumes the same accessor for GET /api/fleet/sync-audit, so the audit surface also reports soft-deleted agents. Both consumers want the filter; nothing depends on deleted agents being included.
Reproduction
- Create an agent with git sync enabled.
DELETE /api/agents/<name>(soft delete — container removed,agent_git_configrow retained).- Tail the backend log:
Error getting git status for <name>: All connection attempts failedrecurs every 60s indefinitely. - After ~3 min the transport breaker opens; after ~36 min it goes
DORMANTand emits an operator-queue alert for the deleted agent. GET /api/fleet/sync-auditstill lists the deleted agent.
Acceptance Criteria
-
list_git_enabled_agents()joinsagent_ownershipand excludes rows wheredeleted_at IS NOT NULL -
SyncHealthServiceno longer issues any HTTP call to a soft-deleted agent -
GET /api/fleet/sync-auditno longer reports soft-deleted agents - No circuit-breaker failure is ever recorded against a soft-deleted agent, and no
circuit_breaker_dormantoperator-queue entry is emitted for one - Audit sweep: every DB accessor consumed by a background loop is checked for the same missing
deleted_atfilter, and the result is recorded in the issue (the scheduler's accessor was hardened; this one was not — there may be others) - Regression test: soft-delete a git-sync-enabled agent, run one
SyncHealthServicecycle, assert zero agent HTTP calls and zero breaker failures recorded
Technical Notes
- Accessor:
src/backend/db/schedules.py:3103— currentlyselect(agent_git_config).where(agent_git_config.c.sync_enabled == 1). - Consumers:
src/backend/services/sync_health_service.py:91(60s loop) andsrc/backend/services/fleet_audit_service.py:28(audit endpoint). Facade delegation atsrc/backend/database.py:1059. - Only
httpx.ConnectError/httpx.ConnectTimeoutincrement the transport breaker (src/backend/services/agent_client.py), which is precisely what a removed container produces — so this poller is a direct breaker-poisoning path. - Minor, same code path:
src/backend/services/git_service.py:674swallows the exception with a bareprint()rather thanlogger.*, so these failures bypass structured logging entirely (no level, no timestamp, invisible to log-based alerting). Worth converting while here. - Companion defect: bug(lifecycle): stale transport circuit-breaker Redis key survives agent delete/recreate — a fresh healthy agent fast-fails as "unhealthy" #1560 — the poisoned
agent:circuit:{name}key is never cleared on delete/recreate, so a new agent under the same name inherits it. Fixing this issue removes the source of the poisoning; fixing bug(lifecycle): stale transport circuit-breaker Redis key survives agent delete/recreate — a fresh healthy agent fast-fails as "unhealthy" #1560 removes the inheritance. Both are needed. - Related: Soft-delete all entities + configurable data retention policy #834 (soft delete + retention), bug(recovery): soft-delete recovery dead-ends —
recovertells you tostart, butstart404s when the container is gone #1559 (soft-delete recovery dead-ends).
Activity
dolho commentedon Jul 10, 2026
Fix in #1565.
Audit-sweep result (AC: "every DB accessor consumed by a background loop is checked for the same missing
deleted_atfilter"):list_git_enabled_agentswas the sole offender. Findings:list_git_enabled_agents(DB)list_all_agents_fast()(Docker)list_all_agents_fast()+status==running(Docker)list_all_enabled_schedules(DB)run_maintenance(60s)list_agents_with_queued(DB)seenkeys, cleared on deleteConclusion: every other per-agent HTTP poller enumerates from Docker (a removed soft-deleted container is inherently absent), and the remaining DB-driven loops either already filter
deleted_at(scheduler) or issue no agent HTTP call (capacity drain is DB-only). No additional missing-filter accessor found on a breaker-affecting path.AC coverage:
agent_ownership+ excludesdeleted_at IS NOT NULLSyncHealthServiceissues no HTTP to a soft-deleted agent/api/fleet/sync-auditno longer reports soft-deleted agents (same accessor)circuit_breaker_dormantentry for a soft-deleted agent (no HTTP → noConnectError)TestSoftDeletedExcluded: excluded from accessor + zero HTTP in one poll cycle)Also converted
git_service.get_git_status's bareprint()→logger.warning(the "minor, same code path" note). Inheritance side (agent:circuit:{name}surviving delete/recreate) stays with the companion #1560.fix(reliability): clear per-agent Redis runtime state across the agen…
fix(sync-health): exclude soft-deleted agents from list_git_enabled_a…
vybe commentedon Jul 10, 2026
Fixed by #1565 (merged to
dev). Promoting tostatus-in-dev— the bare(#1561)reference didn't trip the closing-keyword auto-promotion.Release: v0.8.5 (#1781)