Repository navigation
Description
Summary
Money and metric columns declared REAL in src/backend/db/schema.py are carried to PostgreSQL unchanged, where REAL is a 4-byte float (float4, ~7 significant digits, ceiling ~3.4e38). On SQLite the same keyword is an 8-byte double. So the two supported backends store execution cost with different precision, and a value SQLite accepts can raise on PostgreSQL.
The visible failure: closing a loop run whose cost is outside float4 range raises psycopg2.errors.NumericValueOutOfRange from db.finalize_loop_run (UPDATE agent_loop_runs SET … cost=…), inside LoopService._close_run. advance_on_terminal catches it ("never break a terminal write") and logs, so the run row is never closed and the loop never advances or reaches its stop reason.
Reproduction
Against a disposable PostgreSQL 16 (TEST_POSTGRES_URL set, alembic upgrade head applied):
cd tests && pytest "unit/test_ec_loop_service_edges.py::TestCostAccumulator::test_m16_infinite_budget_never_trips" -q
# [postgres] leg: FAILED — NumericValueOutOfRange: "1e300" is out of range for type real
# [sqlite] leg: passesDeterministic (3 of 3) on a full-suite run of tests/run-full.sh on 2026-10-09 — the postgres tier's only failure (1 failed, 2330 passed).
Context
The test's 1e300 is an edge-case probe, not a realistic cost, but it exposes two real properties:
- Precision drift between backends.
schedule_executions.cost,agent_loop_runs.cost, thetotal_costroll-ups,max_cost_usdon the original table DDL, and the monitoring/utilisation percentages are allfloat4on PostgreSQL. Summing many small per-run costs infloat4drifts from the SQLite result, and budget comparisons (max_cost_usd) are made against a rounded stored value. - An unrepresentable value aborts a terminal write. A cost the column cannot hold leaves the loop run open rather than recording the run and stopping the loop.
The codebase already knows this class: agent_loops.max_cost_usd was added on the PostgreSQL track as DOUBLE PRECISION (Alembic 0008_agent_loops_max_cost), metric_values.value_numeric is DOUBLE PRECISION with a comment in db/tables.py that "REAL would be float4 on PG", and git_dir_bytes was widened to BigInteger for the integer twin of the same defect (#2800). The remaining REAL columns were never swept.
Acceptance Criteria
- Cost columns (
cost,total_cost,max_cost_usd) areDOUBLE PRECISIONon PostgreSQL — fresh installs via the baseline DDL translation, existing installs via a new Alembic revision (SQLite needs no change; note that in thedb/migrations.pyentry per the dual-track rule) - The remaining
REALcolumns are either widened in the same revision or listed with a reason they are safe asfloat4 -
test_m16_infinite_budget_never_trips[postgres]passes, or — if 1e300 is judged out of contract — the cost is clamped/validated before the write and the test pins that behaviour on both backends - A loop run whose cost cannot be persisted still closes (the run is recorded as failed with a named error) rather than being left open
- A schema-parity test asserts no
REALmoney column reaches PostgreSQL asfloat4
Technical Notes
src/backend/db/schema.py—to_postgres_table_ddlpassesREALthrough; ~24REALcolumnssrc/backend/db/tables.py— the same columns areFloatin the SQLAlchemy MetaData (FloatisFLOAT→double precisionon PG, so MetaData and the baseline DDL already disagree)src/backend/services/loop_service.py—_close_run→db.finalize_loop_run;advance_on_terminal's broadexceptswallows the failure- Invariant Feature/vector log retention #3 / Fix git pushing bug #9 (dual-track migrations) apply
Activity
fix(tests): repair the tests and fixtures a full run-full.sh found dr…