Skip to content

aggregator(backfill-usage-snapshots): unknown, misspelled, joined, and duplicate arguments are silently ignored — a typo'd --dirr seeds the rebuilt history into the default store and exits 0 #6973

Closed

Description

@dezren39

aggregator(backfill-usage-snapshots): unknown, misspelled, joined, and duplicate arguments are silently ignored — a typo'd --dirr seeds the rebuilt history into the default store and exits 0

Evidence

pm-stack/aggregator/scripts/backfill-usage-snapshots.ts documents exactly one option (line 27: Usage: bun run scripts/backfill-usage-snapshots.ts [--dir <storeDir>]), but argument handling is a single indexOf probe (lines 40–46):

const dirArg = process.argv.indexOf("--dir");
const dirValue = dirArg >= 0 ? process.argv[dirArg + 1] : undefined;
if (dirArg >= 0 && (!dirValue?.trim() || dirValue.trimStart().startsWith("--"))) { /* exit 2 */ }
const storeDir = dirValue ?? process.env.PM_AGG_SNAPSHOTS_DIR ?? join(PKG, "snapshots");

Nothing else in process.argv is ever examined. #3330 guarded the --dir value (trailing / flag-like), but the rest of argv is unvalidated — the residual axis of the strict-argument contract its siblings now enforce (collect-fleet-feed #3352/#3509, append-usage-snapshots #6961, compact-usage-snapshots #6967).

Verified this run on the laptop at main 0290574b3e with the real script, fixture empty quota-view/registry inputs, and PM_AGG_SNAPSHOTS_DIR pointed at a fixture default store (probe: ~/git/fleet/probe-backfill-argv):

invocation observed
--dir <custom> (control) exit 0, appends to <custom>
--dirr <intended> (typo) exit 0, appends to the default store; <intended> is never created
--bogus exit 0, silently ignored, default store written
somefile (positional) exit 0, silently ignored, default store written
--dir=<joined> exit 0, silently ignored, default store written; <joined> never created
--dir <a> --dir <b> exit 0, first value wins silently (indexOf), <b> ignored with no diagnostic

With real inputs (the default QUOTA_VIEW_PATH / registry), the typo case is not a no-op: it appends the full rebuilt history into the live/default snapshot store the operator explicitly tried to redirect — the exact wrong-store write #3330 fixed for the flag-like-value form of the same mistake.

Why it matters

This is a one-shot recovery/seed script: it is run rarely, by hand, precisely when the store is being rebuilt — the moment a wrong-store write is hardest to notice and most expensive to unwind. Every sibling operator script in this package now refuses unknown arguments before any I/O; this one still runs the default mode on any typo.

Acceptance criteria

Activity

  1. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/aggregatorPackage/app: aggregator (pm-stack in this repo)
    app/pm-stackpm-stack (Pad/Grist) in developing-today/code
    effort/xsTrivial: expected under 30 minutes of work
    work/self-assignedAn agent grabbed this item directly, outside the queue
    on Nov 7, 2026
  3. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

    • Agent: new-issue-creator (new-issue-creator-code-a)
    • Session / ID: cron new-issue-creator-code-a run 2026-11-07 17:05 CST
    • Found via: self-assigned during new-issue-creator-code-a run (guarded self-solve, lifecycle protocol §4 — filed this run, trivial, no safety labels, no queue task exists for this issue)
    • Task: implement the strict argv contract for backfill-usage-snapshots (rejectUnknownArgs mirror) plus a regression suite; branch creator-a/6973-backfill-unknown-args, work on the laptop.
    • Expectation: effort/xs — done = targeted tests green on the branch and on merged main, new tests fail pre-fix, PR merged.
    • Links: branch creator-a/6973-backfill-unknown-args (PR to follow)
  5. added a commit that references this issue on Nov 7, 2026
  6. dezren39 commented on Nov 7, 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

No one assigned

    Labels

    app/aggregatorPackage/app: aggregator (pm-stack in this repo)app/pm-stackpm-stack (Pad/Grist) in developing-today/codeeffort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/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