Repository navigation
Description
Summary
When a generation soft-fails — it completes and returns a thunk rather than raising, but something went wrong — there is currently no public way for a caller to discover that. The only signal is buried in a private attribute, so a caller iterating over results cannot tell a genuine empty completion apart from a failure without reaching into framework internals.
This surfaced in #1161 (follow-up to #599). The Ollama backend's generate_from_raw now soft-fails on an empty done-response: the affected slot gets a ModelOutputThunk with value="", and the RuntimeError is stashed at thunk._generate_log.extra["error"] (with the raw response at ["empty_response"]). Soft-failing rather than raising is deliberate — it preserves sibling results in the same asyncio.gather batch, which a hard raise would discard. But the only way to detect the failure is to read a private attribute.
Why this is a problem
- No public accessor.
_generate_logis private;functional.pyeven asserts it is non-Noneand treats it as internal plumbing. There is no public property exposing it, unlikevalue,generation, orcancelled. - No precedent for this error channel. The
extra["error"]/extra["empty_response"]keys are unique togenerate_from_raw— only the Ollama backend writes them, and only its unit test reads them. No other backend or framework code uses this convention. - It is silent. A caller iterating
resultsseesvalue="", indistinguishable from a legitimately empty completion, unless they happen to know to inspect a private dict key.
Existing patterns this could align with
The codebase already has a closer-fitting mechanism: ModelOutputThunk.cancel_generation(error=...) sets value="", records the error, and exposes a public cancelled property whose own docstring says consumers can use it to "distinguish a genuine result from one cut short". The soft-fail path reimplements a worse version of this without the public surface.
Possible directions (for discussion)
- Surface the soft-fail through the existing
cancelledchannel (mark the empty thunk cancelled, carrying the error), or - Add a public
error/exceptionproperty onModelOutputThunk, or - Reconsider whether
generate_from_rawshould soft-fail at all vs. surfacing per-action errors some other way that doesn't fail the whole batch.
Marking needs-design — the right shape touches the public thunk API and should be consistent across backends, not just Ollama.
Follow-up to #1161. Original empty-response context in #599.
Activity
ajbozarth commentedon Jun 3, 2026
Surfaced this issue during #909 design research. Folded into the #909 design proposal (Discussion #1197) as Area 5 —
mot.generate_logpublic property +mot.errorchannel addresses the same root concern.If Area 5 is approved as written, this issue closes as part of that work.
Comments / pushback on that direction welcome on the Area 5 thread of #1197.
ajbozarth commentedon Jun 5, 2026
Area 5 design (per #1197)
@jakelorocco confirmed Option A in the Area 5 thread — keep this issue's scope narrow;
GenerateLogdeprecation becomes a separate future work item.This issue (folded in as #909 Area 5) is now the sub-issue tracking the work.
Design
Two changes to the public
ModelOutputThunksurface:1. Promote
_generate_logto a public propertymot.generate_logNo shape change to
GenerateLog; just expose the existing private attr officially. The attribute stays as_generate_logunderneath; backends and sampling code keep writing through that name (internal); external consumers readmot.generate_log. Returned by reference — internal sampling already mutates_generate_log.is_final_result, and a frozen view would be surprising for external readers without solving a real problem (OQ6 resolution).2. Add a public
mot.error: Exception | NonepropertyBacked by an internal
_errorattribute on the MOT. Backends that soft-fail set it.cancel_generation(error=...)already records its error at the OTel / hook layer; this gives the same information a public read path on the MOT itself.error is not Nonebecomes the canonical "did this thunk soft-fail" check, sibling tomot.cancelled, not unified with it (OQ5 resolution):cancelledmeans a consumer chose to stop (deliberate, by some reader)errormeans the backend produced an unusable result without raising (involuntary, by the inference layer)Conflating loses information callers need to decide what to do next.
The Ollama soft-fail path migrates from
thunk._generate_log.extra["error"]tothunk.error. Theextra["empty_response"]raw key is dropped — if the raw response is wanted, #909 Area 1 (#1215)'smot.raw.responsecarries it.Caller-facing result
This is the shape the original issue asked for.
Migration
Single PR:
mot.error(private_errorattr + public read property + setter on private name).mot.generate_logpublic read property aliasing_generate_log.OllamaBackend.generate_from_raw's soft-fail path:thunk._error = empty_errinstead of stashing in_generate_log.extra.docs/integrations/openai.mdand any other public docs that reference_generate_log._generate_logkeeps working as a name internally (no rename); it's the read path that gains a public property.Out of scope (future work)
GenerateLogdeprecation. Field-by-field audit (from the #1197 OQ6 thread) shows mostGenerateLogfields are duplicated on the MOT or migrating in #909:GenerateLogfieldmodel_optionsmot._model_options(→mot._call.model_optionsafter #909 Area 3, #1216)model_outputmot.raw.response(#909 Area 1, #1215)actionmot._action(→mot._call.actionafter #909 Area 3, #1216)resultbackendmot.generation.provider+mot.generation.modeldategenerationpromptis_final_resultextramot.errorA future deprecation issue would propose:
mot.generation.prompt,mot.generation.timestamp, flatmot._is_final_result, deprecateGenerateLog+ the publicm.validate(generate_logs=...)parameter +_generate_logtogether, dropextraentirely. Touches every backend'spost_processing, sampling'sis_final_resultplumbing, and the public validate API — bigger than Area 5 should swallow.To be filed as a follow-up issue once the post-#909 dust settles.
Acceptance
mot.error: Exception | Nonepublic property; backed by_errorattributemot.generate_log: GenerateLog | Nonepublic property; aliases_generate_logOllamaBackend.generate_from_rawsoft-fail path usesthunk._error = ...instead of_generate_log.extra["error"]_generate_log.extra["empty_response"]no longer writtenr.error is not Noneandr.cancelled is Falser.cancelled is Trueandr.error is None(separation preserved)result.generate_log/result.errorrather than the underscore namesSequencing
Independent of #909 Area 1 (#1215), Area 3 (#1216), Area 4 (#1217) and of #1181. Smallest of the #909-related changes; recommended to land second after #1181.
ajbozarth commentedon Jun 19, 2026
Refresh (2026-06-19)
Two updates before this gets picked up.
Migration location moved post-#1264. The Ollama soft-fail path now lives in
_generate_from_raw(the publicgenerate_from_rawis a@finalwrapper since #1264). Current writes to migrate are atmellea/backends/ollama.py:611-613:Mechanically the same migration the issue describes; just the function name changes (
generate_from_raw→_generate_from_raw).Path drift.
mellea/stdlib/base.py→mellea/core/base.py.No design changes — the
mot.error+mot.generate_logshape still matches the current MOT.feat(stdlib): public error and generate_log surface on ModelOutputThu…