Skip to content

feat(cli): add --overwrite/--no-overwrite output safety to all output commands#970

Open
xieofxie wants to merge 3 commits into
mainfrom
hualxie/guard_overwrite
Open

feat(cli): add --overwrite/--no-overwrite output safety to all output commands#970
xieofxie wants to merge 3 commits into
mainfrom
hualxie/guard_overwrite

Conversation

@xieofxie

Copy link
Copy Markdown
Contributor

Summary

Output-producing commands silently overwrote an existing file/dir on a re-run — no warning, no prompt, no opt-in (#561). This adds a shared safe-overwrite control so a re-run can't destroy a previous result.

Flag name

Chose --overwrite/--no-overwrite (default --no-overwrite) over the issue body's --force/-f because it matches the dominant --x/--no-x toggle house style, is precise to the file-overwrite concern, avoids the -f collision (run --file), and won't be confused with the existing --rebuild/cache controls.

Shared helpers (utils/cli.py)

  • overwrite_option()--overwrite/--no-overwrite, default no-overwrite.
  • guard_output(path, overwrite, *, label) — fail-fast existence check. Files block when they exist; directories block only when non-empty (a fresh/empty output dir doesn't false-trigger); a None path (stdout) is a no-op.

Wired into 10 commands

export, optimize, quantize, compile, config, eval, analyze, perf, catalog, run.

  • Guard runs before any mkdir/cleanup/work — notably before the quantizer's destructive stale-sidecar unlink().
  • Covers default-derived output paths (e.g. {stem}_qdq.onnx), not just explicit -o.
  • analyze guards both --output and --optim-config.
  • compile guards the resolved -o file or --output-dir (non-empty).

build intentionally excluded

build already has --rebuild plus incremental resume — without --rebuild, existing stage artifacts are reused, not clobbered (e.g. quantize stage skips when QDQ nodes are present). A non-empty-output-dir guard there would break legitimate incremental rebuilds and overlap confusingly with --rebuild.

Tests

  • guard_output / overwrite_option unit tests (file/dir/empty-dir/overwrite-bypass/None/custom-label).
  • Real-command wiring: catalog (file), quantize (file + default-derived path + verifies quantize_onnx is not called when blocked), compile (empty dir OK, non-empty blocked, --overwrite proceeds).
  • Full tests/unit/commands/ + tests/unit/utils/test_cli.py suite green (916 + new tests).

Fixes #561

… commands

Output-producing commands silently clobbered an existing file/dir on a
re-run, with no warning, prompt, or opt-in. Add a shared safe-overwrite
control (default: refuse and error) so a re-run can't destroy a prior result.

Shared helpers in utils/cli.py:
- overwrite_option(): --overwrite/--no-overwrite toggle, default no-overwrite.
- guard_output(path, overwrite): fail-fast existence check. Files block when
  they exist; directories block only when non-empty (so a fresh/empty output
  dir doesn't false-trigger). None path (stdout) is a no-op.

Wired into export, optimize, quantize, compile, config, eval, analyze, perf,
catalog, run. The guard runs before any mkdir/cleanup/work (e.g. before the
quantizer's destructive stale-sidecar unlink) and covers default-derived
output paths (e.g. {stem}_qdq.onnx), not just explicit -o.

build is intentionally excluded: it already has --rebuild plus incremental
resume (existing stage artifacts are reused, not clobbered), so a non-empty
output-dir guard there would break legitimate incremental rebuilds.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cross-cutting] [P2] No safe-overwrite control on any output-producing command

1 participant