Skip to content

fix(receipts): sign synthetic-app runs and MockMed Execute/reward results with demo keys - #2832

Open
abrichr wants to merge 2 commits into
mainfrom
feat/synthetic-run-receipts
Open

abrichr wants to merge 2 commits into
mainfrom
feat/synthetic-run-receipts

Conversation

@abrichr

@abrichr abrichr commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Problem

openadapt-flow tutorial and replay --demo-app run on MockMed, a synthetic app. Their receipt.json was signed with this computer's Seal key, and it could say VERIFIED. A record/run/v1 receipt has no field that marks a run as synthetic, and a key's role comes from the receiver's registry. So anyone who pins this computer's key (for handoffs, say) would take a tutorial receipt as proof about a real system. (Found while closing the A2A handoff gaps in #2830.)

Fix (run receipts)

Runs on a synthetic app are signed with a separate demo key, kept under <seal home>/demo. It is never the Seal key and never a key from OPENADAPT_SEAL_KEY. This uses the demo role that every verifier already has, so there is no schema change:

  • A receiver that pins this computer 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". The handoff verdict adds "A demo key signed it: it checks only inside that demo".
  • A countersignature by the real key is refused (mixed_demo), so a demo receipt can't be upgraded.

write_receipt_record and receipt_after_run take synthetic=True. The tutorial passes it, and so does _finish_replay when --demo-app is set. synthetic=True together with an explicit signer is refused. The terminal note says "receipt (demo key, synthetic app; it proves nothing about a real system)".

I chose this over adding a signed "synthetic" field to record/run/v1 because it closes the hole with no change to the shared format, and it fails closed for every existing receiver.

Fix (Execute and reward workers)

serve-execute signed every seal with the worker's key, including the seeded synthetic MockMed projections. Those report VERIFIED at independent system-of-record strength. It also signed in-process web replays, which only ever drive the worker's bundled MockMed. A client that pinned /health's issuer_key_fingerprint would take those seals as proof about a real system.

  • Demo key. The worker now holds a demo key under <data dir>/demo.
  • When it signs. A seal is demo-signed when the admission is synthetic, or when the result has demo_app set; the synthetic runner and the in-process replay both set it. Fault seals after a synthetic admission are demo-signed too.
  • How a client tells.
    • /health adds demo_key_fingerprint.
    • Demo seals carry X-OpenAdapt-Demo: synthetic-demo-app, and the seal page shows a "Demo key" banner.
    • Replays through --config on another backend are unchanged and still signed with the worker's key.
  • Reward worker. serve-reward --seed-mockmed signed the synthetic contract's certificate and every reward receipt with the worker's data-dir key. Seeding now uses <data dir>/demo, and so does a worker that serves any seeded contract.

Tests. tests/test_execute_demo_key.py has 7 tests:

  • a seeded seal is refused by the pinned worker key and verifies with the demo key, and its page shows the banner;
  • the banner-lie seal is demo-signed;
  • a real admission is signed with the worker key;
  • an in-process demo replay is demo-signed;
  • a synthetic admission is demo-signed even when a custom runner forgets to say so;
  • a fault seal on a synthetic admission is demo-signed;
  • serve-reward --seed-mockmed signs with the demo key.

The existing MockMed seal test now expects the demo key, and the in-process replay test asserts demo_app. Negative control: with the service always signing with the worker key, 6 tests fail. All Execute, reward and JIT dispatch suites: 193 passed. ruff and mypy are clean.

Tests (run receipts)

  • New unit tests. tests/test_synthetic_receipts.py has 7 tests:
    • a synthetic run is signed by the demo key, not the Seal key;
    • this computer's pin refuses it, and a demo pin shows the demo verdict;
    • the handoff verdict says demo;
    • real runs are unchanged;
    • a configured OPENADAPT_SEAL_KEY never signs a synthetic run;
    • another signer is refused;
    • the demo key file is mode 0600;
    • a real-key countersignature is refused as mixed_demo.
  • Headless MockMed run. tests/test_tutorial_demo_app_replay.py runs tutorial and then replay --demo-app headless on MockMed, and asserts both receipts are demo-signed and refused by this computer's pin. Negative control: with the tutorial change undone, this test fails because the Seal key signed the receipt.
  • Regression suites. 15 receipt, seal, handoff, tutorial and quickstart suites: 290 passed and 3 skipped. One test failed once under load (test_cli_seal.py::test_a_qualified_bundle_seals_and_must_be_certified_again, a qualification frame check). It passed when run alone on this branch twice and on main twice, so I think it's a flake.
  • Lint. ruff and mypy are clean on the changed modules.

Not covered

…eal key

The tutorial and replay --demo-app run on MockMed, a synthetic app, but
their receipt.json was signed with this computer's Seal key and could
say VERIFIED. A record/run/v1 receipt has no field that marks a run as
synthetic, and the receiver's registry decides what a key means, so a
receiver that pins this computer would take it as proof about a real
system.

These runs are now signed with a separate demo key under
<seal home>/demo (never the Seal key or OPENADAPT_SEAL_KEY). Receivers
that pin this computer refuse them (unknown_signer), and pinning the
demo key with the existing demo role shows 'Demo key: checks only in
this demo'. A countersignature by the real key is refused as
mixed_demo. No schema change: the demo role already exists in every
verifier.

write_receipt_record and receipt_after_run take synthetic=True; the
tutorial and _finish_replay (when --demo-app) pass it. Passing another
signer with synthetic=True is refused.
serve-execute signed every seal with the worker's key, including seeded
synthetic MockMed projections (VERIFIED at independent system-of-record
strength) and in-process web replays, which only ever drive the
worker's bundled MockMed. A client pinning /health's
issuer_key_fingerprint would take those as proof about a real system.

The worker now holds a demo key under <data dir>/demo. A dispatch is
demo-signed when the admission is synthetic or the result says it ran
on the demo app (DispatchResult.demo_app, set by the synthetic runner
and the in-process replay); faults after a synthetic admission too.
/health adds demo_key_fingerprint; demo seals carry X-OpenAdapt-Demo
and a banner on the seal page.

serve-reward --seed-mockmed signed the synthetic contract's certificate
and every reward receipt with the worker's data-dir key. Seeding and a
worker serving a seeded contract now use <data dir>/demo.
@abrichr abrichr changed the title fix(receipts): sign synthetic-app runs with the demo key, never the Seal key fix(receipts): sign synthetic-app runs and MockMed Execute/reward results with demo keys Nov 30, 2026
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 961cdfb

The design is the right one: a receipt for a run on a synthetic app must not be signed with this computer's Seal key, or anyone who pins that key will treat a tutorial or MockMed result as proof about a real system. The unique work (against merge-base 8a4b1615) does that for the tutorial (receipt_after_run(..., synthetic=True)), replay --demo-app, the Execute worker's bundled demo app, and the seeded reward contracts, using a separately generated demo key under a demo/ directory. Combining a caller-supplied signer with synthetic=True is refused. Tests generate keys at runtime; I did not find committed key material.

This head is not mergeable: required CI is red, including gitleaks and the engine-generality lint, and the branch is well behind main.

Blockers

  1. Gitleaks failed on this commit with two generic-api-key findings, both in 961cdfb45:

    • packages/flow/openadapt_flow/execute/service.py:92 (self._demo_key = load_or_create_private_key(...))
    • packages/flow/openadapt_flow/reward/worker.py:333 (self._key = load_or_create_private_key(self.key_dir))
      Those lines load or create a key at runtime; I did not see a hardcoded secret there. Even so, the scan must be green. Please rephrase, allowlist only if the rule owners agree it is a false positive, or otherwise make the job pass without weakening the scanner.
  2. Flow core lint / engine generality failed because the engine now names a specific application:

    The engine names a specific application. ... A comment that only gives an example may carry '# example:'.
      openadapt_flow/__main__.py: 'mockmed' on line(s) 9563, 9599, 9607, 9622, 9637 (5 found, 3 in the baseline)
      openadapt_flow/execute/dispatch.py: 'mockmed' on line(s) 62 (1 found, 0 in the baseline)
      openadapt_flow/execute/service.py: 'mockmed' on line(s) 89 (1 found, 0 in the baseline)
      openadapt_flow/reward/worker.py: 'mockmed' on line(s) 330 (1 found, 0 in the baseline)
    

    Move app-specific wording into data or fixtures, or mark genuine example comments with # example:, then rerun the check.

  3. Unit, default-at-rest, smoke and launcher run-ci are also red at this head (including test_standalone_cli_constructor_inventory_also_disables_abbreviations on unit shard 2). The branch's merge-base is 8a4b1615 (#2802). Please rebase onto current main, fix whatever still fails on the merge, and re-request review at the new head.

Tests

In this worktree I ran tests/test_execute_demo_key.py, tests/test_synthetic_receipts.py and tests/test_tutorial_demo_app_replay.py: 10 passed, 2 skipped. Those are the new cases I could run in this slim environment; they do not replace a green packages run after rebase.

I am not merging. A release decision, if any, still sits with the maintainer after CI is green.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant