Skip to content

Soft-fail errors on ModelOutputThunk are only reachable via a private attribute #1191

Closed

Description

@planetf1

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_log is private; functional.py even asserts it is non-None and treats it as internal plumbing. There is no public property exposing it, unlike value, generation, or cancelled.
  • No precedent for this error channel. The extra["error"] / extra["empty_response"] keys are unique to generate_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 results sees value="", 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 cancelled channel (mark the empty thunk cancelled, carrying the error), or
  • Add a public error / exception property on ModelOutputThunk, or
  • Reconsider whether generate_from_raw should 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

  1. added
    enhancement
    needs-design
    area/backends
    on Jun 3, 2026
  2. ajbozarth commented on Jun 3, 2026

    @ajbozarth
    Member

    Surfaced this issue during #909 design research. Folded into the #909 design proposal (Discussion #1197) as Area 5 — mot.generate_log public property + mot.error channel 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.

  3. added
    area/stdlib
    and removed
    needs-design
    on Jun 5, 2026
  4. ajbozarth commented on Jun 5, 2026

    @ajbozarth
    Member

    Area 5 design (per #1197)

    @jakelorocco confirmed Option A in the Area 5 thread — keep this issue's scope narrow; GenerateLog deprecation 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 ModelOutputThunk surface:

    1. Promote _generate_log to a public property mot.generate_log

    No shape change to GenerateLog; just expose the existing private attr officially. The attribute stays as _generate_log underneath; backends and sampling code keep writing through that name (internal); external consumers read mot.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 | None property

    Backed by an internal _error attribute 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 None becomes the canonical "did this thunk soft-fail" check, sibling to mot.cancelled, not unified with it (OQ5 resolution):

    • cancelled means a consumer chose to stop (deliberate, by some reader)
    • error means 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"] to thunk.error. The extra["empty_response"] raw key is dropped — if the raw response is wanted, #909 Area 1 (#1215)'s mot.raw.response carries it.

    Caller-facing result

    results = await asyncio.gather(*calls)
    for r in results:
        if r.error is not None:
            # soft-failure
            ...
        elif r.cancelled:
            # explicit cancellation
            ...
        else:
            # ok
            use(r.value)

    This is the shape the original issue asked for.

    Migration

    Single PR:

    1. Add mot.error (private _error attr + public read property + setter on private name).
    2. Add mot.generate_log public read property aliasing _generate_log.
    3. Migrate OllamaBackend.generate_from_raw's soft-fail path: thunk._error = empty_err instead of stashing in _generate_log.extra.
    4. Update docs/integrations/openai.md and any other public docs that reference _generate_log.
    5. _generate_log keeps working as a name internally (no rename); it's the read path that gains a public property.

    Out of scope (future work)

    GenerateLog deprecation. Field-by-field audit (from the #1197 OQ6 thread) shows most GenerateLog fields are duplicated on the MOT or migrating in #909:

    GenerateLog field Duplicated? Where
    model_options yes mot._model_options (→ mot._call.model_options after #909 Area 3, #1216)
    model_output yes mot.raw.response (#909 Area 1, #1215)
    action yes mot._action (→ mot._call.action after #909 Area 3, #1216)
    result yes circular ref back to the MOT
    backend partial mot.generation.provider + mot.generation.model
    date no no datetime on generation
    prompt no the formatted prompt-as-sent isn't anywhere on MOT today
    is_final_result no sampling state
    extra no only systematic use is the ollama error stash, replaced by mot.error

    A future deprecation issue would propose: mot.generation.prompt, mot.generation.timestamp, flat mot._is_final_result, deprecate GenerateLog + the public m.validate(generate_logs=...) parameter + _generate_log together, drop extra entirely. Touches every backend's post_processing, sampling's is_final_result plumbing, 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 | None public property; backed by _error attribute
    • mot.generate_log: GenerateLog | None public property; aliases _generate_log
    • OllamaBackend.generate_from_raw soft-fail path uses thunk._error = ... instead of _generate_log.extra["error"]
    • _generate_log.extra["empty_response"] no longer written
    • Test: a soft-failed Ollama result has r.error is not None and r.cancelled is False
    • Test: a cancelled thunk has r.cancelled is True and r.error is None (separation preserved)
    • Public docs reference result.generate_log / result.error rather than the underscore names

    Sequencing

    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.

  5. added
    p2
    on Jun 18, 2026
  6. ajbozarth commented on Jun 19, 2026

    @ajbozarth
    Member

    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 public generate_from_raw is a @final wrapper since #1264). Current writes to migrate are at mellea/backends/ollama.py:611-613:

    generate_log.extra["error"] = error
    generate_log.extra["empty_response"] = response.model_dump()

    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_log shape still matches the current MOT.

  7. self-assigned this
    on Jun 19, 2026
  8. added a commit that references this issue on Jun 22, 2026
    561c72a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/backendsarea/stdlibenhancementp2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions