Skip to content

fix(personas): eval personas discover exits 1 when its model call fails (#1555) - #1583

Open
antonwolfy wants to merge 10 commits into
intel:mainfrom
antonwolfy:fix/personas-discover-model-error
Open

antonwolfy wants to merge 10 commits into
intel:mainfrom
antonwolfy:fix/personas-discover-model-error

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On main, dokimi eval personas discover ends in a traceback and exit 5 when its one model call fails. With OPENAI_API_KEY set and a model call that raises litellm.AuthenticationError("invalid api key"), the command prints Persona generation failed: litellm.AuthenticationError: invalid api key, then a traceback ending in litellm.exceptions.AuthenticationError, and exits 5. A rate limit that outlasts the retries, a RuntimeError from the call and a reply that is not JSON do the same (exit 5). docs/quickstart.md gives exit 1 to a runtime failure the command reports (a model call) and keeps 5 for a crash.

cmd_personas_discover now catches the failure of that one call and prints one stderr line, Error: persona generation failed (model call to <model>): <exception type>: <message>; nothing was written, then exits 1 with no traceback. The error's line breaks are folded to spaces, so the line stays one record. Under --repo --save-analysis the analysis file is already saved before the call, so the line ends ; no personas file was written; the analysis saved to <path> is kept instead. A reply that came back but is not a persona document (ValueError, which includes json.JSONDecodeError: not JSON, no personas key, an empty personas list, a persona missing fields, a persona entry that is not an object such as null) is also a failed model call: it exits 1 with its own wording, (the reply of the model call to <model> was unusable). The generator marks such a reply with UnusableReply, a ValueError subclass, and wraps an error raised by the call itself (self.llm.invoke) in ModelCallFailed; the command catches those two classes only, so a provider exception that is a ValueError gets the model-call wording, and a bug in building the prompt or in reading a good reply (a KeyError from _typed, say) stays exit 5 with its traceback. The command's catch covers only the generate_personas call, so the missing-credential exit 2 (#1310), --dry-run, the --max-usd exit 3 and the write failures keep their codes. The generator no longer logs an error line of its own before the command's line (in a real run, with no logging handler, Python's last-resort handler printed it to stderr, so stderr was more than one line); the raw reply of a json.JSONDecodeError is logged at debug.

Closes #1555

Changes

  • dokimi/commands/personas.py: a try around generator.generate_personas(...) with two except branches, UnusableReply (unusable reply) and ModelCallFailed (the provider call raised), each calling _fail_generation, which prints one stderr line (line breaks of the error folded to spaces; names the saved analysis when --save-analysis wrote one) and raises SystemExit(EXIT_FAILURE). No other command shares a helper for this: eval_graph.py and tools.py word their own messages.
  • dokimi/personas/generator.py: UnusableReply(ValueError), raised for a reply that is not JSON, has no personas list, has an empty one, has a persona entry that is not an object or has a persona short of fields; ModelCallFailed(RuntimeError) wraps only the self.llm.invoke(prompt) call (the original is .error); the outer except Exception: logger.error(...); raise is gone, and the log lines (including Response was:) for a json.JSONDecodeError are at debug.
  • tests/test_personas_discover_model_error.py: through cli.main with llm.use_adapter(llm.FakeAdapter(respond=...)), one case each for AuthenticationError, RateLimitError, RuntimeError and a reply that is not JSON: exit 1, the stderr line, no Traceback, no output file; each case asserts the captured stderr is exactly one line, and a case replies {"personas": [null]} and expects the unusable-reply wording; a further case raises a ValueError subclass from the call and expects the model-call wording; a case raises a multi-line RuntimeError and expects one stderr line; a case with --repo --save-analysis (a stub analyzer) expects the analysis file kept, no personas file and the line naming the kept analysis; a case replies {"personas": []} and expects the unusable-reply wording; a case makes _typed raise KeyError on a good reply and expects exit 5 (a crash, not a failed call); a case runs the command in a real child process and expects stderr to be exactly the one Error: line.
  • tests/test_personas_generator.py: a case feeds a reply with a dict under personas and expects UnusableReply("'personas' must be a list"); cases feed null, a string, a number and a list as a persona entry and expect UnusableReply; two cases check that Response was: is logged (at debug, with no record at error level) for a JSON syntax error and not for another unusable reply; one case feeds {"personas": []} and expects UnusableReply; one case checks that a raising invoke gives ModelCallFailed and a KeyError from _typed propagates unwrapped.
  • Changelog fragment (Fixed).

Risk

A script that read exit 5 (or a traceback) from a failed eval personas discover call now gets exit 1 and one line on stderr. Output on success, --dry-run, the cap refusal and write failures is unchanged. A reply of {"personas": []} no longer writes an empty personas file and exits 0: it exits 1. A provider exception that is a ValueError subclass is worded as a failed model call, with the same exit 1. generate_personas now raises ModelCallFailed (with the provider's exception as .error and __cause__) where it raised the provider's exception itself; its other caller, the orchestrator pipeline (orchestrator/pipeline.py), does not catch by type, and callers that catch ValueError still do, since UnusableReply is one. Open PR #1581 rewrites this function; a merge moves the new try into its _discover, and its --json document does not cover the new exit 1 yet (the failed call has no document).

Testing

On a Linux review host, at a2e098a6 (on main 1bf62d36):

  • make ci-local: 0 failed, 38 passed, 16 skipped (steps needing other Pythons, micromamba, semgrep, fuzzing, deploy and matrix jobs of other workflows). 35592 tests passed, 28 skipped. test_package_uses_the_new_modules passes now that main has the runs/resolve.py import fix (fix(runs): import InputError from dokimi.files, not dokimi.utils #1609).
  • tests/test_personas_discover_model_error.py and tests/test_personas_generator.py pass on the merged tree (40 passed with tests/test_personas_discover_output.py).
  • In a real child process, before this change, a failed call printed three stderr lines (Persona generation failed: boom, line2, then the Error: line); now the child prints the Error: line only. Mutant: with logger.error("Persona generation failed: ...") put back before the ModelCallFailed raise, the child-process case fails on that three-line stderr; with the empty-list check removed, the empty CLI case and the generator case fail; with the invoke wrapping removed, 8 cases fail (every model-call case); with _typed also wrapped in ModelCallFailed, the crash case (exit 5) and the generator case fail; with Response was: logged at error level, the log-level case fails.
  • On main's code, the new test file gives 4 failed: each case exits 5, assert 5 == 1.
  • On the previous head 2db6a90f, the new ValueError subclass case fails: the provider error is worded as an unusable reply.
  • Mutants: with the except ModelCallFailed branch removed, the auth, rate-limit and runtime cases fail; with the except UnusableReply branch removed, the not-json case fails on the "unusable" wording; with except UnusableReply widened back to except ValueError, the ValueError subclass case fails; with an extra stderr line printed, the auth, rate-limit and runtime cases fail on the one-line assertion; with the line-break folding removed, the multi-line case fails; with the saved analysis ignored, the --save-analysis case fails.
  • With the isinstance(personas, list) check of the generator disabled, the new personas-not-a-list case fails ('str' object has no attribute 'keys'); generator.py line 201 is covered by it in tests/test_personas_generator.py (16 passed).
  • With the persona-is-an-object check removed, the null, string, number and list entry cases and the null-persona CLI case fail (AttributeError: 'NoneType' object has no attribute 'keys', worded as a model call failure); with the json.JSONDecodeError condition replaced by True, the case with a reply that has no JSON object fails because Response was: is logged.
  • Not run: the matrix legs on Python 3.11, 3.12 and 3.14.

Open questions

None.

Revert

A plain revert restores the traceback and exit 5 for a failed model call. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…ls (intel#1555)

A provider error (an invalid key, a rate limit that outlasts the retries, any exception the call raises) from the one generation call reached cli.main's crash handler: the generator logged it and re-raised, so the command ended in a traceback and exit 5, although docs/quickstart.md gives a failed model call exit 1.

cmd_personas_discover now catches the failure of that call and prints one stderr line, `Error: persona generation failed (model call to <model>): <type>: <message>; nothing was written`, then exits 1 with no traceback. A reply that is not a persona document (not JSON, missing `personas`, a persona missing fields: ValueError) gets its own wording, "the reply of the model call to <model> was unusable", and also exits 1. Nothing is written when the call fails. The success path, --dry-run, the --max-usd refusal, the missing-credential exit and the write failures are unchanged.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner December 3, 2026 11:03
@antonwolfy antonwolfy self-assigned this Dec 3, 2026
Copilot AI balanced review requested due to automatic review settings December 3, 2026 11:03
@exai-bot

exai-bot commented Dec 3, 2026 •

Copy link
Copy Markdown

OpenCodeReview: Commit a2e098a was not reviewed. This PR has reached its review limit (6 reviews).

CI at `a2e098a`: 3 still running, 12 passing, 3 skipped
Check Status
Linux Python 3.14 still running
Static checks (ruff, schema, zizmor, licenses, pre-commit, bandit, secrets, changelog, schema com... still running
Windows smoke test (py3.13) still running

To review this commit: re-request review from exai-bot in the Reviewers list.

Last review (931332a): no findings

Open threads from the bot: 0

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Adjusts eval personas discover failure handling so a single model-call failure is treated as a normal command failure (exit 1, one stderr line) rather than a crash (traceback, exit 5), and adds regression tests + changelog note.

Changes:

  • Catch generate_personas(...) exceptions and exit 1 with a single stderr error line (no traceback).
  • Add CLI-level tests covering several provider/runtime failures and unusable (non-JSON) model replies.
  • Add a changelog “Fixed” entry documenting the new behavior/contract.
File Description
dokimi/​dokimi/​commands/​personas.py Wrap persona generation in targeted exception handling and normalize exit behavior to exit 1 with a single error line.
dokimi/​tests/​test_personas_discover_model_error.py Adds regression tests ensuring exit code 1, no traceback, and no output file on model-call failure.
dokimi/​changelog.d/​20261203_120000_personas-discover-model-error.md Documents the behavior change in the changelog.

Review effort: Lite

Comment thread dokimi/dokimi/commands/personas.py Resolved
@codecov-commenter

codecov-commenter commented Dec 3, 2026 •

Copy link
Copy Markdown

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

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.48%. Comparing base (1bf62d3) to head (a2e098a).
⚠️ Report is 2 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1583   +/-   ##
=======================================
  Coverage   96.47%   96.48%           
=======================================
  Files         564      564           
  Lines       74672    74695   +23     
  Branches    12890    12893    +3     
=======================================
+ Hits        72042    72067   +25     
+ Misses       1610     1606    -4     
- Partials     1020     1022    +2     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/personas.py 100.00% <100.00%> (ø)
dokimi/dokimi/personas/generator.py 98.13% <100.00%> (+5.34%) ⬆️

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

…as discover

Settles the review point that the `except ValueError` of `cmd_personas_discover` also catches a provider exception that subclasses `ValueError`, and words it as an unusable reply.

`PersonaGenerator.generate_personas` now raises `UnusableReply` (a `ValueError` subclass, so existing callers and tests still match) for a reply that is not JSON, has no `personas` list, or has a persona short of fields; the command catches that class and every other exception is a failed model call.

The test pins one-line stderr for each case and adds a provider `ValueError` case.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 6 of 31 small breaks of the lines this PR changes

At a2e098a: 25 caught · 6 missed

Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Where Operator Change no test notices Tests reaching the line
dokimi/dokimi/personas/generator.py:99 delete-statement super().__init__(str(error)) → pass 7
dokimi/dokimi/personas/generator.py:201 bump-int 500 → 501 1
dokimi/dokimi/personas/generator.py:216 drop-element {"id", "name", "description", "skill_level", "concerns", "typical_questions"} → {"id", "name", "description", "concerns", "typical_questions"} 19
dokimi/dokimi/commands/personas.py:85 take-branch f"no personas file was written; the analysis saved to {saved_analysis} is kept" → (f"no personas file was written; the analysis saved to {saved_analysis} is kept" 9
dokimi/dokimi/personas/generator.py:216 drop-element {"id", "name", "description", "skill_level", "concerns", "typical_questions"} → {"id", "name", "description", "skill_level", "concerns"} 19
dokimi/dokimi/personas/generator.py:216 drop-element {"id", "name", "description", "skill_level", "concerns", "typical_questions"} → {"name", "description", "skill_level", "concerns", "typical_questions"} 19

Not checked:

  • 11 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.

Comment thread dokimi/dokimi/commands/personas.py Resolved
Comment thread dokimi/dokimi/commands/personas.py Resolved
… names a saved analysis

Settles the two review threads on eval personas discover. The stderr line folds the error's line breaks to spaces, so a multi-line provider message stays one record. Under --repo --save-analysis the analysis file is written before the model call, so the line now says no personas file was written and names the kept analysis instead of claiming nothing was written.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…eply

Settles the codecov point: the `'personas' must be a list` branch of PersonaGenerator.generate_personas had no test. The new test feeds a reply with a dict under `personas` and checks it raises UnusableReply with that message.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

Review points answered at 0817c2c; CI is green.

Declined, with the evidence in the reply:

@napetrov napetrov 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.

Change class: CONTRACT (head 0817c2c)

  • Contract: changed. errors dokimi/dokimi/commands/personas.py:89; errors dokimi/dokimi/personas/generator.py:91
  • Responsibility: none
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The reply diagnostics contradict the PR description (C2 and C4).

Ran 23 focused tests with current main. Stub replies reproduced the misclassified null persona and the expanded raw reply logging.

Comment thread dokimi/dokimi/personas/generator.py Resolved
Comment thread dokimi/dokimi/personas/generator.py Resolved
…eply, and only a JSON syntax error logs the reply

Settles the two blocking threads of the review. A reply such as `{"personas": [null]}` raised AttributeError at `persona.keys()` and was worded as a failed provider call; `generate_personas` now checks that each entry is an object and raises `UnusableReply`, so the command exits 1 with the unusable-reply wording, as for an entry missing fields. The `Response was:` log lines were reached by every `ValueError` the extractor raises since the handler caught `ValueError`; they are now written only for a `json.JSONDecodeError`, the one error that logged the reply before this PR.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) ### Change class: CONTRACT (head 0817c2c)

@napetrov (#1583 (review)): The review body restates the two threads above (the misclassified null persona and the widened reply logging); both are fixed in a0feabc and the description now matches the code.

@antonwolfy

Copy link
Copy Markdown
Contributor Author

Ready for another look at a0feabc; 1 checks still pending (Windows smoke test (py3.13)); failed: Test Linux Python 3.14, Test Linux Wheels Python 3.14, Tests (py3.14).

codecov has not reported on this head yet.
Test Linux Python 3.14 fails the same tests on main (its latest run, at a46a0d6): not this PR's change.
Test Linux Wheels Python 3.14 fails the same tests on main (its latest run, at a46a0d6): not this PR's change.

@antonwolfy
antonwolfy requested a review from napetrov December 3, 2026 17:30
Conflict in dokimi/dokimi/commands/personas.py (the import block): main moved InputError and read_json_input from dokimi.utils to dokimi.files, and this branch added UnusableReply to the generator import. Kept both: the import from dokimi.files and the import of UnusableReply.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from exai-bot December 4, 2026 10:27
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy antonwolfy added the testing-strategy Part of #1595: checks for the bug classes behind our fix series, their sweeps and research label Dec 4, 2026

@vlad-perevezentsev vlad-perevezentsev 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.

🟡 Changes needed · reviewed ab8a6d3

To fix: in a real run, stderr still gets the generator's own log line before the Error: line (line comments); the other points there are smaller.

⚠️ GitHub CI on ab8a6d3: 19 jobs pass, 3 test jobs fail on test_import_architecture from the base (runs/resolve.py, fixed on main by #1609) · ✅ on the merge with main: the persona tests and test_import_architecture pass (86) · ✅ the new tests fail on the base (exit 5 there)

A failed call or an unusable reply now exits 1 with no traceback and no personas file written.

Comment thread dokimi/dokimi/personas/generator.py Resolved
Comment thread dokimi/dokimi/personas/generator.py Resolved
Comment thread dokimi/dokimi/commands/personas.py Resolved
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…n empty reply and wraps only the model call

Settles the review points on intel#1583 about the generator's own log line, an empty `personas` list, and the breadth of the `except Exception`.

- The generator no longer wraps its whole body in `except Exception: logger.error(...); raise`, so a real run (no logging handler, Python's last-resort handler writes to stderr) prints one `Error:` line. The raw reply of a JSON syntax error is logged at debug.
- `{"personas": []}` is an `UnusableReply` ("'personas' is empty"), exit 1, no file written.
- Only `self.llm.invoke(prompt)` is wrapped, in the new `ModelCallFailed` (the original is `.error`); the command catches `ModelCallFailed` and `UnusableReply` only, so a bug in the prompt or in reading a good reply stays exit 5 with its traceback.
- Tests: an `empty` case, a crash case, a subprocess case that checks stderr is one line, and generator cases for the empty list and the wrapping.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) 🟡 Changes needed · reviewed ab8a6d3

@vlad-perevezentsev (#1583 (review)): The review's points are the three threads above (4800874991, 4800875004, 4800875013), all fixed in a2e098a. The three failing test jobs were test_import_architecture through runs/resolve.py, fixed on main by #1609. This tree has that fix, and make ci-local passes.

@antonwolfy

Copy link
Copy Markdown
Contributor Author

Ready for another look at a2e098a; CI is green.

No review of this head yet from exai-bot.

@napetrov napetrov 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.

Change class: CONTRACT (head a2e098a)

  • Contract: changed. errors dokimi/dokimi/commands/personas.py:89; errors dokimi/dokimi/personas/generator.py:91
  • Responsibility: none
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

No new blocking findings on a2e098a6.

Reviewed the diff, edge cases and prior threads. Focused tests: 35 passed on head and 15 passed on merge base. The full local suite was outside coverage.

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

testing-strategy Part of #1595: checks for the bug classes behind our fix series, their sweeps and research

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eval personas discover: a provider error with a key set ends in a traceback and exit 5, not exit 1

6 participants