Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.
fix: derive the generated-image storage-key extension from the resolved mime type (#1164)
Louis Choquelfe316d78d4ab
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1ac75e59f..486c8f353 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,10 @@- **Include a method by address — fetch-on-miss**: a bundle referencing another method by address (`github.com/...->domain.pipe`) that misses the installed methods now fetches the package by reference — honoring an `@<tag>` pin, through the same grammar, bounds, and tags-only rules as a direct fetch, with the same hosted-parity warning for Python structure classes locally and a hard refusal on sandbox-hosted deployments — installs it into `~/.mthds/methods/` (atomic staging write, `.git/` stripped, fetch provenance recorded beside the manifest in a `.provenance.json` sidecar: address, tag, and the resolved commit SHA), and loads it so resolution proceeds. Once installed, the method is reused and the network is never touched again — including for a reference pinning a different tag, which warns and uses the installed copy. The former silent-miss warning in the library manager is now a real diagnostic: a miss that cannot be bridged (fetch disabled via the new `[interpreter.methods] fetch_on_miss` config or the `PIPELEX_METHODS_FETCH_ON_MISS` environment variable, an unfetchable address, or a failed fetch) raises an error naming the address and the remedy, never a silent pass. The install target is guarded by identity: two packages sharing a bare directory name but coming from different addresses collide with a loud error naming both addresses (never a silent load of the wrong package, never an overwrite), a concurrent install of the same package is tolerated (each attempt stages under a unique dot-prefixed directory, and losing the final rename race to a matching occupant uses the winner's copy), and a fetched package containing a symlink is refused outright, since a link's target would bypass the content scans. Installed-method lookup by full address is now case-insensitive, matching GitHub's owner/repository semantics and the fetch path's manifest-identity matching, and discovery skips dot-prefixed directories. See [Packages → Include by Address](building-methods/packages.md) and [Methods Configuration](configuration/config-practical/methods-config.md).+### Fixed++- **Generated-image storage key extension follows the actual mime type**: a generated image could be stored under a `.png` key while its bytes and reported `mime_type` were `image/jpeg`, because `GeneratedContentFactory` picked the key's extension from the *requested* image format while `mime_type` came from the provider's *actual* answer — and a provider may return a different format than requested. The factory now resolves the effective mime type once (provider-reported, then base64-extracted, then the requested format, then the `image/jpeg` default) and derives the storage-key extension from that same value, on every path (stored bytes and fetched remote content alike), so the key and the `mime_type` can no longer diverge and anything inferring a type from the extension sees the truth.+## [v0.55.0] - 2026-08-29### Addeddiff --git a/pipelex/cogt/content_generation/generated_content_factory.py b/pipelex/cogt/content_generation/generated_content_factory.pyindex f7826757b..124fed9ec 100644--- a/pipelex/cogt/content_generation/generated_content_factory.py+++ b/pipelex/cogt/content_generation/generated_content_factory.py@@ -28,8 +28,7 @@ class GeneratedContentFactory:storage_scope: str,*,data: bytes,- mime_type: str | None,- image_format: ImageFormat | None,+ mime_type: str,) -> str:"""Build a storage key using a SHA-256 hash of the data.@@ -42,8 +41,10 @@ class GeneratedContentFactory:key generated content by tenant instead of by uploader, withoutthe runtime learning what a tenant is.data: The binary data to hash- mime_type: Optional MIME type to determine file extension- image_format: Optional output format to determine file extension+ mime_type: The resolved effective MIME type — the same value the+ resulting content reports. It alone decides the file extension,+ so the key can never disagree with the content's `mime_type`+ (a provider may return a different format than requested).Returns:`{storage_scope}/generated/<filename>`, where the filename is@@ -51,20 +52,15 @@ class GeneratedContentFactory:"""hash_digest = hashlib.sha256(data).hexdigest()[:16]- if image_format:- extension = image_format.as_file_extension- elif mime_type:- match mime_type:- case "image/jpeg":- extension = "jpg"- case "image/png":- extension = "png"- case "image/webp":- extension = "webp"- case _:- extension = "jpg"- else:- extension = "jpg"+ match mime_type:+ case "image/jpeg":+ extension = "jpg"+ case "image/png":+ extension = "png"+ case "image/webp":+ extension = "webp"+ case _:+ extension = "jpg"# The `generated/` leaf is HARDCODED, and `uri_format` renders only the# filename under it. It used to render the whole key, `{storage_scope}/…`,# which put generated bytes loose at the root of the scope while the@@ -91,50 +87,38 @@ class GeneratedContentFactory:) -> ImageContent:image_format: ImageFormat | None = Nonebase64_extracted_mime_type: str | None = None- is_remote_url: boolif raw_details.image_format:image_format = ImageFormat(raw_details.image_format)+ # Parse the raw details into either a remote URL or actual bytes,+ # extracting the mime type embedded in a base64 data-URL when present.+ remote_url: str | None = None+ actual_bytes: bytes | None = Noneif raw_details.actual_url:- url = raw_details.actual_url- is_remote_url = True- else:- actual_url: str | None = None- actual_bytes: bytes | None = None- if raw_details.base64_str:- actual_bytes = base64.b64decode(raw_details.base64_str)- elif raw_details.actual_url_or_prefixed_base64:- if raw_details.actual_url_or_prefixed_base64.startswith("http"):- actual_url = raw_details.actual_url_or_prefixed_base64- elif result := extract_base64_str_from_base64_url_if_possible(possibly_base64_url=raw_details.actual_url_or_prefixed_base64):- base64_str, base64_extracted_mime_type = result- actual_bytes = base64.b64decode(base64_str)- else:- msg = "No URL or base64 string could be extracted"- raise NeitherUrlNorDataError(msg)- elif raw_details.actual_bytes:- actual_bytes = raw_details.actual_bytes+ remote_url = raw_details.actual_url+ elif raw_details.base64_str:+ actual_bytes = base64.b64decode(raw_details.base64_str)+ elif raw_details.actual_url_or_prefixed_base64:+ if raw_details.actual_url_or_prefixed_base64.startswith("http"):+ remote_url = raw_details.actual_url_or_prefixed_base64+ elif result := extract_base64_str_from_base64_url_if_possible(possibly_base64_url=raw_details.actual_url_or_prefixed_base64):+ base64_str, base64_extracted_mime_type = result+ actual_bytes = base64.b64decode(base64_str)else:- msg = "No URL or bytes or image found"+ msg = "No URL or base64 string could be extracted"raise NeitherUrlNorDataError(msg)-- if actual_url:- url = actual_url- is_remote_url = True- elif actual_bytes:- storage_key = self._build_storage_key(- storage_scope=storage_scope,- data=actual_bytes,- mime_type=raw_details.mime_type or base64_extracted_mime_type,- image_format=image_format,- )- url = await self.storage_provider.store(data=actual_bytes, key=storage_key)- is_remote_url = False- else:- msg = "No URL or bytes found"- raise NeitherUrlNorDataError(msg)-- mime_type: str | None = None+ elif raw_details.actual_bytes:+ actual_bytes = raw_details.actual_bytes+ else:+ msg = "No URL or bytes or image found"+ raise NeitherUrlNorDataError(msg)++ # Resolve the effective mime type ONCE, before any storage key is built:+ # the provider's actual answer first (reported mime, then base64-extracted),+ # the REQUESTED image format only as a fallback. The storage-key extension+ # derives from this same resolution, so key and mime cannot diverge when a+ # provider returns a different format than requested.+ mime_type: strif raw_details.mime_type:mime_type = raw_details.mime_typeelif base64_extracted_mime_type:@@ -144,6 +128,23 @@ class GeneratedContentFactory:else:mime_type = "image/jpeg"+ is_remote_url: bool+ url: str+ if remote_url:+ url = remote_url+ is_remote_url = True+ elif actual_bytes:+ storage_key = self._build_storage_key(+ storage_scope=storage_scope,+ data=actual_bytes,+ mime_type=mime_type,+ )+ url = await self.storage_provider.store(data=actual_bytes, key=storage_key)+ is_remote_url = False+ else:+ msg = "No URL or bytes found"+ raise NeitherUrlNorDataError(msg)+public_url: str | Noneif is_remote_url and get_config().runtime.storage.is_fetch_remote_content_enabled:try:@@ -156,7 +157,6 @@ class GeneratedContentFactory:storage_scope=storage_scope,data=actual_bytes,mime_type=mime_type,- image_format=image_format,)url = await self.storage_provider.store(data=actual_bytes, key=storage_key)public_url = await self.storage_provider.public_url(uri=url)diff --git a/tests/unit/pipelex/cogt/content_generation/test_generated_content_factory.py b/tests/unit/pipelex/cogt/content_generation/test_generated_content_factory.pynew file mode 100644index 000000000..3c84d29a6--- /dev/null+++ b/tests/unit/pipelex/cogt/content_generation/test_generated_content_factory.py@@ -0,0 +1,58 @@+import pytest+from pytest_mock import MockerFixture++from pipelex.cogt.content_generation.generated_content_factory import GeneratedContentFactory+from pipelex.cogt.image.generated_image import GeneratedImageRawDetails+from pipelex.tools.storage.storage_provider_abstract import StorageProviderAbstract++FAKE_IMAGE_BYTES = b"fake-image-bytes-for-hashing"++[email protected](loop_scope="class")+class TestGeneratedContentFactoryStorageKey:+ @pytest.mark.parametrize(+ ("reported_mime_type", "requested_image_format", "expected_extension", "expected_mime_type"),+ [+ pytest.param("image/jpeg", "png", "jpg", "image/jpeg", id="provider-mime-overrides-requested-format"),+ pytest.param(None, "png", "png", "image/png", id="provider-silent-requested-format-wins"),+ ],+ )+ async def test_storage_key_extension_follows_resolved_mime_type(+ self,+ mocker: MockerFixture,+ reported_mime_type: str | None,+ requested_image_format: str,+ expected_extension: str,+ expected_mime_type: str,+ ):+ """The storage-key extension derives from the same mime resolution the result reports.++ The provider's actual mime type wins over the requested image format, and the requested+ format only fills in when the provider is silent — so the minted key's extension and the+ resulting `mime_type` can never diverge (e.g. a `.png` key holding `image/jpeg` bytes).+ """+ storage_provider = mocker.MagicMock(spec=StorageProviderAbstract)+ storage_provider.store = mocker.AsyncMock(return_value="pipelex-storage://stored-uri")+ storage_provider.public_url = mocker.AsyncMock(return_value=None)+ factory = GeneratedContentFactory(storage_provider=storage_provider)++ raw_details = GeneratedImageRawDetails(+ size=None,+ actual_bytes=FAKE_IMAGE_BYTES,+ mime_type=reported_mime_type,+ image_format=requested_image_format,+ )++ image_content = await factory.make_image_content(+ storage_scope="test/scope",+ raw_details=raw_details,+ )++ storage_provider.store.assert_awaited_once()+ store_call = storage_provider.store.await_args+ assert store_call is not None+ stored_key: str = store_call.kwargs["key"]+ assert stored_key.startswith("test/scope/generated/")+ assert stored_key.endswith(f".{expected_extension}")+ assert image_content.mime_type == expected_mime_type+ assert image_content.url == "pipelex-storage://stored-uri"