Repository navigation
Description
Summary
#2800 widened agent_sync_state.git_dir_bytes to BIGINT because _coerce_nonneg_int admits any value < 2**63 while the PostgreSQL column was int4. The same mismatch remains on seven sibling columns of the same upsert, so the identical NumericValueOutOfRange stays reachable — surfaced by the merge-train review of #2805.
Where
src/backend/services/sync_health_service.py:
:400-403—pack_count,loose_objects,maintenance_failuresgo through_coerce_nonneg_int(bound< 2**63) intoIntegercolumns (int4 on PG).:414-417—ahead_main/behind_main/ahead_working/behind_workingare passed uncoerced from the agent payload (payload.get(...) or 0) into int4 columns.
_coerce_nonneg_int's own docstring names the threat model — "a compromised/prompt-injected agent can persist arbitrary JSON into sync-state.json" — so an agent that writes 2**40 into any of these makes every SyncHealthService upsert for it raise on PostgreSQL, and the agent's sync health goes dark exactly as #2800 described for git_dir_bytes.
Rule (from the #2800 learnings entry)
Audit the boundary guard beside the column: if the coercion allows
< 2**63the column must too.
Either widen the seven columns to BigInteger (dual-track: schema.py + tables.py + one Alembic revision; the SQLite track needs nothing — see the note beside _migrate_agent_sync_state_git_dir_bytes in db/migrations.py), or bound the coercion to int4 for the counters that are genuinely small (pack_count, loose_objects, maintenance_failures, ahead/behind counts cannot plausibly exceed 2**31) and route the four ahead/behind fields through it. The second is the smaller, more honest change: a 2-billion-commit divergence is not a value to store, it is a payload to reject.
Acceptance criteria
- Every agent-supplied integer that reaches the
agent_sync_stateupsert is coerced through one bound that matches its column's PostgreSQL type. - A
requires_postgrestest upserts the maximum admitted value for each of the eight columns and reads it back (the bug: agent_sync_state.git_dir_bytes is a 32-bit INTEGER on PostgreSQL — .git over 2 GiB breaks the sync-state upsert #2800test_git_dir_bytes_is_64_bit_on_postgresshape). - An out-of-bound value is rejected at the boundary (
None), not raised from the driver.
Related
- bug: agent_sync_state.git_dir_bytes is a 32-bit INTEGER on PostgreSQL — .git over 2 GiB breaks the sync-state upsert #2800 / fix(db): agent_sync_state ints are bounded at their own column's ceiling — git_dir_bytes BIGINT (#2800), int4 coercion (#2827) #2805 — the first column of this class
- bug: watchdog cannot close an execution stale >24.8 days — fabricated duration_ms overflows PostgreSQL INTEGER, and the sweep then fails every cycle forever #2434 —
duration_ms, the occurrence before that
Activity
fix(db): #2800 rides dev's Alembic head, and the SQLite track carries…
fix(db): coerce every agent_sync_state integer at its own column's ce…
dolho commentedon Sep 16, 2026
/claim
github-actions commentedon Sep 16, 2026
Claimed by @dolho. Label
status-in-progressadded.Next steps:
feature/2827-<short-slug>Fixes #2827dolho commentedon Sep 16, 2026
Folded into #2805 (the
git_dir_bytesBIGINT PR) rather than a separate PR — same boundary function, same test harness, and the two fixes are one story: #2800 widened the one column that needed 64 bits; this makes the boundary stop admitting 64-bit values for the seven columns that are still int4.Commit: 2d711a487
_coerce_nonneg_intdefault ceiling →INT4_MAX;git_dir_bytes+ the lock-report ints opt intoINT8_MAXexplicitly_coerce_counterboundsahead_main/behind_main/ahead_working/behind_working(and legacyahead/behind) — previously written rawINT4_MAX + 1per column through_sync_agent(int4 → NULL/0, BIGINT admitted),INT4_MAXitself lands, and arequires_postgresround-trip of every column's admitted maximum — the proof boundary and column agreeINT8_MAX, counter left raw) → 3 redPR body carries
Fixes #2827so the status promoter picks it up on merge.fix(db): agent_sync_state ints are bounded at their own column's ceil…
fix(sync-health): a kept divergence clock keeps its counts (trinity-e…
feat(sync-health): divergence age is the signal — red and frozen at >…
feat(sync-health): sync health on fleet health, the fleet audit over …