Skip to content

refactor(cli): name package exit statuses - #1651

Open
napetrov wants to merge 9 commits into
intel:mainfrom
napetrov:arch/r6-7
Open

napetrov wants to merge 9 commits into
intel:mainfrom
napetrov:arch/r6-7

Conversation

@napetrov

@napetrov napetrov commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Dokimi package commands use named nonzero statuses from dokimi/exit_codes.py. EXIT_OF_ERROR uses the same names. The touched container entry points define statuses locally so they can run with the standard library alone.

 dokimi/
-  sys.exit(2)                      # cli.py, ingest.py, evaluate.py
-  sys.exit(EXIT_USAGE if refusals else 1)   # commands/benchmark.py
+  sys.exit(EXIT_USAGE)
+  sys.exit(EXIT_USAGE if refusals else EXIT_FAILURE)
-EXIT_OF_ERROR = {"input": 2, "infra": 5, ...}
+EXIT_OF_ERROR = {"input": EXIT_USAGE, "infra": EXIT_INFRA, ...}
+tests/test_exit_codes_named.py    # AST guard for named exit statuses

Evidence

  • The review examples exposed gaps for qualified and aliased exits, argparse status=, and local entry-point returns. The guard reports the offending lines for each case. It also follows assigned literal and conditional statuses while respecting scope and named rebindings.
  • The full suite passed 36,017 tests with 28 skips and 96% changed-line coverage. All 20 repeat seeds passed. An AST comparison confirmed the numeric status for each of the seven converted return values across six entry points.

Merge Danger

Door: two-way. Revert restores the literals.

No value changes, so consumers and scripts see the same exit codes.

Blast Radius: none (CLI exit names only; values identical).

🤖 Generated with Claude Code

…om the names

The exit codes were a table in exit_codes.py, but 79 exits in the package
still ended the process with a literal number: sys.exit(2), raise
SystemExit(3), a conditional with a 1 arm, parser.exit(2, ...), and a
code=2 keyword to the save and write helpers that exit with it. cli_output
kept its own numbers. A literal reads the same to Python, but only the name
says what the 2 means, and a renumbering of the table would not reach it.

Each exit now names its constant (EXIT_USAGE, EXIT_FAILURE,
EXIT_INCONCLUSIVE, EXIT_INVALID, EXIT_INFRA), and cli_output.EXIT_OF_ERROR
is built from those names. The values are unchanged: an AST comparison of
each changed module against intel/main, with the names folded to their
values, is identical.

tests/test_exit_codes_named.py fails on main (79 literal exits, a literal
EXIT_OF_ERROR) and passes here.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov
napetrov requested a review from a team as a code owner December 5, 2026 08:48
Copilot AI balanced review requested due to automatic review settings December 5, 2026 08:48

Copilot AI 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.

🟡 Changes recommended

The package-wide guard misses qualified and aliased exit calls, keyword status arguments, and literal codes returned by local entry points, allowing unnamed nonzero exit codes to pass.

3 open issues
What changed in this PR

3 new findings.

This PR centralizes exit-code references across dokimi’s CLI while preserving their numeric values.

Changes:

  • Replaces literal exit codes with named constants.
  • Builds EXIT_OF_ERROR from those constants.
  • Adds AST guards and documents the naming convention.
File Description
dokimi/​tests/​test_exit_codes_named.py Adds exit-code naming guards.
dokimi/​dokimi/​commands/​tools.py Names artifact rejection exits.
dokimi/​dokimi/​commands/​tasks.py Names task failure exits.
dokimi/​dokimi/​commands/​tasks_generate.py Names generation failure exits.
dokimi/​dokimi/​commands/​run.py Names gate failure exits.
dokimi/​dokimi/​commands/​report.py Names empty-report failure exit.
dokimi/​dokimi/​commands/​repo.py Names repository command exits.
dokimi/​dokimi/​commands/​repo_skill_reach.py Names skill-reach failure exits.
dokimi/​dokimi/​commands/​repo_run.py Names execution and task-check exits.
dokimi/​dokimi/​commands/​repo_reach.py Names reach failure exits.
dokimi/​dokimi/​commands/​redteam.py Names failed-verdict exit.
dokimi/​dokimi/​commands/​questions.py Names question artifact failures.
dokimi/​dokimi/​commands/​orchestrate.py Names pipeline failure exit.
dokimi/​dokimi/​commands/​memory.py Names lint failure exit.
dokimi/​dokimi/​commands/​llms_txt.py Names documentation check failure.
dokimi/​dokimi/​commands/​leak.py Names failed-verdict exit.
dokimi/​dokimi/​commands/​judge_reliability.py Names output and strict-gate exits.
dokimi/​dokimi/​commands/​ingest.py Names ingestion error exits.
dokimi/​dokimi/​commands/​headroom.py Names artifact rejection exit.
dokimi/​dokimi/​commands/​evaluate.py Names evaluation error exits.
dokimi/​dokimi/​commands/​delivery.py Names failure and inconclusive exits.
dokimi/​dokimi/​commands/​context.py Names context check failures.
dokimi/​dokimi/​commands/​catalog.py Names catalog failure exits.
dokimi/​dokimi/​commands/​catalog_eval.py Names catalog evaluation failure.
dokimi/​dokimi/​commands/​benchmark.py Names benchmark failure exits.
dokimi/​dokimi/​commands/​baseline_regression.py Names regression failure exit.
dokimi/​dokimi/​commands/​_shared.py Names shared helper exits.
dokimi/​dokimi/​commands/​_output.py Names artifact rejection exit.
dokimi/​dokimi/​cli.py Names usage error exits.
dokimi/​dokimi/​cli_output.py Uses constants in the error table.
dokimi/​docs/​quickstart.md Documents exit-code constants.
dokimi/​changelog.d/​20261204_120000_napetrov_arch-r6-7.md Records the naming refactor.

Review effort: Balanced

Comment thread dokimi/tests/test_exit_codes_named.py Resolved
Comment thread dokimi/tests/test_exit_codes_named.py Resolved
Comment thread dokimi/tests/test_exit_codes_named.py Resolved
@exai-bot

exai-bot commented Dec 5, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 39 selected item(s).

CI at 0d89878: 26 passing, 4 skipped.

Test notes (2)
  • dokimi/dokimi/config_check.py:65: With return EXIT_FAILURE changed to return None, the tests still pass: dokimi/tests/test_exit_codes_named.py, dokimi/tests/test_import_architecture.py. If this condition matters, a test should pin it.
  • dokimi/dokimi/harnesses/swebench_grade.py:231: With return 0 if report["resolved"] else EXIT_UNRESOLVED changed to return None, the tests still pass: dokimi/tests/test_exit_codes_named.py, dokimi/tests/test_import_architecture.py. If this condition matters, a test should pin it.
Review details
  • Commit reviewed: 0d89878 against merge base 60948d0
  • Coverage: 39 files in 6 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 314k tokens (155k from cache), 36s
  • Tool calls: 34 (28 file_read, 4 code_search, 1 ci_status, 1 local_check_results)
  • Exit-code infrastructure, architecture checks, and documentation: 9 files
  • Evaluation, benchmarking, and reporting command exit codes: 10 files
  • Repository commands and grading support exit codes: 7 files
  • Knowledge, catalog, and content command exit codes: 6 files
  • Task generation, orchestration, and delivery exit codes: 4 files
  • Configuration and schema validation exit codes: 3 files

@codecov-commenter

codecov-commenter commented Dec 5, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 96.46018% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.44%. Comparing base (60948d0) to head (0d89878).

Files with missing lines Patch % Lines
dokimi/dokimi/commands/delivery.py 66.66% 1 Missing ⚠️
dokimi/dokimi/commands/ingest.py 66.66% 1 Missing ⚠️
dokimi/dokimi/commands/memory.py 50.00% 1 Missing ⚠️
dokimi/dokimi/commands/tasks_generate.py 80.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1651      +/-   ##
==========================================
- Coverage   96.45%   96.44%   -0.01%     
==========================================
  Files         575      575              
  Lines       75872    75892      +20     
  Branches    13076    13076              
==========================================
+ Hits        73179    73192      +13     
- Misses       1644     1646       +2     
- Partials     1049     1054       +5     
Files with missing lines Coverage Δ
dokimi/dokimi/cli_output.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/_output.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/_shared.py 96.36% <100.00%> (+0.02%) ⬆️
dokimi/dokimi/commands/baseline_regression.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/benchmark.py 96.80% <100.00%> (ø)
dokimi/dokimi/commands/catalog.py 98.69% <100.00%> (+<0.01%) ⬆️
dokimi/dokimi/commands/catalog_eval.py 98.97% <100.00%> (+<0.01%) ⬆️
dokimi/dokimi/commands/context.py 97.89% <100.00%> (ø)
dokimi/dokimi/commands/evaluate.py 97.61% <100.00%> (ø)
dokimi/dokimi/commands/headroom.py 98.91% <100.00%> (+<0.01%) ⬆️
... and 22 more

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Not a clean result: some breaks or tests were left out

At 0d89878: 8 caught · 0 missed

This is not a clean result:

  • 300 candidate test files were not run
  • 88 changed lines were not mutated

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g87AEAbe
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g87AEAbz
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g87AEAcA
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@napetrov, could you fix the problem I found and the small thing I've marked fix before merge (in the line comments)? Then push and I'll take another look.

What I checked on 5409056:

  • When I changed the code on purpose, the tests still passed for 12 of 12 changes, and no test pins these down yet (non-blocking): dokimi/dokimi/cli.py:470 (the handled error is raised again), dokimi/dokimi/commands/_output.py:50 (the handled error is raised again), dokimi/dokimi/commands/_shared.py:185 (the handled error is raised again) and 9 more.
  • The 65 changed tests pass, and fail on main as expected.
  • The full test suite passes with main merged in (37,307 tests), apart from failures main has too.
  • It merges cleanly onto main.

Comment thread dokimi/tests/test_exit_codes_named.py Resolved
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>

# Conflicts:
#	dokimi/dokimi/commands/tools.py
Thread: PRRT_kwDOVBg7g87AM0ER
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g87AM0ET
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Preserve the guard’s allowance for the conventional success status.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov

napetrov commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Re: review by vchamarthi

Could you fix the problem I found and the small thing I’ve marked fix before merge?
Both inline findings are fixed. Thanks for checking the exception paths. The three named mutations re-raise errors in existing handlers. I kept this refactor focused on status naming.

@napetrov

napetrov commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

The assignment regression is fixed in 44ffb3894. The tests cover both reported inputs and verify lexical shadowing and named status rebindings. The changelog scope is corrected in 23f825b59. The branch includes current main, including the structured JSON path for tools preference.

@napetrov napetrov changed the title refactor(cli): name every exit code from exit_codes; EXIT_OF_ERROR from the names refactor(cli): name package exit statuses Dec 6, 2026

This branch has not been deployed

No deployments
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.

5 participants