Skip to content

mime_content_type() logs a stream_cast warning on every Assistant preview/output-file request #591

Description

@olddude2

Which version of assistant are you using?

3.4.3

Which version of Nextcloud are you using?

33.0.6.2

Which browser are you using? In case you are using the phone App, specify the Android or iOS version and device please.

Not browser-specific — this is a server-side PHP warning, reproducible via any client including the OCS API directly (e.g. via curl).

Describe the Bug

mime_content_type() logs a PHP warning on every Assistant preview/output-file
request:

mime_content_type(): Icewind\Streams\CallbackWrapper::stream_cast is not implemented!

This comes from lib/Service/AssistantService.php, in getTargetFileName()
and getOutputFilePreviewFile(), both of which call:

mime_content_type($file->fopen('rb'))

File::fopen('rb') can return a stream wrapped in
Icewind\Streams\CallbackWrapper, which does not implement stream_cast().
mime_content_type() needs that to inspect the underlying resource, so PHP
falls back to another detection method and logs the warning as a side
effect.

This is log noise, not a functional bug — I confirmed against a live
33.0.6 instance that translation and image-generation tasks both complete
successfully end-to-end with the mime type still correctly detected; the
only symptom is the warning appearing in the log.

The same warning was previously hit in core's TaskProcessingApiController
and addressed in nextcloud/server#54673.

I have a fix ready (drains the stream into a temp file before calling
mime_content_type(), instead of passing the stream resource directly) and
will open a PR referencing this issue shortly.

Expected Behavior

No warning is logged. The task completes and the mime type is still
correctly detected (this already works today — only the log noise should
be eliminated).

To Reproduce

  1. Run any Assistant task that produces an output file (e.g. text-to-image
    generation), or request a preview of an output file via the OCS API:
    GET .../assistant/api/v1/task/{id}/output-file/{id}/preview
  2. Check data/nextcloud.log (or your configured log target) for entries
    logged during that request.
  3. Observe the mime_content_type() / stream_cast warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions