Skip to content

[codegen] Make regeneration atomic and make --help/check read-only #1099

Description

@bokelley

Summary

scripts/generate_types.py mutates the committed generated tree before it knows generation will succeed, and it has no real CLI parser. Even python scripts/generate_types.py --help starts a full regeneration.

Reproduction

On the current reporting SDK branch:

uv run python scripts/generate_types.py --help

Observed behavior:

  • --help is ignored and generation starts.
  • src/adcp/types/generated_poc/ is deleted before schema flattening/code generation/consolidation completes.
  • An interrupted or failed run can leave hundreds of tracked generated files partially rewritten or missing. In the reporting integration run, the checkout was left with 920 modified files and a large temporary held tree that required manual recovery.

The destructive step is currently near the start of main():

if OUTPUT_DIR.exists():
    shutil.rmtree(OUTPUT_DIR)
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)

Impact

This makes schema release work fragile, makes --help unsafe, and can destroy unrelated in-progress generated changes. A failed dependency, schema reference, collision check, or Ctrl-C leaves the repository in a misleading half-generated state.

Expected

  • Add argparse; --help must be read-only and exit successfully.
  • Generate into a unique temporary directory outside the committed output tree.
  • Run post-processing, consolidation, import smoke tests, and collision checks against that temporary tree.
  • Atomically replace generated_poc/ only after the entire pipeline succeeds.
  • Clean temporary directories on failure, exception, and interruption.
  • Add --check (or equivalent) that generates and reports drift without mutating the checkout.
  • Add a regression test that forces a late generator failure and proves the original output tree is byte-for-byte unchanged.

Discovered while validating adcontextprotocol/adcp#6953 against #1095.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions