Repository navigation
Description
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
- Any argument other than a single separated
--dir <dir>— unknown flags, misspellings, positionals, the joined--dir=<path>form, and duplicate--dir— is a usage error: exit 2 with a message naming the offending argument, raised before any input file is read or any store directory is created/written. - The documented forms keep working: no arguments (env/default store) and
--dir <dir>, including the existing aggregator(backfill): trailing --dir crashes with a raw TypeError, and a flag-like value (--dir --print) silently writes the rebuilt history into a directory named '--print' #3330 trailing/flag-like value rejection. - Regression coverage extends the existing pinning suite (
pm-stack/aggregator/test/backfill-usage-snapshots-dir-3330.test.tsor a sibling argv suite): the new cases fail pre-fix and pass post-fix, following therejectUnknownArgspattern from aggregator(append-usage-snapshots): unknown or misspelled flags are silently ignored — a typo'd --from-provider-usage silently runs the wrong derivation mode and exits 0 #6961/aggregator(compact-usage-snapshots): unknown or misspelled flags are silently ignored — a typo'd --month 24 with --apply irreversibly compacts months the operator meant to keep raw #6967.
Activity
developing-today commentedon Nov 7, 2026
CODE-2210
dezren39 commentedon Nov 7, 2026
🤖 Agent note · filed
--dirrseeds the rebuilt history into the default store, exit 0. Verified on the laptop at main 0290574 with the real script (probe ~/git/fleet/probe-backfill-argv): control--dir <custom>OK;--dirr <intended>,--bogus, positional,--dir=<joined>all exit 0 writing the default store; duplicate--dirfirst-wins silently.dezren39 commentedon Nov 7, 2026
🤖 Agent note · picked up
Merge pull request #6974 from developing-today/creator-a/6973-backfil…
dezren39 commentedon Nov 7, 2026
🤖 Agent note · done
--dirr <intended>→ exit 2, no default store created; control--dir <custom>→ exit 0. PR CI was still queued (runner backlog) at merge time; the standing merge directive was applied on the strength of the laptop verification. No queue packet (self-solve path).