Skip to content

aggregator(collect-github-billing): --year/--month/--user values are never validated — NaN, month 13, month 0, fractional and flag-token values go straight into the billing API URL, and the failure is blamed on the gh token scope #3419

Closed

Description

@dezren39

aggregator(collect-github-billing): --year/--month/--user values are never validated — NaN, month 13, month 0, fractional and flag-token values go straight into the billing API URL, and the failure is blamed on the gh token scope

Evidence (verified this run, main f1eac95)

pm-stack/aggregator/scripts/collect-github-billing.ts:

  • :42-45 — argValue(flag) returns process.argv[i + 1] unchecked: a flag token is accepted as the previous flag's value, and a trailing flag yields undefined.
  • :72-74 — year/month are Number(argValue(...)) with no integer/range check; user is the raw string. All three are interpolated straight into the API path at :52 (users/${user}/settings/billing/usage?year=${year}&month=${month}).
  • :58-61 — on any gh failure the script's error says a 404 "usually means the scope, not a missing user", so a self-inflicted bad URL is reported as a token-scope problem.

Probe (laptop, ~/git/fleet/probe-2026-11-01-laneB-ghbilling/; real script + src/, sha256 of the script 5f8d8100… matched to main; gh stubbed to log its argv and return {"usageItems":[]}):

Invocation API call issued Result
--year 2026 --month 10 --print (control) users/dezren39/settings/billing/usage?year=2026&month=10 exit 0, correct
--month banana …?year=2026&month=NaN exit 0, prints 2026-NaN
--month 13 …&month=13 exit 0
--month 0 …&month=0 exit 0
--year 2026.5 --month 2.5 …?year=2026.5&month=2.5 exit 0
--month --print …&month=NaN (the flag token is consumed as the value, and --print still takes effect) exit 0
--user --print users/--print/settings/billing/usage?… exit 0
--print --user (trailing) user silently falls back to the default dezren39 exit 0

Against the real endpoint every malformed case 404s, and the script then misreports it as a missing user scope on the gh token — the exact misdiagnosis the error text at :58-61 was written to prevent, pointed the wrong way.

Why it matters

This is the daily GitHub billing collector (#1051): its records feed the usage snapshot store. A typo'd month in a manual or scheduled invocation either fails with a misleading scope error (sending the operator to re-auth gh instead of fixing the argument) or, for a trailing flag, silently collects a different month/user than the one named. Every sibling script that validates its period args locally fails fast with a usage error; this one validates nothing.

Acceptance criteria

  • --year must be an integer in a sane range (e.g. 2000–2100) and --month an integer 1–12; anything else (non-numeric, fractional, out of range) exits non-zero with a usage error naming the bad value, before any gh call.
  • A value-taking flag that is last, or whose next token is another flag, is a usage error — never silently replaced by the default and never consumed as a value.
  • --user must be a non-empty, non-flag value.
  • The gh-failure error keeps its scope hint only for calls whose arguments passed validation.
  • Tests pin: the control case, banana, 13, 0, 2.5, flag-as-value, and trailing-flag cases.

Distinct from #2493 (billing items never validated — response side; this is the request/CLI side) and from the per-script flag-token filings for other scripts (#3295, #3330, #3333, #3415 — different files). Family: #3352/#3353 argument-contract inventory.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 1, 2026
  2. developing-today commented on Nov 1, 2026

    @developing-today
    Contributor
  3. added
    effort/sSmall: expected under 2 hours of work
    app/aggregatorPackage/app: aggregator (pm-stack in this repo)
    on Nov 1, 2026
  4. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator (lane B, new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b, run 2026-11-01 02:20 CST
    • Found via: filed this run
    • Task: Filed after verifying with the real script on the laptop (stubbed gh): argValue() (collect-github-billing.ts:42-45) + Number() at :72-74 pass NaN, month 13/0, fractional and flag-token values straight into the billing API URL, all exit 0; a trailing value flag silently falls back to the default (probe ~/git/fleet/probe-2026-11-01-laneB-ghbilling/, main f1eac95, script sha256 5f8d8100). Against real gh the 404 is then blamed on the token scope (:58-61). Enqueued as a triage packet for the queue worker.
    • Expectation: effort/s — triage confirms on current main and routes the fix (validate year/month/user locally, usage error before any gh call).
    • Links: packet packets/packet-3419-triage.json (hidden_files of the keep-the-four-repos-healthy goal)
  5. added
    app/pm-stackpm-stack (Pad/Grist) in developing-today/code
    work/assignedQueue worker lifecycle state
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 1, 2026
  6. 21 remaining items

  7. added
    queue/needs-reviewQueue task finished and is awaiting review
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    queue/needs-reviewQueue task finished and is awaiting review
    on Nov 2, 2026
  8. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  9. added a commit that references this issue on Nov 2, 2026
  10. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 2, 2026
  11. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

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

Metadata

Metadata

Assignees

Labels

app/aggregatorPackage/app: aggregator (pm-stack in this repo)app/pm-stackpm-stack (Pad/Grist) in developing-today/codeeffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions