9 Committed changes and resource dependencies
A resource can declare keys with #:depends-on; the expression runs with validated URI arguments when matching an eligible resource subscription. Keys are a list of JSON values. Mounts and URI views retain the dependency callback.
(resource (document [id String]) #:uri "document:///{id}" #:depends-on (list id) (read-document id)) (tool (save-document [id String] [body String]) #:changes [outcome (list id)] (write-document-and-commit! id body) (committed-result (text-result "Saved") '()))
The data API accepts #:depends-on on make-resource as a procedure of bound arguments, and #:changes on make-tool as a procedure of bound arguments and committed result. runtime-report-change! accepts a runtime, principal, and keys for external committed changes. It invalidates that principal’s entries in runtime-cache before publishing matching resource updates, rechecking the subscriber’s read authorization and principal expiry.
With storage, acknowledged tool changes enter the outbox before publication. Applications sharing SQLite can call record-committed-change! inside store-transaction alongside their mutation, then call runtime-drain-changes! after commit. Outbox callbacks tolerate duplicate publication after interruption. A separately committed external mutation still needs adapter reconciliation if the process exits before recording its change.
Resources opt into caching with #:ttl-ms (default zero), available on both resource and make-resource. Successful ordinary reads are cached; workflow resources and requests carrying durable continuation or invocation state bypass caching and return zero TTL. Input-required results are never cached. Cache hits return their remaining TTL. A parent inherits the earliest expiry of its embedded resources and the verified principal’s expiry.
Entries include the runtime namespace, principal owner, effective authorization context, client capabilities, validated arguments, and dependency keys. Verified principals use all their claims by default. make-runtime’s #:cache-context callback can supply a stable immutable application policy key; it must change when effective authority changes independently of the principal. Opaque or mutable application principals should use that callback. Cache hits recheck read authorization for the resource and all transitively embedded URIs. Changes invalidate all cached authority contexts for their owner, including parent entries dependent on changed children.
A dependency key is scoped to its owner; using the same key for two principals does not grant access or share a cached representation. For application data shared by several owners, the application supplies its sharing relation explicitly. Record one record-committed-change! per affected owner in the same store-transaction as the shared mutation, then call runtime-drain-changes! after commit. Include former owners whose retained entries must be invalidated after revocation. Delivery rechecks each subscriber’s current authorization, so invalidation does not grant notification access.
An external committed-change feed can likewise emit one external-change per affected owner, with distinct stable event IDs. The existing feed transaction records the whole page and cursor together. For ephemeral integrations, runtime-report-change! can be called for each owner after commit; durable applications should use the outbox or reconciled feed to survive interrupted publication. The SDK does not discover an application’s sharing relation or broadcast private dependency keys to all principals. List pages remain private with zero TTL; a new listing refreshes them, while an existing cursor retains its snapshot. MRTR input-required results and continuation reads remain uncached.
make-resource-cache bounds entries with #:limit (default 1024). Computation occurs outside its lock; concurrent loads can compute twice, but invalidation prevents an in-flight old value from being inserted afterward and reduces that returned resource result’s TTL to zero.
9.1 Durable workflow changes
workflow accepts #:changes [outcome expression] after its key clause. The expression sees original bound arguments and the completed result. Its key list enters the outbox in the same transaction as the terminal result; continuation retries retrieve that result without reevaluating the clause. Completion errors do not evaluate it. Like checkpoint computation, change expressions must tolerate rollback and retry before the transaction commits.
An effect adapter can return committed-result containing its ordinary stage value and immediate dependency keys. A transactional adapter’s mutation, validated stage result, and outbox entry share SQLite’s transaction. Idempotent and manual adapters record acknowledged keys with their saved result; uncertain external mutations still require reconciliation or explicit recovery. recover-workflow! accepts an acknowledged result for outcome repair. The journal links each recorded change batch to its stage and outbox handle.
Runtime workflow and task workers attempt publication after committed stages, including before a later input boundary. Publication failure retains the outbox entry and reports a diagnostic without changing an already committed effect or terminal outcome. Direct run-workflow callers can drain the outbox explicitly. Workflow execution owns its transaction boundaries and rejects being wrapped in an existing transaction on the same store.