Repository navigation
fix(personas): eval personas discover exits 1 when its model call fails (#1555) - #1583
antonwolfy wants to merge 10 commits into
Conversation
…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>
|
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
To review this commit: re-request review from exai-bot in the Reviewers list. Last review (931332a): no findingsOpen threads from the bot: 0 |
There was a problem hiding this comment.
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
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
…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>
Mutation of changed linesAt 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
Not checked:
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |
… 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>
|
Review points answered at Declined, with the evidence in the reply:
|
napetrov
left a comment
There was a problem hiding this comment.
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.
…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>
@napetrov (#1583 (review)): The review body restates the two threads above (the misclassified |
|
Ready for another look at codecov has not reported on this head yet. |
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>
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
🟡 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.
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.
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>
@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 |
|
Ready for another look at No review of this head yet from exai-bot. |
napetrov
left a comment
There was a problem hiding this comment.
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.


Summary
On
main,dokimi eval personas discoverends in a traceback and exit 5 when its one model call fails. WithOPENAI_API_KEYset and a model call that raiseslitellm.AuthenticationError("invalid api key"), the command printsPersona generation failed: litellm.AuthenticationError: invalid api key, then a traceback ending inlitellm.exceptions.AuthenticationError, and exits 5. A rate limit that outlasts the retries, aRuntimeErrorfrom the call and a reply that is not JSON do the same (exit 5).docs/quickstart.mdgives exit 1 to a runtime failure the command reports (a model call) and keeps 5 for a crash.cmd_personas_discovernow 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-analysisthe analysis file is already saved before the call, so the line ends; no personas file was written; the analysis saved to <path> is keptinstead. A reply that came back but is not a persona document (ValueError, which includesjson.JSONDecodeError: not JSON, nopersonaskey, an emptypersonaslist, a persona missing fields, a persona entry that is not an object such asnull) 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 withUnusableReply, aValueErrorsubclass, and wraps an error raised by the call itself (self.llm.invoke) inModelCallFailed; the command catches those two classes only, so a provider exception that is aValueErrorgets the model-call wording, and a bug in building the prompt or in reading a good reply (aKeyErrorfrom_typed, say) stays exit 5 with its traceback. The command's catch covers only thegenerate_personascall, so the missing-credential exit 2 (#1310),--dry-run, the--max-usdexit 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 ajson.JSONDecodeErroris logged at debug.Closes #1555
Changes
dokimi/commands/personas.py: atryaroundgenerator.generate_personas(...)with twoexceptbranches,UnusableReply(unusable reply) andModelCallFailed(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-analysiswrote one) and raisesSystemExit(EXIT_FAILURE). No other command shares a helper for this:eval_graph.pyandtools.pyword their own messages.dokimi/personas/generator.py:UnusableReply(ValueError), raised for a reply that is not JSON, has nopersonaslist, has an empty one, has a persona entry that is not an object or has a persona short of fields;ModelCallFailed(RuntimeError)wraps only theself.llm.invoke(prompt)call (the original is.error); the outerexcept Exception: logger.error(...); raiseis gone, and the log lines (includingResponse was:) for ajson.JSONDecodeErrorare at debug.tests/test_personas_discover_model_error.py: throughcli.mainwithllm.use_adapter(llm.FakeAdapter(respond=...)), one case each forAuthenticationError,RateLimitError,RuntimeErrorand a reply that is not JSON: exit 1, the stderr line, noTraceback, 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 aValueErrorsubclass from the call and expects the model-call wording; a case raises a multi-lineRuntimeErrorand 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_typedraiseKeyErroron 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 oneError:line.tests/test_personas_generator.py: a case feeds a reply with a dict underpersonasand expectsUnusableReply("'personas' must be a list"); cases feednull, a string, a number and a list as a persona entry and expectUnusableReply; two cases check thatResponse 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 expectsUnusableReply; one case checks that a raisinginvokegivesModelCallFailedand aKeyErrorfrom_typedpropagates unwrapped.Risk
A script that read exit 5 (or a traceback) from a failed
eval personas discovercall 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 aValueErrorsubclass is worded as a failed model call, with the same exit 1.generate_personasnow raisesModelCallFailed(with the provider's exception as.errorand__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 catchValueErrorstill do, sinceUnusableReplyis one. Open PR #1581 rewrites this function; a merge moves the newtryinto its_discover, and its--jsondocument does not cover the new exit 1 yet (the failed call has no document).Testing
On a Linux review host, at
a2e098a6(onmain1bf62d36):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_modulespasses now thatmainhas theruns/resolve.pyimport fix (fix(runs): import InputError from dokimi.files, not dokimi.utils #1609).tests/test_personas_discover_model_error.pyandtests/test_personas_generator.pypass on the merged tree (40 passed withtests/test_personas_discover_output.py).Persona generation failed: boom,line2, then theError:line); now the child prints theError:line only. Mutant: withlogger.error("Persona generation failed: ...")put back before theModelCallFailedraise, the child-process case fails on that three-line stderr; with the empty-list check removed, theemptyCLI case and the generator case fail; with theinvokewrapping removed, 8 cases fail (every model-call case); with_typedalso wrapped inModelCallFailed, the crash case (exit 5) and the generator case fail; withResponse was:logged at error level, the log-level case fails.main's code, the new test file gives4 failed: each case exits 5,assert 5 == 1.2db6a90f, the newValueErrorsubclass case fails: the provider error is worded as an unusable reply.except ModelCallFailedbranch removed, theauth,rate-limitandruntimecases fail; with theexcept UnusableReplybranch removed, thenot-jsoncase fails on the "unusable" wording; withexcept UnusableReplywidened back toexcept ValueError, theValueErrorsubclass case fails; with an extra stderr line printed, theauth,rate-limitandruntimecases fail on the one-line assertion; with the line-break folding removed, the multi-line case fails; with the saved analysis ignored, the--save-analysiscase fails.isinstance(personas, list)check of the generator disabled, the newpersonas-not-a-list case fails ('str' object has no attribute 'keys');generator.pyline 201 is covered by it intests/test_personas_generator.py(16 passed).null, string, number and list entry cases and thenull-personaCLI case fail (AttributeError: 'NoneType' object has no attribute 'keys', worded as a model call failure); with thejson.JSONDecodeErrorcondition replaced byTrue, the case with a reply that has no JSON object fails becauseResponse was:is logged.Open questions
None.
Revert
A plain revert restores the traceback and exit 5 for a failed model call. Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)