ADL 41 · Part V — Execution, presentation, and integration

0.5.1 baseline + 0.6 edition note

Media libraries and file references

ADL 0.6.0 reference · Review draft 1 · November 14, 2026.

Contents · Source map · Evidence

The 0.6 edition note

This chapter retains the detailed language contract and its source-specific observations. Its chapter number and numbered sections remain stable. The 0.6 additions do not by themselves change this subject’s defaults or supply fresh execution evidence for it.

Reverification should cover file-reference validation, media authority, and lifecycle cleanup. Use the original examples and evidence links below to recover the earlier test context. The new edition’s source map records this chapter as inherited detail; the current draft does not claim those historical tests were rerun.

Retained reference detail

The numbered sections below are carried from 41-media-libraries-and-file-references.md. Their original baseline and evidence remain attached to the source. Statements about “current” or “checked” behavior in this retained text refer to those original observations unless the edition note explicitly updates them. This is a consolidated draft, not a claim of complete re-verification.

41.1 Scope and edition boundary

A domain media library catalogs uploaded assets and records which resource fields reference them. ADL owns the library permission declaration, generated management interface, media reference semantics, and author-visible failures. The platform owns file-provider deployment, byte serving, storage roots, and provider credentials. ADL 30 owns media field constraints such as MIME acceptance, file size, and image dimensions. This chapter does not duplicate those constraints or treat a library permission as a resource-field permission.

There is no inherited body for this chapter’s previously empty slot. Its contract is developed from the current parser, generated actions, media library, real local file provider, and the checked examples. The native fixture uploads actual bytes, attaches the returned asset ID to a resource, and checks both catalog state and physical file state after deletion.

41.2 Domain media permission declaration

Place the three tiers under domain.media.permissions:

# Domain fragment from library.yaml.
media:
  permissions:
    browse: [reader, uploader, manager]
    upload: [uploader]
    manage: [manager]
TierGenerated operations
browseLibrary list and individual asset metadata get
uploadUpload bytes and create a library record
manageDelete, bulk delete, and orphan listing

Each tier is an array of permission tokens. It is evaluated independently: upload does not imply browse, and manage does not automatically grant upload. The complete example gives an uploader browse access explicitly. A resource’s own create/update permission still controls assignment of an asset to that resource.

The implementation translates tier tokens into action metadata as follows:

DeclarationCurrent registration behavior
Omitted or empty tierAny authenticated user
"*" anywhere in the tierPublic action; other tokens do not narrow it
authenticatedAny authenticated user; concrete role tokens do not narrow it
ownerCurrently treated as authenticated, without per-asset ownership
Concrete role names onlyAuthenticated caller holding any named role

An empty array does not deny access. A manager-only policy must name the required role, and an ownership policy must not rely on the current owner shortcut to limit access to the uploader’s assets. permission-defaults.yaml verifies public browse, owner upload by an ordinary member, and authenticated management from an empty manage tier.

The current action generator creates a media library and its management actions for each activated domain, including domains with no media field or explicit media block. Omitting media therefore does not itself disable the endpoints. Transport authentication remains a separate platform concern.

41.2.1 Who may read the file bytes: media.public

The three tiers govern the catalog. A fourth key, media.public, governs the bytes the catalog points at:

media:
  public: false          # the default when the key is absent
  permissions:
    browse: [reader]
media.publicWho may read a file the library catalogs
absent or falseA caller who satisfies browse, on every route that serves the bytes
trueAnyone. The catalog itself stays under browse

The library is closed unless the domain opens it. Only the literal true opens it; a string or a number leaves it closed, and the reference validator reports MEDIA_PUBLIC_NOT_BOOLEAN.

The rule follows the file, not the URL. The file provider serves bytes by storage path, and before it serves one it asks whether a closed library catalogs that path. So the path returned by upload answers 401 to an anonymous caller, and 403 to a caller without a browse role, exactly as the catalog does. This holds for files uploaded before the key existed.

Three consequences to design for:

  • A page that shows media to visitors with a plain <img src> needs public: true. A browser sends no Authorization header for an image, so a closed library’s files must be fetched with the header and shown from a blob: URL.
  • Because browse: ["*"] makes the catalog public, it also makes the bytes of a closed library readable by anyone: the bytes follow browse.
  • The server setting files.serve_public: false still requires a signed-in caller for every file, public library or not. media.public: true cannot open what the operator closed.

41.3 Catalog records, bytes, and references

The library catalog has an asset ID, original filename, MIME type, size, path, dimensions, capture time, GPS position, domain name, and creation time. The catalog ID is the identifier assigned to media fields. It differs from the file provider’s storage key and from the generated download path.

For a JPEG the library reads the APP1 EXIF segment (EXIF 2.32, TIFF 6.0) at upload, in either byte order:

FieldSourceForm
captured_atExif IFD DateTimeOriginal (0x9003), with OffsetTimeOriginal (0x9011) when presentYYYY-MM-DDTHH:MM:SS, plus ±HH:MM when the photo recorded an offset
latitude, longitudeGPS IFD tags 1–4: N/S/E/W references and degree/minute/second rationalssigned decimal degrees, south and west negative

All three are nullable. A file with no EXIF, a non-JPEG, a truncated or malformed segment, a zero denominator, a latitude past 90 or a longitude past 180 leaves the affected fields null. EXIF never fails an upload. Latitude and longitude are set together or not at all. Without an offset tag, captured_at is the camera’s local wall-clock time and carries no zone; the library does not guess one. A library created by an earlier plugin gains the three columns at activation, and its existing rows read null.

The library stores the uploaded bytes unchanged, GPS included. Stripping GPS from stored files is not part of this edition.

The reference table records media ID, resource name, record ID, and field name. Ordinary media-field writes maintain those references. The checked Record contains an attachment field of type media, restricted to text/plain by ADL 30’s field grammar. Assigning the uploaded ID creates one reference; clearing the field with JSON null removes that reference.

An asset reference is not a filesystem path. Do not place a server’s absolute storage path in a resource field to bypass the library. Library browse authority also does not grant permission to read the referencing resource or every field on it; the asset get operation nevertheless exposes reference metadata, so that information belongs in the application’s access review.

In this fixture the upload body contains five bytes, hello, while its supplied size claims 999. The response and catalog use the actual stored size, five. The provider stores those bytes in a temporary directory, which the verifier inspects independently of the library response.

41.4 Upload request and failures

The generated upload action expects filename and mime_type, plus uploaded file bytes from the transport adapter. The HTTP form is multipart upload; the native fixture supplies the adapter’s internal _files array with base64 content. That internal shape is evidence for the handler and is not a proposed browser API or a new ADL declaration.

Only the first uploaded file entry is consumed by this action. It decodes the content, checks MIME signatures it understands, calls the registered file provider’s checked store operation, and inserts a catalog record. Success is 201, returning ID, filename, MIME type, actual size, path, width, and height.

FailureResponse at the checked action boundary
Missing filename or MIME type400 MALFORMED_REQUEST
No registered file provider503 NO_FILE_STORE
No uploaded file entry400 NO_FILE
Empty uploaded content400 EMPTY_FILE
Declared MIME contradicts recognized file signature415 MIME_MISMATCH
Provider disallows MIME type415 UNSUPPORTED_MEDIA_TYPE
Provider size limit exceeded413 FILE_TOO_LARGE
Provider cannot persist bytes502 STORE_FAILED
Caller lacks upload tier403 FORBIDDEN

MIME inspection is bounded by the signatures the library recognizes. It is not a general content-safety or file-format validator. The checked text falsely labelled as PNG is rejected; unrecognized formats still depend on the provider and field policy. Image dimension extraction likewise does not establish full image decoding or safe rendering.

The local provider fixture uses files.root, files.base_url, files.allowed_types, and files.max_file_size. Those are host configuration, not keys under domain.media. The native adapter registers the real provider without loading its plugin binary. Provider installation and HTTP download behavior require platform evidence beyond this test.

41.5 List, get, and orphan operations

For the example domain, the media base is /api/v1/assets/media. The registered route inventory records upload, list, get, delete, bulk-delete, and orphan paths. Use that inventory for exact routing; catalog and byte-serving URLs are different interfaces.

List supports bounded pagination, search, MIME filtering, sorting, and an orphan filter. The current handler defaults to a limit of 50, caps it at 500, accepts nonnegative offset, and sorts newest creation first. It returns items and a pagination meta block. Individual get requires an ID, returns catalog fields plus references, and returns 404 NOT_FOUND when the asset is absent. A missing required ID yields 422 VALIDATION_ERROR.

Orphans are catalog assets with no tracked resource references. The manage-tier orphan operation returns orphans and count. After the example attachment is cleared, the uploaded asset becomes a catalog orphan. This operation does not scan provider storage for uncatalogued bytes, and it does not establish whether external URLs or applications still refer to an asset.

41.6 Deletion and unresolved storage

Single deletion refuses an asset with tracked references using 409 MEDIA_IN_USE. The checked attached asset remains in the catalog and on disk after that refusal. After detachment, the delete action returns 204 and subsequent metadata get returns 404 NOT_FOUND.

However, the physical file remains in the checked local-provider fixture. The action passes the catalog URL-like path to the provider’s remove operation, whereas LocalFileStore::remove expects a relative storage key and rejects an absolute path. The action ignores that remove result after deleting catalog metadata. A successful metadata deletion therefore does not prove byte removal in this revision.

Bulk deletion accepts an ids array, skips referenced assets with a reason, and returns deleted/skipped information. It silently ignores non-string entries; the current count can include an unknown string ID. The checked request with one missing ID and one numeric entry reports one deletion despite removing no asset. Treat this count as an action report, not an independent storage reconciliation.

There is another transaction boundary on upload: provider bytes are stored before the catalog insert, whose failure is not checked by the action. The failure fixture installs a SQLite trigger that refuses the insert. Upload still returns 201 and leaves a file, while the library remains empty. This demonstrates uncatalogued storage after a catalog write failure; it is not an acceptable successful upload contract.

An application using the current implementation needs explicit verification or reconciliation for both directions: catalog entries whose bytes cannot be read, and stored bytes with no catalog entry. This chapter does not promise an automatic orphan collector, distributed transaction, storage cleanup job, or deletion from provider backups.

The checked examples distinguish browse/upload/manage callers, MIME and size failures, provider absence, stored byte length, attachment tracking, in-use delete refusal, detachment, orphan reporting, catalog deletion, remaining files, and a forced catalog-insert failure. Native parser/export/registry results and modeller results are reported separately. Source-backed reconstruction retains the library permissions, but export and source-free reconstruction lose the media block. The resulting authenticated defaults must not be mistaken for the original role policy.

The probes dispatch management actions through the kernel and use the real local file store in disposable directories. They do not exercise multipart HTTP parsing, download authorization, cloud providers, concurrent attachment/deletion, nested media reference traversal, or recovery after a process crash. Those need separate operation-level evidence; none follows merely from parser acceptance.

Use ADL 30 for field constraints, ADL 21 for resource authority, ADL 39 for generated documents, and the platform storage chapter for configuring and operating file providers. A generated document ID and a media-library asset ID are not interchangeable unless an explicitly verified integration connects their catalogs.