Skip to content

Run comparator cells in recycled worker processes - #7063

Merged
Koudai Aono (koxudaxi) merged 2 commits into
mainfrom
run-comparator-cells-in-recycled-workers
Nov 18, 2026
Merged

Koudai Aono (koxudaxi) merged 2 commits into
mainfrom
run-comparator-cells-in-recycled-workers

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Documentation

    • Updated the comparison-with-release guide to describe how generation runs are handled and isolated.
  • Chores

    • Comparison runs now reuse workers for multiple jobs, with workers replaced after a set number of jobs or when a run requires it.
    • Each run retains its own working directory, logs, warnings, timeout, and memory limit. Import checks continue to use a fresh process.
    • The comparison tool now excludes both watch and debug options.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T00:12:24.197465Z c18ef24 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Walkthrough

Generation now runs in warm workers that handle multiple jobs. Each job has isolated output, working-directory, timeout, warning, and memory-limit handling. Workers are recycled under defined conditions, while import checks run in forked children.

Changes: Warm comparison workers

Layer / File(s) Summary
Worker behavior and comparison options
docs/development-contributing.md, scripts/compare_release.py, scripts/behaviour_diff.py, tests/test_behaviour_diff_script.py
The documentation describes warm workers and their recycling. behaviour_diff.py excludes both --watch and --debug and describes the memory cap as applying to worker data memory. The Windows skip reasons list the required POSIX features.
Isolated job execution
scripts/compare_release.py
Generation runs in the worker under a scope that restores output redirection, working directory, and alarm settings. Memory caps apply to generator execution. Import checks use forked children.
Worker lifecycle and verification
scripts/compare_release.py, tests/test_compare_release_script.py, tests/test_compare_release_script.refs
Runner replaces workers after the recycle limit, process exit, out-of-memory results, or state-changing options. Tests cover worker reuse, import failures, debug runs, recycling, and out-of-memory replacement.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Runner
  participant Worker
  participant Generator
  participant ImportCheckChild
  Runner->>Worker: send generation job
  Worker->>Generator: run generation in job scope
  Worker->>ImportCheckChild: fork for import check
  ImportCheckChild-->>Worker: return import-check status
  Worker-->>Runner: return job result
Loading

Possibly related PRs

Merge Risk: Low · previous review c18ef

Comparator cells now run in recycled warm workers. The remaining concern is that an import check forked from a warm worker could inherit stale modules and miss a failing generated module. No current comparison cell is shown to trigger this, so the risk is low and limited to the release-comparison tooling.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Run comparator cells in recycled worker processes" matches the main change in the changeset. The raw summary shows that scripts/behaviour_diff.py and scripts/compare_release.py now use warm…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Run comparator cells in recycled worker processes" matches the main change in the changeset. The raw summary shows that scripts/behaviour_diff.py and scripts/compare_release.py now use warm, recycled workers that run jobs in-process, replacing a fresh forked child per generation. The title names the primary change (recycled workers) and the subject (comparator cells). It omits details such as memory caps, timeouts, and the test additions, which the title does not need to cover. The PR objectives describe the same intent, so the title is consistent with the stated goal.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c18ef249bc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread scripts/compare_release.py Resolved
@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 94.09%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 53 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 53 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_client_calls[async] 47.6 ms 21.5 ms ×2.2
⚡ test_perf_load_pyproject_config[config-multiple] 294.4 µs 135.5 µs ×2.2
⚡ test_perf_client_calls[sync] 43 ms 19.9 ms ×2.2
⚡ test_perf_load_pyproject_config[mapping-multiple] 290.4 µs 135.2 µs ×2.1
⚡ test_perf_inherited_required_fields[required-base-first] 917.8 ms 429.7 ms ×2.1
⚡ test_perf_load_pyproject_config[mapping-None] 273.4 µs 129 µs ×2.1
⚡ test_perf_load_pyproject_config[config-None] 271.5 µs 129 µs ×2.1
⚡ test_perf_mapped_reference_users 881.8 ms 425.2 ms ×2.1
⚡ test_perf_openapi_large 3.5 s 1.7 s ×2.1
⚡ test_perf_pydantic_field_name_resolution 2.7 ms 1.3 ms ×2.1
⚡ test_perf_scalar_root_collapsed_builtin 230.2 ms 112.3 ms ×2.1
⚡ test_perf_simple_msgspec_unset_field_rendering 597.4 ms 292.1 ms ×2
⚡ test_perf_large_models_pydantic_v2_builtin_double_quotes 1,779 ms 870.2 ms ×2
⚡ test_perf_large_models_pydantic_v2 3.9 s 1.9 s ×2
⚡ test_perf_false_reference_validation 395.9 ms 194.8 ms ×2
⚡ test_perf_multiple_files_input 4.3 s 2.1 s ×2
⚡ test_perf_large_models_dataclass_builtin 1,684.1 ms 833.7 ms ×2
⚡ test_perf_large_models_pydantic_v2_noformat 1,602.1 ms 796.5 ms ×2
⚡ test_perf_large_models_typed_dict[legacy-requiredness] 1,410.1 ms 704.9 ms ×2
⚡ test_perf_unique_items_runtime_scalar_validation 3.1 ms 1.6 ms +99.85%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing run-comparator-cells-in-recycled-workers (8ef5502) with main (965ae81)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1

scripts/compare_release.py-305-305: 1

305-305: Major · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Remove generation-loaded modules from import checks.

If --custom-formatters model loads an importable formatter module, generation leaves model in the worker's sys.modules. This child inherits that entry. _import_modules then imports "model" and returns the formatter instead of executing the generated model.py. A generated file containing raise ImportError("generated failure") therefore passes the import check. Previously, the formatter import stayed in the separate generation child. (raw.githubusercontent.com)

Start import checks from a clean worker, or remove generated module names and their package trees before importing them.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1e18f32 and c18ef24.

Files ignored due to path filters: 3

  • docs/llms-full.txt is excluded by none and included by none
  • tests/data/expected/compare_release_script/a_run_out_of_memory_closes_its_worker.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/compare_release_script/a_worker_runs_each_job_as_a_fresh_process.txt is excluded by !tests/data/**/*.txt and included by none
Files selected for processing: 6

  • docs/development-contributing.md
  • scripts/behaviour_diff.py
  • scripts/compare_release.py
  • tests/test_behaviour_diff_script.py
  • tests/test_compare_release_script.py
  • tests/test_compare_release_script.refs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@koxudaxi
Koudai Aono (koxudaxi) merged commit 7b92a16 into main Nov 18, 2026
116 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the run-comparator-cells-in-recycled-workers branch November 18, 2026 01:22
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR only touches internal developer tooling and its tests and docs: scripts/compare_release.py now runs generations inside warm workers rather than a forked child per run, adds worker recycling, a memory cap context manager and fresh workers for --debug runs; scripts/behaviour_diff.py excludes --debug from its cells and rewords a help string; contributor documentation and test files are updated to match. Nothing under the datamodel_code_generator package source, its CLI options, Python API, templates, defaults, error handling or supported Python versions is changed. The behaviour diff gate lists only both-fail cells, with no accepted or violation cells, so default generated output is unchanged. The changes do not affect users of the released package, so there are no breaking changes.


This analysis was produced by the release draft workflow

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.98.0

This PR is now available in the latest release. See the release notes for details.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant