Skip to content

bug: git_dir_bytes is int32 on PostgreSQL — git-bloat alerting is inoperable above ~2 GiB #2240

Closed

Description

@vybe

Summary

agent_sync_state.git_dir_bytes is declared INTEGER on the PostgreSQL track, but it stores an agent's .git directory size in bytes. PostgreSQL INTEGER is 32-bit (max 2,147,483,647 ≈ 2 GiB), while the git-bloat alert threshold GIT_DIR_ALERT_BYTES defaults to 10 GiB (10,737,418,240) — 5× beyond what the column can hold.

The consequence is worse than a truncated metric: the value is written as part of the agent_sync_state upsert, so on PostgreSQL any agent whose .git exceeds ~2 GiB makes the whole statement raise psycopg2.errors.NumericValueOutOfRange and the sync-health row never lands. The #1595/#1596 bloat detection is therefore inoperable exactly in the regime it exists to detect — the architecture notes record 44 GB / 97%-garbage repos as the motivating incident.

SQLite is unaffected (dynamic typing, 64-bit ints), which is why this only surfaces in the PostgreSQL tier and has been invisible in ordinary local runs.

Context

Found by a full-suite run on dev (691e7dc9). The PostgreSQL tier reported 15 failures, 30 of them NumericValueOutOfRange. Failing test:

tests/unit/test_1595_sync_health_signals.py::TestGitBloatAlerts::test_size_crossing_emits_once[postgres]

It writes GIT_DIR_ALERT_BYTES ± 1 — both far past int32 — and the upsert raises.

Sources:

  • src/backend/db/tables.py:736 — Column("git_dir_bytes", Integer)
  • src/backend/migrations/versions/0019_agent_sync_state_git_dir_bytes.py — ADD COLUMN IF NOT EXISTS git_dir_bytes INTEGER
  • src/backend/services/sync_health_service.py:38 — GIT_DIR_ALERT_BYTES = int(os.getenv("GIT_DIR_ALERT_BYTES", str(10 * 1024**3)))

Sibling: duration_ms

The same int32 ceiling applies to duration_ms (Integer in schedule_executions, agent_loop_runs, agent_activities, voip_call_logs), which overflows past ~24.8 days of elapsed milliseconds. Nine further PostgreSQL failures in tests/unit/test_1771c_schedules_cas_edges.py hit it, though partly through their own fixed started_at="2026-01-01…" (tracked separately as a calendar-expiring test).

Production reachability for duration_ms is a narrower tail than git_dir_bytes — it needs a running row to survive the 5-minute watchdog for >24.8 days (a long backend outage, then the recovery sweep terminal-writes it) — but it is the same column class and cheap to fix in the same pass.

Acceptance Criteria

  • agent_sync_state.git_dir_bytes is BIGINT on the PostgreSQL track (new Alembic revision) and BigInteger in db/tables.py
  • A .git size of 10 GiB+ round-trips through the sync-health upsert on PostgreSQL without raising
  • The edge-triggered git_bloat operator-queue alert fires on PostgreSQL at the 10 GiB threshold, same as on SQLite
  • test_1595_sync_health_signals.py::TestGitBloatAlerts passes in the postgres tier
  • duration_ms is widened to BIGINT/BigInteger in the same pass (all four tables), or explicitly deferred with a note saying why
  • Dual-track parity holds: the SQLite DDL in db/schema.py/db/tables.py and the new Alembic revision agree (Invariant Feature/vector log retention #3), and schema-parity CI is green
  • The Alembic version-line still resolves to exactly one head

Technical Notes

  • SQLite needs no data migration — its column is already effectively 64-bit; only the declared type in the shared MetaData and the PG DDL move.
  • ALTER TABLE … ALTER COLUMN … TYPE BIGINT on PostgreSQL rewrites the table; agent_sync_state is one row per git-enabled agent, so this is small. schedule_executions is the large one — size the duration_ms half accordingly, or split it into its own revision.
  • Reads coerce agent-supplied ints at the boundary already (the /health clone_status convention), so no read-path change is expected.

Activity

  1. added
    priority-p1
    type-bug
    theme-reliability
    complexity-low
    status-ready
    on Aug 17, 2026
  2. removed
    status-ready
    on Aug 17, 2026
  3. vybe commented on Aug 17, 2026

    @vybe
    ContributorAuthor

    /claim

  4. added
    status-in-progress
    on Aug 17, 2026
  5. github-actions commented on Aug 17, 2026

    @github-actions

    Claimed by @vybe. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/2240-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #2240
  6. added
    complexity-medium
    and removed
    complexity-low
    on Sep 2, 2026
  7. added
    status-in-dev
    and removed
    status-in-progress
    on Sep 17, 2026
  8. vybe commented on Sep 17, 2026

    @vybe
    ContributorAuthor

    Release hygiene (v0.9.5 cut): fixed by #2805 (git_dir_bytes → BIGINT, Alembic 0063, tracked as #2800) → moving to status-in-dev so this closes with the v0.9.5 release.

  9. removed
    status-in-dev
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-mediumpriority-p1theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions