Licences and the gate #

What is new: a licence is the owner's signed permission for one licensee, for named uses, until a date, and nothing is used without one. Every refusal carries a typed reason, and every decision is recorded.

Why it matters: "we checked the licence" usually means someone read a contract once. Here the check runs on every use, in code, before the use starts, and the record of it is signed.

One licence, four refusals #

import hashlib
import tensorchain.cloud as tc

p = tc.Local("gate.sqlite")
p.add_source("stock-footage")
p.license("stock-footage", "agent:trainer", ["train"], days=30)
p.ingest("stock-footage", [["clip-001.mp4", hashlib.sha256(b"clip").hexdigest(), 4096]])

def gate(consumer, use, sources):
    try:
        p.dataset(consumer, use, sources)
        return "allowed"
    except tc.Refused as e:
        return e.code

print("trainer / train:   ", gate("agent:trainer", "train", ["stock-footage"]))
print("trainer / publish: ", gate("agent:trainer", "publish", ["stock-footage"]))
print("someone else:      ", gate("agent:intern", "train", ["stock-footage"]))
print("never registered:  ", gate("agent:trainer", "train", ["mystery-crawl"]))
assert gate("agent:trainer", "train", ["stock-footage"]) == "allowed"
assert gate("agent:trainer", "publish", ["stock-footage"]) == "use_not_licensed:stock-footage"
assert gate("agent:intern", "train", ["stock-footage"]) == "licence_required:stock-footage"
assert gate("agent:trainer", "train", ["mystery-crawl"]) == "source_unregistered"
Output (captured at build)
trainer / train:    allowed
trainer / publish:  use_not_licensed:stock-footage
someone else:       licence_required:stock-footage
never registered:   source_unregistered

An unregistered source fails closed: data nobody has claimed is not trained on.

Licences end #

A licence carries its own end date. The gate reads the clock at the moment of use; here we ask it about a date past the licence's end.

import time
from tensorchain import ingest
from tensorchain.workspace import Workspace

later = int(time.time() * 1000) + 31 * 86400 * 1000            # 31 days from now: past the 30-day licence
with Workspace(p.path, actor="agent:docs") as ws:
    heads = ingest.heads(ws, ["stock-footage"])
    try:
        ingest.dataset(ws, p.reg, p.issuer, "agent:trainer", "train", heads, now_ms=later)
        at_day_31 = "allowed"
    except ingest.IngestError as e:
        at_day_31 = e.code
print("on day 31:", at_day_31)
assert at_day_31 == "licence_expired:stock-footage"
Output (captured at build)
on day 31: licence_expired:stock-footage

Every decision is recorded #

with Workspace(p.path, actor="agent:docs") as ws:
    decisions = [t for t in ws.tags() if t.startswith("gate/")]
print(len(decisions), "gate decisions recorded")
assert len(decisions) >= 4
Output (captured at build)
7 gate decisions recorded