Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CAPABILITIES.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
| Receipts: one signed record per run, with any outcome (`receipt.json`, a DSSE envelope over an in-toto `record/run/v1` statement): one line per write with its check, strength and what it didn't check; digests, enums, counts and salted commitments only, never screenshots, typed values, URLs or page text; the outcome copied, never upgraded; signer roles from a pinned registry (this computer, customer key, OpenAdapt Cloud countersignature, public log, demo), unknown key, role or schema fails closed; a public card is the same envelope with only allow-listed values opened (`openadapt.public-disclosure/v1`) | Branch ([#2394](https://github.com/OpenAdaptAI/OpenAdapt/pull/2394)) | Unit tests with synthetic runs (stopped runs, tampered report and payload, unknown signer, embedded image refused); 15 shared vectors for the Python, Cloud and web verifiers | `openadapt verify <file\|folder\|link>`, `openadapt receipt verify\|view\|publish\|unpublish`; [RECEIPTS.md](packages/flow/docs/RECEIPTS.md); [vectors](packages/types/tests/vectors/record-run-v1/README.md) |
| Receipts: one signed record per run, with any outcome (`receipt.json`, a DSSE envelope over an in-toto `record/run/v1` statement): one line per write with its check, strength and what it didn't check; digests, enums, counts and salted commitments only, never screenshots, typed values, URLs or page text; the outcome copied, never upgraded; signer roles from a pinned registry (this computer, customer key, OpenAdapt Cloud countersignature, public log, demo), unknown key, role or schema fails closed; runs on a synthetic app (the tutorial, `replay --demo-app`) are signed with a separate demo key, never this computer's Seal key, so a receiver that pins this computer refuses them (the reference Execute worker's MockMed seals and the seeded reward contract use their own demo keys the same way); a public card is the same envelope with only allow-listed values opened (`openadapt.public-disclosure/v1`) | Branch ([#2394](https://github.com/OpenAdaptAI/OpenAdapt/pull/2394)) | Unit tests with synthetic runs (stopped runs, tampered report and payload, unknown signer, embedded image refused); tutorial and `replay --demo-app` receipts on headless MockMed checked as demo-signed and refused by this computer's pin; 15 shared vectors for the Python, Cloud and web verifiers | `openadapt verify <file\|folder\|link>`, `openadapt receipt verify\|view\|publish\|unpublish`; [RECEIPTS.md](packages/flow/docs/RECEIPTS.md); [vectors](packages/types/tests/vectors/record-run-v1/README.md) |
2 changes: 1 addition & 1 deletion capabilities/CAPABILITIES.md.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6b0c7d386eb68b516766993b4afb1ffe6a0ea4461851850db38a845a47648b81
edf84a8e86d8b4ee8715734751fa8af1a60bacd4c42d52e0ac6cf064228555f0
76 changes: 70 additions & 6 deletions llms-full.txt

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions packages/flow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ passed. `--seed-mockmed` registers two simulated MockMed workflows, an honest
app and one that drops the save, which return results without opening a
browser.

Results about MockMed, a synthetic app, are signed with the worker's demo key,
not its own key. That covers the seeded workflows and any bundle the worker
replays in process on its bundled demo app. `GET /health` names the worker's
key as `issuer_key_fingerprint` and the demo key as `demo_key_fingerprint`. A
client that pins `issuer_key_fingerprint` refuses a demo seal, and the seal
page and the `X-OpenAdapt-Demo` header say it was a synthetic demo app.

`openadapt-flow emit-mcp bundle --out server.py` writes a standalone MCP
server for one bundle. Web and desktop tools use the same governed `run` CLI.
Start the server with `--config deploy.yaml --profile standard
Expand Down
16 changes: 16 additions & 0 deletions packages/flow/docs/RECEIPTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ OpenAdapt Cloud countersigns the same envelope; it doesn't issue a separate
object. An unknown key, role or schema fails closed, even beside a valid
signature, and so does a demo key next to a real one.

### Runs on a synthetic app use the demo key

The tutorial and `replay --demo-app` run on MockMed, a synthetic app. Their
`receipt.json` is signed with this computer's **demo key**, kept under
`<seal home>/demo`. It is never the Seal key, and never a key named by
`OPENADAPT_SEAL_KEY`. A receipt has no field that marks a run as synthetic,
and the receiver's registry decides what a key means. So a synthetic run
signed with this computer's key would read like proof about a real system.

- A receiver that pins this computer's key refuses the receipt
(`unknown_signer`), and so does `openadapt verify` by default.
- A receiver that pins the demo key with the role `demo` sees "Demo key:
checks only in this demo".
- Adding this computer's signature to it is refused as a mixed demo
signature.

## Check one

```bash
Expand Down
5 changes: 4 additions & 1 deletion packages/flow/docs/REWARD_WORKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ python -m openadapt_flow serve-reward --seed-mockmed --port 8788
```

`--seed-mockmed` writes two contract bundles and their stores under the data
directory and serves the tier-2 one when `--contract` is omitted.
directory and serves the tier-2 one when `--contract` is omitted. The seeded
contracts describe MockMed, a synthetic app, so their certificates and every
reward receipt for them are signed with the demo key under `<data dir>/demo`,
not the worker's own key. A client that pins the worker's key refuses them.

`contracts/mockmed` reads `mockmed/records.db` through the `sqlite` recipe,
channel `db`, tier 2. The database starts with two rows for the duplicate
Expand Down
5 changes: 5 additions & 0 deletions packages/flow/docs/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ free-form halt reason. It carries the bundle digest, so anyone can run the same
public tutorial and compare. The complete field set is in
[`RECEIPTS.md`](RECEIPTS.md).

The tutorial's signed `receipt.json` is signed with the demo key, not this
computer's Seal key, because MockMed is a synthetic app. A receiver that pins
this computer's key refuses it, so it can't pass for proof about a real
system. See [`RECEIPTS.md`](RECEIPTS.md#runs-on-a-synthetic-app-use-the-demo-key).

## Drive the same stages by hand

```bash
Expand Down
29 changes: 23 additions & 6 deletions packages/flow/openadapt_flow/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,12 +1116,15 @@ def _undo_run_target_problem(args: argparse.Namespace, workflow) -> Optional[str


def _print_terminal_receipt(
run_dir: Path, report, *, require_opt_in: bool = False
run_dir: Path, report, *, require_opt_in: bool = False, synthetic: bool = False
) -> None:
from openadapt_flow.receipt_record import receipt_after_run

note = receipt_after_run(
run_dir, require_opt_in=require_opt_in, expected_report=report
run_dir,
require_opt_in=require_opt_in,
expected_report=report,
synthetic=synthetic,
)
if note:
print(note, file=sys.stderr)
Expand Down Expand Up @@ -1174,7 +1177,10 @@ def _finish_replay(
_maybe_report_break(run_dir, report)
_maybe_report_run(run_dir, report, args, backend_kind=backend_kind)
if args is not None:
_print_terminal_receipt(run_dir, report)
# --demo-app replays run on the bundled synthetic app: demo key.
_print_terminal_receipt(
run_dir, report, synthetic=bool(getattr(args, "demo_app", False))
)
_maybe_attest_run(run_dir, report, args)
if getattr(report, "execution_profile", None) in {"standard", "regulated"}:
return 0 if outcome == "VERIFIED" else 1
Expand Down Expand Up @@ -13428,24 +13434,32 @@ def _cmd_serve_reward(args: argparse.Namespace) -> int:
contract = args.contract
seeded_paths: dict[str, Path] = {}
seeded_store: Optional[tuple[Path, Path]] = None
key_dir: Optional[Path] = None
if args.seed_mockmed:
from openadapt_flow.execute.keys import (
DEMO_KEY_DIR,
fingerprint_of,
load_or_create_private_key,
)
from openadapt_flow.tutorial import seed_demo_reward

key = load_or_create_private_key(data_dir)
# The seeded contracts are about synthetic MockMed: the demo key signs
# them, never this worker's own key.
demo_dir = data_dir / DEMO_KEY_DIR
key = load_or_create_private_key(demo_dir)
issuer_key_id = "self_signed:" + fingerprint_of(key.public_key())
seeded_paths, store_db, store_screen = seed_demo_reward(
data_dir, key, issuer_key_id
)
seeded_store = (store_db, store_screen)
if contract is None:
contract = str(seeded_paths["tier2"])
seeded = {Path(p).resolve() for p in seeded_paths.values()}
if Path(contract).resolve() in seeded:
key_dir = demo_dir
if contract is None:
raise SystemExit("serve-reward needs --contract <bundle dir> or --seed-mockmed")
worker = RewardWorker(contract, data_dir, token=args.token)
worker = RewardWorker(contract, data_dir, token=args.token, key_dir=key_dir)
print("openadapt-flow reference reward worker")
print(f" http://{args.host}:{args.port}")
print(f" data dir {data_dir}")
Expand All @@ -13457,7 +13471,10 @@ def _cmd_serve_reward(args: argparse.Namespace) -> int:
)
print(f" certificate {'present' if worker.certificate else 'absent'}")
print(f" token {worker.token}")
print(" issuer self_signed")
print(
" issuer self_signed"
+ (" (demo key: synthetic MockMed contract)" if key_dir is not None else "")
)
print(f" fingerprint {worker.fingerprint}")
print(f" {REWARD_NOTICE}")
for label, path in seeded_paths.items():
Expand Down
34 changes: 26 additions & 8 deletions packages/flow/openadapt_flow/execute/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def health() -> dict[str, Any]:
"service": "openadapt-execute-ref",
"issuer": "self_signed",
"issuer_key_fingerprint": store.fingerprint,
# Results about the bundled synthetic demo app are signed with
# this key instead. Pin issuer_key_fingerprint, not this one.
"demo_key_fingerprint": store.demo_fingerprint,
"production_seal": False,
}

Expand Down Expand Up @@ -95,7 +98,7 @@ def get_receipt(
body = receipt.model_dump(mode="json")
return JSONResponse(
content=body,
headers=_issuer_headers(store),
headers=_issuer_headers(store, demo=store.is_demo_execution(execution_id)),
)

@app.get("/seals/{seal_id}", response_model=None)
Expand All @@ -107,16 +110,20 @@ def get_seal(
# Local analog of a public verify page: the seal has no PHI.
del authorization
seal = store.get_seal(seal_id)
demo = seal.issuer_key_fingerprint == store.demo_fingerprint
accept = request.headers.get("accept", "")
want_json = request.query_params.get("format") == "json" or (
_JSON in accept and "text/html" not in accept
)
if want_json:
return JSONResponse(
content=seal.model_dump(mode="json"),
headers=_issuer_headers(store),
headers=_issuer_headers(store, demo=demo),
)
return HTMLResponse(_render_seal_html(seal), headers=_issuer_headers(store))
return HTMLResponse(
_render_seal_html(seal, demo=demo),
headers=_issuer_headers(store, demo=demo),
)

@app.post("/mcp", response_model=None)
async def mcp_endpoint(
Expand Down Expand Up @@ -200,12 +207,17 @@ def _require_bearer(store: ExecuteService, authorization: Optional[str]) -> None
raise HTTPException(status_code=401, detail="invalid bearer token")


def _issuer_headers(store: ExecuteService) -> dict[str, str]:
return {
def _issuer_headers(store: ExecuteService, *, demo: bool = False) -> dict[str, str]:
headers = {
"X-OpenAdapt-Issuer": "self_signed",
"X-OpenAdapt-Issuer-Fingerprint": store.fingerprint,
"X-OpenAdapt-Issuer-Fingerprint": (
store.demo_fingerprint if demo else store.fingerprint
),
"X-OpenAdapt-Production-Seal": "false",
}
if demo:
headers["X-OpenAdapt-Demo"] = "synthetic-demo-app"
return headers


async def _json_object(request: Request) -> dict[str, Any]:
Expand Down Expand Up @@ -325,14 +337,20 @@ def _call_mcp_tool(store: ExecuteService, name: str, arguments: dict[str, Any])
raise ExecuteServiceError(404, "unknown_tool", f"no MCP tool named {name!r}")


def _render_seal_html(seal: SelfSignedSealV1) -> str:
def _render_seal_html(seal: SelfSignedSealV1, *, demo: bool = False) -> str:
receipt = seal.receipt
outcome = html.escape(str(receipt.get("outcome", "")))
receipt_id = html.escape(str(receipt.get("receipt_id", "")))
execution_id = html.escape(str(receipt.get("execution_id", "")))
digest = html.escape(str(receipt.get("workflow_digest", "")))
fingerprint = html.escape(seal.issuer_key_fingerprint)
notice = html.escape(seal.notice)
demo_banner = (
'\n <div class="banner"><strong>Demo key.</strong> This run was on the '
"bundled synthetic demo app. It proves nothing about a real system.</div>"
if demo
else ""
)
return f"""<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -349,7 +367,7 @@ def _render_seal_html(seal: SelfSignedSealV1) -> str:
<body>
<div class="banner">
<strong>Self-signed.</strong> This is not an OpenAdapt production Seal.
</div>
</div>{demo_banner}
<h1>Local Execute receipt</h1>
<p>{notice}</p>
<dl>
Expand Down
17 changes: 13 additions & 4 deletions packages/flow/openadapt_flow/execute/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import hashlib
import json
from dataclasses import dataclass
from dataclasses import dataclass, replace
from pathlib import Path
from typing import Any, Callable, Optional

Expand Down Expand Up @@ -58,6 +58,9 @@ class DispatchResult:
compensation_effect_verified: bool
workflow_digest: str
evidence_digest: str
#: The run was on the worker's bundled demo app (a synthetic projection or
#: an in-process replay on MockMed). Its seal is signed with the demo key.
demo_app: bool = False


def default_runner(
Expand Down Expand Up @@ -103,7 +106,7 @@ def synthetic_runner(

strength = EffectStrengthV1(request.minimum_effect_strength)
if admission.break_it or _request_break_it(request):
return _result(
result = _result(
outcome=ExecuteTerminalOutcomeV1.RECONCILIATION_REQUIRED,
authorization_passed=True,
identity_passed=True,
Expand All @@ -115,7 +118,8 @@ def synthetic_runner(
workflow_digest=request.workflow_digest,
evidence_tag="synthetic-banner-lie",
)
return _result(
return replace(result, demo_app=True)
result = _result(
outcome=ExecuteTerminalOutcomeV1.VERIFIED,
authorization_passed=True,
identity_passed=True,
Expand All @@ -127,6 +131,7 @@ def synthetic_runner(
workflow_digest=request.workflow_digest,
evidence_tag="synthetic-verified",
)
return replace(result, demo_app=True)


def live_replay(
Expand Down Expand Up @@ -217,7 +222,11 @@ def live_replay(
except Exception as exc:
# The replay may have dispatched a write before it failed.
raise DispatchError(f"local replay failed: {exc}", pre_effect=False) from exc
return project_run_report(report, workflow_digest=request.workflow_digest)
# In process, the worker replays only on the demo app it serves itself.
return replace(
project_run_report(report, workflow_digest=request.workflow_digest),
demo_app=True,
)


def _surface_replay(
Expand Down
3 changes: 3 additions & 0 deletions packages/flow/openadapt_flow/execute/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
)

_KEY_NAME = "ed25519.pem"
#: Subdirectory of a worker's data dir that holds its demo key: the key that
#: signs results about the bundled synthetic demo app, never the worker's key.
DEMO_KEY_DIR = "demo"
_PUB_NAME = "ed25519.pub"


Expand Down
Loading
Loading