Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
- `impact`, `lineage` and `drift` refuse `--models` pointing to a folder with no `.sql` files with `status: error` and a `next_step` instead of reporting zero models or empty impact. Thanks to @shaw778! (#122, #147)
`spend --days N` refuses a value above 365 (the same limit as `top`) with `status: error` and a `next_step`, and exits 1 instead of crashing with an `OverflowError` traceback on a huge N. Thanks to @rohangoud17! (#107, #161)

## 0.4.0 - 2026-11-11

Expand Down
4 changes: 4 additions & 0 deletions src/gulliver/runaway.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
REPEAT_FREE_USD = 0.01 # repeats cheaper than this ...
REPEAT_FREE_BYTES = 1024**3 # ... and smaller than this are never treated as a loop
SPEND_BY = ("agent", "day", "table", "session", "task", "connection", "kind")
MAX_SPEND_DAYS = 365 # same limit as `top`; the ledger itself has no retention limit

_NONDETERMINISTIC = {"CurrentDate", "CurrentTimestamp", "CurrentTime", "CurrentDatetime", "CurrentTimestampLTZ",
"Localtimestamp", "Localtime", "Rand", "Randn", "Uuid", "TableSample"}
Expand Down Expand Up @@ -313,6 +314,9 @@ def spend(settings: Settings, by: str = "agent", days: int = 7) -> dict[str, Any
return _error(f"by must be one of {', '.join(SPEND_BY)}", "Use --by agent, day or table.")
if days < 1:
return _error("--days must be at least 1.", "Give a positive number of days, for example --days 7.")
if days > MAX_SPEND_DAYS:
return _error(f"--days must be between 1 and {MAX_SPEND_DAYS}.",
f"Use a window of at most {MAX_SPEND_DAYS} days, for example --days 30.")
days = int(days)
first = now_utc().date() - timedelta(days=days - 1)
groups: dict[str, dict[str, Any]] = {}
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cli_and_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,10 @@ def test_mcp_check_by_name_and_status_checks(demo_db, state, tmp_path, monkeypat
err_data = json.loads(err_res.content[0].text)
assert err_data.get("status") == "error"
assert "Unknown configured check" in err_data.get("error", "")


def test_cli_spend_refuses_days_above_365(demo_db, state, capsys):
for days in ("99999999999", "366"):
assert main(["--dsn", demo_db, "spend", "--days", days, "--json"]) == 1
data = json.loads(capsys.readouterr().out)
assert data["status"] == "error" and "365" in data["error"]
9 changes: 9 additions & 0 deletions tests/test_runaway.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,3 +859,12 @@ def test_prune_cli(settings, capsys):
# Bad argument
with pytest.raises(SystemExit):
main(["prune", "--older-than", "invalid_period"])


def test_spend_refuses_a_window_above_365_days(settings):
"""A huge --days used to crash with OverflowError in the date math (#107)."""
for days in (99999999999, 366):
res = runaway.spend(settings, by="agent", days=days)
assert res["status"] == "error" and "365" in res["error"] and res["next_step"]
for days in (1, 365):
assert runaway.spend(settings, by="agent", days=days)["status"] == "ok"