Skip to content

spend: a very large --days crashes with a Python traceback instead of an error message #107

Open

Description

@laaielichter

gulliver spend refuses --days below 1 (#92), but a very large number crashes with a raw Python traceback instead of a message:

gulliver spend --by table --days 99999999999 --json
# OverflowError: Python int too large to convert to C int

gulliver spend --days 1000000 --json
# OverflowError: date value out of range

gulliver top --days 99999999999 already handles this well: it returns status: "error" with the message "days must be between 1 and 365." (exit code 1). spend should give the same kind of answer. Please pick the upper limit with care: top allows up to 365 days, and the receipts and ledger that spend reads may allow a different window, so check what is sensible and say so in the message.

Where to start

  • src/gulliver/runaway.py (around line 311): spend(...), which already refuses days < 1 and shows the _error(message, next_step) style
  • src/gulliver/features.py or src/gulliver/core.py: look for where top produces "days must be between 1 and 365" and reuse the idea (or the constant)
  • src/gulliver/cli.py: the spend parser (around line 340) and its handler
  • Tests: tests/test_runaway.py (spend), tests/test_cli_and_mcp.py for main([...])

Done when

  • spend --days N above the chosen upper limit returns status: "error" with a clear message and next_step (exit code 1), not a traceback; the limit is stated in the message
  • --days 1 and every valid value up to the limit behave exactly as before
  • A test for a huge value (for example 99999999999) and one just above the limit, through the function and through main([...])
  • Leave CHANGELOG.md alone; the maintainer adds the entry with credit to you when it is merged
  • pytest and ruff check . pass

Comment here to claim it and you'll be assigned.

Activity

  1. mPiha commented on Nov 10, 2026

    @mPiha

    AI-assisted. I would reuse the same practical upper bound as top: 365 days. It avoids timedelta overflow and matches the existing user-facing window.

    Suggested patch in src/gulliver/runaway.py:

    MAX_SPEND_DAYS = 365
    
    
    def spend(settings: Settings, by: str = "agent", days: int = 7) -> dict[str, Any]:
        if by not in SPEND_BY:
            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 smaller window, for example --days {MAX_SPEND_DAYS}.",
            )
    
        days = int(days)
        first = now_utc().date() - timedelta(days=days - 1)

    The check should happen before timedelta(days=days - 1) so huge values cannot reach the date arithmetic.

    Suggested tests:

    • spend(settings, days=99999999999) returns status: "error" with the limit in the message and a next_step;
    • spend(settings, days=366) returns status: "error";
    • spend(settings, days=1) and spend(settings, days=365) still return status: "ok";
    • main(["spend", "--days", "99999999999", "--json"]) exits with code 1 and emits the same error shape;
    • main(["spend", "--days", "366", "--json"]) exits with code 1.

    Not claiming the issue.

  2. rohangoud17 commented on Nov 10, 2026

    @rohangoud17
    Contributor

    Hi, I’d like to work on this one too. My plan: in spend (runaway.py), add an upper bound check next to the existing days < 1 check and return _error(...) with the limit stated in the message and a next_step, matching top’s “days must be between 1 and 365” behaviour. I’ll check what window the receipts/ledger support before picking the limit (reusing top’s constant if 365 makes sense) and confirm it here. Tests through spend() and main([...]) for a huge value and limit + 1, plus a changelog line. I’ll keep it as a separate PR from #138.

  3. added a commit that references this issue on Nov 11, 2026
    3192205
  4. laaielichter commented on Nov 11, 2026

    @laaielichter
    OwnerAuthor

    Thanks @rohangoud17, you asked for #107 at 20:37 on 2026-11-10, and that is the first claim on this thread (the earlier comment from @mPiha says "not claiming"), so I have assigned it to you. Your plan matches the issue.

    Two things for when you start:

    • Another new contributor opened PR fix(spend): reject a --days window wider than a year #140 for this issue at 00:57 today without commenting on it first. I have let them know, kindly, that the claim is yours, so you can go ahead without racing anyone.
    • On the limit: top allows 1 to 365 days (days must be between 1 and 365, in src/gulliver/workload.py, and le=365 on the MCP tool gulliver_top). I did not find a retention limit for the ledger that spend reads, so 365 would be a choice for consistency with top, not a technical limit. The issue asks you to say what you chose and why, in the message or the PR description; one sentence is enough. Please also keep --days 1 and every value up to the limit working as before.

    Please finish the small CHANGELOG fix on #138 first if you can; both PRs are small, so either order is fine.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions